POC模拟攻击利器—Nuclei入门

开发 开发工具
Nuclei是一款基于YAML语法模板的开发的定制化快速漏洞扫描器。

引入Nuclei的缘由

使用dependency check 发现的问题,需要研发人员修复,研发人员要求复现问题!这个的确有难度不仅仅要了解cve 相关bug的具体含义,还要模拟攻击,对于测试人员显然要求过高!凭借自己多年的各种测试工具调研经验,直觉告诉自己,应该有类似的工具,经过各种技术调研选择了Nuclei。使用Nuclei主要对cve相关问题进行模拟,另外并不是所有的cve问题该工具都能模拟,建议大家使用前可以自行查看需要验证的cve问题是否在nuclei的template中,如果不在,还需要自行创建。

Nuclei基础

Nuclei是一款基于YAML语法模板的开发的定制化快速漏洞扫描器。它使用Go语言开发,具有很强的可配置性、可扩展性和易用性。Nuclei使用零误报的定制模板向目标发送请求,同时可以对大量主机进行快速扫描。Nuclei提供TCP、DNS、HTTP、FILE等各类协议的扫描,通过强大且灵活的模板,可以使用Nuclei模拟各种安全检查。

Nuclei安装

  • 首先安装go环境(go1.17以上版本)。
  • 下载对应平台的安装包,默认安装即可,本文默认安装windows版本。
  • https://github.com/projectdiscovery/nuclei/releases。

Nuclei基础使用介绍

原理:根据yaml模板中的内容模拟攻击请求,然后根据响应结果来判断系统中是否存在漏洞。内置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标签时会执行该yaml。

requests,表示要模拟的请求,关于method: GET、path"{{BaseURL}} "、就不详细讲解了,他们与http协议中定义的内容一致。

Matchers,简单的说就是用于对请求响应的校验,上述代码中校验了响应中的两项内容:

通过正则方式- type: regex校验响应body里是否有满足正则表达式- "root:.*:0:0:"的内容。

校验响应的状态码- type: status 是否是200。

这两项校验内容是与的关系,matchers-condition: and(默认是or),关于更多的matcher相关知识我会加后面的文章中提及。

关于编写http请求的详细规则请参考:

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规则的检测(通过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, 控制台输出统计结果-stats,检测的漏洞级别是critical和high,并把结果输出到result2.json(推荐,json形式的报告统计信息非常详细)。

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"

调用时,执行如下命令即可:

nuclei -u https://example.com -t mytemplate.yaml

nuclei使用总结

  • 首先确认要扫描的接口(http,url),这点没有appscan,zap工具方便,他们可以主动探索攻击。
  • 然后确认要扫描的规则,即确认yaml文件(根据tag选择想检测的内容,例如:cve、panel、lfi、xss等等),我们可以使用nuclei自带的yaml,也可以自定义yaml,为了提升扫描效率我们还可以自定义workflows,这个话题会在后面的文章中提及。
  • 最后就是通过命令运行脚本并生成测试报告。
责任编辑:姜华 来源: 今日头条
相关推荐

2021-08-26 13:07:05

编程语言攻击恶意软件

2013-04-27 10:43:26

2011-06-27 10:34:42

2024-03-15 08:18:05

Shelve模块Python工具

2013-07-11 09:25:49

2014-05-12 10:37:41

2018-08-05 08:20:22

2015-04-21 10:51:42

2010-07-23 20:06:18

2024-03-05 10:41:51

Rollup前端开发

2022-08-02 14:11:50

nucleiWorkflowsMathcer

2021-11-30 09:35:32

Linux监控Sysdig

2013-11-22 15:05:13

DDoSDDoS攻击

2023-04-07 09:12:11

2021-11-10 11:51:33

BrakTooth安全漏洞蓝牙设备

2023-12-07 19:48:42

2009-09-04 16:05:08

2020-12-25 10:08:30

漏洞Windows操作系统

2009-09-22 12:39:04

2010-09-16 15:19:12

点赞
收藏

51CTO技术栈公众号