Wednesday, February 8, 2012

netcat - File Transfer and Port Scanning

netcat command finds it's uses for
  • File Transfer
  • Port Scanning
File Transfer using netcat
  
Using netcat, the server can either send or retrieve data

Scenario 1 : Server sending the file to client 

# start the sending server
$ cat testfile | nc -l -p 13000

# start the retrieving client
$ nc <server> 13000 > testfile


Scenario 2 : Client sending the file to server
# start the retrieving server
$ nc -l -p 13000 > testfile

# start the sending client
$ cat testfile | nc <server> 13000


To monitor the progress of file transfer 


Using pv command we can monitor the progress of file transfer

# start sending server
$ cat test.iso | pv -b | nc -l  13000

# start receiving client
$ nc <server> 13000 | pv -b > test.iso
  11B 0:00:08 [1.32B/s ] [ <=> 


Transfer Compressed Data

# create an ISO image on the fly and compress the data stream
$ dd if=/dev/sr0 | gzip -9 | nc -l  13000

# retrieve and decompress the data stream at client side
$ nc <server> 13000 | gunzip | pv -b > testdvd.img


Port Scanning using netcat

# scan ports within the interval [20..80]
$ nc -v -z  <mywebsite.com> 21-80

# scan local ports [21..25], 80 and 8080
$ echo QUIT | nc -v -z localhost 21-25 80 8080
localhost [127.0.0.1] 25 (smtp) open
localhost [127.0.0.1] 22 (ssh) open
localhost [127.0.0.1] 80 (www) open

Good Reference:
http://injustfiveminutes.com/2013/11/19/netcat-cheat-sheet/



No comments:

Post a Comment