Linux Netcat command - The swiss army knife of networking - MyLinuxBook

Linux Netcat NC Command

http://mylinuxbook.com/linux-netcat-command/

http://www.thegeekstuff.com/2012/04/nc-command-examples/

1. Port scanning

$nc -z -v -n 172.31.100.7 21-25

z option tell netcat to use zero IO .i.e the connection is closed as soon as it opens and no actual data exchange take place.

n option tell netcat not to use the DNS lookup for the address.



The netcat utility can be run in the server mode on a specified port listening for incoming connections.

$ nc -l 2389

Also, it can be used in client mode trying to connect on the port(2389) just opened

$ nc localhost 2389



Use Netcat to Transfer Files

we run the server as :

$ nc -l 2389 > test

and run the client as :

cat testfile | nc localhost 2389



Server

$nc -l 1567 < file.txt

Client

$nc -n 172.31.100.7 1567 > file.txt



Server

$nc -l 1567 > file.txt

Client

$nc 172.31.100.23 1567 < file.txt



4. Directory transfer

Server

$tar -cvf – dir_name | nc -l 1567

Client

$nc -n 172.31.100.7 1567 | tar -xvf



Server

$tar -cvf – dir_name| bzip2 -z | nc -l 1567

Compress the archive using the bzip2 utility.

Client

$nc -n 172.31.100.7 1567 | bzip2 -d |tar -xvf -



7. Cloning a device

Server

$dd if=/dev/sda | nc -l 1567

Client

$nc -n 172.31.100.7 1567 | dd of=/dev/sda

dd is a tool which reads the raw data from the disk



8. Opening a shell

Server

$nc -l 1567 -e /bin/bash -i

Client

$nc 172.31.100.7 1567



$nc 172.31.100.7 1567 -p 25

$nc -u 172.31.100.7 1567 -s 172.31.100.5 > file.txt



Netcat Supports Timeouts

nc -w 10 localhost 2389

The connection above would be terminated after 10 seconds.



Force Netcat Server to Stay Up

This behavior can be controlled by using the -k flag at the server side to force the server to stay up even after the client has disconnected.

$ nc -k -l 2389



from Google Plus RSS Feed for 101157854606139706613 http://mylinuxbook.com/linux-netcat-command

via LifeLong Community

No comments:

Post a Comment