Dev9269/ssh-honeypot
GitHub: Dev9269/ssh-honeypot
一款集成了 Ollama AI 分析、MITRE ATT&CK 映射和实时监控仪表盘的现代化 SSH 蜜罐平台,用于网络安全研究与威胁情报收集。
Stars: 0 | Forks: 0
# 🛡️ SSH Honeypot v2.0
[](https://github.com/Dev9269/ssh-honeypot)
[](https://github.com/Dev9269/ssh-honeypot/forks)
[](LICENSE)
[](https://python.org)
[](https://docker.com)
[](https://attack.mitre.org)
[](https://github.com/Dev9269/ssh-honeypot/pulls)
[](https://github.com/Dev9269/ssh-honeypot/actions/workflows/ci.yml)
[](https://github.com/sponsors/Dev9269)
[](https://www.buymeacoffee.com/jainammaru)
一个现代化、可用于生产环境的 SSH Honeypot 平台,用于网络安全研究、威胁情报收集和攻击模式分析。
**作者** [Jainam Maru](https://github.com/Dev9269)
## v2.0 最新特性
- **Fake Shell 交互** — 在逼真的 Linux shell 环境中捕获攻击者命令
- **IP 地理定位** — 将攻击者 IP 映射到城市/国家/ASN(使用 GeoIP2 或 ip-api.com 作为备选)
- **威胁情报** — 集成 AbuseIPDB、AlienVault OTX 和 VirusTotal
- **实时告警** — 支持 Webhook、Slack、Discord 和邮件通知
- **Web 仪表盘** — 基于 FastAPI 并带有身份验证的实时监控 UI
- **SQLite 数据库** — 结构化存储,便于查询和分析
- **MITRE ATT&CK 映射** — 使用 TTP ID 自动标记攻击
- **速率限制** — 基于单 IP 的连接限流并支持自动封禁
- **动态指纹** — 随机化 SSH banner 以规避检测
- **日志轮转** — 具备大小/备份数量限制的自动轮转机制
- **YAML 配置** — 通过 `honeypot.yaml` 进行全面配置
- **Docker 支持** — 结合 docker-compose 进行容器化部署
- **SFTP 模拟** — 逼真的虚假文件传输环境
- **Prometheus Metrics** — 提供 /metrics endpoint 用于监控
## 功能
| 功能 | 描述 |
|---------|-------------|
| SSH 模拟 | 逼真的 OpenSSH banner 伪装,支持动态指纹轮转 |
| 认证日志 | 捕获用户名、密码、密钥指纹、认证方式及时间戳 |
| 命令捕获 | Fake shell 会记录攻击者执行的每一条命令 |
| 地理定位 | IP → 位置映射(离线 GeoIP2 或免费的 ip-api.com API) |
| 威胁评分 | 多源威胁情报评分(0-10) |
| MITRE ATT&CK | 自动将攻击分类至 TTP 框架(T1110, T1059, T1098 等) |
| 告警 | 支持 Webhook、Slack、Discord、SMTP 邮件通知 |
| 仪表盘 | 提供 Web UI 实时展示统计信息、高频 IP 及近期攻击 |
| 速率限制 | 基于单 IP 的连接数限制并支持自动临时封禁 |
| IP 过滤 | 基于 IP 或 CIDR 范围的白名单/黑名单 |
| 数据库 | 使用 SQLite 进行结构化查询和分析 |
| Docker | 通过 Dockerfile + docker-compose 进行容器化部署 |
| macOS .app | 原生支持 macOS 应用程序 |
## 快速开始
### 安装说明
```
git clone https://github.com/Dev9269/ssh-honeypot.git
cd ssh-honeypot
pip install -r requirements.txt
```
### 基本用法
```
python main.py
```
### 启用仪表盘
```
python main.py --dashboard
# 打开 http://127.0.0.1:8080 (用户: admin, 密码: admin)
```
### 使用 YAML 配置
```
python main.py --config honeypot.yaml
```
## 命令行选项
```
python main.py --help
Options:
--host HOST Host interface (default: 0.0.0.0)
--port PORT Port (default: 2222)
--config CONFIG Path to YAML config file
--dashboard Enable web dashboard
--no-shell Disable fake shell
--no-geo Disable geolocation
--no-db Disable database logging
--blacklist BLACKLIST Comma separated IPs/CIDRs to block
--whitelist WHITELIST Comma separated IPs/CIDRs to allow
--version Show version
```
## 控制台输出
```
[*] SSH Honeypot v2.0.0 listening on 0.0.0.0:2222
[*] Fake banner: SSH-2.0-OpenSSH_7.9p1 Debian-10
[*] Logs: logs/attacks.log, logs/attacks.json
[*] Database: logs/honeypot.db
[*] Geolocation: enabled
[*] Threat Intelligence: enabled
[*] Alerts: enabled
[*] Fake Shell: enabled (ubuntu-server)
[*] Dashboard: http://127.0.0.1:8080
[*] Press Ctrl+C to stop
[+] Connection from 192.168.1.100:54321 [New York, US] [threat: 6/10]
[+] Connection from 10.0.0.5:12345 [London, GB] [threat: 0/10]
[!] Rate limit exceeded for 203.0.113.5
[-] Connection closed from 192.168.1.100 (duration: 12.5s)
```
## Fake Shell 示例
当攻击者建立连接时(Honeypot 会拒绝认证,但仍会提供一个 shell 环境):
```
Linux ubuntu-server 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2025 x86_64 GNU/Linux
root@ubuntu-server:/root$ whoami
root
root@ubuntu-server:/root$ id
uid=0(root) gid=0(root) groups=0(root)
root@ubuntu-server:/root$ uname -a
Linux ubuntu-server 5.15.0-91-generic #101-Ubuntu SMP...
root@ubuntu-server:/root$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
root@ubuntu-server:/root$ exit
logout
```
所有命令都将记录到 `attacks.log`、`attacks.json` 以及 SQLite 数据库中,并附带 MITRE ATT&CK 分类。
## Docker 部署
```
# 构建并运行
docker-compose up --build
# 或手动构建
docker build -t ssh-honeypot .
docker run -d -p 2222:2222 -p 8080:8080 ssh-honeypot
```
## 项目结构
```
ssh-honeypot/
├── honeypot/
│ ├── __init__.py
│ ├── server.py # SSH server + client handler
│ ├── shell.py # Fake shell with command responses
│ ├── config.py # Configuration (YAML + defaults)
│ ├── logger.py # Logging (.log, .json, rotation)
│ ├── db.py # SQLite database backend
│ ├── geo.py # IP geolocation (GeoIP2 + ip-api.com)
│ ├── intel.py # Threat intelligence (AbuseIPDB, OTX, VT)
│ ├── alerts.py # Alerting (webhook, Slack, Discord, email)
│ ├── ratelimiter.py # Per-IP rate limiter with auto-ban
│ ├── analyzer.py # MITRE ATT&CK framework mapping
│ ├── dashboard.py # FastAPI web dashboard
│ └── sftp_server.py # SFTP simulation
├── logs/ # Attack logs + database
├── main.py # Entry point
├── honeypot.yaml # YAML configuration
├── Dockerfile # Docker build
├── docker-compose.yml # Docker compose
├── requirements.txt # Python dependencies
└── README.md
```
## 配置 (YAML)
所有设置均可通过 `honeypot.yaml` 进行配置:
```
server:
host: 0.0.0.0
port: 2222
rate_limit:
max_connections: 10
window: 60
ban_duration: 300
alerts:
enabled: true
slack_webhook: "https://hooks.slack.com/services/..."
discord_webhook: "https://discord.com/api/webhooks/..."
min_severity: medium
```
完整选项请查看 `honeypot.yaml` 文件。
## 日志文件
### attacks.log (人类可读)
```
2026-06-24 14:30:22,123 - IP: 192.168.1.100 | Username: root | Password: password123 | Method: password | MITRE: T1110:Brute Force
2026-06-24 14:30:45,678 - Activity | IP: 10.0.0.5 | command: whoami
```
### attacks.json (结构化)
```
[
{
"event": "auth_attempt",
"timestamp": "2026-06-24T14:30:22.123456",
"ip": "192.168.1.100",
"username": "root",
"password": "password123",
"method": "password",
"mitre": "T1110:Brute Force"
}
]
```
### SQLite 数据库
直接查询攻击数据:
```
sqlite3 logs/honeypot.db "SELECT ip, username, password FROM auth_attempts ORDER BY timestamp DESC LIMIT 10;"
```
## MITRE ATT&CK 覆盖范围
| 技术 | ID | 检测依据 |
|-----------|----|-------------|
| 暴力破解 | T1110 | 密码认证尝试 |
| 账户操纵 | T1098 | SSH 密钥认证尝试 |
| 命令与脚本 | T1059 | Shell 命令执行 |
| 网络发现 | T1046 | 侦察命令 (nmap 等) |
| 远程服务 | T1021 | 横向移动命令 |
| 权限提升 | T1068 | sudo/chown 命令 |
| 防御规避 | T1562 | rm -rf, shutdown 等 |
| 数据收集 | T1005 | tar, zip, find 命令 |
## 安全提示
**本工具仅供经过授权的安全研究与教育使用。**
- 仅在您拥有或已获授权监控的网络中部署
- 遵守所有适用法律法规
- 作者不对任何滥用行为承担责任
## 开源许可
MIT License — 详见 [LICENSE](LICENSE)
## 致谢
- [Paramiko](https://www.paramiko.org/) — SSH 协议库
- [MaxMind GeoIP2](https://www.maxmind.com/) — 地理定位数据
- [AbuseIPDB](https://www.abuseipdb.com/) — 威胁情报
- [MITRE ATT&CK](https://attack.mitre.org/) — TTP 框架标签:AI风险缓解, DLL 劫持, LLM评估, Ollama, PE 加载器, SSH, 大语言模型, 威胁情报, 开发者工具, 自定义请求头, 蜜罐, 证书利用, 请求拦截, 逆向工具