偵察的第一步是確定系統上的開放埠。Nmap被廣泛認為是無可爭議的埠掃描之王,但某些情況需要不同的工具。Metasploit可以直接從框架內部進行埠掃描,我們將向您展示三種類型的埠掃描:TCP,SYN和XMAS。
什麼是埠掃描?
埠掃描是探測一系列埠以確定這些埠狀態的過程 - 通常是打開或關閉的。主機上有65,536個可用埠,前1,024個埠保留用於眾所周知的服務。埠可以使用TCP協議,UDP或兩者進行通信。
我們將介紹的第一種掃描類型是TCP掃描,也稱為TCP連接。這種類型的掃描利用系統調用來建立連接,就像Web瀏覽器或其他網絡應用程式一樣。當埠打開時,TCP掃描將啟動並完成完整的三次握手,然後關閉連接。此類掃描有效,但噪聲很大,因為可以記錄IP位址。
第二種類型的掃描是SYN掃描。這是默認的Nmap掃描,被認為是最流行的埠掃描類型。與TCP連接掃描相反,SYN掃描使用原始數據包連接到埠而不是系統調用。這是有利的,因為連接永遠不會完全完成,使其相對隱蔽並且更有可能逃避防火牆。由於可以訪問原始網絡,因此還可以更好地控制請求和響應。
我們將要進行的第三種掃描是XMAS掃描。此掃描設置數據包上的FIN,PSH和URG標誌,據說它像聖誕樹一樣點亮它(因此得名)。雖然現代入侵檢測系統仍然可以檢測到它們,但XMAS掃描甚至可以比SYN掃描更隱蔽。無論如何,如果其他掃描方法失敗,值得嘗試。
選項1
TCP掃描
在進行任何掃描之前我們需要做的第一件事是通過在終端中鍵入msfconsole來啟動Metasploit 。將顯示隨機橫幅,以及版本信息和當前加載的模塊數。
msfconsole, , / \ ((__---,,,---__)) (_) O O (_)_________ \ _ / |\ o_o \ M S F | \ \ _____ | * ||| WW||| ||| ||| =[ metasploit v4.17.8-dev ]+ -- --=[ 1803 exploits - 1027 auxiliary - 311 post ]+ -- --=[ 538 payloads - 41 encoders - 10 nops ]+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]msf >掃描儀是Metasploit 中的一種輔助模塊,為了找到埠掃描儀,我們可以在提示符下鍵入搜索埠掃描。
msf > search portscan[!] Module database cache not built yet, using slow searchMatching Modules================ Name Disclosure Date Rank Description ---- --------------- ---- ----------- auxiliary/scanner/http/wordpress_pingback_access normal Wordpress Pingback Locator auxiliary/scanner/natpmp/natpmp_portscan normal NAT-PMP External Port Scanner auxiliary/scanner/portscan/ack normal TCP ACK Firewall Scanner auxiliary/scanner/portscan/ftpbounce normal FTP Bounce Port Scanner auxiliary/scanner/portscan/syn normal TCP SYN Port Scanner auxiliary/scanner/portscan/tcp normal TCP Port Scanner auxiliary/scanner/portscan/xmas normal TCP "XMas" Port Scanner auxiliary/scanner/sap/sap_router_portscanner normal SAPRouter Port Scanner這會返回一些結果,包括我們將要查看的三種類型的埠掃描。讓我們從簡單的TCP掃描開始。鍵入use auxiliary / scanner / portscan / tcp以加載模塊。我們現在可以通過鍵入選項來查看模塊設置:
msf auxiliary(scanner/portscan/tcp) > optionsModule options (auxiliary/scanner/portscan/tcp): Name Current Setting Required Description ---- --------------- -------- ----------- CONCURRENCY 10 yes The number of concurrent ports to check per host DELAY 0 yes The delay between connections, per thread, in milliseconds JITTER 0 yes The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds. PORTS 1-10000 yes Ports to scan (e.g. 22-25,80,110-900) RHOSTS yes The target address range or CIDR identifier THREADS 1 yes The number of concurrent threads TIMEOUT 1000 yes The socket connect timeout in milliseconds在這裡,我們可以進行當前設置及其說明。與許多漏洞利用模塊不同,此掃描器除了可以使用單個IP位址外,還可以使用一系列目標地址。在這種情況下,由於我們只有一臺目標機器,因此只需一個地址。
還可以增加線程數以幫助掃描更快地運行。對於Unix系統,建議將此值保持在256以下,對於本機Win32系統,建議保持在16以下。為了安全起見,我們可以將其設置為類似8.所有其他選項現在可以保留為默認選項。
msf auxiliary(scanner/portscan/tcp) > set rhosts 172.16.1.102rhosts => 172.16.1.102msf auxiliary(scanner/portscan/tcp) > set threads 8threads => 8現在我們準備開始掃描了。在Metasploit中,run命令只是exploit的別名,所以它會做同樣的事情。鑑於我們只進行掃描,運行似乎更合適,儘管它確實無關緊要。
msf auxiliary(scanner/portscan/tcp) > run[+] 172.16.1.102: - 172.16.1.102:21 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:23 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:22 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:25 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:53 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:80 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:111 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:139 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:445 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:513 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:514 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:512 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:1099 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:1524 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:2049 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:2121 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:3306 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:3632 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:5432 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:5900 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:6000 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:6667 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:6697 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:8009 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:8180 - TCP OPEN[+] 172.16.1.102: - 172.16.1.102:8787 - TCP OPEN[*] Scanned 1 of 1 hosts (100% complete)[*] Auxiliary module execution completedTCP掃描運行得非常快,一旦完成,我們就可以看到目標上有許多開放埠。
選項2
SYN掃描
接下來,我們將繼續進行SYN掃描。鍵入返回以返回主提示符,然後使用auxiliary / scanner / portscan / syn加載模塊。同樣,我們可以鍵入選項以查看此模塊的當前設置:
msf auxiliary(scanner/portscan/syn) > optionsModule options (auxiliary/scanner/portscan/syn): Name Current Setting Required Description ---- --------------- -------- ----------- BATCHSIZE 256 yes The number of hosts to scan per set DELAY 0 yes The delay between connections, per thread, in milliseconds INTERFACE no The name of the interface JITTER 0 yes The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds. PORTS 1-10000 yes Ports to scan (e.g. 22-25,80,110-900) RHOSTS yes The target address range or CIDR identifier SNAPLEN 65535 yes The number of bytes to capture THREADS 1 yes The number of concurrent threads TIMEOUT 500 yes The reply read timeout in milliseconds與TCP掃描相比,這裡有一些不同的選項,但在大多數情況下,它非常相似,包括接受一系列目標地址和要設置的線程數的選項。
在單個目標上執行多次掃描或攻擊時,可能會一次又一次地設置相同的選項。幸運的是,有一個命令可以在全局設置一個選項,這意味著在使用不同的模塊時不必重新輸入。使用setg設置全局選項。
msf auxiliary(scanner/portscan/syn) > setg rhosts 172.16.1.102rhosts => 172.16.1.102msf auxiliary(scanner/portscan/syn) > setg threads 8threads => 8現在,鍵入run以開始掃描。
msf auxiliary(scanner/portscan/syn) > run[+] TCP OPEN 172.16.1.102:21[+] TCP OPEN 172.16.1.102:22[+] TCP OPEN 172.16.1.102:23[+] TCP OPEN 172.16.1.102:25[+] TCP OPEN 172.16.1.102:53[+] TCP OPEN 172.16.1.102:80[+] TCP OPEN 172.16.1.102:111[+] TCP OPEN 172.16.1.102:139[+] TCP OPEN 172.16.1.102:445[+] TCP OPEN 172.16.1.102:512[+] TCP OPEN 172.16.1.102:513[+] TCP OPEN 172.16.1.102:514[+] TCP OPEN 172.16.1.102:1099[+] TCP OPEN 172.16.1.102:1524[+] TCP OPEN 172.16.1.102:2049[+] TCP OPEN 172.16.1.102:2121[+] TCP OPEN 172.16.1.102:3306[+] TCP OPEN 172.16.1.102:3632[+] TCP OPEN 172.16.1.102:5432[+] TCP OPEN 172.16.1.102:5900[+] TCP OPEN 172.16.1.102:6000[+] TCP OPEN 172.16.1.102:6667[+] TCP OPEN 172.16.1.102:6697[+] TCP OPEN 172.16.1.102:8009[+] TCP OPEN 172.16.1.102:8180[+] TCP OPEN 172.16.1.102:8787[*] Scanned 1 of 1 hosts (100% complete)[*] Auxiliary module execution completed與TCP掃描相比,SYN掃描需要更長的時間才能完成,但一旦完成,我們可以看到,與之前的掃描相比,我們獲得了類似的結果。
選項3
XMAS掃描
我們要做的第三種掃描是XMAS掃描。再次,鍵入back退出當前模塊,然後使用auxiliary / scanner / portscan / xmas加載模塊。由於我們之前為遠程主機和線程設置了全局選項,因此我們應該在現在查看選項時看到這些設置已經填充。