fix(honeypot): 蜜罐封禁与 enable_auto_ban 解耦 + 泄露扫描后缀匹配
- autoban: 新增 RecordHoneypot 独立通道(不受 enabled 约束)+ 独立阈值/时长; IsBanned 不再因 enable_auto_ban=false 而忽略已有封禁 - honeypot: 新增 honeypotSuffixes 后缀匹配,覆盖 /backup.zip、/db.sql、/id_rsa.pem - 新增配置 honeypot_threshold / honeypot_ban_minutes - 补测试:autoban/honeypot_test.go、route 侧禁用自动封禁仍封禁
This commit is contained in:
@@ -63,12 +63,14 @@ func (h *honeypotHandler) Serve(ctx flamego.Context) {
|
||||
ip := shared.LimitKey(shared.ResolveClientIP(req))
|
||||
path := req.URL.Path
|
||||
|
||||
// 记录与封禁:走既有 autoban 链路,复用阈值封禁与告警。
|
||||
// 封禁:走 autoban 的蜜罐独立通道(RecordHoneypot)。
|
||||
//
|
||||
// 刻意不用常规的 Record:它受 enable_auto_ban 开关约束,
|
||||
// 而蜜罐是显式开启的功能 —— 开了就该封禁,不该被另一个开关连坐。
|
||||
// 蜜罐路径与业务路由零交集,正常访客不可能命中,阈值取 1(一次即封)。
|
||||
banned := false
|
||||
if h.ab != nil && ip != "" {
|
||||
h.ab.Record(ip, path, autoban.KindSensitive)
|
||||
// Record 内部在触发封禁时把 IP 写入 banned 表;此处再查一次得到确切状态。
|
||||
banned = h.ab.IsBanned(ip)
|
||||
banned = h.ab.RecordHoneypot(ip, path)
|
||||
}
|
||||
|
||||
// body 只能读一次:先提取凭据(POST 时读 body),再决定写哪种响应。
|
||||
|
||||
Reference in New Issue
Block a user