← 返回列表

Nuclei: 基于Go语言开发的开源安全漏洞扫描工具使用初探

聚合站 SecWiki技术 作者 我的安全学习笔记 发布 2021年2月5日 23:52 入库 2026-11-18T20:41:16

0x1. 背景:

最近在刷Twitter的时候无意中看到的一个工具,在推特上看到关联推送的消息如下:

看着是在用这个工具批量检测最近出的Apache Druid的RCE漏洞,从这个工具的界面看着 挺清新的,然后就去搜索查了一波,这一下让我如获珍宝。我敢肯定的说, 它就是开源版的Xray(小声biu biu~)。

0x2. Nuclei介绍

Nuclei是一款基于Go语言开发的运行速度非常快且易于使用的开源安全漏洞扫描工具,它可以帮助研究人员基于模板执行可配置的目标扫描任务,并提供了大量可扩展接口以辅助使用。关于Nuclei的介绍文章,我只搜到了FB上面有一篇记录:https://www.freebuf.com/articles/network/235745.html 【2020-06-12】

2.1 如何安装

官方的文档如下:https://nuclei.projectdiscovery.io/nuclei/get-started/,提到了多种安装方法:

这里就讲最简单的办法,就是到 https://github.com/projectdiscovery/nuclei/releases 下载当前系统对应的二进制版本直接使用了。

Linux系统:

tar -xzvf nuclei-linux-amd64.tar.gz

mv nuclei /usr/bin/

nuclei -h

Mac系统:

mv /Users/cfhb/Downloads/nuclei_2.2.0_macOS_amd64/nuclei /usr/local/bin/

将可执行文件放到了系统执行变量里,就可以直接使用了。

2.2 如何获取扫描规则

安装好后,执行命令:nuclei -update-templates

下载Nuclei工具所需要的POC规则文件到本地用户目录,如下所示:

规则文件地址:https://github.com/projectdiscovery/nuclei-templates ,这些规则由开源社区136位+白帽子维护。

目前的规则版本为v8.0.6,按照不同的类型分类如下:

0x3. Nuclei使用介绍

3.1 命令参数介绍

Nuclei有很多的参数,了解了这些参数的作用对于我们发挥其能力有很大帮助。官方提供了中文介绍文档,可以供大家查阅。

https://github.com/projectdiscovery/nuclei/blob/master/README_CN.md

3.2 模版插件介绍

我之所以觉得Nuclei是个很不错的工具,主要因为它是开源的,且漏洞规则由众多白帽子维护贡献的。它的POC规则也是YAML格式的文件,语法简单,可读性强。模板以YAML文件形式编写定义如何发送和处理请求,可以帮助使用者快速编写自己心中想要的漏洞检测模版,定义复杂的检测执行过程。

官方的模版规则指南文档如下,我们来看看它到底有多秀:

https://nuclei.projectdiscovery.io/templating-guide/

对比过X-ray的POC语法规则定义,你会发现它们的语法定义是非常相似的。

Xray的POC结构文档:https://docs.xray.cool/#/guide/poc?id=poc-%e7%bb%93%e6%9e%84

一个Nuclei的POC规则如下:

id:basic-exampleinfo:name:Test HTTP Templateauthor:pdteamseverity:inforequests:-method: GETpath:-"{{BaseURL}}/“ //BaseURL Nuclei会自动填充matchers:// 匹配器-type: word //字符串类型words://可以定义多个字符串condition:and // 多个字符串的关系。AND (默认为OR)-"This is test matcher text” //匹配返回内容中的这个字符串-"This is test” //匹配返回内容中的这个字符串

一个 Xray的POC规则如下:

name:poc-yaml-example-comrules:-method: GETpath:"/"expression:|response.status==200 && response.body.bcontains(b'Example Domain')detail:author:name(link)links:-http://example.com

它们的规则文件都是以键值对形式构成,其中的相似之处如下:

Nuclei 的 id 类似 Xray 的name

Nuclei 的 info 类似 Xray 的detail

Nuclei 的 requests 类似 Xray 的rules

Nuclei 的matchers 定义 类似 Xray 的expression的功能,matchers支持对返回Body进行多种类型的匹配

他们都支持多个请求的复杂验证

Nuclei的模版也有独特的地方,比如:

支持RAW格式的请求

RAW格式的请求,匹配返回内容中包含XX字符串的例子

requests:-raw: //RAW格式的请求-|GET/ HTTP/1.1Host:{{Hostname}} //Hostname Nuclei会自动填充Origin:{{BaseURL}}Connection:closeUser-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko)Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8Accept-Language:en-US,en;q=0.9matchers:-type: wordwords:-"Test is test matcher text”

多个匹配器

定义多个匹配条件,

