craigderington/spectre-ssh-honeypot
GitHub: craigderington/spectre-ssh-honeypot
一个用 Go 编写的高保真 SSH/TTY 蜜罐系统,通过模拟 Linux Shell 环境捕获攻击者会话并提供可视化威胁情报仪表板。
Stars: 0 | Forks: 0
# SpecterPot 🛡️
SpecterPot 是一个高保真的开源 SSH/TTY 蜜罐和威胁情报仪表板。它接受任何登录尝试,生成一个完全模拟的 Linux 命令 shell,记录所有使用的凭证,并将整个终端会话(逐个按键)记录在 PostgreSQL 数据库中,以供实时监控和回放。
## 功能
- **SSH 蜜罐服务器**:采用 Go 实现,接受密码和公钥认证尝试。
- **模拟 PTY Shell**:模拟标准的 Ubuntu 实用程序(`whoami`、`ls`、`cat /etc/passwd`、带有模拟下载指示器的 `wget`/`curl`、`sudo`、`apt-get`、`top` 等)。
- **实时终端流**:WebSocket 通道将实时按键和输出广播到 Web UI。
- **可视化回放播放器**:由 `xterm.js` 提供支持的交互式终端播放器,可通过可调速度控制(1x、2x、5x、10x)重现黑客会话。
- **威胁分析仪表板**:时尚的玻璃拟态暗色模式界面,用于追踪最常被攻击的凭证(用户名/密码)、源 IP、Bot 命令以及活动/历史日志。
- **生产级就绪部署**:预配置的 Docker Compose 技术栈,包含 PostgreSQL。
## 项目结构
```
.
├── api.go # REST HTTP Handlers & WebSocket coordination
├── database.go # PostgreSQL schema migrations & statistics queries
├── main.go # Entry point initializing servers
├── ssh_server.go # SSH Server, PTY emulator, and mock commands
├── Dockerfile # Multi-stage Go and static web compiler
├── docker-compose.yml # Containerized application stack
├── .gitignore
├── web/ # Frontend Single Page App (SPA)
│ ├── index.html # Dashboard layout & CDNs
│ ├── style.css # Custom dark cyberpunk styling
│ └── app.js # WS client, players, and page state manager
└── README.md # Project documentation
```
## 本地开发设置
### 1. 运行 PostgreSQL 数据库
启动一个本地 PostgreSQL 实例:
```
docker run --name specterpot-postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=specterpot \
-p 5432:5432 -d postgres:15-alpine
```
### 2. 运行应用程序
设置环境变量并启动 Go 后端:
```
# 设置环境(默认为 localhost db)
export DATABASE_URL="postgres://postgres:postgres@localhost:5432/specterpot?sslmode=disable"
export SSH_PORT="2222"
export API_PORT="8080"
# 获取 packages 并执行
go run *.go
```
在 Web 浏览器中打开 [http://localhost:8080](http://localhost:8080)。你可以从另一个终端登录来测试蜜罐:
```
ssh anyuser@localhost -p 2222
# 输入一些命令(例如,whoami、ls、curl http://malware.com/exec)
```
## 生产环境部署 (AWS Lightsail / Docker Compose)
要在反向代理后面的生产节点(例如 AWS Lightsail)上运行 SpecterPot:
### 1. 迁移主机 SSH 端口
在将 SpecterPot 绑定到公共 IP 的 `22` 端口之前,你**必须**更改主机的管理 SSH daemon 端口,以避免被锁定:
1. 打开 SSH 配置:
sudo nano /etc/ssh/sshd_config
2. 将 `Port 22` 行更改为另一个端口,例如 `Port 22022`。
3. 更新 AWS Lightsail 控制台上的防火墙规则,以允许端口 `22022` 入站。
4. 重启 SSH daemon:
sudo systemctl restart sshd
5. **在**关闭当前活动会话之前,在新终端中测试通过新端口登录(`ssh user@ip -p 22022`)。
### 2. 部署 Container 技术栈
修改 `docker-compose.yml` 文件端口映射,将主机的 `22` 端口重定向到容器的 `2222` 端口:
```
ports:
- "22:2222" # Public SSH honeypot
- "8080:8080" # Local Dashboard
```
启动 containers:
```
docker compose up -d --build
```
## Apache 反向代理配置
要通过 Apache 服务器路由将 Web UI 仪表板暴露在 `https://your-domain.com` 上,并指向容器端口 `8080`:
确保你在 Apache 中启用了代理模块:
```
sudo a2enmod proxy proxy_http proxy_wstunnel rewrite ssl
```
创建/更新你的 VirtualHost 配置(通常是 `/etc/apache2/sites-available/specterpot.conf`):
```
ServerName specterpot.gb10.studio
Redirect permanent / https://specterpot.gb10.studio/
ServerName specterpot.gb10.studio
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/specterpot.gb10.studio/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/specterpot.gb10.studio/privkey.pem
# Security Headers
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "DENY"
Header always set X-XSS-Protection "1; mode=block"
# Websocket routing for live stream
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^/ws(/.*)?$ ws://localhost:8080/ws$1 [P,L]
# Standard Web API routing
ProxyPreserveHost On
ProxyPass /ws ws://localhost:8080/ws
ProxyPassReverse /ws ws://localhost:8080/ws
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ErrorLog ${APACHE_LOG_DIR}/specterpot_error.log
CustomLog ${APACHE_LOG_DIR}/specterpot_access.log combined
```
启用网站并重启 Apache:
```
sudo a2ensite specterpot.conf
sudo systemctl restart apache2
```
标签:Docker, EVTX分析, Go, Ruby工具, SSH, 威胁情报, 安全, 安全防御评估, 开发者工具, 日志审计, 测试用例, 版权保护, 蜜罐, 证书利用, 请求拦截, 超时处理