多種Nmap Ping 掃描姿勢

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 CSTNmap scan report for 172.17.0.2Host 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 CSTNmap scan report for 172.17.0.2Host 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請求。

多種Nmap Ping 掃描姿勢

  • 通過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 DROPsudo iptables -I INPUT -p tcp --tcp-flags ALL ACK --dport 80 -j DROPsudo iptables -I INPUT -p tcp --tcp-flags ALL SYN --dport 443 -j DROP
  • 現在我們在來掃一下,看到並沒有檢測到有存活主機,這說明我們配置的防火牆成功攔截了Nmap的Ping掃描。

sudo nmap -sn 192.168.43.132 -disable-arp-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-06 23:46 CSTNote: Host seems down. If it is really up, but blocking our ping probes, try -PnNmap 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-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 20:11 CSTNmap 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 secondskali-team@Kali-Team:~$
  • 現在我使用TCP SYN數據包Ping掃描繞過防火牆的規則,因為我們使用了-PS參數,-PS默認在80端口發送TCP SYN數據包;我們還可以指定端口,比如-PS443(指定443)端口。看下面的圖就比較清楚了。

多種Nmap Ping 掃描姿勢

過濾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-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:01 CSTNote: Host seems down. If it is really up, but blocking our ping probes, try -PnNmap done: 1 IP address (0 hosts up) scanned in 2.09 secondskali-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-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:06 CSTNmap scan report for 192.168.43.132Host 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 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

- 現在有發現可以檢測到主機在線了。在上面的圖片中你可以看到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-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:18 CSTNote: Host seems down. If it is really up, but blocking our ping probes, try -PnNmap done: 1 IP address (0 hosts up) scanned in 2.10 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

- 然後上次的方法又不行了是吧,然而目標主機並不鳥我,請忽視第三個ssh協議的,那是我ssh登錄上執行命令的。

使用ICMP迴環繞過TCP ACK Ping

sudo nmap -sP -PE 192.168.43.132 -disable-arp-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:25 CSTNmap scan report for 192.168.43.132Host 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 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

- 我們要用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-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:42 CSTNote: Host seems down. If it is really up, but blocking our ping probes, try -PnNmap done: 1 IP address (0 hosts up) scanned in 2.09 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

- 目標也沒有回應,攔截成功。

使用ICMP時間戳Ping繞過ICMP迴環

sudo nmap -sP -PP 192.168.43.132 -disable-arp-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:46 CSTNmap scan report for 192.168.43.132Host 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 secondskali-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-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 21:59 CSTNote: Host seems down. If it is really up, but blocking our ping probes, try -PnNmap done: 1 IP address (0 hosts up) scanned in 2.10 secondskali-team@Kali-Team:~$
  • 看,又發現不了主機了,攔截也起作用了。

  • 注意:這會把你的ssh斷開,不讓你連接。可以輸入下面命令清空防火牆規則。

sudo iptables -F

使用UDP繞ICMP掃描

  • 上面我們已經學了很多種檢測主機是否存活的方法了,就上一個防火牆的配置已經把ICMP掃描攔截了,或者把TCP的數據包攔截了,這樣我們就很難知道主機是否存活。到這裡我們來學習另一種方式:UDP掃描,所以我們要用-PU參數。

sudo nmap -sP -PU 192.168.43.132 -disable-arp-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:11 CSTNmap scan report for 192.168.43.132Host 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 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

- 看到目標回覆Destination unreachable (Port unreachable)沒,這就表示主機還活著。

再再把UDP攔截了

sudo iptables -I INPUT -p ICMP -j DROPsudo iptables -I INPUT -p tcp --tcp-flags ALL ACK --dport 80 -j DROPsudo iptables -I INPUT -p tcp --tcp-flags ALL SYN --dport 443 -j DROPsudo iptables -I INPUT -p udp -j DROP
  • 配置好上面的就反人類了。UDP掃描沒發現主機存活。

sudo nmap -sP -PU 192.168.43.132 -disable-arp-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:22 CSTNote: Host seems down. If it is really up, but blocking our ping probes, try -PnNmap done: 1 IP address (0 hosts up) scanned in 2.10 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

利用協議繞過UDP和Ping

sudo nmap -sP -PO 192.168.43.132 -disable-arp-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:25 CSTNmap scan report for 192.168.43.132Host 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 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

- 在ICMP TCP和UDP都被攔截時,我們可以用-PO參數發送有IP頭中特定協議號的IP數據包,如果沒有指定協議,則發送多個用於ICMP,IGMP和IP-in-IP協議。

- 在上面抓包可以看出來:

1.發送ICMP Echo到目標主機

2.向目標發送IGMP查詢

3.發送IPv4到目標主機

4.收到ICMP Destination unreachable (Port unreachable) 最後一個禁止IP協議掃描

sudo iptables -I INPUT -p ICMP -j DROPsudo iptables -I INPUT -p tcp --tcp-flags ALL ACK --dport 80 -j DROPsudo iptables -I INPUT -p tcp --tcp-flags ALL SYN --dport 443 -j DROPsudo iptables -I INPUT -p udp -j DROPsudo iptables -I INPUT -p IP -j DROP
  • 就是在上一個加上攔截IP協議的就可以了。基本可以攔截很多方式的掃描了。

多種Nmap Ping 掃描姿勢

  • 這個更反人類是吧,那怎麼繞呢?

使用NO Ping繞過IP協議

  • 當Ping掃描被攔截就用-PN參數,不用Ping掃描啊,這種方法可以判斷主機的狀態時up還是down。

sudo nmap -sP -PN 192.168.43.132 -disable-arp-pingStarting Nmap 7.01 ( https://nmap.org ) at 2018-03-07 22:41 CSTNmap scan report for 192.168.43.132Host is up.Nmap done: 1 IP address (1 host up) scanned in 0.04 secondskali-team@Kali-Team:~$

多種Nmap Ping 掃描姿勢

- 發現啥都沒有,但是可以看到主機的狀態時up的,完了!!!

0x03 後續

  • 寫了足足兩天,其中docker裡的iptables報錯問題沒解決,後面搭建了一臺32位的Ubuntu,湊合用了。

  • Nmap神器不解釋,希望能幫到大家,如果哪裡講的不對的話歡迎指正。

多種Nmap Ping 掃描姿勢


分享到:


相關文章: