[网络安全] Dirsearch 工具的安装、使用详细教程

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: [网络安全] Dirsearch 工具的安装、使用详细教程

Dirsearch简介

Dirsearch 是一个用于探测Web服务器上的隐藏目录和文件的工具。它通过发送HTTP请求来尝试访问可能存在的路径,从而找到不列在网站目录页面上的隐藏资源。

Dirsearch 的主要特点包括:

1.多线程:Dirsearch 采用多线程方式进行目录扫描,充分利用系统资源提高扫描效率。

2.字典支持:它支持使用自定义字典文件来进行目录爆破,你可以使用自己的字典文件或使用内置的常用字典。(注:字典必须是文本文件)

3.支持多种形式的网页(asp,php)

4.支持HTTP代理

5.启发式检测无效的网页

6.指定扩展名:你可以选择限制扫描的文件扩展名范围,以便更加精确地进行目录扫描。

7.进度追踪:Dirsearch 提供实时进度追踪,你可以看到当前扫描的进度和已发现的目录和文件。

8.结果输出:完成扫描后,Dirsearch 会生成详细的扫描报告(纯文本,JSON),展示已发现的隐藏目录和文件。



安装步骤

由于dirsearch是基于python3的,所以需保证本机含有python3环境。

python3环境读者可自行安装配置,本文不再赘述。

注意,当同时存在python3和python2时,要将两者的exe文件重命名为下图:

python3改为python.exe,python2改为python2.exe即可。

将zip包解压后放入python3的Dirsearch目录中

接着进入C:\Python3\Dirsearch\dirsearch-master目录中,输入cmd:

进入命令行后,输入PIP3 install DirSearch

下载失败,但我们看一下警告:

这个警告表示当前使用的 pip 版本为 21.2.4,但是还有更新的版本可用(版本号为 23.0),建议通过命令 C:\Python3\python.exe -m pip install --upgrade pip 来升级 pip。


于是我们输入C:\Python3\python.exe -m pip install --upgrade pip

但还是下载失败,原因是依赖项未升级。

因此我们输入pip install --upgrade -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/


该命令会根据 requirements.txt 文件中列出的依赖项,自动安装或升级所需的包,并使用指定的阿里云镜像源来获取依赖项的安装文件。

下载成功:

现在,就可以开始正常使用dirsearch了。

接下来将介绍dirsearch的使用方法。

注意:dirsearch的命令必须在C:\Python3\Dirsearch\dirsearch-master目录下运行


语法及参数

输入python dirsearch.py -h得到dirsearch帮助

回显如下:

C:\Python3\Dirsearch\dirsearch-master>python dirsearch.py -h
Usage: dirsearch.py [-u|--url] target [-e|--extensions] extensions [options]
Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  Mandatory:
    -u URL, --url=URL   Target URL(s), can use multiple flags
    -l PATH, --urls-file=PATH
                        URL list file
    --stdin             Read URL(s) from STDIN
    --cidr=CIDR         Target CIDR
    --raw=PATH          Load raw HTTP request from file (use '--scheme' flag
                        to set the scheme)
    -s SESSION_FILE, --session=SESSION_FILE
                        Session file
    --config=PATH       Path to configuration file (Default:
                        'DIRSEARCH_CONFIG' environment variable, otherwise
                        'config.ini')
  Dictionary Settings:
    -w WORDLISTS, --wordlists=WORDLISTS
                        Wordlist files or directories contain wordlists
                        (separated by commas)
    -e EXTENSIONS, --extensions=EXTENSIONS
                        Extension list separated by commas (e.g. php,asp)
    -f, --force-extensions
                        Add extensions to the end of every wordlist entry. By
                        default dirsearch only replaces the %EXT% keyword with
                        extensions
    -O, --overwrite-extensions
                        Overwrite other extensions in the wordlist with your
                        extensions (selected via `-e`)
    --exclude-extensions=EXTENSIONS
                        Exclude extension list separated by commas (e.g.
                        asp,jsp)
    --remove-extensions
                        Remove extensions in all paths (e.g. admin.php ->
                        admin)
    --prefixes=PREFIXES
                        Add custom prefixes to all wordlist entries (separated
                        by commas)
    --suffixes=SUFFIXES
                        Add custom suffixes to all wordlist entries, ignore
                        directories (separated by commas)
    -U, --uppercase     Uppercase wordlist
    -L, --lowercase     Lowercase wordlist
    -C, --capital       Capital wordlist
  General Settings:
    -t THREADS, --threads=THREADS
                        Number of threads
    -r, --recursive     Brute-force recursively
    --deep-recursive    Perform recursive scan on every directory depth (e.g.
                        api/users -> api/)
    --force-recursive   Do recursive brute-force for every found path, not
                        only directories
    -R DEPTH, --max-recursion-depth=DEPTH
                        Maximum recursion depth
    --recursion-status=CODES
                        Valid status codes to perform recursive scan, support
                        ranges (separated by commas)
    --subdirs=SUBDIRS   Scan sub-directories of the given URL[s] (separated by
                        commas)
    --exclude-subdirs=SUBDIRS
                        Exclude the following subdirectories during recursive
                        scan (separated by commas)
    -i CODES, --include-status=CODES
                        Include status codes, separated by commas, support
                        ranges (e.g. 200,300-399)
    -x CODES, --exclude-status=CODES
                        Exclude status codes, separated by commas, support
                        ranges (e.g. 301,500-599)
    --exclude-sizes=SIZES
                        Exclude responses by sizes, separated by commas (e.g.
                        0B,4KB)
    --exclude-text=TEXTS
                        Exclude responses by text, can use multiple flags
    --exclude-regex=REGEX
                        Exclude responses by regular expression
    --exclude-redirect=STRING
                        Exclude responses if this regex (or text) matches
                        redirect URL (e.g. '/index.html')
    --exclude-response=PATH
                        Exclude responses similar to response of this page,
                        path as input (e.g. 404.html)
    --skip-on-status=CODES
                        Skip target whenever hit one of these status codes,
                        separated by commas, support ranges
    --min-response-size=LENGTH
                        Minimum response length
    --max-response-size=LENGTH
                        Maximum response length
    --max-time=SECONDS  Maximum runtime for the scan
    --exit-on-error     Exit whenever an error occurs
  Request Settings:
    -m METHOD, --http-method=METHOD
                        HTTP method (default: GET)
    -d DATA, --data=DATA
                        HTTP request data
    --data-file=PATH    File contains HTTP request data
    -H HEADERS, --header=HEADERS
                        HTTP request header, can use multiple flags
    --headers-file=PATH
                        File contains HTTP request headers
    -F, --follow-redirects
                        Follow HTTP redirects
    --random-agent      Choose a random User-Agent for each request
    --auth=CREDENTIAL   Authentication credential (e.g. user:password or
                        bearer token)
    --auth-type=TYPE    Authentication type (basic, digest, bearer, ntlm, jwt)
    --cert-file=PATH    File contains client-side certificate
    --key-file=PATH     File contains client-side certificate private key
                        (unencrypted)
    --user-agent=USER_AGENT
    --cookie=COOKIE
  Connection Settings:
    --timeout=TIMEOUT   Connection timeout
    --delay=DELAY       Delay between requests
    -p PROXY, --proxy=PROXY
                        Proxy URL (HTTP/SOCKS), can use multiple flags
    --proxies-file=PATH
                        File contains proxy servers
    --proxy-auth=CREDENTIAL
                        Proxy authentication credential
    --replay-proxy=PROXY
                        Proxy to replay with found paths
    --tor               Use Tor network as proxy
    --scheme=SCHEME     Scheme for raw request or if there is no scheme in the
                        URL (Default: auto-detect)
    --max-rate=RATE     Max requests per second
    --retries=RETRIES   Number of retries for failed requests
    --ip=IP             Server IP address
  Advanced Settings:
    --crawl             Crawl for new paths in responses
  View Settings:
    --full-url          Full URLs in the output (enabled automatically in
                        quiet mode)
    --redirects-history
                        Show redirects history
    --no-color          No colored output
    -q, --quiet-mode    Quiet mode
  Output Settings:
    -o PATH/URL, --output=PATH/URL
                        Output file or MySQL/PostgreSQL URL (Format:
                        scheme://[username:password@]host[:port]/database-
                        name)
    --format=FORMAT     Report format (Available: simple,plain,json,xml,md,csv
                        ,html,sqlite,mysql,postgresql)
    --log=PATH          Log file
See 'config.ini' for the example configuration file

翻译如下:

用法:dirsearch.py [-u|--url] 目标 [-e|--extensions] 扩展名 [选项]
选项:
  --version             显示程序的版本号并退出
  -h, --help            显示此帮助消息并退出
必需:
  -u URL, --url=URL     目标URL,可以使用多个选项指定多个目标URL
  -l PATH, --urls-file=PATH
                        URL列表文件
  --stdin               从标准输入读取URL
  --cidr=CIDR           目标CIDR
  --raw=PATH            从文件加载原始HTTP请求(使用'--scheme'标志设置方案)
  -s SESSION_FILE, --session=SESSION_FILE
                        会话文件
  --config=PATH         配置文件路径(默认为'DIRSEARCH_CONFIG'环境变量,否则为'config.ini')
字典设置:
  -w WORDLISTS, --wordlists=WORDLISTS
                        单词列表文件或包含单词列表文件的目录(以逗号分隔)
  -e EXTENSIONS, --extensions=EXTENSIONS
                        扩展名列表,以逗号分隔(例如:php,asp)
  -f, --force-extensions
                        在每个单词列表条目的末尾添加扩展名。默认情况下,dirsearch只替换%EXT%关键字为扩展名。
  -O, --overwrite-extensions
                        使用指定的扩展名覆盖单词列表中的其他扩展名(通过'-e'选择)
  --exclude-extensions=EXTENSIONS
                        排除的扩展名列表,以逗号分隔(例如:asp,jsp)
  --remove-extensions   删除所有路径中的扩展名(例如:admin.php -> admin)
  --prefixes=PREFIXES   将自定义前缀添加到所有单词列表条目中(以逗号分隔)
  --suffixes=SUFFIXES   将自定义后缀添加到所有单词列表条目中,忽略目录(以逗号分隔)
  -U, --uppercase       单词列表转为大写
  -L, --lowercase       单词列表转为小写
  -C, --capital         单词首字母大写
通用设置:
  -t THREADS, --threads=THREADS
                        线程数
  -r, --recursive       递归地进行强制破解
  --deep-recursive      在每个目录深度上执行递归扫描(例如:api/users -> api/)
  --force-recursive     对找到的每个路径执行递归强制破解,而不仅仅是目录
  -R DEPTH, --max-recursion-depth=DEPTH
                        最大递归深度
  --recursion-status=CODES
                        用于执行递归扫描的有效状态码,支持范围(以逗号分隔)
  --subdirs=SUBDIRS     扫描给定URL的子目录(以逗号分隔)
  --exclude-subdirs=SUBDIRS
                        在递归扫描期间排除以下子目录(以逗号分隔)
  -i CODES, --include-status=CODES
                        包括的状态码,以逗号分隔,支持范围(例如:200,300-399)
  -x CODES, --exclude-status=CODES
                        排除的状态码,以逗号分隔,支持范围(例如:301,500-599)
  --exclude-sizes=SIZES
                        根据大小排除响应,以逗号分隔(例如:0B,4KB)
  --exclude-text=TEXTS  根据文本排除响应,可以使用多个标志
  --exclude-regex=REGEX
                        根据正则表达式排除响应
  --exclude-redirect=STRING
                        如果此正则表达式(或文本)与重定向URL匹配,则排除响应(例如:'/index.html')
  --exclude-response=PATH
                        排除类似于此页面响应的响应,路径作为输入(例如:404.html)
  --skip-on-status=CODES
                        每当命中这些状态码之一时跳过目标,以逗号分隔,支持范围
  --min-response-size=LENGTH
                        响应的最小长度
  --max-response-size=LENGTH
                        响应的最大长度
  --max-time=SECONDS    扫描的最大运行时间
  --exit-on-error       发生错误时退出
请求设置:
  -m METHOD, --http-method=METHOD
                        HTTP请求方法(默认为GET)
  -d DATA, --data=DATA  HTTP请求数据
  --data-file=PATH      包含HTTP请求数据的文件
  -H HEADERS, --header=HEADERS
                        HTTP请求标头,可以使用多个标志
  --headers-file=PATH   包含HTTP请求标头的文件
  -F, --follow-redirects
                        跟随HTTP重定向
  --random-agent        每个请求选择一个随机User-Agent
  --auth=CREDENTIAL     认证凭据(例如:user:password或bearer token)
  --auth-type=TYPE      认证类型(basic、digest、bearer、ntlm、jwt)
  --cert-file=PATH      包含客户端证书的文件
  --key-file=PATH       包含客户端证书私钥的文件(未加密)
  --user-agent=USER_AGENT
  --cookie=COOKIE
