当前位置:网站首页>ncat详细介绍(转载)
ncat详细介绍(转载)
2022-06-30 20:35:00 【xupeng1644】
ncat简介
ncat即Netcat。Netcat用于从TCP/UDP连接中读取或发送网络数据。cat是Linux中查看或连接文件的命令,所以netcat本意为从网络上查看文件内容。而Netcat的作者Hobbit为它添加了非常丰富的功能,使它几乎能够完成网络操作中各式各样的操作,所以Netcat在网络安全领域被称作“TCPIP的瑞士军刀”(“Swiss-army knife forTCP/IP”)。
Netcat稳定版1.10由Hobbit在1996年3月发布(开源软件),之后作者没有再对其进行维护,但该工具十多年来依然在被广泛地使用,而且基于Netcat的各种衍生工具也层出不穷,他们在很多方面增强或扩展了Netcat的功能。
Nmap团队开发了Ncat作为Netcat的升级版本,增加了更多的功能(如ssl加密、代理连接通过socks4 获取http),让其更能适应现代网络环境的需求。
安装
yum install -y nmap-ncat
安装完后可以通过nc或者ncat来使用。
参数说明
命令格式:
ncat [options] [hostname] [port]
1
-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
使用场景
1 监听入站连接
通过 -l 选项,ncat 可以进入监听模式,使我们可以在指定端口监听入站连接。
ncat -l port_number
2 连接远程系统
使用下面命令可以用 nc 来连接远程系统,类似于telnet ip port ,建立一个与服务器的连接。可以发送命令
ncat IP_address port_number
3 连接 UDP 端口
默认情况下,nc 创建连接时只会连接 TCP 端口。 不过我们可以使用 -u 选项来连接到 UDP 端口
ncat -l -u 1234
假设我们想发送或者说测试某个远程主机 UDP 端口的连通性,我们可以使用下面命令
ncat -v -u {
host-ip} {
udp-port}
比如
ncat -v -u 192.168.105.150 53
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 192.168.105.150:53
4 将 nc 作为聊天工具
nc 也可以作为聊天工具来用,我们可以配置服务器监听某个端口,然后从远程主机上连接到服务器的这个端口,就可以开始发送消息了。 在服务器这端运行:
ncat -l 8080
在远程客户端主机上运行:
ncat 192.168.1.100 8080
之后开始发送消息,这些消息会在服务器终端上显示出来。
5 将 nc 作为代理
nc 也可以用来做代理。比如下面这个例子
ncat -l 8080 | ncat 192.168.1.200 80
所有发往我们服务器 8080 端口的连接都会自动转发到 192.168.1.200 上的 80 端口。 不过由于我们使用了管道,数据只能被单向传输。 要同时能够接受返回的数据,我们需要创建一个双向管道。 使用下面命令可以做到这点
mkfifo 2way
ncat -l 8080 0<2way | ncat 192.168.1.200 80 1>2way
现在你可以通过 nc 代理来收发数据了
5 使用 nc 拷贝文件
nc 还能用来在系统间拷贝文件,虽然这么做并不推荐,因为绝大多数系统默认都安装了 ssh/scp。 不过如果你恰好遇见个没有 ssh/scp 的系统的话, 你可以用 nc 来作最后的努力。
在要接受数据的机器上启动 nc 并让它进入监听模式:
ncat -l 8080 > file.txt
现在去要被拷贝数据的机器上运行下面命令:
ncat 192.168.1.100 8080 --send-only < data.txt
这里,data.txt 是要发送的文件。 -–send-only 选项会在文件拷贝完后立即关闭连接。 如果不加该选项, 我们需要手工按下 ctrl+c 来关闭连接。
我们也可以用这种方法拷贝整个磁盘分区,不过请一定要小心
6 通过 nc 创建后门
nc 命令还可以用来在系统中创建后门,并且这种技术也确实被黑客大量使用。 为了保护我们的系统,我们需要知道它是怎么做的。 创建后门的命令为:
ncat -l 10000 -e /bin/bash
-e 标志将一个 bash 与端口 10000 相连。现在客户端只要连接到服务器上的 10000 端口就能通过 bash 获取我们系统的完整访问权限:
ncat 192.168.1.100 10000
7 通过 nc 进行端口转发
我们通过选项 -c 来用 nc 进行端口转发,实现端口转发的语法为:
ncat -u -l 80 -c 'ncat -u -l 8080'
这样,所有连接到 80 端口的连接都会转发到 8080 端口
8 设置连接超时
nc 的监听模式会一直运行,直到手工终止。 不过我们可以通过选项 -w 设置超时时间:
ncat -w 10 192.168.1.100 8080
这会导致连接 10 秒后终止,不过这个选项只能用于客户端而不是服务端。
9 使用 -k 选项强制 nc 待命
当客户端从服务端断开连接后,过一段时间服务端也会停止监听。 但通过选项 -k 我们可以强制服务器保持连接并继续监听端口。 命令如下:
ncat -l -k 8080
现在即使来自客户端的连接断了也依然会处于待命状态
边栏推荐
- Is it safe to open an account for online stock trading!?
- No "history of blood and tears" in home office | community essay solicitation
- Implementation principle of PostgreSQL heap table storage engine
- Lambda expression principle analysis and learning (June 23, 2022)
- What are database OLAP and OLTP? Same and different? Applicable scenarios
- 毕业设计
- What bank card do you need to open an account online? In addition, is it safe to open an account online now?
- Basic concepts of tree
- Web host iptables firewall security script
- PHP require/include 区别
猜你喜欢
![[1175. prime number arrangement]](/img/f2/d427db03da151786ea1dfb7a76328a.png)
[1175. prime number arrangement]

1. Introduction to generating countermeasures network

Binary search tree (1) - concept and C language implementation

Lumiprobe cell biology - dia, instructions for lipophilic tracer

Testing principle and precautions of biovendor rage ELISA Kit

centos——开启/关闭oracle

Lumiprobe biotin phosphimide (hydroxyproline) instructions

Study on lumiprobe dye NHS ester BDP FL NHS ester

Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing

Lumiprobe 聚乙二醇化和 PEG 接头丨碘-PEG3-酸研究
随机推荐
PM reports work like this, and the boss is willing to give you a raise
第81场双周赛
Dynamic style binding --style and class
Lumiprobe protein quantitation - qudye Protein Quantitation Kit
请问海量数据如何去取最大的K个
PHP obtains opcode and C source code
AVL balanced binary tree (I) - concept and C language implementation
基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享
第299场
Installation and use of securecrtportable
NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer
哈夫曼樹(一)基本概念與C語言實現
翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]
Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒
Black apple server system installation tutorial, black apple installation tutorial, teach you how to install black apple in detail [easy to understand]
PHP获取Opcode及C源码
Jerry's determination of detection sensitivity level [chapter]
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
Go 语言标识符、包名规范
Informatics Olympiad 1362: family problems