首页 > 编程知识 正文

linux命令,linux撤回上一步命令

时间:2023-05-06 05:06:58 阅读:208655 作者:1700

00. 目录

文章目录 00. 目录01. 命令概述02. 命令格式03. 常用选项04. 参考示例05. 附录

01. 命令概述

ncat命令有着网络界的瑞士军刀美誉。因为它短小精悍、功能实用,被设计为一个简单、可靠的网络工具

ncat的作用

(1)实现任意TCP/UDP端口的侦听,nc可以作为server以TCP或UDP方式侦听指定端口

(2)端口的扫描,nc可以作为client发起TCP或UDP连接

(3)机器之间传输文件

(4)机器之间网络测速

02. 命令格式 格式:ncat [选项] [参数] 03. 常用选项 -g<网关>:设置路由器跃程通信网关,最多设置8个;-G<指向器数目>:设置来源路由指向器,其数值为4的倍数;-h:在线帮助;-i<延迟秒数>:设置时间间隔,以便传送信息及扫描通信端口;-l:使用监听模式,监控传入的资料;-n:直接使用ip地址,而不通过域名服务器;-o<输出文件>:指定文件名称,把往来传输的数据以16进制字码倾倒成该文件保存;-p<通信端口>:设置本地主机使用的通信端口;-r:指定源端口和目的端口都进行随机的选择;-s<来源位址>:设置本地主机送出数据包的IP地址;-u:使用UDP传输协议;-v:显示指令执行过程;-w<超时秒数>:设置等待连线的时间;-z:使用0输入/输出模式,只在扫描通信端口时使用。 04. 参考示例

4.1 启动TCP服务端,端口为9999

[root@localhost ~]# ncat -l 9999

或者

[deng@localhost ~]$ ncat -v -lp 9999Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Listening on :::9999Ncat: Listening on 0.0.0.0:9999

4.2 启动TCP客户端连接服务端

[root@localhost ~]# ncat 172.16.0.51 10086

或者

[deng@localhost ~]$ nc -v 172.16.0.76 9999Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 172.16.0.76:9999.hello itcast

服务端 IP:172.16.0.76

端口号:10086

4.3 启动UDP服务端,端口9999

[deng@localhost ~]$ ncat -lu 9999

4.4 启动UDP客户端连接UDP服务端

[deng@localhost ~]$ ncat -u 172.16.0.51 10086hello world

UDP服务端IP:172.16.0.51

UDP服务端端口:10086

4.5 作为客户端工具进行端口探测

[deng@localhost ~]$ ncat -vzw 2 172.16.0.76 10086Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 172.16.0.76:10086.Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.[deng@localhost ~]$

或者

[deng@localhost ~]$ ncat -vz -w 2 172.16.0.76 10086Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 172.16.0.76:10086.Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.[deng@localhost ~]$

-v可视化,-z扫描时不发送数据,-w超时几秒,后面跟数字

4.6 扫描连续端口

服务端执行

[deng@localhost ~]$ ncat -l 10086 &[1] 77654[deng@localhost ~]$ ncat -l 10087 &[2] 77659[deng@localhost ~]$

客户端执行

[deng@localhost ~]$ ncat -vzw 2 172.16.0.76 10086-10087

4.7 使用ncat传输文件

服务端执行

[deng@localhost ~]$ ncat -l 1234 > txt[deng@localhost ~]$

客户端执行

[root@localhost ~]# ncat 172.16.0.76 1234 < /etc/passwd[root@localhost ~]#

4.8 设置本地端口连接服务端

[root@localhost ~]# ncat -p 1234 -w 5 172.16.0.76 8888hello world

4.9 模拟http协议首部

[root@localhost ~]# ncat www.baidu.com 80

4.10 扫描80端口

[root@localhost ~]# ncat -nv 172.16.0.76 80Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connection refused.[root@localhost ~]#

4.11 扫描UDP端口

[root@localhost ~]# ncat -u -z -w 2 172.16.0.76 1-1000[root@localhost ~]#

4.12 扫描TCP端口

[root@localhost ~]# ncat -z -w 2 172.16.0.76 1-1000 [root@localhost ~]#

4.13 传输目录

