Nmap Development mailing list archives

Re: netcat missing example (is this even possible?)


From: David Burrows <snadge () gmail com>
Date: Wed, 2 Jun 2010 15:44:43 +1000

Hi (response below),

On Wed, Jun 2, 2010 at 9:43 AM, David Fifield <david () bamsoftware com> wrote:

On Wed, Jun 02, 2010 at 03:42:53AM +1000, David Burrows wrote:
Hello again!

Sorry to reply to my own post so soon, but it appears that I have found a
solution that could save someone the trouble of what I just went though.

(on server)
socat /dev/urandom TCP4-LISTEN:9999
(on client - substitute localhost for the servers ip if not localhost)
socat TCP4:localhost:9999 PTY,link=/dev/newrandom,raw,echo=0

The server socat command can be substituted with: ncat -l -k 9999 -c 'cat
/dev/urandom'
I'm not sure if there would be a netcat equivalent of the client
connection.
Now you can "dd bs=nnn count=1 /dev/newrandom of=/dev/null" and cat, etc
all
works as expected with the newly cloned device.

Ncat doesn't have code to create a pty. You could probably do it with a
fifo:

$ ncat -l -k 9999 --sh-exec "cat /dev/urandom"
$ mkfifo /dev/newrandom
$ ncat localhost 9999 > /dev/newrandom


Ok this works as expected, except when a test dd process closes the
/dev/newrandom fifo, the second ncat exits with the error "Broken pipe".
Unfortunately, using socat with a pty doesn't help either, as sometimes the
reads coming from the tcp socket, come in short, and then it writes the
short response straight to the pty.  eg, 512 byte reads come back usually as
512 bytes, but sometimes smaller.

So at this stage I either need to figure out the buffering issue I have with
socat, or find a way to make the second ncat command not exit with a "broken
pipe" error.



If you're replacing socat with Ncat on the server, you're doing it the
right way. This is the wrong way:

$ ncat -l -k 9999 < /dev/urandom

The reason that's wrong is that Ncat will accept multiple client
connections, and each one of them will receive the same random bytes.
There's some discussion about this in
http://nmap.org/ncat/guide/ncat-simple-services.html in the chargen
example.


This shouldn't be a problem for me, but that is good to know.  :)



David Fifield


Regards,

David B.
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: