首页 > 其他分享 >【工具介绍】nuclei-yaml脚本编写

【工具介绍】nuclei-yaml脚本编写

时间:2024-07-17 11:57:16浏览次数:9  
标签:body status 请求 yaml path 编写 nuclei type 模板

文章目录


nuclei 是一款基于 Go 语言开发的快速、灵活的自动化漏洞扫描工具,它使用 YAML 格式的模板来定义扫描规则。YAML(YAML Ain’t Markup Language)是一种用于配置文件和数据序列化的数据描述语言,它以易读性著称。

YAML 脚本语法基础

  1. 缩进:YAML 使用空格进行缩进,通常每个缩进级别为两个空格。
  2. 键值对:YAML 通过键值对来存储数据,键和值之间用冒号 `` 分隔。
  3. 列表:使用短横线 - 来表示列表中的项。
  4. 注释:以 # 开头的行是注释。
  5. 字符串:字符串可以不使用引号,也可以使用单引号或双引号。

nuclei 模板语法

nuclei 模板通常包含以下几个部分:

  • id:模板的唯一标识符。
  • info:包含模板的基本信息,如名称、作者、版本等。
  • author:模板作者。
  • severity:漏洞的严重性等级。
  • tags:用于分类的标签。
  • requests:定义了如何与目标进行交互的请求部分。
    • method:HTTP 方法,如 GET 或 POST。
    • path:请求的路径。
    • headers:请求头。
    • body:请求体。
    • payloads:用于定义可能的输入值。
  • response:定义了如何分析响应以确定是否发现漏洞。
    • status:期望的 HTTP 状态码。
    • headers:期望的响应头。
    • body:期望的响应体内容。

常见使用场景

命令执行

id command-injection-scan
info
  name Command Injection Vulnerability Scan
  author your_name
  severity critical
  description The scan checks for command injection vulnerabilities by sending specially crafted payloads.

http
  - method GET
    path
      - {{BaseURL}}cmd=whoami

    matchers
      - type regex
        part body
        regex
          - rootadministratorwww-data

  - method POST
    path
      - {{BaseURL}}execute
    body cmd=cat etcpasswd

    matchers
      - type regex
        part body
        regex
          - rootx00

# Optional You can also include a response body capture to check for command output
  - raw
      - 
        GET {{BaseURL}}cmd={{rand_base64}} HTTP1.1
        Host {{Hostname}}

    matchers
      - type dsl
        dsl
          - contains(tolower(body), 'rootx00')

解释:

  • id 模板的唯一标识符。
  • info 包含模板的名称、作者、严重性和描述。
  • http 包含 HTTP 请求的配置。
    • method 请求方法,示例中包括 GET 和 POST 方法。
    • path 请求路径,{{BaseURL}} 会被替换为目标 URL。
    • body 对于 POST 请求,这里是发送的数据体。
  • matchers 定义匹配响应的条件。
    • type 匹配类型,示例中使用了正则表达式。
    • part 匹配响应的哪一部分,这里是响应体。
    • regex 正则表达式,用于匹配特定的命令输出,如用户列表。
  • raw 可选,用于发送原始 HTTP 请求,这里使用了 base64 编码的随机字符串来避免被某些防护机制拦截。
  • dsl 一种脚本语言,用于更复杂的匹配逻辑,示例中用于匹配小写转换后的响应体中是否包含特定的字符串。

sql延时注入

id sql-delay-injection-scan
info
  name SQL Delay Injection Detection
  author your_name
  severity critical
  description This template detects SQL delay injection vulnerabilities by measuring the response time of crafted payloads.

http
  - method GET
    path
      - {{BaseURL}}index.phpid=1  # Example path, adjust according to the application's parameter
    headers
      User-Agent Mozilla5.0 (Windows NT 10.0; Win64; x64) AppleWebKit537.36 (KHTML, like Gecko) Chrome58.0.3029.110 Safari537.3

    payloads
      delay
        - 1'
        - ' AND (SELECT  FROM (SELECT(SLEEP(5)))a) AND '1'='1

    attack clusterbomb  # This will send all payloads for each path

    matchers
      - type dsl
        dsl
          - duration=5000  # The response time should be greater than 5000ms (5 seconds) to indicate a potential delay

    extractors
      - type regex
        part body
        regex
          - SQL syntaxSQL injection  # Extracts error messages that may indicate SQL injection

解释:

  • id 模板的唯一标识符。
  • info 包含模板的名称、作者、严重性和描述。
  • http 包含 HTTP 请求的配置。
    • method 请求方法,这里使用 GET。
    • path 请求路径,需要根据实际应用调整。
    • headers 可以设置请求头,这里给出了一个 User-Agent 示例。
    • payloads 定义用于测试的 payload 列表,这里包括了可能触发延时的 SQL 语句。
    • attack 使用 clusterbomb 策略,意味着对每个路径发送所有 payload。
  • matchers 定义匹配响应的条件。
    • type 使用 DSL 匹配器。
    • dsl 使用 duration 检查响应时间,如果响应时间超过 5 秒,则可能表明存在 SQL 延时注入。
  • extractors 用于从响应中提取可能表明 SQL 注入的特定字符串。

任意文件读取

id arbitrary-file-read-scan
info
  name Arbitrary File Read Detection
  author your_name
  severity high
  description The template checks for arbitrary file read vulnerabilities by attempting to access sensitive files.

http
  - method GET
    path
      - {{BaseURL}}pathtosensitivefilesfile=etcpasswd
      - {{BaseURL}}downloadpath=........etcshadow
      - {{BaseURL}}viewfilefilename=............varwwwhtmlconfig.php

    matchers
      - type regex
        part body
        regex
          - rootx00  # Typical line in etcpasswd
          - shadowx     # Typical line in etcshadow
          - DB_PASSWORD=  # Example of a configuration file containing a password

      - type status
        status
          - 200

    extractors
      - type regex
        part body
        name sensitive_files
        regex
          - (etcpasswdetcshadowconfig.php)  # Adjust the regex to match the files you are looking for

    response
      - status 403  # Forbidden status code, indicating the file is protected but accessible
        headers 
          - Content-Type textplain  # Example of a header that might be returned for a protected file
      - status 404  # Not Found status code, indicating the file does not exist or is not accessible

解释:

  • id 模板的唯一标识符。
  • info 包含模板的名称、作者、严重性和描述。
  • http 包含 HTTP 请求的配置。
    • method 请求方法,这里使用 GET。
    • path 请求路径,包括尝试访问的敏感文件路径。需要根据目标应用的实际路径进行调整。
  • matchers 定义匹配响应的条件。
    • type 使用正则表达式匹配响应体。
    • regex 正则表达式列表,用于匹配敏感文件中可能包含的特定字符串。
    • status 检查响应状态码,200 表示文件被成功读取。
  • extractors 用于从响应中提取可能表明文件内容的字符串。
    • type 使用正则表达式提取器。
    • regex 正则表达式,用于匹配响应体中的敏感文件名。
  • response 可选,定义了响应的状态码和头部信息,用于进一步验证文件的可访问性。

跨站脚本攻击

id reflected-xss-scan
info
  name Reflected XSS Vulnerability Detection
  author your_name
  severity medium
  description This template detects reflected XSS vulnerabilities by sending payloads to the target URL and checking for the presence of the payload in the response.

