3 Star 16 Fork 13

aqztcom / cc_iptables

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
block_attack_ips.sh 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
ppabc 提交于 2014-10-16 13:38 . update
#!/bin/bash
# http://www.111cn.net/sys/linux/61035.htm
logfile=/webserver/blog/logs/rainbow_access.log
function check_root(){
if [ $EUID -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
}
function block_ips(){
blacklist=$@
if [ ! -z "${blacklist}" ]; then
for ip in ${blacklist}
do
if ! $(/sbin/iptables-save | grep -wq ${ip}); then
echo /sbin/iptables -I INPUT -s ${ip}/32 -p tcp -m tcp --dport 80 -j DROP
/sbin/iptables -I INPUT -s ${ip}/32 -p tcp -m tcp --dport 80 -j DROP
fi
done
fi
}
function check_login(){
tailnum=10000
page=wp-login.php
retry=5
command="grep -w POST ${logfile} |tail -n ${tailnum} |grep -w ${page} |awk '{print $1}' |sort |uniq -c |awk '($1 > ${retry}){print $2}'"
blacklist=$(eval ${command})
block_ips ${blacklist}
}
function check_others(){
tailnum=10000
retry=400
command="tail -n ${tailnum} ${logfile} |awk '{print $1}' |sort |uniq -c |awk '($1 > ${retry}){print $2}'"
blacklist=$(eval ${command})
block_ips ${blacklist}
}
check_root
check_login
check_others
Shell
1
https://gitee.com/null_564_0890/cc_iptables.git
git@gitee.com:null_564_0890/cc_iptables.git
null_564_0890
cc_iptables
cc_iptables
master

搜索帮助