连接设置:
  --timeout=TIMEOUT     连接超时时间
  --delay=DELAY         请求之间的延迟
  -p PROXY, --proxy=PROXY
                        代理URL(HTTP/SOCKS),可以使用多个标志
  --proxies-file=PATH   包含代理服务器的文件
  --proxy-auth=CREDENTIAL
                        代理认证凭据
  --replay-proxy=PROXY  用于重放已发现路径的代理
  --tor                 使用Tor网络作为代理
  --scheme=SCHEME       原始请求的协议或URL中没有协议时使用的协议(默认为自动检测)
  --max-rate=RATE       每秒请求数最大值
  --retries=RETRIES     失败请求的重试次数
  --ip=IP               服务器IP地址
高级设置:
  --crawl               在响应中爬取新路径
显示设置:
  --full-url            在输出中显示完整URL(在静默模式下自动启用)
  --redirects-history   显示重定向历史记录
  --no-color            不使用彩色输出
  -q, --quiet-mode      安静模式
输出设置:
  -o PATH/URL, --output=PATH/URL
                        输出文件或MySQL/PostgreSQL数据库URL(格式:
                        scheme://[username:password@]host[:port]/database-
                        name)
  --format=FORMAT       报告格式(可用:simple、plain、json、xml、md、csv、html、
                        sqlite、mysql、postgresql)
  --log=PATH            日志文件
有关示例配置文件,请参见“config.ini”

常见Payload

1.扫描单个URL,并限制线程数和扩展名:

python dirsearch.py -u http://example.com -t 10 -e php,asp --exclude-extensions=html

该命令将对 http://example.com 进行目录扫描,使用最多 10 个线程并仅检查扩展名为 phpasp 的路径,同时排除扩展名为 html 的路径。

2.从URL列表文件中批量扫描:

python dirsearch.py -l urls.txt -t 5 -e php

该命令将从 urls.txt 文件中读取目标URL列表,并使用最多 5 个线程对每个URL进行目录扫描,仅检查扩展名为 php 的路径。

3.使用自定义字典和深度递归扫描:

python dirsearch.py -u http://example.com -w custom-wordlist.txt -r --deep-recursive

该命令将对 http://example.com 进行目录扫描,使用自定义的单词列表文件 custom-wordlist.txt,并启用深度递归扫描,即在每个目录的所有深度上执行递归扫描。

4.在请求中使用自定义HTTP头:

python dirsearch.py -u http://example.com -H "X-Custom-Header: Value" -H "Authorization: Bearer toke

该命令将对 http://example.com 进行目录扫描,并在每个请求中包含自定义的HTTP头,如 X-Custom-HeaderAuthorization

5.指定线程数和延迟时间:

python dirsearch.py -u http://example.com -t 20 --delay 0.5

上述命令将使用20个线程并设置每个请求之间的延迟为0.5秒。

6.使用自定义的请求头和超时时间:

python dirsearch.py -u http://example.com -H "Custom-Header: value" --timeout 10

这个命令将在每个请求中添加一个自定义的请求头 “Custom-Header: value”,并将超时时间设置为10秒。

7.包含和排除特定状态码:

python dirsearch.py -u http://example.com -i 200,302 -x 404,500

上述命令将只包含状态码为200和302的响应,并排除状态码为404和500的响应。

8.使用代理进行扫描:

python dirsearch.py -u http://example.com -p http://127.0.0.1:8080

这个命令将通过指定的HTTP代理(例如Burp Suite)对目标URL进行扫描。

9.保存输出到文件中:

python dirsearch.py -u http://example.com -o output.txt

上述命令将扫描结果输出到指定的文件 output.txt

10.使用代理链进行扫描:

python dirsearch.py -u http://example.com -p http://proxy1:8080 -p http://proxy2:8080

上述命令将通过两个代理服务器 proxy1proxy2 进行目标URL的扫描。

11.从标准输入读取URL:

cat urls.txt | python dirsearch.py --stdin -t 10

这个命令通过管道从 urls.txt 中读取URL,并使用最多 10 个线程对每个URL进行目录扫描。

12.启用递归扫描和重定向跟随:

python dirsearch.py -u http://example.com -r -F

上述命令将启用目录的递归扫描,并且在扫描时跟随HTTP重定向。