http
  - method GET
    path
      - {{BaseURL}}searchq={{randstr}}
      - {{BaseURL}}param={{randstr}}

    payloads
      payload
        - {{randstr}}
        - %3Cscript%3Ealert%28%27xss%27%29%3B%3C%2Fscript%3E  # Encoded scriptalert('xss');script

    attack chain  # This will send the payloads after the randstr

    matchers
      - type word
        part body
        words
          - scriptalert('xss');script  # Look for the exact payload in the response
          - {{randstr}}  # Look for the random string in the response

      - type status
        status
          - 200

    extractors
      - type regex
        part body
        regex
          - [^]script[^].alert.((.)).[^]script  # Regex to capture scripts with alert
          - (i)(hrefsrc)=(datajscriptvbscriptlivescriptmhtmljavascriptaboutmochaframesetxmlxsltx-xrdsbeap#)  # Regex to capture potential XSS vectors

解释:

  • id 模板的唯一标识符。
  • info 包含模板的名称、作者、严重性和描述。
  • http 包含 HTTP 请求的配置。
    • method 请求方法,这里使用 GET。
    • path 请求路径,这里给出了两个示例,需要根据实际应用调整。
    • payloads 定义用于测试的 payload 列表,包括随机字符串和 XSS 攻击向量。
    • attack 使用 chain 策略,意味着在每个路径后附加 payload。
  • matchers 定义匹配响应的条件。
    • type 使用 word 匹配器查找响应体中是否包含特定的字符串或 payload。
    • status 检查响应状态码,200 表示请求成功。
  • extractors 用于从响应中提取可能表明 XSS 漏洞的字符串。
    • type 使用正则表达式提取器。
    • regex 正则表达式列表,用于匹配可能的 XSS 向量。

反序列化漏洞

id snakeyaml-deserialization-scan
info
  name SnakeYAML Deserialization Vulnerability Detection
  author your_name
  severity high
  description Checks if the application is vulnerable to SnakeYAML deserialization attacks by sending serialized Java objects.

http
  - method POST
    path
      - {{BaseURL}}apideserialize  # 假设的反序列化处理接口

    headers
      Content-Type applicationx-java-serialized-object

    body 
      ACED00057372002D6F626A6563742E7365727665726C65735F7365727665726C6966652E5472696F6E67496E766F6B65...

    matchers
      - type word
        part body
        words
          - java.lang.ClassCastException
          - java.io.InvalidClassException
        condition or

      - type status
        status
          - 500

解释:

  • id 模板的唯一标识符。
  • info 包含模板的名称、作者、严重性和描述。
  • http 包含 HTTP 请求的配置。
    • method 请求方法,这里使用 POST。
    • path 请求路径,需要根据实际应用的反序列化处理接口进行调整。
    • headers 设置 Content-Type 为 Java 序列化对象的 MIME 类型。
    • body 包含序列化后的 Java 对象的二进制数据。这里的数据是示例,实际使用时应根据可能的反序列化对象进行调整。
  • matchers 定义匹配响应的条件。
    • 第一个 type word 匹配器查找响应体中的错误消息,这可能表明反序列化过程中发生了异常。
    • 第二个 type status 匹配器查找 500 状态码,这可能表明服务器端发生了错误。

弱密码

id weak-password-detection
info
  name Weak Password Detection
  author your_name
  severity info
  description Attempts to detect weak passwords for basic auth, form logins, or specific APIs by sending common credentials.

http
  - method POST
    path
      - {{BaseURL}}login
    body 
      username={{username}}&password={{password}}
    headers
      Content-Type applicationx-www-form-urlencoded

    # 定义 payload 提供用户名和密码组合
    payloads
      username
        - admin
      password
        - 123456  # 可以根据需要添加更多常见弱密码

    # 使用 attack clusterbomb 模式发送所有用户名和密码的组合
    attack clusterbomb

    matchers
      - type dsl
        dsl
          - status_code==200 && contains(tolower(body), 'login successful')  # 假设登录成功会返回 200 状态码和包含 'login successful' 文本
          - cookiecontains=auth_token  # 假设登录成功会设置一个 auth_token 的 cookie

解释:

  • id 模板的唯一标识符。
  • info 包含模板的名称、作者、严重性和描述。
  • http 包含 HTTP 请求的配置。
    • method 请求方法,这里使用 POST。
    • path 假设的登录接口路径。
    • body 发送的数据,包含用户名和密码字段。
    • headers 发送的 HTTP 头部,指定内容类型为表单编码。
    • payloads 定义要尝试的用户名和密码,这里只是示例,可以根据实际情况扩展。
    • attack 使用 clusterbomb 模式,尝试所有用户名和密码的组合。
  • matchers 定义匹配响应的条件,这里假设登录成功会返回 200 状态码和包含特定文本,或者设置特定的 cookie。

文件上传

任意文件上传漏洞允许攻击者上传不应该被允许的文件类型,这可能导致服务器被攻击者控制。编写用于检测任意文件上传漏洞的 Nuclei YAML 脚本时,需要考虑上传接口的特征以及如何构造有效的上传请求。以下是一个基础的示例脚本:

id arbitrary-file-upload-scan
info
  name Arbitrary File Upload Vulnerability Detection
  author your_name
  severity high
  description The template checks for arbitrary file upload vulnerabilities by attempting to upload files with known vulnerable extensions.

http
  - method POST
    path
      - {{BaseURL}}upload  # 假设的上传接口路径

    headers
      Content-Type multipartform-data; boundary=----WebKitFormBoundaryX

    # 构造一个带有文件上传的请求体
    body 
      ------WebKitFormBoundaryX
      Content-Disposition form-data; name=uploadfile; filename={{randstr}}.php
      Content-Type applicationx-php

      php echo 'File uploaded successfully'; 
      ------WebKitFormBoundaryX--

    matchers
      - type word
        part body
        words
          - File uploaded successfully  # 假设上传成功会返回特定的成功消息

      - type status
        status
          - 200

解释:

  • id 模板的唯一标识符。
  • info 包含模板的名称、作者、严重性和描述。
  • http 包含 HTTP 请求的配置。
    • method 请求方法,这里使用 POST。
    • path 假设的上传接口路径,需要根据实际应用调整。
    • headers 设置请求头,指定内容类型为多部分表单数据。
    • body 构造请求体,包含文件上传的详细信息,这里使用 PHP 脚本作为示例。
  • matchers 定义匹配响应的条件。
    • type 使用 word 匹配器查找响应体中是否包含特定的成功消息。
    • status 检查响应状态码,200 表示请求成功。

使用这些模板时,nuclei 会发送请求到目标 URL,并根据模板中的 response 部分来检查响应,以确定是否存在安全漏洞。这些只是一些基本示例,实际使用时可以根据需要创建更复杂的规则。

标签:body,status,请求,yaml,path,编写,nuclei,type,模板
From: https://blog.csdn.net/LongL_GuYu/article/details/140375247

相关文章

  • Hive自定义函数编写方法(含源代码解读,超详细,易理解)
    一、Hive自定义函数介绍        1.内置函数        Hive自带了一些函数。比如:max/min等,但是数量有限,自己可以通过自定义UDF来方便的扩展。2.自定义函数        当Hive提供的内置函数无法满足你的业务处理需要时,此时就可以考虑使用用户自定义函数(UD......
  • 【c语言】函数递归的一些例题1.编写一个函数,不许创建临时变量,求字符串长度 2.求n的阶
    1.intmy_strlen(char*str){   if(*str!='\0')   {      return1+my_strlen(str+1);//利用递归求字符串长度:递归一次就是多一个字符这样就可以求出字符串的长度了   }   else      return0;}intmain(){   //编写......
  • golang使用yaml文件做配置文件
    yaml配置文件host:localhost:3306user:rootpwd:112233dbname:1安装yaml读取工具gogetgopkg.in/yaml.v2从yaml文件读取配置packagemain​import("fmt""gopkg.in/yaml.v2""os")​typeConfstruct{Host string`yaml:"host&qu......
  • Nuclei的安装
    一、安装基础Golang通过yuminstallgo安装的go版本是1.20.14,无法满足nuclei的环境要求,使用yumremovego卸载删除已安装的go语言环境,通过go官网下载需要的go版本,https://go.dev/dl/  下载在/usr/local目录下,cd/usr/local,wget https://go.dev/dl/go1.22.4.linux-......
  • Vue3中,使用TSX/JSX编写的父组件,如何向子组件中传递具名插槽(slot)的内容
    子组件(Child)-模板代码:<template><divclass="child-component"><divclass="header-box"><slotname="header"></slot></div><slot></slot></div></tem......
  • 软件测试——缺陷编写
    缺陷编写以以前编写的区号的测试用例来说,假如有一个验证程序,验证完得到以下结果可以发现有两条不能通过的案例(标红)缺陷编写缺陷标题想要达到的效果:知道问题在哪缺陷标题分析:测试数据+执行结果(预期)测试数据+执行结果(需求)测试数据+预期+实际缺陷的跟踪流程提交缺陷......
  • C#编写CAN上位机与仪器通讯
    C#编写CAN上位机与仪器通讯1.前期准备安装配置好winform环境在文章结尾下载整理好的所需文件将ControlCAN.dll文件放入项目的bin/Debug文件夹下如果之后执行失败,就还需将kerneldlls文件夹也放入bin/Debug文件夹下引用导入的ControlCAN.dll(右键项目引用->添加引......
  • 在Linux中,如何编写shell脚本将当前目录下大于10K的文件转移到/tmp目录下?
    编写一个shell脚本来将当前目录下大于10K的文件转移到/tmp目录下,你可以遵循以下步骤:打开你的Linux终端。使用文本编辑器创建一个新的shell脚本文件,例如使用nano或vim:nanomove_large_files.sh在打开的编辑器中,编写以下脚本内容:#!/bin/bash#定义目标目录TARGET_DIR......
  • C++ //练习 14.44 编写一个简单的桌面计算器使其能处理二元运算。
    C++Primer(第5版)练习14.44练习14.44编写一个简单的桌面计算器使其能处理二元运算。环境:LinuxUbuntu(云服务器)工具:vim 代码块/************************************************************************* >FileName:ex14.44.cpp >Author: >Mail: >C......
  • 5.1编写ansibleplaybook批量安装二进制
    本节重点介绍:ansibleplaybook编写rsyslog和logrotateservice_deployyaml的编写配置机器直接的ssh免密码登录节点主机名host解析节点主机名写入hostsecho"192.168.3.200prome-master01">>/etc/hostsecho"192.168.3.201prome-node01">>/etc/hosts......