服务端

[root@localhost ~]# ncat -l 1234 | tar -xzvf -

客户端

[deng@localhost ~]$ tar -czvf - /etc | ncat 172.16.0.76 1234

4.14 执行shell命令

我们可以使用远程shell-使用telnet和ssh,但是如果这两个命令没有安装并且我们没有权限安装他们,我们也可以使用netcat创建远程shell。

ncat支持 -c -e 参数

服务端

[deng@localhost ~]$ ncat -v -c /qkdzt/bash -lp 9999Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Listening on :::9999Ncat: Listening on 0.0.0.0:9999Ncat: Connection from 172.16.0.76.Ncat: Connection from 172.16.0.76:22730.

客户端

[deng@localhost ~]$ ncat -v 172.16.0.76 9999Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 172.16.0.76:9999.ls

4.15 执行shell

如果ncat不支持-c 或者 -e 参数(openbsd ncat),我们仍然能够创建远程shell

服务端

[deng@localhost ~]$ mkfifo /tmp/fifo[deng@localhost ~]$ cat /tmp/fifo | /qkdzt/bash -i 2>&1 | nc -v -lp 9999 > /tmp/fifoNcat: Version 7.50 ( https://nmap.org/ncat )Ncat: Listening on :::9999Ncat: Listening on 0.0.0.0:9999Ncat: Connection from 172.16.0.76.Ncat: Connection from 172.16.0.76:22732.

这里我们创建了一个fifo文件,然后使用管道命令把这个fifo文件内容定向到shell 2>&1中。是用来重定向标准错误输出和标准输出,然后管道到ncat运行的端口9999上。至此,我们已经把ncat的输出重定向到fifo文件中。

说明:

从网络收到的输入写到fifo文件中

cat 命令读取fifo文件并且其内容发送给bash命令

bash命令进程受到输入并把它写回到ncat。

ncat通过网络发送输出到client

至于为什么会成功是因为管道使命令平行执行,fifo文件用来替代正常文件,因为fifo使读取等待而如果是一个普通文件,cat命令会尽快结束并开始读取空文件。

客户端

[deng@localhost ~]$ ncat 172.16.0.76 9999[deng@localhost ~]$ pwd pwd/home/deng[deng@localhost ~]$

4.16 反向shell

反向shell是指在客户端打开的shell。反向shell这样命名是因为不同于其他配置,这里服务器使用的是由客户提供的服务。

服务端

[deng@localhost ~]$ ncat -v -lp 9999Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Listening on :::9999Ncat: Listening on 0.0.0.0:9999Ncat: Connection from 172.16.0.76.Ncat: Connection from 172.16.0.76:22736.pwd/home/deng

客户端

[deng@localhost ~]$ ncat -v 172.16.0.76 9999 -c /qkdzt/bashNcat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 172.16.0.76:9999.

反向shell经常被用来绕过防火墙的限制,如阻止入站连接。

4.17 指定源端口

使用-p选项指定源端口。

服务端

[deng@localhost ~]$ ncat -v -lp 9998Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Listening on :::9998Ncat: Listening on 0.0.0.0:9998Ncat: Connection from 172.16.0.76.Ncat: Connection from 172.16.0.76:9999.

客户端

[deng@localhost ~]$ ncat -v 172.16.0.76 9998 -p 9999Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 172.16.0.76:9998.

4.18 指定源地址

假设你的机器有多个地址,希望明确指定使用哪个地址用于外部数据通讯。我们可以在ncat中使用-s选项指定ip地址

服务端

[deng@localhost ~]$ ncat -v -lp 9998Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Listening on :::9998Ncat: Listening on 0.0.0.0:9998Ncat: Connection from 172.16.0.76.Ncat: Connection from 172.16.0.76:15827.hello world

客户端

[deng@localhost ~]$ ncat -v 172.16.0.76 9998 -s 172.16.0.76Ncat: Version 7.50 ( https://nmap.org/ncat )Ncat: Connected to 172.16.0.76:9998.hello world 05. 附录

参考:【Linux】一步一步学Linux系列教程汇总

参考:https://www.jianshu.com/p/9c2d8b1f0c5a

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。