Nmap Ping 扫描(防火墙 Bypass)

0x00 前言
- 在本文中,我们将使用不同的Nmap Ping扫描来扫描发现目标主机。
- 一个系统管理员可能只会使用Ping来检测某个主机是否存活,但一个安全人员可能会使用各种方法绕过防火墙进行检测。
- 在Namp中使用Ping扫描来检测主机是否存活。我们知道在默认情况下,Ping发送ICMP回应请求,并在系统处于活动状态时获取ICMP响应回复。默认情况下,Ping扫描发送一个ARP数据包来获取主机是否存活。
- Nmap会根据它扫描的网络来改变它的扫描方式。
1.如果扫描的时本地网络,Nmap在每次扫描时发送ARP数据包
2.如果是扫描外网就发送以下请求数据包:
- ICMP回应请求
- ICMP时间戳请求
- TCP SYN到端口443
- TCP ACK到端口80
- 在本文,我们使用-disable-arp-ping属性来更改Nmap的扫描行为,将本地网络当作外网。
0x01 开始
- 为了在不使用ARP请求数据包的情况下识别存活主机,Nmap使用称扫描的-sP选项。我们可以使用-sn标志,这意味没有端口扫描也称为Ping扫描。
- 我的IP:172.17.0.1【Ubuntu】
- 目标IP:172.17.0.2 【Ubuntu】- docker
> sudo nmap -sP 172.17.0.2 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-06 16:58 CST
Nmap scan report for 172.17.0.2
Host is up (0.00013s latency).
MAC Address: 02:42:AC:11:00:02 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.31 seconds
或者
sudo nmap -sn 172.17.0.2 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-06 16:59 CST
Nmap scan report for 172.17.0.2
Host is up (0.000096s latency).
MAC Address: 02:42:AC:11:00:02 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.29 seconds
- 从上面可以看到它发现有一台主机存活。再看下面的图片,由于我使用了参数--disable-arp-ping禁用了本地网络扫描的ARP请求数据包,所以这里并没有看到ARP请求。
- 通过wireshark可以看到这连个网络之间的请求和响应
- ICMP回应请求
- ICMP回应回复
- TCP SYN到端口443
- TCP RST,ACK到端口443
- TCP ACK到端口80
- TCP RST到端口80
- ICMP时间戳请求
- ICMP时间戳答复
防Ping扫描
- 现在我在docker中用IPTABLES设置防火墙规则来拦截刚刚看到的ICMP数据包和443端口上的TCP SYN数据包还有80端口上的TCP ACK数据包,就应该可以防Ping扫描来了。
出了点状况
docker的iptables出了问题
- 现在我的IP改为:192.168.43.236
- 目标IP改为:192.168.43.132 (虚拟机)
- 好,我们接着上面在目标主机设置防火墙:
sudo iptables -I INPUT -p ICMP -j DROP
sudo iptables -I INPUT -p tcp --tcp-flags ALL ACK --dport 80 -j DROP
sudo iptables -I INPUT -p tcp --tcp-flags ALL SYN --dport 443 -j DROP
- 现在我们在来扫一下,看到并没有检测到有存活主机,这说明我们配置的防火墙成功拦截了Nmap的Ping扫描。
sudo nmap -sn 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-06 23:46 CST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.08 seconds
使用TCP SYN Ping绕过防火墙
- 下面的就可以发现存活主机了哦。
sudo nmap -sP -PS 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 20:11 CST
Nmap scan report for ubuntu (192.168.43.132)
Host is up (0.00062s latency).
MAC Address: 08:00:27:7D:2A:31 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 0.31 seconds
kali-team@Kali-Team:~$
- 现在我使用TCP SYN数据包Ping扫描绕过防火墙的规则,因为我们使用了-PS参数,-PS默认在80端口发送TCP SYN数据包;我们还可以指定端口,比如-PS443(指定443)端口。看下面的图就比较清楚了。
过滤TCP SYN Ping扫描
- 升级一下,绕过管理员把TCP SYN数据包里的SYN数据包都过滤了怎么办?
sudo iptables -I INPUT -p tcp --tcp-flags ALL SYN -j DROP
- 现在Nmap有扫描不到主机是否存活了
sudo nmap -sP -PS 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:01 CST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 2.09 seconds
kali-team@Kali-Team:~$
使用TCP ACK Ping绕过TCP SYN Ping
- 为了绕过它,我们使用TCP ACK数据包的Ping扫描,所有要使用-PA参数来在80端口发送TCP ACK数据包,和上面一样也可以指定端口。
sudo nmap -sP -PA 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:06 CST
Nmap scan report for 192.168.43.132
Host is up (0.00082s latency).
MAC Address: 08:00:27:7D:2A:31 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 0.36 seconds
kali-team@Kali-Team:~$
- 现在有发现可以检测到主机在线了。在上面的图片中你可以看到ACK数据包发送到80端口。目标以RST数据包回复。
再拦截上面的TCP ACK Ping扫描
- 这次把防火墙设置成TCP连接中的ACK数据包都拦截掉。
sudo iptables -I INPUT -p tcp --tcp-flags ALL ACK -j DROP
- 设置好了,试试效果
sudo nmap -sP -PA 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:18 CST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 2.10 seconds
kali-team@Kali-Team:~$
- 然后上次的方法又不行了是吧,然而目标主机并不鸟我,请忽视第三个ssh协议的,那是我ssh登录上执行命令的。
使用ICMP回环绕过TCP ACK Ping
sudo nmap -sP -PE 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:25 CST
Nmap scan report for 192.168.43.132
Host is up (0.00081s latency).
MAC Address: 08:00:27:7D:2A:31 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 0.49 seconds
kali-team@Kali-Team:~$
- 我们要用Ping扫描ICMP数据包来绕过刚刚的规则,所以我们要使用-PE参数发送ICMP回环数据包。
再拦截上面的ICMP回环
sudo iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -j DROP
- 设置好了,试试效果
sudo nmap -sP -PE 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:42 CST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 2.09 seconds
kali-team@Kali-Team:~$
- 目标也没有回应,拦截成功。
使用ICMP时间戳Ping绕过ICMP回环
sudo nmap -sP -PP 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:46 CST
Nmap scan report for 192.168.43.132
Host is up (0.00087s latency).
MAC Address: 08:00:27:7D:2A:31 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 0.35 seconds
kali-team@Kali-Team:~$
- 我们使用Ping扫描和ICMP数据包来绕,所以我们要使用-PP参数来发送ICMP时间戳数据包。
我再拦截所有ICMP扫描
sudo iptables -I INPUT -p ICMP -j DROP
- 设置好了,试试效果
sudo nmap -sP -PP 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:59 CST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 2.10 seconds
kali-team@Kali-Team:~$
- 看,又发现不了主机了,拦截也起作用了。
- 注意:这会把你的ssh断开,不让你连接。可以输入下面命令清空防火墙规则。
sudo iptables -F
使用UDP绕ICMP扫描
- 上面我们已经学了很多种检测主机是否存活的方法了,就上一个防火墙的配置已经把ICMP扫描拦截了,或者把TCP的数据包拦截了,这样我们就很难知道主机是否存活。到这里我们来学习另一种方式:UDP扫描,所以我们要用-PU参数。
sudo nmap -sP -PU 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:11 CST
Nmap scan report for 192.168.43.132
Host is up (0.00086s latency).
MAC Address: 08:00:27:7D:2A:31 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 0.35 seconds
kali-team@Kali-Team:~$
- 看到目标回复Destination unreachable (Port unreachable)
没,这就表示主机还活着。
再再把UDP拦截了
sudo iptables -I INPUT -p ICMP -j DROP
sudo iptables -I INPUT -p tcp --tcp-flags ALL ACK --dport 80 -j DROP
sudo iptables -I INPUT -p tcp --tcp-flags ALL SYN --dport 443 -j DROP
sudo iptables -I INPUT -p udp -j DROP
- 配置好上面的就反人类了。UDP扫描没发现主机存活。
sudo nmap -sP -PU 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:22 CST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 2.10 seconds
kali-team@Kali-Team:~$
利用协议绕过UDP和Ping
sudo nmap -sP -PO 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:25 CST
Nmap scan report for 192.168.43.132
Host is up (0.00078s latency).
MAC Address: 08:00:27:7D:2A:31 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 0.35 seconds
kali-team@Kali-Team:~$
- 在ICMP TCP和UDP都被拦截时,我们可以用-PO参数发送有IP头中特定协议号的IP数据包,如果没有指定协议,则发送多个用于ICMP,IGMP和IP-in-IP协议。
- 在上面抓包可以看出来:
1.发送ICMP Echo到目标主机
2.向目标发送IGMP查询
3.发送IPv4到目标主机
4.收到ICMPDestination unreachable (Port unreachable)
最后一个禁止IP协议扫描
sudo iptables -I INPUT -p ICMP -j DROP
sudo iptables -I INPUT -p tcp --tcp-flags ALL ACK --dport 80 -j DROP
sudo iptables -I INPUT -p tcp --tcp-flags ALL SYN --dport 443 -j DROP
sudo iptables -I INPUT -p udp -j DROP
sudo iptables -I INPUT -p IP -j DROP
- 就是在上一个加上拦截IP协议的就可以了。基本可以拦截很多方式的扫描了。
- 这个更反人类是吧,那怎么绕呢?
使用NO Ping绕过IP协议
- 当Ping扫描被拦截就用-PN参数,不用Ping扫描啊,这种方法可以判断主机的状态时up还是down。
sudo nmap -sP -PN 192.168.43.132 -disable-arp-ping
Starting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:41 CST
Nmap scan report for 192.168.43.132
Host is up.
Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
kali-team@Kali-Team:~$
- 发现啥都没有,但是可以看到主机的状态时up的,完了!!!
0x03 后续
- 写了足足两天,其中docker里的iptables报错问题没解决,后面搭建了一台32位的Ubuntu,凑合用了。
- Nmap神器不解释,希望能帮到大家,如果哪里讲的不对的话欢迎指正。