针对 CVE-2021-44228 的增强型 Docker 化蜜罐,具有全面的安全特性、监控和告警能力。
# 生成 SSL 证书
./generate-ssl.sh
# 使用 docker-compose 启动
docker-compose up -d
# 监控日志
./monitor.py --tail
# 以 root 身份运行以便设置 fail2ban
sudo ./deploy.sh
# x86_64
docker run -d -p 8080:8080 \
-e HONEYPOT_NAME="log4shell-honeypot" \
-e LOG_FORMAT="json" \
-e RATE_LIMIT_REQUESTS="100" \
--name="log4shell-honeypot" \
msanford/log4shell-honeypot:latest
# ARM(例如 Raspberry Pi)
docker run -d -p 8080:8080 \
-e HONEYPOT_NAME="log4shell-honeypot" \
--name="log4shell-honeypot" \
msanford/log4shell-honeypot:arm-latest
# 从配置文件加载
docker-compose --env-file config.env up -d
蜜罐检测以下 Log4Shell 模式:
${jndi: - JNDI 查找(主要攻击向量)${ldap: - LDAP 目录查找${rmi: - RMI 远程方法调用${dns: - DNS 查找${env: - 环境变量访问${sys: - 系统属性访问${java: - Java 运行时信息# 格式化输出跟踪日志
./monitor.py --tail
# 分析最近 24 小时
./monitor.py --hours 24
# 分析最近 1 小时
./monitor.py --hours 1
curl http://localhost/health
curl http://localhost/metrics
sudo fail2ban-client status log4shell-honeypot
增强的 JSON 日志格式包含:
{
"timestamp": "2024-01-15T10:30:45Z",
"honeypot": "log4shell-honeypot",
"event_type": "log4shell_attempt",
"source_ip": "192.168.1.100",
"real_ip": "10.0.0.5",
"method": "POST",
"url": "http://honeypot.local/",
"user_agent": "Mozilla/5.0...",
"detected_patterns": ["${jndi:", "${env:"],
"detection_source": "form_field:username",
"headers": {...},
"form_data": {...},
"query_params": {...},
"content_length": 45
}
结构化 JSON 日志可轻松导入:
基于以下条件设置告警:
# 构建容器
docker build -t log4shell-honeypot:latest .
# 使用特定标签构建
docker build -t log4shell-honeypot:v2.0 .
docker-compose ps
docker-compose logs log4shell-honeypot
curl -f http://localhost/health || echo "健康检查失败"
sudo fail2ban-client status
sudo tail -f /var/log/fail2ban.log
# 检查近期攻击
./monitor.py --hours 1
# 查看原始日志
tail -f /var/log/log4shell-honeypot.log
RATE_LIMIT_REQUESTSMAX_LOG_SIZE 和 LOG_BACKUP_COUNT# 在 docker-compose.yml 中
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 128M
这是 BinaryDefense/log4shell-honeypot-flask 的增强 fork,包含显著的安全和运维改进。
| 变量 | 默认值 | 描述 |
|---|
HONEYPOT_NAME | log4shell-honeypot | 蜜罐的名称标识符 |
LOG_LEVEL | INFO | 日志级别(DEBUG、INFO、WARNING、ERROR、CRITICAL) |
LOG_FORMAT | json | 日志格式(json 或 text) |
MAX_LOG_SIZE | 10485760 | 最大日志文件大小(字节,10MB) |
LOG_BACKUP_COUNT | 5 | 保留的备份日志文件数量 |
RATE_LIMIT_REQUESTS | 100 | 每个 IP 在每个窗口内的最大请求数 |
RATE_LIMIT_WINDOW | 3600 | 速率限制窗口(秒,1 小时) |