d3xm0s/Quarry

GitHub: d3xm0s/Quarry

纯 Ruby 编写的 Web 内容发现扫描器,通过自动校准目标的 soft-404 行为来精准发现隐藏目录与文件。

Stars: 0 | Forks: 0

# QUARRY [![ci](https://static.pigsec.cn/wp-content/uploads/repos/cas/99/993938d8ce5e902ccfb9d6747725c320d855dea3235ed9a304cedf0d94c9321f.svg)](https://github.com/d3xm0s/quarry/actions/workflows/ci.yml) 内容发现扫描器。这是一个目录和文件暴破工具,它会根据目标自身的 not-found 行为进行校准,因此那些对所有 URL 都返回友好的 200 状态码的 soft-404 不会淹没真正的发现结果。 为它指定一个 base URL。它会针对目标请求一个 wordlist,并且在此之前,它会先了解目标上“未命中”的情况是什么样的——即一个不可能存在的路径会返回怎样的状态码和响应体。只有当候选路径确实能与该基准区分开来时,才会被算作一次有效命中。它采用纯 Ruby stdlib,因此只要 Ruby 能运行的地方它就能运行。 QUARRY discovering content against the bundled lab ## 为什么要进行校准 大多数目标会以以下两种方式之一来响应未知路径: - 一个干净的 **404** - 很简单,除此之外的所有内容都值得关注; - 一个 **soft-404**:返回带有 "page not found" 模板的 200 状态码,且对于每次未命中的响应都完全相同。普通的暴破工具在面对这种情况时,会将整个 wordlist 里的词全都作为结果上报。 Quarry 会首先对每个目录采样几个随机的、不可能存在的路径。如果它们返回 200,它就会将其标记为 **wildcard**,并学习该通配响应的指纹:即状态码,以及将请求路径剔除后的响应体摘要(这样,对于那些回显 `not found: /` 的页面,每次计算出的哈希值都是相同的)。在扫描过程中,只有当响应的状态码是全新的,或者其响应体确实与该通配响应不同时——而不仅仅是因为服务器返回了 200——才会被作为结果上报。 ## 用法 ``` quarry http://target/ # scan with the builtin wordlist quarry target.com -x php,txt,bak # append extensions to every word quarry http://target/ -w big.txt # bring your own wordlist quarry http://target/ -r 2 # recurse two levels into found dirs quarry http://target/ -t 40 # more workers quarry http://target/ -o report.json # write a JSON report quarry http://target/ -H "Cookie: sid=x" # authenticated scan quarry http://target/ --proxy http://127.0.0.1:8080 # through Burp ``` 单纯的词会单独进行尝试(它可能是一个目录),并且会结合每个 `-x` extension 再尝试一次。已经带有 extension 或路径分隔符的词将按原样发送。使用 `--slash` 时,每个词还会以添加尾部斜杠的方式进行探测。 ## 目录与递归 当服务器发出标准的“添加斜杠”重定向(`301 -> /path/`)或者响应了带尾部斜杠的请求时,该命中会被标记为目录。使用 `-r N`,发现的每个目录都会被依次扫描,最深可达 `N` 层,并且每一层都会根据其自身的 not-found 行为重新校准。 ## WAF 与速率限制 所有请求都通过同一个客户端汇聚发送,因此节奏控制和重试机制适用于所有 worker。遇到 429/503 时会进行重试,并采用指数退避策略(遵循 `Retry-After`),最多重试 `--retry` 次,默认为 2 次。`--rate` 限制所有 worker 每秒的请求总数,`--delay` 控制每个 worker 请求的间隔时间,而 `--jitter` 会对该延迟进行随机化处理。当目标开始进行拦截时,quarry 会对 WAF 进行指纹识别(如 Cloudflare、Imperva、Akamai、ModSecurity 等),并在运行结束时告知您。 ``` quarry http://target/ --rate 20 --delay 0.1 --jitter 0.4 # gentle quarry http://target/ --retry 5 # ride out 429s ``` ## Wordlist `data/common.txt` 中内置了一个精简的列表——包含常见的 admin panels、api roots、config 和 backup 文件、VCS metadata 以及 status endpoints。您可以通过 `-w` 指定您自己的更庞大的列表;以 `#` 开头的行将被忽略。 ## Flags ``` -u, --url URL target base url (also accepted as a positional arg) -w, --wordlist FILE wordlist to use (default: bundled data/common.txt) -x, --ext a,b,c append these extensions to each word, e.g. php,txt,bak --slash also probe each word with a trailing slash -t, --threads N concurrent workers (default 20) -T, --timeout SEC per-request timeout (default 10) -r, --recurse N recurse into found directories up to N levels (default 0) --delay SEC delay before each request per worker (default 0) --jitter FRAC randomise --delay by +/- this fraction, e.g. 0.3 --rate N cap total requests per second across all workers --retry N retry 429/503 up to N times with backoff (default 2) -H, --header 'K: V' extra request header, repeatable --cookie STR Cookie header for an authenticated scan -A, --user-agent UA custom user agent --proxy URL route requests through an http proxy --secure verify TLS certificates (off by default) -o, --output FILE write a JSON report --no-banner suppress the banner ``` ## 在内置的实验环境中进行尝试 `lab/` 目录下提供一个小型目标,这样您无需接触任何不属于自己的系统即可看到它的运行效果。它仅绑定到 localhost。 ``` ruby lab/testserver.rb # terminal 1: http://127.0.0.1:8100 (hard 404s) ruby lab/testserver.rb 8100 soft # ...or a soft-404 catch-all to see the filter quarry http://127.0.0.1:8100 # terminal 2: scan it ``` ## 环境要求 Ruby >= 3.0。运行无需额外的 gems。 ## 安装 ``` git clone quarry cd quarry chmod +x bin/quarry ln -s "$PWD/bin/quarry" ~/.local/bin/quarry # optional, puts it on PATH ``` ## 开发说明 没有运行时的 gems 依赖;测试在随 Ruby 一起提供的 minitest 和 rake 上运行。 ``` rake test # boots the lab and drives the real scanner against it ``` 测试套件会以 hard-404 和 soft-404 两种模式启动 `lab/testserver.rb`,对它们进行扫描,并断言预设的路径能够被发现、通配的干扰信息已被过滤,以及递归、重试和 WAF 指纹识别功能均能正常工作。 ## 适用范围 主动扫描器:它会向目标发送未经请求的请求。请仅对您已获得授权测试的系统运行此工具。
标签:Ruby, Web安全, 大数据, 目录扫描, 知识库, 蓝队分析, 路径暴破