使用fail2ban对恶意的ssh扫描登录进行iptables封禁,单ip封禁效率太低。
启用ipset进行封禁。
借用firehol对ipset强大的管控能力,达到目的。
废话不多,直接上配置:
root@sklinux:/etc/fail2ban# cat jail.local
[default]
banaction = iptables-ipset-proto6-allports
[sshd]
port = 2292
logpath = %(sshd_log)s
backend = %(sshd_backend)s
#backend=systemd
banaction = iptables-ipset-proto6-allports
enabled=true
bantime = 30m
findtime = 60m
maxretry = 3
```bash
#注意timeout不能超过bantime,默认没有超时。需要加上timeout参数
ipv4 ipset create f2b-sshd hash:ip timeout 0
ipv4 blacklist full ipset:f2b-sshd
#配置完成,重启fail2ban服务,查看iptables规则:
#查看封锁列表
ipset list f2b-sshd
Name: f2b-sshd
Type: hash:ip
Revision: 4
Header: family inet hashsize 1024 maxelem 65536 timeout 0
Size in memory: 200
References: 5
Number of entries: 0
Members:
#查看iptables规则
iptables -L -n -v
root@sklinux:/etc/fail2ban# iptables -L -nv |grep sshd
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 match-set f2b-sshd src reject-with icmp-port-unreachable
0 0 BLACKLIST.bi.1.in all -- * * 0.0.0.0/0 0.0.0.0/0 match-set f2b-sshd src ! update-counters ! update-subcounters
0 0 BLACKLIST.bi.1.in all -- * * 0.0.0.0/0 0.0.0.0/0 match-set f2b-sshd src ! update-counters ! update-subcounters
0 0 BLACKLIST.bi.1.out all -- * * 0.0.0.0/0 0.0.0.0/0 match-set f2b-sshd dst ! update-counters ! update-subcounters
0 0 BLACKLIST.bi.1.out all -- * * 0.0.0.0/0 0.0.0.0/0 match-set f2b-sshd dst ! update-counters ! update-subcounters
#默认
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 match-set f2b-sshd src reject-with icmp-port-unreachable
0 0 BLACKLIST.bi.1.in all -- * * 0.0.0.0/0 0.0.0.0/0 match-set f2b-sshd src ! update-counters ! update-subcounters
firehol介绍:
firehol是一个开源的IP地址库,用于管理IP地址,并使用IP地址库来创建IP地址集。IP地址集可以用来限制访问,或者用于创建防火墙规则。
firehol的安装:
apt-get install firehol
firehol -h
firehol -c /etc/firehol/firehol.conf
firehol -c /etc/firehol/firehol.conf -s
firehol -c /etc/firehol/firehol.conf -s -u
#其中fireqos是一个开源的IPQoS工具,用于管理IPQoS,并使用IPQoS来创建IPQoS规则。IPQoS规则可以用来限制访问,或者用于创建防火墙规则。也是给力的工具。下次介绍
下面是比较有用的网络安全情报信息,主要是通过全世界部署的蜜罐系统,来捕捉各类恶意的扫描行为,并封禁。
firehol_level1
它是由 FireHOL 项目维护的一个高度可信的复合黑名单(IPSet)。
它是最基础、最严苛的防线,专门用于屏蔽互联网上那些“毫无疑问的坏蛋”。
它自动汇总了多个全球权威的黑名单源,包括:
- bogons: 非法 IP 地址(未分配的、保留的或私有的 IP 空间,不应出现在公网上)。
- fullbogons: 由 Spamhaus 维护的更详细的未分配地址。
- dshield: 最近 48 小时内最活跃的攻击者 IP。
- spamhaus_drop: 确定的垃圾邮件发送者和恶意软件托管服务器。
- feodo: 被僵尸网络控制的服务器。
零容忍(No False Positives)
该列表的目标是零误报。只有当一个 IP 被确认为恶意或根本不该存在于公网时,才会被加入。
自动更新:列表通常每分钟到每小时更新一次,确保防御的时效性。