CobaltoSec/kestrel
GitHub: CobaltoSec/kestrel
Kestrel 是一个 AI 原生的 HTB 交战编排框架,通过智能指纹分类和分阶段工作流将目标侦察到漏洞利用的流程自动化,减少人工决策点并支持跨会话恢复。
Stars: 1 | Forks: 0

[](LICENSE)
# Kestrel — AI 原生 HTB 交战框架
Kestrel 是一个 [Claude Code](https://claude.ai/code) 技能,它在对目标 VM 执行操作之前应用一个智能层。它不运行通用的扫描,而是首先对目标进行分类——然后引导执行指向可能的攻击链,并实时进行叙述。
## 为什么
大多数 HTB 自动化要么运行完全盲目的侦察(缓慢、嘈杂),要么要求你已经知道攻击链。Kestrel 介于两者之间:指纹识别 → 知识查询 → 定向执行——将大约 19 个人工决策点减少到约 6 个。
## 架构 — 4 层
```
┌─────────────────────────────────────────────────────────┐
│ 4. MEMORY │
│ estado.md · state.json · writeup.md │
│ KB synthesis · cross-session resume │
│ → persists between sessions, learns from each run │
├─────────────────────────────────────────────────────────┤
│ 3. EXECUTION │
│ delegated to /pentest --mode lab │
│ discovery → vuln → exploit │
│ → Kestrel orchestrates, doesn't execute directly │
├─────────────────────────────────────────────────────────┤
│ 2. ORCHESTRATION │
│ phases p0 → p1 → p1.5 → p2 → p3 → p4 → p5 → p6 │
│ mode switching · HITL gates · continuous narration │
│ → workflow engine, core of Kestrel │
├─────────────────────────────────────────────────────────┤
│ 1. INTEL │
│ WebSearch retired + blind_fingerprint.py active │
│ intel.md · fingerprint.json · optional KB query │
│ → the hover before the dive │
└─────────────────────────────────────────────────────────┘
```
## 模式
| 模式 | 适用场景 | 情报来源 |
|---|---|---|
| **Guided** | 已退役机器 | WebSearch writeup 综合 → `intel.md` → 定向执行 |
| **Blind** | 活动机器 | `blind_fingerprint.py` 发现后处理 → 攻击类别分类 → 可选的 KB 查询 |
HTB TOS:禁止搜索活跃机器的 writeup。Blind 模式是合规的途径。
## 独立脚本
这两个脚本可以完全独立于完整的 Claude Code 技能运行。
### `scripts/blind_fingerprint.py`
根据 nmap/httpx 的输出,将目标分类并附带置信度分数归入相应的攻击类别。
```
# 从 nmap 文件
python3 scripts/blind_fingerprint.py \
--nmap /tmp/scan.gnmap \
--target 10.10.10.x \
--os Windows \
--difficulty Medium \
--output ./fingerprint.json
# 或者内联 JSON(无需文件)
python3 scripts/blind_fingerprint.py \
--ports-json '{"ports":["88","445","389"],"services":["kerberos","smb","ldap"],"banners":[]}' \
--target 10.10.10.x \
--output ./fingerprint.json
```
示例输出:
```
{
"target_ip": "10.10.10.x",
"os_likely": "windows",
"ad_joined": true,
"attack_categories": [
{"category": "ad-abuse", "confidence": 0.92, "tactics": [3, 6, 8, 9, 10]},
{"category": "smb-exploit", "confidence": 0.70, "tactics": [3, 4, 10]}
],
"summary": "Windows host. Top path: ad-abuse (conf=0.92). ATT&CK tactics: 3, 6, 8."
}
```
可选:连接到 pgvector KB 以获取技术上下文(设置 `KESTREL_KB_PATH` — 参见 `.env.example`)。
### `scripts/resume_validator.sh`
在恢复会话之前验证会话状态:VPN 已连接、机器可达、监听器活跃。专为在 Kali VM 上运行而设计。
```
MACHINE_IP=10.10.10.x \
LISTENERS_JSON='[{"pid":1234,"port":9001,"type":"nc","cmd":"nc -lvnp 9001"}]' \
bash scripts/resume_validator.sh
```
输出:
```
{
"vpn_up": true,
"machine_reachable": false,
"listeners_alive": [{"port": 9001, "alive": false}],
"needs_recovery": true,
"recovery_actions": ["respawn_machine", "restart_listener_9001"]
}
```
## ATT&CK 覆盖范围
| 战术 | # | Kestrel 如何覆盖 |
|---|---|---|
| Reconnaissance | 1 | p1.5 WebSearch(Guided 模式)+ blind_fingerprint.py 端口/ banner 分类(Blind 模式) |
| Initial Access | 3 | p3 exploit 阶段通过 /pentest |
| Execution | 4 | p3 获取立足点后的命令 |
| Privilege Escalation | 6 | p3 LinPEAS/WinPEAS + 来自 intel 的 guided 向量 |
| Credential Access | 8 | hash 识别 + Hash Policy 自动化(上限 5 分钟 → GPU 卸载) |
| Discovery | 9 | p3 PASO 1 + fingerprint.py 分类 |
缺口(仅限复杂攻击链):Persistence (5)、Defense Evasion (7)、Lateral Movement (10) — 在检测到时通过委派给 `/pentest-ad` 处理。
## 环境要求
- Python 3.10+
- [Claude Code](https://claude.ai/code) CLI(用于完整的编排技能)
- 具备 SSH 访问权限的 Kali Linux VM(执行平台)
- HTB VPN 连接
- 可选:pgvector + Ollama 用于增强 KB 的 blind 模式
## 配置
```
cp .env.example .env
# 使用您的值编辑 .env
```
## 状态
- **v0.1.0** (2026-05-08):核心框架 — blind 指纹识别 + 跨会话恢复 + 架构文档
- **v0.2** (路线图):多路径假设 + L3 反馈循环 + 活跃 Hard 机器验证
- **v0.3** (路线图):净化后的阶段库 + 完整案例分析 + 与 AutoPwn/HackBot 对比
## 案例分析
- **Kobold**(Easy Linux,已退役)— CVE-2026-23520 命令注入 → Docker socket 逃逸 → root。Guided 模式,约 90 分钟,intel 匹配=完全。
- **Garfield**(Hard Windows,已退役)— blind 模式验证;攻击链:SYSVOL → RBCD → KeyList 攻击。遇到 HTB flag 重新生成 bug(已记录,非 Kestrel 问题)。
由 [CobaltoSec](https://cobalto-sec.tech) 构建 · 进阶安全平台工程
标签:AI智能体, AI风险缓解, Claude Code, 安全, 实时处理, 密码管理, 应用安全, 数据展示, 红队, 超时处理, 运行时操纵, 逆向工具