POC模擬攻擊利器—Nuclei入門
引入Nuclei的緣由
使用dependency check 發(fā)現(xiàn)的問題,需要研發(fā)人員修復,研發(fā)人員要求復現(xiàn)問題!這個的確有難度不僅僅要了解cve 相關bug的具體含義,還要模擬攻擊,對于測試人員顯然要求過高!憑借自己多年的各種測試工具調研經驗,直覺告訴自己,應該有類似的工具,經過各種技術調研選擇了Nuclei。使用Nuclei主要對cve相關問題進行模擬,另外并不是所有的cve問題該工具都能模擬,建議大家使用前可以自行查看需要驗證的cve問題是否在nuclei的template中,如果不在,還需要自行創(chuàng)建。
Nuclei基礎
Nuclei是一款基于YAML語法模板的開發(fā)的定制化快速漏洞掃描器。它使用Go語言開發(fā),具有很強的可配置性、可擴展性和易用性。Nuclei使用零誤報的定制模板向目標發(fā)送請求,同時可以對大量主機進行快速掃描。Nuclei提供TCP、DNS、HTTP、FILE等各類協(xié)議的掃描,通過強大且靈活的模板,可以使用Nuclei模擬各種安全檢查。
Nuclei安裝
- 首先安裝go環(huán)境(go1.17以上版本)。
- 下載對應平臺的安裝包,默認安裝即可,本文默認安裝windows版本。
- https://github.com/projectdiscovery/nuclei/releases。
Nuclei基礎使用介紹
原理:根據(jù)yaml模板中的內容模擬攻擊請求,然后根據(jù)響應結果來判斷系統(tǒng)中是否存在漏洞。內置yaml文件路徑如下:(本文只關注cve相關漏洞)。
上圖中一個yaml文件其實就模擬了一個攻擊請求,以CVE-2022-29298.yaml為例,文件內如如下:
id: CVE-2022-29298info:name: SolarView Compact 6.00 - Directory Traversalauthor: ritikchaddhaseverity: highdescription: SolarView Compact ver.6.00 allows attackers to access sensitive files via directory traversal.reference:- https://www.exploit-db.com/exploits/50950- https://drive.google.com/file/d/1-RHw9ekVidP8zc0xpbzBXnse2gSY1xbH/view- https://nvd.nist.gov/vuln/detail/CVE-2022-29298- https://drive.google.com/file/d/1-RHw9ekVidP8zc0xpbzBXnse2gSY1xbH/view?usp=sharingclassification:cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:Ncvss-score: 7.5cve-id: CVE-2022-29298cwe-id: CWE-22metadata:shodan-query: http.html:"SolarView Compact"verified: "true"tags: cve,cve2022,lfi,solarviewrequests:- method: GETpath:- "{{BaseURL}}/downloader.php?file=../../../../../../../../../../../../../etc/passwd%00.jpg"matchers-condition: andmatchers:- type: regexpart: bodyregex:- "root:.*:0:0:"- type: statusstatus:- 200
我們可以重點關注以下字段:
severity表示這個cve漏洞的級別。
tags,表示這個漏洞被定義的標簽,cve表示在命令行中輸入cve標簽時會執(zhí)行該yaml。
requests,表示要模擬的請求,關于method: GET、path"{{BaseURL}} "、就不詳細講解了,他們與http協(xié)議中定義的內容一致。
Matchers,簡單的說就是用于對請求響應的校驗,上述代碼中校驗了響應中的兩項內容:
通過正則方式- type: regex校驗響應body里是否有滿足正則表達式- "root:.*:0:0:"的內容。
校驗響應的狀態(tài)碼- type: status 是否是200。
這兩項校驗內容是與的關系,matchers-condition: and(默認是or),關于更多的matcher相關知識我會加后面的文章中提及。
關于編寫http請求的詳細規(guī)則請參考:
https://nuclei.projectdiscovery.io/templating-guide/protocols/http/。
具體template編寫語法請參考:
https://github.com/projectdiscovery/nuclei/blob/master/SYNTAX-REFERENCE.md。
備注:從v2.5.2開始,nuclei在運行時會自動更新template。
注意:這里有的同學可能要問下面的語法形式是什么意思呢?
- type: statusstatus:- 200
這是yaml語法,大家可以自行百度之!
Nuclei常用命令
Nuclei幫助文檔。
nuclei –h
這里就不再詳細介紹了,自行查看即可。其他常用命令如下:
1.對url https://example.com,進行cve規(guī)則的檢測(通過tags cve),檢測的漏洞級別是critical和high,作者是geeknik。
nuclei -u https://example.com -tags cve -severity critical,high -author geeknik -o result.txt
2.對url https://example.com, 控制臺輸出統(tǒng)計結果-stats,檢測的漏洞級別是critical和high,并把結果輸出到result2.json(推薦,json形式的報告統(tǒng)計信息非常詳細)。
nuclei -u https://example.com -stats -severity critical,high -o result2.json -json -irr
nuclei -debug -u https://example.com -it cves -severity critical,high -o result.txt
3.對url https://example.com,進行模板CVE-2022-1439.yaml的檢測。
nuclei -debug -u https://example.com -t \cves\2022\CVE-2022-1439.yaml
4.nuclei也支持對不同的url進行掃描,定義一個txt文件,然后里面保存需要掃描的url,具體使用如下:
nuclei -list urls.txt
urls.txt包括的內容如下:
- http://example.com
- http://app.example.com
- http://test.example.com
- http://uat.example.com
5.如果想把結果以不同格式輸出,參考如下:
#輸出結果為JSON格式
nuclei -u https://example.com -json
#輸出結果保存到Markdown格式文件
nuclei -u https://example.com -me result
更多輸出結果,請參考nuclei –h 的OUTPUT字段,內容如下:
OUTPUT:-o, -output string output file to write found issues/vulnerabilities-sresp, -store-resp store all request/response passed through nuclei to output directory-srd, -store-resp-dir string store all request/response passed through nuclei to custom directory (default "output")-silent display findings only-nc, -no-color disable output content coloring (ANSI escape codes)-json write output in JSONL(ines) format-irr, -include-rr include request/response pairs in the JSONL output (for findings only)-nm, -no-meta disable printing result metadata in cli output-nts, -no-timestamp disable printing timestamp in cli output-rdb, -report-db string nuclei reporting database (always use this to persist report data)-ms, -matcher-status display match failure status-me, -markdown-export string directory to export results in markdown format-se, -sarif-export string file to export results in SARIF format
自定義檢測模板
Nuclei支持自定義編寫YAML語法模板,您可以工具自己的需求編寫自己的檢測模板。
例如定義模板mytemplate.yaml,內容如下:
id: basic-exampleinfo:name: Test HTTP Templateauthor: pdteamseverity: inforequests:- method: GETpath:- "{{BaseURL}}/"matchers:- type: wordwords:- "This is test matcher text"
調用時,執(zhí)行如下命令即可:
nuclei -u https://example.com -t mytemplate.yaml
nuclei使用總結
- 首先確認要掃描的接口(http,url),這點沒有appscan,zap工具方便,他們可以主動探索攻擊。
- 然后確認要掃描的規(guī)則,即確認yaml文件(根據(jù)tag選擇想檢測的內容,例如:cve、panel、lfi、xss等等),我們可以使用nuclei自帶的yaml,也可以自定義yaml,為了提升掃描效率我們還可以自定義workflows,這個話題會在后面的文章中提及。
- 最后就是通過命令運行腳本并生成測試報告。