Friday, August 8, 2008

netcat useful examples

a. Transferring file between machines using client and server mode
server machine:
$ cat myfile | nc -l 9898

$client machine:
nc serverip 9898 > myfile

b. Port scanning
$ nc -z 192.168.0.1 80-90

c. Connecting a webserver
$ echo -e "GET http://www.google.com HTTP/1.0\n\n" | nc www.google.com 80

d. TCP proxy logging everything between server and client

$ mknod backpipe p
$ nc -l -p 80 0<backpipe | tee -a inflow | nc localhost 81 | tee -a outflow 1>backpipe

e. remote shell
$ nc -l -p 9898 -e /bin/bash

f. Chat application
my machine
$ netcat -l -p 9898

your machine
$ nc mymachine 9898

References:
http://www.stearns.org/doc/nc-intro.current.html
http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/

No comments: