Dirsearch使用教程#

软件介绍#

Dirsearch是一款用Python编写的高级目录扫描工具,专注于网站目录和文件的暴力破解。它支持多种扫描模式,能够快速发现网站的隐藏目录和文件。

入门级使用#

基本目录扫描#

功能说明:使用默认设置扫描目标网站的目录和文件

使用示例

# 基本目录扫描
dirsearch -u https://example.com

# 扫描多个URL
dirsearch -u https://example.com -u https://test.com

# 从文件中读取URL列表
dirsearch -l urls.txt

# 将结果输出到文件
dirsearch -u https://example.com -o results.txt

参数说明

  • -u:指定目标URL
  • -l:从文件中读取URL列表
  • -o:指定输出文件

简单的字典设置#

功能说明:使用自定义字典进行目录扫描

使用示例

# 使用默认小字典
dirsearch -u https://example.com -e php

# 使用指定字典
dirsearch -u https://example.com -w /path/to/wordlist.txt

# 使用多种文件扩展名
dirsearch -u https://example.com -e php,html,asp

# 使用大字典
dirsearch -u https://example.com -w db/dicc.txt

参数说明

  • -e:指定文件扩展名
  • -w:指定自定义字典

初级使用#

扫描控制#

功能说明:控制扫描的行为和速度

使用示例

# 设置线程数
dirsearch -u https://example.com -t 50

# 设置请求延迟
dirsearch -u https://example.com -s 1

# 设置超时时间
dirsearch -u https://example.com -T 10

# 设置最大重试次数
dirsearch -u https://example.com -r 3

# 限制扫描深度
dirsearch -u https://example.com --max-depth 3

参数说明

  • -t:设置线程数
  • -s:设置请求延迟(秒)
  • -T:设置超时时间(秒)
  • -r:设置最大重试次数
  • --max-depth:限制扫描深度

结果过滤#

功能说明:过滤和处理扫描结果

使用示例

# 仅显示特定状态码的结果
dirsearch -u https://example.com -i 200,301,302

# 排除特定状态码的结果
dirsearch -u https://example.com -x 404,403

# 最小响应大小过滤
dirsearch -u https://example.com --minimal 1000

# 最大响应大小过滤
dirsearch -u https://example.com --maximal 10000

# 仅显示有内容的响应
dirsearch -u https://example.com --full-url

参数说明

  • -i:仅包含指定的状态码
  • -x:排除指定的状态码
  • --minimal:设置最小响应大小
  • --maximal:设置最大响应大小
  • --full-url:显示完整URL

中级使用#

高级扫描选项#

功能说明:使用高级选项进行更深入的目录扫描

使用示例

# 递归扫描
dirsearch -u https://example.com -r

# 强制递归扫描
dirsearch -u https://example.com -R

# 启用随机用户代理
dirsearch -u https://example.com -a

# 使用指定用户代理
dirsearch -u https://example.com -H "User-Agent: Mozilla/5.0"

# 启用跟随重定向
dirsearch -u https://example.com -f

# 自定义请求方法
dirsearch -u https://example.com -m POST

参数说明

  • -r:启用递归扫描
  • -R:强制递归扫描
  • -a:启用随机用户代理
  • -H:设置自定义HTTP头
  • -f:启用跟随重定向
  • -m:设置请求方法

认证和会话#

功能说明:处理需要认证的网站

使用示例

# 基本认证
dirsearch -u https://example.com --basic-auth username:password

# 使用cookie
dirsearch -u https://example.com --cookie "session=abc123"

# 使用会话文件
dirsearch -u https://example.com --session session.json

# 从浏览器导入cookie
dirsearch -u https://example.com --cookie "$(cat cookie.txt)"

# 使用CSRF令牌
dirsearch -u https://example.com -H "X-CSRF-Token: token123"

参数说明

  • --basic-auth:设置基本认证凭据
  • --cookie:设置cookie
  • --session:使用会话文件
  • -H:设置自定义HTTP头

