Nuclei 使用笔记
参数备忘
部分参数的中文翻译:
-ft, -fuzzing-type string 覆盖模板中设置的模糊测试类型(替换,前缀,后缀,中缀)
-fm, -fuzzing-mode string 覆盖模板中设置的模糊测试模式(多参数,单参数)
-fuzz 启用模糊测试模板加载(已弃用:请使用 -dast 参数替代)
-dast 启用/运行动态应用安全测试(DAST)类 nuclei 模板
-dts, -dast-server 启用 DAST 服务器模式(实时模糊测试)
-dtr, -dast-report 将 DAST 扫描报告写入文件
-dtst, -dast-server-token string DAST 服务器令牌(可选配置)
-dtsa, -dast-server-address string DAST 服务器地址(默认 "localhost:9055")
-dfp, -display-fuzz-points 输出中显示模糊测试点用于调试
-fuzz-param-frequency int 跳过前对无价值参数的模糊测试频率(默认 10)
-fa, -fuzz-aggression string 模糊测试攻击强度,控制负载生成数量(低,中,高)(默认 "低")
-cs, -fuzz-scope string[] 配置模糊测试的目标 URL 正则表达式范围
-cos, -fuzz-out-scope string[] 配置模糊测试需排除的 URL 正则表达式范围
-sf, -secret-file 包含nuclei认证扫描密钥的配置文件路径
-ps, -prefetch-secrets 预先从密钥文件中获取密钥
Batch Fuzzing of Burp Suite Logs
保存 Burp 日志
proxy 和 repeater 两个模块都可右键选择【Save Item】 保存,但 proxy 模块可选多个数据包
⚠️注意:不要取消勾选 base64 加密,否则会出现 xml 版本不支持的报错
编写 Fuzzing 模板
选择 fuzzing 的区域时,需要注意关键字
part为复数形式的parts
id: arbitrary-file-read
info:
name: Arbitrary File Read Detection
author: pdteam
severity: medium
http:
- pre-condition:
- type: dsl
dsl:
- 'method == "POST"'
- 'method == "GET"'
condition: or
payloads:
LinuxPayload:
- "../../../../../etc/passwd"
- "../../../../../../etc/passwd"
# attack: pitchfork
fuzzing:
- parts:
- query
- body
# - path
type: replace
mode: single
fuzz:
- "{{LinuxPayload}}"
matchers-condition: and
matchers:
- type: word
part: body
words:
- "root:"
Nuclei Secret File Formats
# static secrets
static:
# 1. Basic Auth based auth
- type: basicauth
domains:
- scanme.sh
username: test
password: test
# 2. API Key (via query parameters) based auth
- type: query
domains:
- example.com
params:
- key: token
value: 1a2b3c4d5e6f7g8h9i0j
# 3. Bearer Token based auth
- type: bearertoken
domains-regex:
- .*scanme.sh
- .*pdtm.sh
token: test
# 4. Custom Header based auth
- type: header
domains:
- api.projectdiscovery.io
- cve.projectdiscovery.io
- chaos.projectdiscovery.io
headers:
- key: x-pdcp-key
value: <api-key-here>
Nuclei 参数说明
nuclei 必须使用
--fuzz参数来启用 fuzzing 模板
完整的命令示例
nuclei -duc -t linux-lfi-fuzzing.yaml -im burp -l history.burp --fuzz -proxy http://127.0.0.1:8080 -stats
在上述命令的基础上,可以配合 secret-file 来确保数据包认证信息是有效的,参考命令如下:
nuclei -duc -t linux-lfi-fuzzing.yaml -im burp -l history.burp --fuzz -proxy http://127.0.0.1:8080 -stats -ps -sf Secret.yaml
- 似乎目前 nuclei 关于
secret-file的实现逻辑是追加认证字段到数据包中,burp 日志与secret-file组合使用,会导致 cookie 的格式错乱- 临时的解决办法,配合 burp proxy 模块的替换功能,使用正则表达式进行替换
踩坑备忘
nuclei 理论上是同时支持 burp 和 proxfiy 的日志结果作为扫描目标的,测试发现,使用 proxfiy 日志时会出现 POST 请求的 body 缺失的情况,暂未深究,不知道是 bug 还是参数配置的问题,后续需要仔细确认
利用 Nuclei 模板保存和归档 Raw API
大致思路
- 按照 host 列进行排序,或者针对不同的 host 建立 scope
- 然后按照 URL 列进行排序,多选出现频率较多的 URL 进行删除,完成简单清洗
- 全选所有数据包,右键发送到 nuclei 插件中创建 nuclei 模板
- 复制 nuclei 插件中,对应模板的命令并备份
格式化 Nuclei 模板(可跳过)
使用 sed 模板对生成的 nuclei 模板进行格式化
- 模板 id 不支持使用动态变量,多个模板需要手动修改,避免 id 冲突
@host绑定的方式体验不佳,后续可以验证使用
# script.sed
# 将 |- 改为 |+
s/^ - |-/ - |+/
# 替换 author(包含可能的缩进)
s/^\(\s*\)author: .*/\1author: templatebot/
# 删除特定的请求头
/^.*Sec-Ch-Ua:.*$/d
/^.*Sec-Ch-Ua-Mobile:.*$/d
/^.*Sec-Ch-Ua-Platform:.*$/d
/^.*Sec-Fetch-Dest:.*$/d
/^.*Sec-Fetch-Mode:.*$/d
/^.*Sec-Fetch-Site:.*$/d
/^.*Dnt:.*$/d
/^.*Priority:.*$/d
/^.*User-Agent:.*$/d
/^.*Accept-Encoding:.*$/d
/^.*Accept-Language:.*$/d
/^.*Origin:.*$/d
/^.*Accept:.*$/d
/^.*Eagleeye-Traceid:.*$/d
/^.*Eagleeye-Sessionid:.*$/d
/^.*Eagleeye-Pappname:.*$/d
# 删除多余的空行
/^\s*$/{ N; /^\s*\n\s*$/D }
# 替换 Cookie 行
s/^\(\s\+\)Cookie:.*$/\1Cookie: {{cookies}}/
# 在 tags: tags 和 http: 之间添加 variables
/^ tags: tags$/{
n
/^$/{
i\variables:\
cookies: "xxx"
}
}
进行批量替换:
sed -i -b -f script.sed .\nuclei15660962180258986928.yaml
示例模板:
variables:
cookies: "xxx"
http:
- raw:
- |+
POST /api/post HTTP/1.1
Host: {{Hostname}}
Cookie: {{cookies}}
Content-Length: 14
Content-Type: application/json
Referer: https://fat.baidu.com/
Connection: keep-alive
{"page":1,"pagesize":10}
运行模板
在运行命令中,通过 -var 参数动态指定 cookies 变量的值
-var参数指定的变量名称,需要与模板中变量的名称保持一致(包括大小写)
nuclei -proxy http://127.0.0.1:8080 -stats -duc -t nuclei15660962180258986928.yaml -u https://fat.baidu.com:443/ -var cookies="xxxx"
审计模板
Windows 安全加固与审计
为确保这些模板能够正常运行,您必须使用最新版本的 nuclei,截至本文撰写时,该版本为 v3.3.7。
nuclei -id smb-v1-enabled -code -duc
nuclei -profile windows-audit -code -duc
nuclei -t code\windows\audit -code -duc
windows-audit:Windows 安全加固与审计k8s-cluster-security:Kubernetes 安全模板