分类 教程 下的文章

登录官方后台,任何第三方面板都没有入站防火墙功能!

点击防火墙,firewall rules 总共可以建立5个

建立一条规则 起名 坏ip验证码,选择threat score,然后选择greater than or equal to 空格里写2,下面的行为选择Challenge (Captcha)
意思就是,只要ip的bad评分值等于或者大于2,就启动验证码!

为了避免爬虫也被验证码拦截,我们附加一个and,
选择known bots ,然后把开关点到off,
意思就是不是已知爬虫
两个条目合起来就是

当ip的坏蛋值达到2分以上,并且不属于已知的爬虫,将使用验证码拦截访问。
已知爬虫参见 官方常见问题
https://developers.cloudflare.com/firewall/known-issues-and-faq/#how-does-firewall-rules-handle-traffic-from-known-bots页面的
How does Firewall Rules handle traffic from known bots? 部分

location.href=((d=(await(await fetch("./home.php?mod=spacecp&ac=avatar",{credentials:'include'})).text()).match(/\/\/\S+\/images\/ca\S+&ag/g)[0].replace('images/camera.swf?','?m=user&a=delete&'))&&confirm('删除ID'))?d:'';

听大佬们讨论如何防CC攻击,有大佬提出禁止国外IP访问,可以有所缓解,因此从路由器中移植了如下脚本,在CENTOS 6下调试通过。

使用:

先运行如下语句获取国内IP网段,会保存为/root/china_ssr.txt

wget -q --timeout=60 -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /root/china_ssr.txt

将下面脚本保存为/root/allcn.sh,设置可执行权限

运行
/root/allcn.sh
运行后国外IP无法访问网站

停止
/root/allcn.sh stop
运行后国外IP恢复访问网站

mmode=$1

下面语句可以单独执行,不需要每次执行都获取网段表

wget -q --timeout=60 -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F| '/CN|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /root/china_ssr.txt

CNIP="/root/china_ssr.txt"

gen_iplist() {

    cat <<-EOF
            $(cat ${CNIP:=/dev/null} 2>/dev/null)

EOF
}

flush_r() {
iptables -F ALLCNRULE 2>/dev/null
iptables -D INPUT -p tcp -j ALLCNRULE 2>/dev/null
iptables -X ALLCNRULE 2>/dev/null
ipset -X allcn 2>/dev/null
}

mstart() {
ipset create allcn hash:net 2>/dev/null
ipset -! -R <<-EOF
$(gen_iplist | sed -e "s/^/add allcn /")
EOF

iptables -N ALLCNRULE
iptables -I INPUT -p tcp -j ALLCNRULE
iptables -A ALLCNRULE -s 127.0.0.0/8 -j RETURN
iptables -A ALLCNRULE -s 169.254.0.0/16 -j RETURN
iptables -A ALLCNRULE -s 224.0.0.0/4 -j RETURN
iptables -A ALLCNRULE -s 255.255.255.255 -j RETURN

可在此增加你的公网网段,避免调试ipset时出现自己无法访问的情况

iptables -A ALLCNRULE -m set --match-set allcn src -j RETURN
iptables -A ALLCNRULE -p tcp -j DROP

}

if [ "$mmode" == "stop" ] ;then
flush_r
exit 0
fi

flush_r
sleep 1
mstart

IP库:https://github.com/17mon/china_ip_list