中上级使用#

绕过防护#

功能说明:绕过网站的安全防护措施

使用示例

# 启用随机延迟
dirsearch -u https://example.com --random-agent --delay 1

# 自定义请求头
dirsearch -u https://example.com -H "X-Forwarded-For: 127.0.0.1" -H "Referer: https://google.com"

# 使用代理
dirsearch -u https://example.com --proxy http://127.0.0.1:8080

# 使用SOCKS代理
dirsearch -u https://example.com --proxy socks5://127.0.0.1:1080

# 禁用SSL验证
dirsearch -u https://example.com --no-ssl-validation

# 分片请求
dirsearch -u https://example.com --chunk-size 10

参数说明

  • --random-agent:使用随机用户代理
  • --delay:设置请求延迟
  • -H:设置自定义HTTP头
  • --proxy:使用HTTP代理
  • --no-ssl-validation:禁用SSL验证
  • --chunk-size:设置分片大小

自定义扫描#

功能说明:创建和使用自定义扫描配置

使用示例

# 使用自定义配置文件
dirsearch -u https://example.com --config config.json

# 自定义搜索模式
dirsearch -u https://example.com -e php --wordlist /path/to/wordlist.txt

# 扫描特定路径
dirsearch -u https://example.com/admin/ -e php

# 多线程深度扫描
dirsearch -u https://example.com -r -t 50

# 组合多种技术
dirsearch -u https://example.com -e php,html -w /path/to/wordlist.txt -r -t 30 -o detailed_results.txt

参数说明

  • --config:使用自定义配置文件
  • -e:指定文件扩展名
  • -w:指定自定义字典
  • -r:启用递归扫描
  • -t:设置线程数
  • -o:指定输出文件

高级使用#

大规模扫描#

功能说明:处理大规模的目录扫描任务

使用示例

# 批量扫描多个网站
dirsearch -l urls.txt -e php -o batch_results.txt

# 分布式扫描(使用多个实例)
# 实例1
dirsearch -l urls1.txt -e php -o results1.txt
# 实例2
dirsearch -l urls2.txt -e php -o results2.txt

# 合并结果
cat results1.txt results2.txt | sort -u > final_results.txt

# 增量扫描
dirsearch -u https://example.com -e php -w new_wordlist.txt -o incremental_results.txt

参数说明

  • -l:从文件中读取URL列表
  • -e:指定文件扩展名
  • -o:指定输出文件
  • -w:指定自定义字典

结果分析#

功能说明:分析和处理扫描结果

使用示例

# 统计发现的文件和目录
grep -E "\[200\]" results.txt | wc -l

# 过滤特定状态码的结果
grep -E "\[200\]|\[301\]" results.txt > valid_results.txt

# 提取完整URL
grep -E "\[200\]" results.txt | awk -F' ' '{print $5}' > valid_urls.txt

# 与其他工具结合使用
cat valid_urls.txt | xargs -I {} curl -I {}

# 验证发现的文件是否可访问
cat valid_urls.txt | xargs -I {} curl -m 2 {}

参数说明

  • 结合shell命令和其他工具进行结果分析

大师级使用#

自定义插件和脚本#

功能说明:创建和使用自定义插件和脚本

使用示例

# 使用自定义Python脚本处理结果
#!/usr/bin/env python3
import re

with open('results.txt', 'r') as f:
    for line in f:
        if '[200]' in line:
            url = re.search(r'\s+(.+)$', line).group(1)
            print(f'Found: {url}')

# 批量扫描脚本
#!/bin/bash
while read url; do
    echo "Scanning: $url"
    dirsearch -u "$url" -e php,html -t 30 -o "results_$(echo $url | sed 's/\///g').txt"
done < urls.txt

# 结果汇总脚本
#!/bin/bash
for file in results_*.txt; do
    echo "Processing: $file"
    grep -E "\[200\]|\[301\]|\[302\]" "$file" >>汇总结果.txt
done

参数说明

  • 使用自定义脚本处理Dirsearch的结果

高级扫描策略#

功能说明:使用高级策略进行更有效的目录扫描

使用示例

# 多阶段扫描策略
# 第一阶段:快速扫描(小字典)
dirsearch -u https://example.com -e php -t 50 -o fast_scan.txt

# 第二阶段:深度扫描(大字典)
dirsearch -u https://example.com -e php,html,asp -w db/dicc.txt -t 20 -o deep_scan.txt

# 第三阶段:定向扫描(针对特定路径)
dirsearch -u https://example.com/admin/ -e php -w admin_wordlist.txt -o admin_scan.txt

# 智能扫描策略
# 1. 先扫描常见目录
dirsearch -u https://example.com -e php -w common_dirs.txt -o common_scan.txt

# 2. 基于发现的目录进行递归扫描
dirsearch -u https://example.com -e php -r -w specific_wordlist.txt -o recursive_scan.txt

# 3. 针对发现的文件类型进行专门扫描
dirsearch -u https://example.com -e sql,backup,log -w backup_wordlist.txt -o backup_scan.txt

参数说明

  • -e:指定文件扩展名
  • -w:指定自定义字典
  • -t:设置线程数
  • -o:指定输出文件
  • -r:启用递归扫描

实战案例#

案例1:网站安全评估#

任务:评估目标网站的目录结构和潜在安全问题

执行步骤

  1. 基本扫描

    dirsearch -u https://target.com -e php,html,asp -o initial_scan.txt
  2. 深度扫描

    dirsearch -u https://target.com -e php,html,asp,js,css -w db/dicc.txt -r -t 30 -o deep_scan.txt
  3. 敏感目录扫描

    dirsearch -u https://target.com -e php -w sensitive_dirs.txt -o sensitive_scan.txt
  4. 结果分析

    # 过滤敏感文件和目录
    grep -E "backup|admin|config|db|log" deep_scan.txt > sensitive_findings.txt
    
    # 验证发现的内容
    cat sensitive_findings.txt | awk -F' ' '{print $5}' | xargs -I {} curl -I {}

案例2:漏洞挖掘前的信息收集#

任务:在漏洞挖掘前收集目标网站的详细信息

执行步骤

  1. 多轮扫描

    # 第一轮:常见目录
    dirsearch -u https://target.com -e php,html -o round1.txt
    
    # 第二轮:更多扩展名
    dirsearch -u https://target.com -e php,html,asp,aspx,jsp,js,css -o round2.txt
    
    # 第三轮:递归扫描
    dirsearch -u https://target.com -e php,html -r -o round3.txt
  2. 合并和去重

    cat round1.txt round2.txt round3.txt | sort -u > all_findings.txt
  3. 重点分析

    # 查找可能的漏洞点
    grep -E "upload|admin|config|backup|test|dev" all_findings.txt > potential_vulns.txt
    
    # 检查是否存在敏感文件
    grep -E "\.sql|\.bak|\.zip|\.tar|\.gz|\.log" all_findings.txt > sensitive_files.txt

总结#

Dirsearch是一款功能强大的目录扫描工具,专注于网站目录和文件的暴力破解。通过本教程的学习,您应该能够:

  1. 入门级:掌握基本的目录扫描和简单的字典设置
  2. 初级:了解扫描控制和结果过滤
  3. 中级:使用高级扫描选项和处理认证
  4. 中上级:掌握绕过防护和自定义扫描
  5. 高级:进行大规模扫描和结果分析
  6. 大师级:使用自定义插件和脚本,以及高级扫描策略

Dirsearch的优势在于其速度快、配置灵活、支持多种扫描模式。在实际使用中,Dirsearch常常与其他安全工具结合使用,以实现更全面的安全评估。