MassDNS:一款功能強大的高性能DNS子域名查詢枚舉偵察工具
- 2020 年 2 月 20 日
- 筆記

MassDNS是一款功能強大的高性能DNS stub解析工具,它可以幫助研究人員解析數百萬甚至上億個域名。在沒有特殊配置的情況下,MassDNS可以利用公共可用的解析器每秒鐘解析超過350000個域名。
項目編譯
首先,使用下列命令將MassDNS源碼克隆至本地目錄中:
git clone https://github.com/blechschmidt/massdns.git
使用cd命令切換到本地項目目錄中:
cd massdns
接下來,運行」make」命令構建源碼。
如果你使用的不是Linux作業系統,那麼則需要運行下列命令:
make nolinux
在Windows平台下,你還需要安裝Cygwin包、gcc-core、git和make。
工具使用
Usage: ./bin/massdns [options] [domainlist] -b --bindto Bind to IP address and port. (Default: 0.0.0.0:0) --busy-poll Use busy-wait polling instead of epoll. -c --resolve-count Number of resolves for a name before giving up. (Default: 50) --drop-group Group to drop privileges to when running as root. (Default: nogroup) --drop-user User to drop privileges to when running as root. (Default: nobody) --flush Flush the output file whenever a response was received. -h --help Show this help. -i --interval Interval in milliseconds to wait between multiple resolves of the same domain. (Default: 500) -l --error-log Error log file path. (Default: /dev/stderr) --norecurse Use non-recursive queries. Useful for DNS cache snooping. -o --output Flags for output formatting. --predictable Use resolvers incrementally. Useful for resolver tests. --processes Number of processes to be used for resolving. (Default: 1) -q --quiet Quiet mode. --rcvbuf Size of the receive buffer in bytes. --retry Unacceptable DNS response codes. (Default: REFUSED) -r --resolvers Text file containing DNS resolvers. --root Do not drop privileges when running as root. Not recommended. -s --hashmap-size Number of concurrent lookups. (Default: 10000) --sndbuf Size of the send buffer in bytes. --sticky Do not switch the resolver when retrying. --socket-count Socket count per process. (Default: 1) -t --type Record type to be resolved. (Default: A) --verify-ip Verify IP addresses of incoming replies. -w --outfile Write to the specified output file instead of standard output. Output flags: S - simple text output F - full text output B - binary output J - ndjson output
如果你需要查看更詳細的操作選項以及幫助手冊(尤其是輸出格式),你可以使用「—help」命令。
工具使用樣例
解析目標域名(位於lists的resolvers.txt中)的AAAA記錄,並將結果存儲至result.txt中:
$ ./bin/massdns -r lists/resolvers.txt -t AAAA domains.txt > results.txt
或者運行下列命令:
$ ./bin/massdns -r lists/resolvers.txt -t AAAA -w results.txt domains.txt
樣本輸出
默認配置下,MassDNS將會輸出響應數據包,格式為文本格式,輸出樣例如下:
;; Server: 77.41.229.2:53 ;; Size: 93 ;; Unix time: 1513458347 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51298 ;; flags: qr rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0 ;; QUESTION SECTION: example.com. IN A ;; ANSWER SECTION: example.com. 45929 IN A 93.184.216.34 ;; AUTHORITY SECTION: example.com. 24852 IN NS b.iana-servers.net. example.com. 24852 IN NS a.iana-servers.net. 輸出結果包含了解析的IP地址,可以幫助我們輕鬆對輸出結果進行過濾。
數據解析
程式碼庫中包含了一個名為resolvers.txt的文件,其中包含了一套有subbrute項目提供的已過濾的解析器子集。請注意,MassDNS的使用可能會提升系統/網路負載,因為需要載入大量解析器,具體將取決於你的ISP。
MassDNS的DNS解析實現目前還不完整,只支援最常見的一些記錄類型。歡迎您通過程式碼貢獻來幫助改變這種狀況。
PTR記錄
MassDNS包含了一個Python腳本,允許我們解析所有的IPv4 PTR記錄:
$ ./scripts/ptr.py | ./bin/massdns -r lists/resolvers.txt -t PTR -w ptr.txt
請注意,in-addr.arpa中的標籤會被反轉。為了解析域名為1.2.3.4的地址,MassDNS將需要以「4.3.2.1.in-addr.arpa」的方式來作為輸入查詢名稱。此時,Python腳本並不會按升序解析記錄,這樣可以避免在IP v4子網的域名伺服器上突然出現的負載激增。
網路偵察&爆破子域名
注意:請不要隨意使用該工具,適當調整-s參數以避免給權威域名伺服器造成負載壓力。
跟subbrute類似,MassDNS允許我們使用subbrute.py腳本來對子域名進行爆破枚舉:
$ ./scripts/subbrute.py lists/names.txt example.com | ./bin/massdns -r lists/resolvers.txt -t A -o S -w results.txt
作為一種額外的網路偵察手段,ct.py腳本可以從crt.sh中抓取數據,並從證書透明日誌中提取子域名:
$ ./scripts/ct.py example.com | ./bin/massdns -r lists/resolvers.txt -t A -o S -w results.txt
工具運行截圖

安全性
MassDNS的運行不需要Root許可權, 我們建議用戶以非特權用戶的身份運行MassDNS。除此之外,我們不建議大家使用「—root」參數來運行。另外,除了Master以外的其他分支不適用於生產環境。
項目地址
MassDNS:【點擊底部閱讀原文查看】
* 參考來源:blechschmidt,FB小編Alpha_h4ck編譯,轉載請註明來自FreeBuf.COM