CredAttack — 凭据攻击工具包
⚠️ 法律声明 — 仅限授权安全测试。
使用本工具针对您不拥有或未经明确书面许可的系统进行测试,在美国《计算机欺诈与滥用法》、英国《计算机滥用法》及全球同等法律下均属违法行为。请参阅 SECURITY.md。
目录
什么是 CredAttack?
CredAttack 是一套模块化、生产级凭据测试套件,适用于授权渗透测试项目。它覆盖了完整的凭据攻击生命周期:
| 阶段 | CredAttack 能力 |
|---|
| 侦察 | 默认凭据数据库(200+ 组合)、基于用户名的智能模式生成 |
| 攻击 | 17 种协议攻击器、6 种攻击模式、多目标攻击活动 |
| 规避 | 锁定检测、可配置速率限制、抖动、代理轮换 |
攻击模式
支持的协议
架构
credattack.py ← 精简入口:从检出目录执行 `python credattack.py ...`
│
├── credattack/cli.py ← CLI(Typer)— 8 个攻击模式子命令;pip 安装后
│ 也是 `credattack` 控制台脚本
├── credattack/core/
│ ├── config.py ← Pydantic v2 Settings,CREDATTACK_* 环境变量覆盖
│ ├── engine.py ← AttackEngine(ThreadPoolExecutor + Rich 进度界面)
│ ├── lockout.py ← LockoutDetector(滑动窗口,线程安全)
│ ├── proxy.py ← ProxyRotator(轮询、健康检查、降级)
│ ├── mutator.py ← PasswordMutator(leet、季节性、后缀、键盘行走…)
│ ├── result.py ← AttemptResult + SessionReport 数据类
│ ├── report.py ← Jinja2 HTML 报告生成器
│ └── logger.py ← Rich 日志 + JSONL 审计写入器
│
├── credattack/protocols/
│ └── *.py ← 18 个 ProtocolAttacker 实现
│
├── credattack/data/
│ ├── default_creds.json ← 200+ 真实默认凭据组合
│ ├── smart_patterns.json ← 140+ 企业密码模板
│ └── wordlists/ ← 按服务分类的默认密码列表
│
└── tests/ ← 50+ pytest 测试(单元 + 协议模拟)
快速开始
# 克隆并设置
git clone https://github.com/amibhai/credential-attacks-toolkit.git
cd credential-attacks-toolkit
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
# 检查版本
python credattack.py --version
# 试运行(不建立连接 — 验证您的字典列表)
python credattack.py ssh -t 192.168.1.100 -u admin -P wordlists/common_passwords.txt --dry-run
# 真实 SSH 字典攻击
python credattack.py ssh -t 192.168.1.100 -u admin -P /path/to/rockyou.txt
# 密码喷洒(限速、锁定安全)
python credattack.py spray -t 192.168.1.100 --protocol ssh -U users.txt -p "Summer2024!" --delay 30
# 智能模式 — 从用户名 + 公司生成模式
python credattack.py smart -t 192.168.1.100 --protocol ssh -u john.doe --company ACME
# 尝试服务默认凭据
python credattack.py defaults -t 192.168.1.100 --protocol mysql
# 多目标攻击活动
python credattack.py multi --targets hosts.txt --protocol ssh -U users.txt -P passes.txt
安装
选项 A — pip + virtualenv(推荐)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install -r requirements.txt
选项 B — Makefile 快捷方式
make install # 核心依赖
make install-dev # + pytest-cov、ruff、mypy
选项 C — pip 安装(可编辑或从 wheel)
pip install -e . # 仅核心依赖
pip install -e .[full] # + SMB/RDP/MySQL/MSSQL/Redis/MongoDB/WinRM/LDAP
pip install -e .[dev] # + pytest/ruff/mypy
credattack --version # 控制台脚本,等同于 `python credattack.py`
选项 D — Docker
docker build -t credattack -f docker/Dockerfile .
docker run --rm credattack --help
# 挂载您的字典列表并收集输出
docker run --rm \
-v $(pwd)/wordlists:/app/wordlists:ro \
-v $(pwd)/output:/app/output \
credattack ssh -t 192.168.1.100 -u admin -P wordlists/common_passwords.txt
CLI 参考
全局选项
python credattack.py [OPTIONS] COMMAND [ARGS]...
选项:
-V, --version 显示版本并退出。
--help 显示帮助。
通用标志(适用于所有协议命令)
子命令
# 协议专用(每个映射到专用攻击器)
python credattack.py ssh|ftp|smb|rdp|smtp|pop3|imap|mysql|mssql|redis|mongodb|winrm|ldap|telnet|vnc \
-t HOST -u USER -P passes.txt
# HTTP(表单 / basic / digest)
python credattack.py http -t http://target/login --mode form \
--form-user-field username --form-pass-field password --success-string "Dashboard"
# 喷洒 — 单个密码、多个用户、长延迟
python credattack.py spray -t HOST --protocol ssh -U users.txt -p "Password1" --delay 30
# 组合 — 用户 × 密码的笛卡尔积
python credattack.py combo -t HOST --protocol smb -U users.txt -P passes.txt
# 智能 — 基于 OSINT 的生成
python credattack.py smart -t HOST --protocol ssh -u firstname.lastname --company TargetCorp
# 默认 — 尝试厂商默认凭据
python credattack.py defaults -t HOST --protocol mysql
# 多目标 — 跨多个主机执行相同攻击
python credattack.py multi --targets hosts.txt --protocol ssh -U users.txt -P passes.txt
# 完整 — 按顺序执行所有协议
python credattack.py full -t HOST -U users.txt -P passes.txt
密码变异引擎
credattack/core/mutator.py 中的 PasswordMutator 支持可组合策略:
from credattack.core.mutator import PasswordMutator
m = PasswordMutator(max_mutations=5000)
# 组合所有策略
for pw in m.smart_generate("john.doe", company="ACME"):
print(pw)
# 仅季节性模式
for pw in m.seasonal_patterns(company="Contoso"):
print(pw)
默认凭据数据库
credattack/data/default_creds.json 包含 200+ 个真实默认凭据组合,涵盖:
Cisco · F5 · Juniper · Palo Alto · VMware · Jenkins · GitLab · Tomcat · WordPress · MySQL · MSSQL · Redis · MongoDB · PostgreSQL · Elasticsearch · RabbitMQ · Splunk · Nagios · Zabbix · pfSense · MikroTik · Huawei · HP iLO · Dell iDRAC · IPMI
# 查看某服务的所有默认凭据
python credattack.py defaults -t HOST --protocol mysql --dry-run
# 针对目标运行
python credattack.py defaults -t 10.0.0.1 --protocol ssh
代理轮换
传入代理文件(每行一个代理,host:port 格式):
# proxies.txt
192.168.1.10:1080
192.168.1.11:1080
socks5://10.0.0.5:9050
python credattack.py ssh -t TARGET -u admin -P passes.txt --proxy-file proxies.txt
ProxyRotator 在启动时执行健康检查,并将超过失败率阈值的代理降级。失效代理会被自动排除。
HTML 报告
每次非试运行攻击后,都会在 ./output/ 中自动生成 HTML 报告:
- 统计卡片:总尝试次数、成功率、持续时间、每秒尝试次数
- 已发现凭据表:主机 · 协议 · 用户名 · 密码(可复制到剪贴板)
- 深色主题 Jinja2 模板
# 运行后打开
start output/report_*.html # Windows
open output/report_*.html # macOS
配置与环境变量
credattack/core/config.py 中的所有设置均可通过 CREDATTACK_* 环境变量覆盖:
export CREDATTACK_THREADS=20
export CREDATTACK_TIMEOUT=3.0
export CREDATTACK_DELAY=1.0
export CREDATTACK_JITTER=0.5
export CREDATTACK_LOCKOUT_THRESHOLD=3
export CREDATTACK_VERBOSITY=2
或在 CLI 层使用标准标志(--threads、--timeout 等)。
Docker
# 构建镜像
docker build -t credattack -f docker/Dockerfile .
# 使用 Docker Compose 运行
cd docker
docker compose run credattack ssh -t 192.168.1.100 -u admin -P /app/wordlists/common_passwords.txt
# 通过环境变量设置配置
docker run --rm \
-e CREDATTACK_THREADS=20 \
-e CREDATTACK_TIMEOUT=3 \
-v $(pwd)/output:/app/output \
credattack defaults -t 10.0.0.1 --protocol mysql
测试
# 运行所有测试
pytest -q
# 带覆盖率
pytest --cov=credattack --cov-report=term-missing -q
# Makefile 快捷方式
make test-cov
当前测试套件:50+ 个测试,涵盖:
字典列表
⚠️ 内置的 wordlists/ 文件仅为最小冒烟测试桩。 真实评估请自行提供。
推荐来源
# 使用任何外部字典列表
python credattack.py ssh -t TARGET -u admin -P /opt/wordlists/rockyou.txt
项目结构
credential-attacks-toolkit/
├── credattack.py # 精简入口 -> credattack.cli:app(源码检出使用)
├── pyproject.toml # PEP 517/518 构建与工具配置
├── requirements.txt # 运行时依赖
├── Makefile # 开发者快捷方式
├── VERSION # 版本唯一来源
├── CHANGELOG.md
├── SECURITY.md
├── .github/
│ └── workflows/ci.yml # GitHub Actions:lint + 测试矩阵 + mypy
├── docker/
│ ├── Dockerfile
│ └── docker-compose.yml
├── credattack/
│ ├── cli.py # CLI(Typer)— 打包,支撑控制台脚本
│ ├── core/
│ │ ├── config.py # Pydantic v2 Settings
│ │ ├── engine.py # AttackEngine(ThreadPoolExecutor)
│ │ ├── lockout.py # LockoutDetector(滑动窗口)
│ │ ├── proxy.py # ProxyRotator
│ │ ├── mutator.py # PasswordMutator
│ │ ├── result.py # AttemptResult、SessionReport
│ │ ├── report.py # HTML 报告生成器
│ │ └── logger.py # Rich 日志器 + JSONL 写入器
│ ├── protocols/ # 18 个 ProtocolAttacker 实现
│ │ └── base.py # 抽象 ProtocolAttacker
│ └── data/
│ ├── default_creds.json # 200+ 厂商默认凭据
│ ├── smart_patterns.json # 140+ 企业模板
│ └── wordlists/ # 按服务分类的入门列表
├── attacks/ # 独立单文件工具(早于 credattack/;
│ └── *.py # 保留给尚未移植的脚本:JWT 破解、
│ # WAF 检测、基于时机的用户枚举)
├── utils/
│ └── credential_utils.py # attacks/ 脚本的共享辅助函数
├── tests/
│ ├── conftest.py # 共享夹具
│ ├── test_lockout.py
│ ├── test_mutator.py
│ ├── test_mutator_extended.py
│ ├── test_proxy.py
│ ├── test_result.py
│ ├── test_protocols_ssh.py
│ ├── test_protocols_ftp.py
│ └── test_protocols_http.py
├── wordlists/ # 最小冒烟测试桩
└── output/ # 生成的日志与报告(git 忽略)
攻击成功率(参考值)
贡献
请参阅 CONTRIBUTING.md。
提交大型 PR 前请先开启 issue。
所有贡献必须遵守 SECURITY.md 中的道德使用政策。
负责任地使用。合乎道德地测试。保持合法。