「Kali Linux網絡掃描祕籍系列」使用 Nmap 探索TCP

特此強調一下: 筆者在做實驗的時候,有一個問題大家特別要注意:(注:如果你的kali運行在虛擬機裡而且網卡是nat模式,三層的話測試就不準了,下面的主機ip實際上都是不存在的,但是如果kali,在橋接模式下橋接模式下是沒有問題的

「Kali Linux網絡掃描秘籍系列」使用 Nmap 探索TCP/IP的二層

網絡映射器(Nmap)是Kali Linux 中最有效和強大的工具之一。 Nmap 可以用於執行大範圍的多種掃描技術,並且可高度定製。 這個工具在整本書中會經常使用。 在這個特定的秘籍中,我們將討論如何使用Nmap 執行第2層掃描。

準備

要使用ARPing 執行ARP 發現,你需要在LAN 上至少擁有一個響應ARP 請求的系統。

操作步驟

Nmap 是使用單個命令執行自動化第二層發現掃描的另一個方案。 -sn 選項在Nmap 中稱為ping 掃描(-sn: Ping Scan - disable port scan)。 雖然術語“ping 掃描”自然會導致你認為正在執行第三層發現,但實際上是自適應的。 假設將同一本地子網上的地址指定為參數,可以使用以下命令執行第2層掃描:

root@kali:~# nmap 172.16.155.1 -sn

Starting Nmap 7.70 ( [url=https://nmap.org]https://nmap.org[/url] ) at 2018-05-29 03:41 EDT

Nmap scan report for 172.16.155.1

Host is up (0.00027s latency).

MAC Address: 00:50:56:C0:00:08 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds

此命令向LAN 廣播地址發送ARP 請求,並根據接收到的響應確定主機是否處於活動狀態。 或者,如果對不活動主機的IP 地址使用該命令,則響應會表示主機關閉:

root@kali:~# nmap 172.16.155.100 -sn

Starting Nmap 7.70 ( [url=https://nmap.org]https://nmap.org[/url] ) at 2018-05-29 03:42 EDT

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 0.48 seconds

我們可以修改此命令,來使用破折號符號對一系列順序IP 地址執行第2層發現。 要掃描完整的/ 24 範圍,可以使用0-255 :

root@kali:~# nmap 172.16.155.1-254 -sn

Starting Nmap 7.70 ( [url=https://nmap.org]https://nmap.org[/url] ) at 2018-05-29 03:43 EDT

Nmap scan report for 172.16.155.1

Host is up (0.00020s latency).

MAC Address: 00:50:56:C0:00:08 (VMware)

Nmap scan report for 172.16.155.2

Host is up (0.00044s latency).

MAC Address: 00:50:56:E4:E6:AF (VMware)

Nmap scan report for 172.16.155.254

Host is up (0.00017s latency).

MAC Address: 00:50:56:EE:88:3C (VMware)

Nmap scan report for 172.16.155.150

Host is up.

Nmap done: 254 IP addresses (4 hosts up) scanned in 2.76 seconds

使用此命令將向該範圍內的所有主機發送ARP 廣播請求,並確定每個主動響應的主機。 也可以使用-iL 選項對IP 地址的輸入列表執行此掃描:

root@kali:~# ls output.txt

output.txt

root@kali:~# cat output.txt

172.16.155.1

172.16.155.2

172.16.155.254

172.16.155.150

root@kali:~# nmap -iL output.txt -sn

Starting Nmap 7.70 ( [url=https://nmap.org]https://nmap.org[/url] ) at 2018-05-29 03:46 EDT

Nmap scan report for 172.16.155.1

Host is up (0.00045s latency).

MAC Address: 00:50:56:C0:00:08 (VMware)

Nmap scan report for 172.16.155.2

Host is up (0.00099s latency).

MAC Address: 00:50:56:E4:E6:AF (VMware)

Nmap scan report for 172.16.155.254

Host is up (0.014s latency).

MAC Address: 00:50:56:EE:88:3C (VMware)

Nmap scan report for 172.16.155.150

Host is up.

Nmap done: 4 IP addresses (4 hosts up) scanned in 0.30 seconds

當使用-sn 選項時,Nmap 將首先嚐試使用第2層ARP 請求定位主機,並且如果主機不位於LAN 上,它將僅使用第3層ICMP 請求。 注意對本地網絡(在172.16.155.0/24 專用範圍)上的主機執行的Nmap ping 掃描才能返回MAC 地址。 這是因為MAC 地址由來自主機的ARP 響應返回。 但是,如果對不同LAN 上的遠程主機執行相同的Nmap ping 掃描,則響應不會包括系統的MAC地址。 (注:三層的話測試就不準了,下面的主機ip實際上都是不存在的)

root@kali:~# nmap 172.16.1.1-254 -sn

Starting Nmap 7.70 ( [url=https://nmap.org]https://nmap.org[/url] ) at 2018-05-29 03:48 EDT

Nmap scan report for 172.16.1.1

Host is up (0.014s latency).

Nmap scan report for 172.16.1.2

Host is up (0.0045s latency).

Nmap scan report for 172.16.1.3

Host is up (0.015s latency).

Nmap scan report for 172.16.1.4

Host is up (0.015s latency).

Nmap scan report for 172.16.1.5

Host is up (0.016s latency).

Nmap scan report for ....

......

當對遠程網絡範圍(公共範圍172.16.1.0/24 )執行時,你可以看到,使用了第三層發現,因為沒有返回MAC 地址。 這表明,Nmap 會盡可能自動利用第二層發現的速度,但在必要時,它將使用可路由的ICMP 請求,在第三層上發現遠程主機(特別注意:這些ip實際上不存在,沒有reply的報文, 但是nmap還是把他們報告存活,所以nmap x.x.x.x -sn 不適合做跨三層的ip存活檢查)。

root@kali:~# tcpdump not tcp port 22 -n

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes

04:00:46.446852 IP 172.16.155.150 > 172.16.1.2: ICMP echo request, id 24535, seq 0, length 8

04:00:46.446966 IP 172.16.155.150 > 172.16.1.3: ICMP echo request, id 13971, seq 0, length 8

04:00:46.447021 IP 172.16.155.150 > 172.16.1.4: ICMP echo request, id 6749, seq 0, length 8

04:00:46.447137 IP 172.16.155.150 > 172.16.1.5: ICMP echo request, id 57289, seq 0, length 8

04:00:46.447218 IP 172.16.155.150 > 172.16.1.6: ICMP echo request, id 63355, seq 0, length 8

04:00:46.447276 IP 172.16.155.150 > 172.16.1.7: ICMP echo request, id 19443, seq 0, length 8

04:00:46.447502 IP 172.16.155.150 > 172.16.1.8: ICMP echo request, id 8520, seq 0, length 8

04:00:46.447781 IP 172.16.155.150 > 172.16.1.9: ICMP echo request, id 6980, seq 0, length 8

04:00:46.447860 IP 172.16.155.150 > 172.16.1.10: ICMP echo request, id 27215, seq 0, length 8

04:00:46.447937 IP 172.16.155.150 > 172.16.1.11: ICMP echo request, id 9896, seq 0, length 8

04:00:46.559346 ARP, Request who-has 172.16.155.2 tell 172.16.155.150, length 28

04:00:46.559608 ARP, Reply 172.16.155.2 is-at 00:50:56:e4:e6:af, length 46

04:00:47.449237 IP 172.16.155.150 > 172.16.1.14: ICMP echo request, id 44063, seq 0, length 8

04:00:47.449506 IP 172.16.155.150 > 172.16.1.15: ICMP echo request, id 24681, seq 0, length 8

04:00:47.449829 IP 172.16.155.150 > 172.16.1.16: ICMP echo request, id 19344, seq 0, length 8

04:00:47.451613 IP 172.16.155.150 > 172.16.1.17: ICMP echo request, id 46601, seq 0, length 8

如果你使用tcpdump 監控流量,而Nmap 對本地網絡上的主機執行ping 掃描。 在以下屏幕截圖中,你可以看到Nmap 利用ARP 請求來識別本地段範圍內的主機:

root@kali:~# tcpdump not tcp port 22 -n

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes

04:03:04.668788 ARP, Request who-has 172.16.155.2 tell 172.16.155.150, length 28

04:03:04.669356 ARP, Request who-has 172.16.155.3 tell 172.16.155.150, length 28

04:03:04.670004 ARP, Request who-has 172.16.155.4 tell 172.16.155.150, length 28

04:03:04.670256 ARP, Reply 172.16.155.2 is-at 00:50:56:e4:e6:af, length 46

04:03:04.670459 ARP, Request who-has 172.16.155.5 tell 172.16.155.150, length 28

04:03:04.671149 ARP, Request who-has 172.16.155.6 tell 172.16.155.150, length 28

04:03:04.671374 ARP, Request who-has 172.16.155.7 tell 172.16.155.150, length 28

04:03:04.671729 ARP, Request who-has 172.16.155.8 tell 172.16.155.150, length 28

04:03:04.672124 ARP, Request who-has 172.16.155.9 tell 172.16.155.150, length 28

工作原理

Nmap 已經高度功能化,需要很少甚至無需調整就可以運行所需的掃描。 底層的原理是一樣的。 Nmap 將ARP 請求發送到一系列IP 地址的廣播地址,並通過標記響應來識別活動主機。 但是,由於此功能已集成到Nmap 中,因此可以通過提供適當的參數來執行。

如果您對本文感興趣的,你還可以參考往期的文章連接如下:


分享到:


相關文章: