menu LittleJake's Blog
color_lens
avatar
Jake Liu
Never Settle
creative commons by-nc-sa
hit
Category
keyboard_arrow_down

© 2024 LittleJake's Blog.

萌ICP备20223020号

IP攻击黑名单进阶plus版,基于iptables、ipset、多blacklist

前言

接着上一篇文章:IP攻击黑名单进阶版,基于iptables、ipset、USTC blacklist,写出了个方便调用的集合规则github repo:LittleJake/ip-blacklist,方便更好的获取到混合规则。

大致攻击分析

  1. 百度整网段 Search Engine Spider (182.61.0.0/18、106.12.64.0/18、106.12.96.0/20)
  2. 腾讯云(中国、中国香港、新加坡) Tencent Cloud Computing
  3. DigitalOcean LLC
  4. UCloud Shanghai UCloud Information Technology Company Limited
  5. 匿名洋葱路由出口
  6. 中国云南省
  7. 中国辽宁省
  8. 中国江苏省

规则介绍

免责条款:请在操作前确认自己的ip不在以上黑名单内或添加本机ip为白名单,不对任何无法连接到服务器负责。

名称 Filename 来源 Source 备注 Comment
abuseipdb_blacklist_ip_score_100.txt AbuseIPDB 可信分数 Score = 100
abuseipdb_blacklist_ip_score_75.txt AbuseIPDB 可信分数 Score >= 75
neucert_blacklist_ip.txt NEUCERT -
ustc_blacklist_ip.txt USTC -
all_blacklist.txt ALL 混合规则 Mixed,可信分数 Score >= 75

操作前提

  1. ipset-service
  2. iptables/ip6tables
  3. wget

配置脚本

此脚本直接封禁ip,非22端口

命令行窗口执行:

cat > /etc/blacklist.sh << EOF
#/bin/bash
wget https://cdn.jsdelivr.net/gh/LittleJake/ip-blacklist/all_blacklist.txt -O /tmp/blackip.txt
ipset create ipban hash:net family inet maxelem 100000
iptables -D INPUT -m set --match-set ipban src -j DROP
iptables -I INPUT -m set --match-set ipban src -j DROP

ipset create ipbanv6 hash:net family inet6 maxelem 100000
ip6tables -D INPUT -m set --match-set ipbanv6 src -j DROP
ip6tables -I INPUT -m set --match-set ipbanv6 src -j DROP

ipset flush ipban
ipset flush ipbanv6

for ip in \`cat /tmp/blackip.txt\`;
do
    if echo \$ip|grep -q ":";
    then
        ipset add ipbanv6 \$ip
    else
        ipset add ipban \$ip
    fi
done

service ipset save
EOF

echo "0 0 * * * root /bin/bash /etc/blacklist.sh &> /dev/null" >> /etc/crontab

效果

使用前

每小时攻击次数约24次,目前已开启fail2ban进行封禁。

使用前

使用后

(待续)

下一步

  1. 对恶意IP段进行封禁,由于AbuseIPDB订阅仅仅为webmaster级别,只能够支持查询/24段的IP。目前正在测试/24段IP,查询若大于分数阈值且数量多于阈值,则视为恶意IP段,进行全段IP封禁。

  2. 考虑搭建一个CERT网站。

Buy me a beer
Jake Liu
Never Settle

Title: IP攻击黑名单进阶plus版,基于iptables、ipset、多blacklist

Author: Jake Liu

Origin:

Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) For any re-post you must give appropriate credit.

文章遵循CC许可 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 转载请注明出处

Tag:ip黑名单, blacklist, abuseipdb, ustc, neucert, ssh

评论区

Add a new comment.

Theme