13.排除指定大小范围的响应:

python dirsearch.py -u http://example.com --exclude-sizes 0-100B,500KB-1MB

该命令将排除大小在 0 到 100 字节以及 500千字节到 1 兆字节范围内的响应。

14.设定最大运行时间和最大重试次数:

python dirsearch.py -u http://example.com --max-time 300 --retries 5

上述命令将设置最长运行时间为 300 秒,并允许失败请求最多重试 5 次。

15.指定自定义的User-Agent头:

python dirsearch.py -u http://example.com --user-agent "Custom User Agent"

上述命令将在HTTP请求中指定自定义的User-Agent头。

16.使用代理认证进行扫描:

python dirsearch.py -u http://example.com -p http://proxy.example.com --proxy-auth "username:password"

这个命令将使用指定的代理服务器 proxy.example.com 进行扫描,并提供代理认证的用户名和密码。

17.启用递归扫描并限制最大递归深度:

python dirsearch.py -u http://example.com -r -R 5

上述命令将启用递归目录扫描,并限制最大递归深度为5层。

18.排除特定文本出现的响应:

python dirsearch.py -u http://example.com --exclude-text "Not Found" --exclude-text "Error"

该命令将排除响应中包含指定文本(如 “Not Found” 和 “Error”)的路径。

19.设置最小和最大响应长度:

python dirsearch.py -u http://example.com --min-response-size 1000 --max-response-size 50000

上述命令将只包含响应长度在1000到50000字节之间的路径。


渗透实例

Dirsearch具体实战可参考CTF赛题:极客大挑战PHP解题详析 【Dirsearch使用实例+php反序列化】


本文举个简单的渗透例子:

在C:\Python3\Dirsearch\dirsearch-master路径下输入python dirsearch.py -u http://101.43.57.52:41080/ (某题目地址)

得到如下结果:

成功发现该网站目录页面上的隐藏资源,之后进行访问等操作即可实现命令执行等。


总结

以上为Dirsearch 工具的安装、使用详细教程,读者可结合官方文档躬身实践。

我是秋说,我们下次见。

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1月前
|
运维 网络协议 安全
【Shell 命令集合 网络通讯 】Linux 网络抓包工具 tcpdump命令 使用指南
【Shell 命令集合 网络通讯 】Linux 网络抓包工具 tcpdump命令 使用指南
44 0
|
1月前
|
网络协议 Linux 网络安全
curl(http命令行工具):Linux下最强大的网络数据传输工具
curl(http命令行工具):Linux下最强大的网络数据传输工具
50 0
|
1月前
|
数据采集 JavaScript 前端开发
实用工具推荐:适用于 TypeScript 网络爬取的常用爬虫框架与库
实用工具推荐:适用于 TypeScript 网络爬取的常用爬虫框架与库
|
5天前
|
存储 Linux 网络安全
centos7使用yum网络安装
这些是使用Yum进行网络安装的基本步骤。根据你的需求,你可以重复步骤3和4来安装其他软件包。请注意,执行Yum操作需要root或具有sudo权限的用户。
18 1
|
8天前
|
安全 网络安全 网络虚拟化
《计算机网络简易速速上手小册》第3章:计算机网络设备和工具(2024 最新版)
《计算机网络简易速速上手小册》第3章:计算机网络设备和工具(2024 最新版)
26 1
|
1月前
|
Shell Linux C语言
【Shell 命令集合 网络通讯 】Linux 即时通讯工具 ytalk命令 使用指南
【Shell 命令集合 网络通讯 】Linux 即时通讯工具 ytalk命令 使用指南
25 0
|
1月前
|
网络协议 Shell Linux
【Shell 命令集合 网络通讯 】⭐Linux 远程登录工具 telnet 命令 使用指南
【Shell 命令集合 网络通讯 】⭐Linux 远程登录工具 telnet 命令 使用指南
30 0
|
1月前
|
Kubernetes 应用服务中间件 nginx
Kubernetes服务网络Ingress网络模型分析、安装和高级用法
Kubernetes服务网络Ingress网络模型分析、安装和高级用法
36 5
|
1月前
|
缓存 网络协议 Linux
性能工具之网络 Benchmark iperf3 快速入门
Benchmark 评估服务器之前的网络带宽简单方法,大家做性能测试是否也是这样评估网络带宽?
36 2
性能工具之网络 Benchmark iperf3 快速入门