id:http-multiple-matchersinfo:name:Test HTTP Templateauthor:pdteamseverity:inforequests:-method: GETpath:-"{{BaseURL}}/"matchers:// 3个 type 定义了3个语言的特征,默认是OR的关系-type: word //匹配返回头中 PHP特征字符串name:phpwords:-"X-Powered-By: PHP"-"PHPSESSID"part:header //指定匹配的位置-返回头部-type: word //匹配返回头中,NodeJS特征字符串name:nodewords:-"Server: NodeJS"-"X-Powered-By: nodejs"condition:orpart:header-type: word //匹配返回头中,Python特征字符串name:pythonwords:-"Python/2."-"Python/3."part:header

Fuzz模式,支持Intruder里的三种爆破模式 (sniper、pitchfork、clusterbomb)

简单的表单爆破:

requests:-payloads:username:-admin //用户名字典password://用密码字典-admin-guest-password-test-12345-123456attack:clusterbomb //类似于定义Burpsuite里,Intruder的爆破模式# 可用的模式: 狙击模式sniper, 一对一模式(pitchfork) 组合模式(clusterbomb)raw:-|POST/?username=§username§&password=§password§ HTTP/1.1 //插入2个变量点User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5)Host:{{Hostname}}another_header:{{base64('§password§')}} // base64编码Accept:/body=testmatchers:-type: wordwords:-"Test is test matcher text"

条件竞争测试(类似Turbo Intruder)

id:race-condition-testinginfo:name:Race condition testingauthor:pdteamseverity:inforequests:-raw: // 需要重放的包RAW格式-|POST/coupons HTTP/1.1Host:{{Hostname}}Pragma:no-cacheCache-Control:no-cache, no-transformUser-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0promo_code=20OFFrace:truerace_count:15 // 15次matchers:-type: statuspart:headerstatus:-200

更多的Fuzz参考:

https://nuclei.projectdiscovery.io/template-examples/fuzzing/#http-intruder-fuzzing

https://blog.projectdiscovery.io/nuclei-fuzz-all-the-things/ 有更多的Fuzz使用方法的介绍。

支持通用和有条件的工作流

工作流可以理解为由各个插件模版拼成的自定义的攻击模块,比如:

通用基线安全工作流:

id: workflow-envvulnsinfo:name: Test env vulnsTemplateauthor: pdteamworkflows:// 这个可以称为基线安全的工作流,里面包含了多个备份文件,源码泄露等等类型的插件。-template: files/git-config.yaml-template: files/svn-config.yaml-template: files/env-file.yaml-template: files/backup-files.yaml

自定义springboot框架漏洞检测工作流:

id: springboot-workflowinfo:name: Springboot Security Checksauthor: dwisiswant0workflows:-template: security-misconfiguration/springboot-detect.yaml// 当检测到springboot框架时subtemplates://执行下面的springboot漏洞的检测规则-template: cves/CVE-2018-1271.yaml-template: cves/CVE-2018-1271.yaml-template: cves/CVE-2020-5410.yaml-template: vulnerabilities/springboot-actuators-jolokia-xxe.yaml-template: vulnerabilities/springboot-h2-db-rce.yaml

对比xray的插件语法来看,xray能实现的复杂的处理和构造POC检测,Nuclei也可以实现,就漏洞扫描而言,Nuclei甚至可以实现更多xray不能实现的需要。

3.3 漏洞扫描实战

批量 Apache Druid 漏洞

从FoFa得到 一些URL链接,使用检测命令如下:

nuclei-l fofa_apache_druid.txt -t cves/2021/CVE-2021-25646.yaml -silent -stats -o result.txt -json -include-rr -rate-limit 5000nuclei-l fofa_apache_druid.txt -t cves/2021/CVE-2021-25646.yaml -stats -o result.txt -rate-limit 5000

批量执行工作流

nuclei-l springboot.xt -t workflows/springboot-workflow.yaml -stats

0x5. 总结

个人觉得Nuclei是一款高度可定制化的,开源的,优秀的,通用POC扫描工具。Nuclei拥有很丰富的POC规则,可以多学习已有的规则,写出更多复杂的特殊场景的POC来。本笔记仅为简单的介绍,有更多的用法期待着读者去挖掘。 值得一提的是,从GitHub的Pull Requests数据来看大家的开源贡献规则的热度是和xray有的一拼的,同为Go语言开发,在Nuclei的基础上学习和定制开发自己的工具一定是很酷的事~

参考:

1、https://blog.projectdiscovery.io/nuclei-fuzz-all-the-things/

2、https://nuclei.projectdiscovery.io/templating-guide/#workflows

3、https://nuclei.projectdiscovery.io/template-examples/http/

4、https://twitter.com/pdnuclei 推特账号

‍

原文链接:https://mp.weixin.qq.com/s/C_-FRZMqF4ifzlx-ij4iIQ