fix(honeypot): 取证记精确地址、封禁用 /64 键,并补建封与拦截日志
线上实测:IPv6 访问蜜罐后收到「你的 IP 已被封禁」,邮件里却是 `2408:…::/64` —— 既不像自己的地址,也说不清封了多大范围;同时用户自己 仍能正常访问,看日志也无从判断到底有没有封。 根因是「取证地址」与「封禁键」混用同一个变量(都取 LimitKey 的折叠值): - 取证丢掉精确 IPv6 后 64 位,事后无法定位到具体主机、没法和其他日志对账; - 邮件只给聚合键,运维第一反应是「不是我」,排查方向直接被带偏。 改动: - Serve 拆 clientIP(ResolveClientIP,精确)与 banKey(LimitKey,/64): DB / 凭据文件 / 告警邮件用前者,封禁 / 探测采样 / 告警去重用后者; - autoban.Options 新增 OnBan 回调(保持纯标准库、不引入 logrus), route.newBanner 注入后每次建封打 WARN:ban_key / reason / duration / expires_at; 中间件 403 分支加 Debug 日志(被封者会持续请求,Info 会被刷屏); - 告警邮件新增「封禁范围」行,仅 ip != ban_key 时渲染(IPv4 不重复显示), 顺带把过时的「已入库」改为「写入取证文件」——凭据早就外置了; - honeypot stats 的来源排行改按 LimitKey 合并,否则 IPv6 轮换地址会把 排行碎成几十条各 1 次的记录;合并口径与封禁完全一致。 测试(每项都做了变异验证:改坏→确认变红→恢复): - TestHoneypotRecordsExactIPv6ButBansByPrefix:精确地址进 DB 与凭据文件、 /64 才是封禁键、同 /64 换地址仍 403; - TestOnBanCallback:建封回调带键/时长/原因,封禁期内重复命中不重复回调; - TestHoneypotAlertTemplateRenders:IPv6 渲染封禁范围、IPv4 不重复; - TestMergeSourcesByKey:同 /64 合并、IPv4 原样、limit 与空输入。
This commit is contained in:
@@ -31,6 +31,9 @@
|
||||
<div style="font-family: Roboto-Regular,Helvetica,Arial,sans-serif; font-size: 14px; color: rgba(0,0,0,0.87); line-height: 22px; padding-top: 20px; text-align: left;">
|
||||
<div style="padding: 12px 14px; border-radius: 6px; background-color: #fff4e5; border: 1px solid #ffe0b2; margin-bottom: 14px;">
|
||||
<div><b>来源 IP:</b>{{.ip}}</div>
|
||||
{{if ne .ip .ban_key}}
|
||||
<div style="margin-top: 4px;"><b>封禁范围:</b>{{.ban_key}}(IPv6 按 /64 前缀聚合,整段一起封)</div>
|
||||
{{end}}
|
||||
<div style="margin-top: 4px;"><b>网络归属:</b>{{.provider}}</div>
|
||||
<div style="margin-top: 4px;"><b>诱饵路径:</b>{{.path}}</div>
|
||||
<div style="margin-top: 4px;"><b>处置:</b>{{.disposition}}</div>
|
||||
@@ -45,8 +48,8 @@
|
||||
</div>
|
||||
<div style="font-size: 12px; color: rgba(0,0,0,0.54); margin-top: 12px;">
|
||||
攻击者在假登录页上提交了凭据(假页面只返回静态内容,从不校验、也从不返回任何真实信息)。
|
||||
完整记录(含 User-Agent、Referer、原始 body)已入库,可用
|
||||
<code>TamaBox honeypot hits</code> 命令查看。
|
||||
完整记录(含 User-Agent、Referer、原始 body)已写入取证文件,可用
|
||||
<code>TamaBox honeypot hits</code> 命令查看;用户名与密码只存在该文件里,不写入数据库。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user