mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 08:05:49 -06:00
[GH-ISSUE #3832] [Feature Request] 服务端好像没有防火墙类的插件?fail2ban 使用说明 #3047
Labels
No labels
In Progress
WIP
WaitingForInfo
bug
doc
duplicate
easy
enhancement
future
help wanted
invalid
lifecycle/stale
need-issue-template
need-usage-help
no plan
proposal
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/frp#3047
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doveppp on GitHub (Dec 7, 2023).
Original GitHub issue: https://github.com/fatedier/frp/issues/3832
Describe the feature request
最近服务器ssh被爆破上了挖矿病毒,看了下是内网穿透的原因,找了一圈服务端好像没有防火墙类的插件,在issues里找到了使用fail2ban的办法,但没有找到具体的配置过程,在此记录下,减少后人走的弯路。
安装过程就不说了,安装完成之后在/etc/fail2ban/filter.d/目录下新建frps-ssh.conf,写入:
该文件是为了匹配frps的连接日志
之后将/etc/fail2ban/jail.conf 复制为 jail.local
在最后添加:
配置好之后重启fail2ban服务即可
以上
Describe alternatives you've considered
No response
Affected area
@doveppp commented on GitHub (Dec 7, 2023):
然而,效果并不明显,别人的爆破脚本很机智,不会一直爆破,有间隔时间:
半小时后仅仅才ban了4个ip:
暂未找到更好的解决办法
@fatedier commented on GitHub (Dec 7, 2023):
在未来的版本重构之后,会计划增加 ip 白名单的功能。
但是防火墙是很复杂的能力,也不是项目核心,目前可以尝试通过服务端插件的功能进行扩展,https://github.com/fatedier/frp/blob/dev/doc/server_plugin.md#newuserconn
效果怎么样不确定。
@doveppp commented on GitHub (Dec 7, 2023):
不知是否可以屏蔽那些多次在短时间内创建连接并关闭的ip,等有时间了尝试写一下插件试试
@duchenpaul commented on GitHub (Dec 27, 2023):
可以考虑更严格的fail2ban策略,比如失败3次ban一年
@doveppp commented on GitHub (Dec 27, 2023):
目前的策略是大时间窗口检测,24小时内触发250次就ban。
@doveppp commented on GitHub (Dec 27, 2023):
失败3次不行,frps没办法判断这个连接是成功了还是失败了
@pansila commented on GitHub (Jan 10, 2024):
为了更准确一点,可以结合 #2470 里面介绍的方法,从frpc client端拿到真实ip,
重写client端fail2ban的sshd的action,发送结果到frps server端(再打洞nc发过去?),然后server的fail2ban再接力自定义filter+action把这个ip ban掉。更简单一点的办法是,从client中过滤出fail的auth log,然后写到server端的syslog里面去,由server端的fail2ban自动处理这些非法访问。
jail.conf
maxRetry和banTime尽量改小是因为,我们把报告事件当成ban action,这两个频率不一样,需要让server尽量感知变化。
action.d/report2frps.conf
最后因为复用了sshd的filter和action,默认只会ban ssh默认的port(22),需要把内网转发的port(<ddd>自行替换)也加到规则里
或者server端jail.conf里面把iptables改成iptables-allport
@SwimmingLiu commented on GitHub (Jan 3, 2025):
@pansila 您好,请问如果使用了跳板机的话,从跳板机经
frp进去的ip都是127.0.0.1。没办法识别攻击者的ip怎么办呢?@JsonSong89 commented on GitHub (Jan 20, 2025):
那你在跳板机处理ip啊
@JsonSong89 commented on GitHub (Jan 20, 2025):
我是用服务端插件处理的
其实代码也没几行啊,
hono.js写的:
自行维护IpList Set