使用Gemini根据sing-box日志生成fail2ban拦截配置文件

最近无缘故的看了一下sing-box服务端后台日志,发现很多尝试连接的错误日志,虽然都是失败的,但是还是看着揪心,于是把错误日志信息都输出到“sing-box_error.log"文件,接下来就请Gemini搬我完善拦截规则了。 Prompt: 附件sing-box_error.log是sing-box日志中尝试访问anytls、shadowsocks和Hysteria2服务尝试访问者报错日子,使用fail2ban增加规则可以识别日志,尝试超过5次后加入屏蔽名单 于是就有了下文,基本无修改就可以识别进行正常拦截了。 1. 更新过滤规则 (/etc/fail2ban/filter.d/sing-box.conf) 您的日志中包含大量 Shadowsocks 的认证失败、头部错误以及 AnyTLS 的握手错误。针对 Hysteria2,日志中大部分错误似乎没有直接附带源 IP(如 handle stream request),但 AnyTLS 和 Shadowsocks 的记录非常清晰。 请使用以下内容覆盖或更新您的 filter 文件: [Definition] # 匹配 Shadowsocks 和 AnyTLS 的恶意探测/错误 # <HOST> 是 Fail2Ban 用于提取 IP 的变量 failregex = ^.*inbound/shadowsocks\[.*\]: process (connection|packet) from <HOST>:\d+: .*cipher: message authentication failed.*$ ^.*inbound/shadowsocks\[.*\]: process (connection|packet) from <HOST>:\d+: .*bad header.*$ ^.*inbound/shadowsocks\[.*\]: process (connection|packet) from <HOST>:\d+: .*salt not unique.*$ ^.*inbound/shadowsocks\[.*\]: process (connection|packet) from <HOST>:\d+: .*packet too short.*$ ^.*inbound/anytls\[.*\]: process connection from <HOST>:\d+: .*unknown user password.*$ ^.*inbound/anytls\[.*\]: process connection from <HOST>:\d+: .*fallback disabled.*$ ^.*inbound/anytls\[.*\]: process connection from <HOST>:\d+: .*TLS handshake:.*$ # 忽略规则 (ignoreregex) # 如果您想通过正则忽略某些特定情况(例如忽略本地 IP 127.0.0.1 的错误),可以使用如下格式: # ignoreregex = ^.*process connection from 127\.0\.0\.1.*$ # 但通常建议在 jail.local 中使用 ignoreip 来处理白名单。 ignoreregex = 2. 配置 Jail 适配 Debian + UFW (/etc/fail2ban/jail.local) 在 Debian 系统中使用 ufw 作为防火墙时,需要在 jail.local 中明确指定 banaction 为 ufw。同时,我已添加了您要求的 ignoreip 设置位置。 ...

十一月 23, 2025 · 2 分钟 · 298 字 · Byter ·  AI ·  fail2ban