Linux--nc(netcat)

reference:

https://www.cnblogs.com/hxsyl/p/6118078.html

https://www.oschina.net/translate/linux-netcat-command

https://blog.csdn.net/qq_29499107/article/details/82384393 

 

nc functionality provided: can read and write data through the network and Tcp Udp. It is the work done to establish a connection between the two computers and returns two data streams, based on the function can have a lot of usage scenarios.

nc usage scenarios 1-- port scan

Open port on the machine used to discover

$ Nc -v -z -W 2 127.0.0.1 1-100
Connection to 127.0.0.1 22 port [tcp/ssh] succeeded!
Connection to 127.0.0.1 53 port [tcp/domain] succeeded!
Connection to 127.0.0.1 80 port [tcp/http] succeeded!
...
nc: connect to 127.0.0.1 port 100 (tcp) failed: Connection refused

This command prints developed port 1-100.

z parameter tells netcat use 0 IO, immediately closes the connection after a successful connection, data exchange is not performed (thanks @jxing pointers)

v parameter display execution

n Do not use the domain name parameter tells netcat reverse DNS lookup of IP addresses

Once open ports found, you can use the nc connection service to crawl banner. Banner is a connection to send your service to your text messages. When you try to identify the type and version of vulnerability or service time, Banner information is very useful. However, not all services will send banner.

nc -v 172.31.100.7 21

netcat command connection port 21 open and print banner is running on the port services.

nc file transfer application scenarios 2--

If a file transfer is only temporary, nc do not use ftp configuration trouble and so on.

First, at the receiving end 192.168.1.3: nc -l 1234> file.txt

Then on the transmitting side 192.168.1.2: nc 192.168.1.3 <file.txt

server    $nc -l 1567 < file.txt 

client     $nc -n 172.31.100.7 1567 > file.txt 

Here are created on a server A, and redirect input netcat as a file file.txt, if there are connections to the 1234 port, nc will send the contents of the document file.

In our client to redirect the output file.txt, when B is connected to A, A to send the file content, B content to save the file file.txt.

No need to create source files as Server, we can also use the opposite approach. We like the following to send the file from B to A, but created on the server A, this time we only need to redirect the output netcat and redirect input file B.

B as the Server

Server        $nc -l 1567 > file.txt 

Client          nc 172.31.100.23 1567 < file.txt 

Note: Run first receiving terminal, a designated port 1234, test.txt file, and then perform the transmission side, and the client must send the same name exists in the file test.txt

 

-l open listening mode, is used to specify nc will be in a listening mode. Usually such a service on behalf of the port waiting for clients to link specific.

-p <communications port> Set the communication port used by the local host. There may close

-k <communications port> nc forced standby link. When the client disconnects from the server, over a period of time the server will stop listening. But through -k option we can force the server to stay connected and continue to monitor port.

nc directory transport scenarios 3--

From server1 (192.168.16.233) to copy the contents of the directory nginx on server2 (192.168.48.47). Need to be on server2, nc activated by listening,

Run on server2: # nc -l 1234 | tar xzv-

Run on server1: # tar czv- nginx | ​​nc 192.168.48.47 1234 

nc scenarios 4-- session

On the Server (192.168.1.2):

$nc -l 1567

On the Client (192.168.1.3):

$nc 192.168.1.2 1567

 

Guess you like

Origin www.cnblogs.com/Jing-Wang/p/11030152.html