cognis-digital/c2detect
GitHub: cognis-digital/c2detect
基于内置签名库离线扫描遥测数据,识别二十种主流 C2 框架指纹的防御性安全检测工具。
Stars: 26 | Forks: 7

# C2DETECT
### C2 服务器指纹识别工具 — Cobalt Strike, Sliver, Mythic, Havoc, Brute Ratel

[](https://pypi.org/project/cognis-c2detect/) [](https://github.com/cognis-digital/c2detect/actions) [](LICENSE) [](https://github.com/cognis-digital)
*红队 / 进攻性安全 — 用于授权交战的对手工具。*
```
pip install cognis-c2detect
c2detect scan . # → prioritized findings in seconds
```
## 使用说明 — 逐步指南
`c2detect` 是一款用于防御性 C2 基础设施的筛选工具:它根据内置的签名数据库扫描遥测/观测记录,并标记信标通信、可疑的 TLS 指纹以及 staging URI。无网络请求,无主动探测能力。
1. **安装** (Python 3.10+):
pip install -e . # 或者:pipx install c2detect
2. **扫描观测文件 / 遥测文本 / 目录 / stdin**:
c2detect scan telemetry.json
cat telemetry.log | c2detect scan
3. 在命令行**匹配显式指标**(无需文件):
c2detect match --ja4 t13d1516h2_8daaf6152771_b186095e22b6 --port 443 --beacon-interval 60 --jitter 0.1
c2detect db # 列出内置的 C2 签名数据库
4. 以 JSON / SARIF / HTML / badge(例如用于代码扫描)格式**读取输出**:
c2detect scan telemetry.json --format sarif > c2.sarif
c2detect scan telemetry.json --format json | jq '.findings'
5. 使用 `--fail-on
`(在该严重级别或更高时以非零状态退出)**拦截 CI**。可选的 `--ai` 会增加一个自愿开启的 Cognis-fleet LLM 处理流程,如果未配置后端则降级为基于规则的检测:
- 运行:pip install -e . && c2detect scan telemetry.json --fail-on high
## 目录
## 为什么选择 c2detect?
C2 服务器指纹识别工具 — 涵盖 Cobalt Strike, Sliver, Mythic, Havoc, Brute Ratel — 无需搭建繁重的基础设施。
`c2detect` 具有单一用途、可脚本化且支持自托管:将其指向目标,即可获得符合您现有工作流优先格式的排序结果(表格 · JSON · SARIF),在此基础上拦截 CI,并允许代理通过 MCP 驱动它。
## 功能
- ✅ **20 个 C2 家族**指纹识别 — Cobalt Strike, Metasploit, Sliver, Covenant, Mythic, Brute Ratel, Empire, Havoc, PoshC2, Merlin, Deimos, NimPlant, Villain, Caldera, Pupy, Koadic, SILENTTRINITY, Godzilla + 通用自签名/信标启发式检测
- ✅ **TLS 及行为指标** — JA4 / JA4S / JA4X / JA3 / JA3S / JARM,以及**信标通信间隔/抖动节律**、校验和/编码的 **URI 正则表达式**、默认的 **User-Agents**、证书特征及端口
- ✅ 输出:**表格 · JSON · SARIF · HTML 报告 · shields.io 徽章**
- ✅ **可重用的 GitHub Action** (`uses: cognis-digital/c2detect@main`) — 在 PR 上评论发现结果,根据 `--fail-on` 使 CI 失败
- ✅ **自愿开启的 AI 模式** (`--ai`) 基于您的本地 Cognis 集群运行 — **默认关闭**,不开启时结果确定且基于规则
- ✅ 支持 Linux/macOS/Windows · Docker · devcontainer · MCP 服务器
- ✅ 支持 Python, JavaScript, Go 和 Rust 多语言移植版本 (`ports/`)
- 🛡️ 严格用于**防御** — 仅从观测结果进行检测,无网络交互,无主动探测能力
## 快速开始
```
pip install cognis-c2detect
c2detect --version
c2detect scan . # scan current project
c2detect scan . --format json # machine-readable
c2detect scan . --fail-on high # CI gate (non-zero exit)
```
## 示例
```
$ c2detect scan .
[HIGH ] C2D-001 example finding (./src/app.py)
[MEDIUM ] C2D-002 another signal (./config.yaml)
2 findings · risk score 5 · 38ms
```
## 检测深度
`c2detect` 根据包含 **20 个 C2 家族**的内置数据库对每个观测结果进行评分。
每个家族都是*观测性*指标的组合 — 这里不描述攻击本身,只包含防御者能够发现的默认配置特征:
| 指标类别 | 示例 |
|---|---|
| **TLS 指纹** | JA4, JA4S, JA4X (x509), JA3, JA3S, JARM |
| **行为** | 信标通信间隔窗口 + 抖动上限(例如 CS 默认 60s / ~0% 抖动),URI 校验和/编码正则表达式 |
| **HTTP** | 默认 User-Agent 字符串,伪造的 `Server` 响应头,默认监听器 URI |
| **PKI** | 证书主题/颁发者/序列号特征(例如 *“Major Cobalt Strike”*,序列号 `146473198`) |
| **网络** | 默认监听端口(权重较低,仅作佐证) |
置信度(0–100)是加权综合计算的结果;两个或多个*强*指标可获得佐证奖励。使用 `--threshold` 调整下限。有关节律/抖动启发式算法,请参阅 [`demos/03-behavioral`](demos/03-behavioral)。
## GitHub Action
在 CI 中扫描遥测数据,在 PR 上评论发现结果,并在达到严重性阈值时使构建失败 —
只需将以下内容放入任意代码仓库的 `.github/workflows/c2detect.yml` 中:
```
name: c2detect
on: [push, pull_request]
permissions:
contents: read
pull-requests: write # to comment findings on PRs
security-events: write # to upload SARIF
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cognis-digital/c2detect@main
with:
path: telemetry/ # file or dir to scan
format: sarif # table | json | sarif | html | badge
fail-on: high # fail the build at/above this severity
threshold: "35" # min confidence to report
comment-pr: "true" # post a findings comment via gh api
```
## 状态徽章
`--format badge` 会输出一个可供您托管和引用的 [shields.io 端点](https://shields.io/endpoint) JSON:
```
c2detect scan telemetry/ --format badge > badge.json
# {"schemaVersion":1,"label":"c2detect","message":"clean","color":"brightgreen"}
```
```

```
## HTML 报告
```
c2detect scan telemetry/ --format html > report.html # clean, self-contained
```
一个独立的 HTML 文件(无外部资源依赖),包含基于主机的发现结果、严重性标记、指标分解以及任何 AI 建议的候选项。
## AI 模式(自愿开启,默认关闭)
添加 `--ai`,在扫描器已处理的**相同**数据源之上叠加一层基于本地集群的 LLM 分析。AI 的发现结果会被合并进来,标记为 `source="ai"`,标记出新候选对象,并与确定性规则的发现结果进行**去重**:
```
# 指向 LOCAL OpenAI 兼容 endpoint(没有任何数据离开本机):
export COGNIS_AI_BACKEND=uncensored-fleet # or COGNIS_AI_ENDPOINT=http://127.0.0.1:8774/v1
c2detect scan telemetry/ --ai
```
保证:
- **默认关闭。** 不使用 `--ai` 时,输出结果为**逐字节确定性**的,且不包含任何 AI 密钥。
- **绝不崩溃。** 如果指定了 `--ai` 但未配置后端,或后端无法访问,`c2detect` 将打印明确的提示,并仅继续输出基于规则的发现结果。
- **本地优先。** 支持 `COGNIS_AI_BACKEND` / `COGNIS_AI_ENDPOINT` / `COGNIS_AI_MODEL` / `COGNIS_AI_KEY` — 专为 [uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet) 和 `cognis-code` 本地端点设计。
## 架构
```
flowchart LR
IN[input] --> P[c2detect
analyze + score]
P --> OUT[report]
```
## 在任何 AI 技术栈中使用
`c2detect` 可与目前所有主流的 AI 使用方式互操作:
- **MCP 服务器** — `c2detect mcp` (Claude Desktop, Cursor, Cognis.Studio, [uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet))
- **OpenAI 兼容 / JSON** — 通过管道将 `c2detect scan . --format json` 传给任何代理或 LLM
- **LangChain · CrewAI · AutoGen · LlamaIndex** — 只需一行代码即可将 CLI/JSON 封装为工具
- **CI / 脚本** — 为非 AI 流水线提供退出代码 + SARIF
## 功能对比
| | **Cognis c2detect** | salesforce |
|---|:---:|:---:|
| 可自托管,无需账号 | ✅ | 视情况而定 |
| 单条命令,零配置 | ✅ | ⚠️ |
| 适用于 CI 的 JSON + SARIF | ✅ | 视情况而定 |
| MCP 原生支持 (AI 代理) | ✅ | ❌ |
| 多语言移植 (JS/Go/Rust) | ✅ | ❌ |
| 开源许可 | ✅ COCL | 视情况而定 |
*秉持 **salesforce/jarm** 的精神,以 Cognis 的方式重新构建。遗漏了致谢?欢迎提交 PR。*
## 集成
可接入您的技术栈:用于代码扫描的 **SARIF**,用于任何场景的 **JSON**,面向 AI 代理的 **MCP 服务器** (`c2detect mcp`),以及用于 SIEM/Slack/Jira 的 webhook 转发器。详见 [`docs/INTEGRATIONS.md`](docs/INTEGRATIONS.md)。
## 安装 — 各种方式,全平台支持
```
pip install "git+https://github.com/cognis-digital/c2detect.git" # pip (works today)
pipx install "git+https://github.com/cognis-digital/c2detect.git" # isolated CLI
uv tool install "git+https://github.com/cognis-digital/c2detect.git" # uv
pip install cognis-c2detect # PyPI (when published)
docker run --rm ghcr.io/cognis-digital/c2detect:latest --help # Docker
brew install cognis-digital/tap/c2detect # Homebrew tap
curl -fsSL https://raw.githubusercontent.com/cognis-digital/c2detect/main/install.sh | sh
```
| Linux | macOS | Windows | Docker | Cloud |
|---|---|---|---|---|
| `scripts/setup-linux.sh` | `scripts/setup-macos.sh` | `scripts/setup-windows.ps1` | `docker run ghcr.io/cognis-digital/c2detect` | [DEPLOY.md](docs/DEPLOY.md) (AWS/Azure/GCP/k8s) |
## 相关 Cognis 工具
- [`payloadlab`](https://github.com/cognis-digital/payloadlab) — 静态恶意负载分析器 — PE/ELF/LNK/macro/OneNote
- [`redpath`](https://github.com/cognis-digital/redpath) — Active Directory 攻击路径映射工具 — 最小成本路径 + 修复优先级
- [`pwnreview`](https://github.com/cognis-digital/pwnreview) — 渗透测试报告生成器 — 将 YAML 结果转化为 CREST 级别的 PDF
- [`crackq`](https://github.com/cognis-digital/crackq) — 自托管密码破解队列 — 带有审计日志的多用户 hashcat
**探索全套装工具 →** [🗂️ 所有 170+ 工具](https://github.com/cognis-digital/cognis-neural-suite) · [⭐ awesome-cognis](https://github.com/cognis-digital/awesome-cognis) · [🔗 cognis-sources](https://github.com/cognis-digital/cognis-sources) · [🤖 uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet) · [🧠 engram](https://github.com/cognis-digital/engram)
## 互操作性
`{}` 可与包含 300+ 工具的 Cognis 套件组合使用 — JSON 输入/输出以及共享的 OpenAI 兼容 `/v1` 骨干网络。有关套件图谱、组合模式及参考技术栈,请参阅 **[INTEROP.md](INTEROP.md)**。
## 许可证
在 **Cognis Open Collaboration License (COCL) v1.0** 协议下提供源码(源代码可见) — 个人使用、内部评估、研究和教育用途免费;**商业 / 生产环境使用需要获得** (licensing@cognis.digital)。详见 [LICENSE](LICENSE)。
Cognis Digital · Cognis Neural Suite 170+ 工具之一 · Making Tomorrow Better Today 标签:Blue Team, C2日志可视化, IP 地址批量处理, Python, 云存储安全, 命令与控制(C2), 威胁情报, 开发者工具, 指纹识别, 无后门, 网络扫描, 请求拦截, 逆向工具