dblanko/honeypot-analysis

GitHub: dblanko/honeypot-analysis

一套基于真实攻击数据的蜜罐日志分析脚本集,主要对 Cowrie 等蜜罐的会话、凭据、payload 和攻击者行为进行自动化统计与取证分析。

Stars: 0 | Forks: 0

# honeypot-analysis 用于 Cowrie、OpenCanary、Dionaea 和 Telnethoney 蜜罐的分析脚本。 [SSHLab 安全研究系列](https://sshlab.eu) 的一部分 —— 包含六本关于蜜罐部署和日志分析的书籍,使用了来自运行中的 VPS 的真实攻击数据。 ## 这是什么 一台 VPS 同时运行五个蜜罐传感器: - **Cowrie** — SSH/Telnet 蜜罐(凭据收集、会话记录、payload 捕获) - **OpenCanary** — 多服务蜜罐(RDP、MSSQL、HTTP、SMB、MySQL) - **Dionaea** — 恶意软件蜜罐(通过 SMB、MySQL、MSSQL 进行完整二进制文件捕获) - **Telnethoney** — 自定义 IoT/Telnet 蜜罐(自行编写,模拟 BusyBox 路由器) - **Suricata** — 网络 IDS(跨传感器关联) 所有脚本均基于此部署收集的真实数据运行。 没有合成数据集,没有实验室环境。 ## 仓库结构 ``` cowrie/ install_dynamic_fs.sh — corporate honeyfs setup script log_loader.py — core log loader (used by all other scripts) analyze_cowrie.py — 10-day overview report analyze_creds_commands.py — credential and command frequency analysis session_analysis.py — session-level behavioral analysis attacker_profiling.py — per-IP profiling + MITRE ATT&CK mapping classify_cowrie.py — session classifier (HASSH + regex + ML/KMeans) extract_downloads.py — downloaded payload grouping by SHA256 analyze_uploads.py — SFTP upload analysis analyze_payloads.py — static binary analysis (entropy, IoC, architecture) generate_time_activity.py — hourly and daily attack timing charts attack_stats.py — full statistics report with ASCII bar charts analyze_chains.py — attack chain reconstruction timeline_builder.py — forensic session timeline with millisecond deltas opencanary/ — coming soon dionaea/ — coming soon telnethoney/ — coming soon suricata/ — coming soon ``` ## Cowrie — 企业 honeyfs 默认的 Cowrie 文件系统看起来像是一个普通的 Debian 安装 —— 经验丰富的攻击者会立即识别出它。`install_dynamic_fs.sh` 将其替换为一个模拟的企业集群,包括: - Kubernetes, Docker, Ansible, Terraform, Jenkins, GitLab Runner - PostgreSQL, MySQL, Redis, RabbitMQ, Kafka, Zookeeper - Prometheus, Grafana, Elasticsearch, Logstash, Kibana - HashiCorp Vault, Consul, Nomad, Harbor registry, MinIO - 伪造凭据、SSH 密钥、数据库转储以及 CI/CD 产物 每次运行都会生成随机的用户名、密码、GitHub token 和攻击者 IP —— 因此环境在每个会话中看起来都不一样。 所有脚本使用的 **日志路径**: ``` LOG_DIR = '/home/cowrie/cowrie/var/log/cowrie' ``` 如果你的安装使用了不同的路径,请在每个脚本顶部编辑此常量。 ## 脚本依赖 大多数脚本是独立的。两个例外: **`log_loader.py`** 被 `session_analysis.py`、`attacker_profiling.py` 和 `classify_cowrie.py` 用作共享模块。请将其保持在同一目录中。 **`analyze_chains.py`** 需要首先由其他脚本生成三个输入文件: ``` malware_commands.json ← from analyze_creds_commands.py malware_files.json ← from extract_downloads.py malware_uploads.json ← from analyze_uploads.py ``` ## 示例输出 **analyze_cowrie.py** — 10 天概览 ``` ================================================== COWRIE 10-DAY REPORT ================================================== Unique sessions : 52,278 Unique IPs : 1,585 Top 10 IPs: 45.148.10.183 19,586 94.154.35.215 16,346 45.148.10.240 16,145 2.57.122.177 14,430 185.246.128.133 12,196 Top passwords (successful logins): toor 2,683 3245gs5662d34 2,512 admin 171 firedancer 165 Top commands: 3499 uname -s -v -n -r -m 2587 cd ~; chattr -ia .ssh; lockr -ia .ssh 2587 cd ~ && rm -rf .ssh && mkdir .ssh && echo "ssh-rsa ... ``` **classify_cowrie.py** — 会话分类器(HASSH + regex + ML) ``` [+] Sessions loaded: 1,854 [+] Classified: 1,854 sessions family Cluster-0 1,349 (unclassified, ML-grouped) Go-scanner 253 (SSH-2.0-Go crypto-targeting scanner) Cluster-1 151 mdrfckr 77 (libssh_0.11.1 SSH backdoor) Gafgyt 19 (DDoS bot loader) ``` **attack_stats.py** — 带有 ASCII 条形图的完整统计数据 ``` ============================================================ COWRIE HONEYPOT — FULL STATISTICS REPORT ============================================================ Connections : 1,854 Unique sessions : 1,857 Unique IPs : 100 Login failures : 1,478 Login successes : 432 Commands logged : 335 Payload downloads: 77 === HASSH Fingerprints (top 5) === 0a07365c 709 Unknown f555226d 494 Unknown 16443846 253 Go-scanner / SSH-2.0-Go a7a87fbe 19 Gafgyt loader === Session Duration Distribution === <1s ███████ 266 1-5s ████████████████████████████████████████ 1,354 5-30s █████ 192 30s-2m 26 >2m 19 ``` **timeline_builder.py** — 取证会话时间线 ``` SESSION b890da0fdc04 IP 103.14.33.174 EVENTS 13 + 0ms (+ 0ms) [CONNECT ] + 1ms (+ 1ms) [VERSION ] SSH-2.0-libssh_0.9.6 + 216ms (+ 215ms) [HASSH ] hassh=f555226df1963d1d + 1116ms (+ 899ms) [SUCCESS ] root:Welcome12! + 1560ms (+ 1ms) [CMD ] cd ~; chattr -ia .ssh; lockr -ia .ssh + 2263ms (+ 228ms) [CMD ] cd ~ && rm -rf .ssh && mkdir .ssh && echo "ssh-rsa... + 2482ms (+ 218ms) [DOWNLOAD] sha=a8460f446be5... + 6597ms (+ 4113ms) [CLOSE ] duration=6.6s ``` ## 环境要求 ``` pip install pandas matplotlib scikit-learn ``` `analyze_payloads.py` 还使用系统工具:`file`、`strings`、`readelf`、`upx` (在大多数 Linux 系统上可用,可通过 `apt install binutils upx-ucl` 安装) ## 书籍 这些脚本是安全研究系列中记录的分析工具的维护版本。与印刷附录的一些差异反映了路径修正和发布后的增强功能。 | 书籍 | 蜜罐 | 脚本 | |------|----------|---------| | [Book 1 — Cowrie SSH 蜜罐](https://leanpub.com/cowrie) | Cowrie | `cowrie/` | | Book 2 — OpenCanary | OpenCanary | `opencanary/` (即将推出) | | Book 3 — Dionaea 恶意软件蜜罐 | Dionaea | `dionaea/` (即将推出) | | Book 4 — Telnethoney IoT | Telnethoney | `telnethoney/` (即将推出) | | Book 5 — Suricata | Suricata | `suricata/` (即将推出) | | Book 6 — 关联分析 | 所有传感器 | — | 完整系列和博客:[sshlab.eu](https://sshlab.eu) ## License MIT — 见 [LICENSE](LICENSE) 脚本可自由使用。如果您在研究或写作中使用它们,请注明 SSHLab Research。
标签:Metaprompt, PE 加载器, Python, 代码示例, 威胁情报, 开发者工具, 攻击溯源, 数据分析, 无后门, 蜜罐, 证书利用, 逆向工具