Skip to main content
Nuclei 为 HTTP 协议的各种功能提供了广泛的支持。支持原始和基于模型的 HTTP 请求,同时还支持非 RFC 客户端请求。此外,还可以指定有效载荷(Payloads),并且可以根据有效载荷值转换原始请求,以及本页后面将展示的更多功能。 HTTP 请求以 request 块开始,它指定了模板请求的起始点。
# Start the requests for the template right here
http:

请求方法

请求方法可以是 GETPOSTPUTDELETE 等,根据需求而定。
# Method is the method for the request
method: GET
重定向可以为每个模板指定重定向条件。默认情况下,不会跟随重定向。但是,如果需要,可以在请求详情中通过 redirects: true 启用重定向。默认情况下最多跟随 10 个重定向,这对于大多数用例应该足够了。可以使用 max-redirects 字段对跟随的重定向数量进行更精细的控制。
使用示例:
http:
  - method: GET
    path:
      - "{{BaseURL}}/login.php"
    redirects: true
    max-redirects: 3
目前重定向是按模板定义的,而不是按请求定义的。

路径

请求的下一部分是请求的路径。可以在路径中放置动态变量,以在运行时修改其行为。 变量以 {{ 开始,以 }} 结束,且区分大小写。 {{BaseURL}} - 这将在运行时在请求中被目标文件中指定的输入 URL 替换。 {{RootURL}} - 这将在运行时在请求中被目标文件中指定的根 URL 替换。 {{Hostname}} - Hostname 变量在运行时被包括目标端口在内的主机名替换。 {{Host}} - 这将在运行时在请求中被目标文件中指定的输入主机替换。 {{Port}} - 这将在运行时在请求中被目标文件中指定的输入端口替换。 {{Path}} - 这将在运行时在请求中被目标文件中指定的输入路径替换。 {{File}} - 这将在运行时在请求中被目标文件中指定的输入文件名替换。 {{Scheme}} - 这将在运行时在请求中被目标文件中指定的协议方案替换。 下面提供了一个示例 - https://example.com:443/foo/bar.php
变量
{{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
一些动态变量替换示例:
path: "{{BaseURL}}/.git/config"
# This path will be replaced on execution with BaseURL
# If BaseURL is set to  https://abc.com then the
# path will get replaced to the following: https://abc.com/.git/config
还可以在一个请求中指定多个路径,这些路径将被请求目标。

请求头

还可以指定请求头随请求一起发送。请求头以键/值对的形式放置。请求头配置示例如下:
# headers contain the headers for the request
headers:
  # Custom user-agent header
  User-Agent: Some-Random-User-Agent
  # Custom request origin
  Origin: https://google.com

请求体

Body 指定随请求一起发送的请求体。例如:
# Body is a string sent along with the request
body: "{\"some random JSON\"}"

# Body is a string sent along with the request
body: "admin=test"

会话

为了在多个请求之间维护基于 cookie 的类浏览器会话,默认情况下会重用 cookie。当您希望在一系列请求之间维护会话以完成利用链或执行认证扫描时,这非常有用。如果需要禁用此行为,可以使用 disable-cookie 字段。
# disable-cookie accepts boolean input and false as default
disable-cookie: true

请求条件

请求条件允许检查多个请求之间的条件,用于编写复杂的检查和利用,涉及各种 HTTP 请求以完成利用链。 如果 DSL matchers/extractors 包含带有相应属性的后缀数字,则该功能将自动启用。 例如,属性 status_code 将指向当前正在处理的请求/响应对的有效状态码。可以通过在属性名称后添加 _n 来访问之前的响应状态码,其中 n 是基于 1 的第 n 个有序请求。因此,如果模板有四个请求,我们目前位于第 3 个请求:
  • status_code:将引用请求编号 3 的响应码
  • status_code_1status_code_2 将引用序列响应编号一和二的响应码
例如,使用 status_code_1status_code_3body_2
    matchers:
      - type: dsl
        dsl:
          - "status_code_1 == 404 && status_code_2 == 200 && contains((body_2), 'secret_string')"
请求条件可能需要更多内存,因为会将之前响应的所有属性保留在内存中

HTTP 模板示例

上面提到的 .git/config 文件的最终模板文件如下:
id: git-config

info:
  name: Git Config File
  author: Ice3man
  severity: medium
  description: Searches for the pattern /.git/config on passed URLs.

http:
  - method: GET
    path:
      - "{{BaseURL}}/.git/config"
    matchers:
      - type: word
        words:
          - "[core]"
更完整的示例在这里提供