├── .gitattributes ├── README.md ├── deletelog.sh └── fakeipcf.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BT-CF 2 | 宝塔配合fakeipcf脚本自动提交恶意攻击IP到cf,精准屏蔽 3 | 4 | 宝塔收费版防火墙效果有这好?有这还需要杜甫???? 5 | 6 | 7 | 先配置下获取用户真实IP 8 | 相关教程 9 | 10 | 切记,一定要配置好获取用户真实IP,不然拉黑的都是cf的IP。。。。。。。 11 | 12 | 宝塔面板安装LNMP存放nginx配置文件位置在: 13 | /www/server/nginx/conf/nginx.conf 14 | 15 | 将下面段代码加入 “include proxy.conf;”下方 16 | 17 | log_format main '$http_x_forwarded_for [$time_local] "$request" ' 18 | '$status $body_bytes_sent "$http_referer" ' 19 | '$http_user_agent $remote_addr $request_time'; 20 | 21 | 22 | 保存好后,我们找到VPS上使用了Cloudflare CDN加速的那个网站,-->设置-->配置修改: 23 | 拉到差不多最底下,给网站日志文件后面加上main标签。改为使用main这个日志格式,具体操作为搜索 24 | 25 | 将 access_log /www/wwwlogs/www.xxx.com.log; 26 | 修改为 access_log /www/wwwlogs/www.xxx.com.log main; 27 | 28 | 参考文章:https://www.pigji.com/224.html 29 | 30 | 然后重启NGINX 31 | 32 | 33 | 修改fakeipcf.sh和deletelog.sh脚本的配置,然后直接复制粘贴到宝塔定时任务的shell脚本中。 34 | 35 | 参考文章:https://jhrs.com/2019/33092.html 36 | 37 | fakeipcf.sh推荐设置2分钟执行一次 38 | 39 | deletelog.sh推荐设置2小时30分钟执行一次 40 | -------------------------------------------------------------------------------- /deletelog.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | #删除指定网站日志 3 | rm -rf /www/wwwlogs/www.fun.log 4 | touch /www/wwwlogs/www.fun.log 5 | rm -rf /www/wwwlogs/log_ip_top10 6 | touch /www/wwwlogs/log_ip_top10 -------------------------------------------------------------------------------- /fakeipcf.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | #创建black.txt 3 | touch /www/wwwlogs/black.txt 4 | #日志文件,你需要改成你自己的路径 5 | logfile=/www/wwwlogs/ 6 | last_minutes=1 7 | #开始时间1分钟之前(这里可以修改,如果要几分钟之内攻击次数多少次,这里可以自定义) 8 | start_time= date +"%Y-%m-%d %H:%M:%S" -d '-1 minutes' 9 | echo $start_time 10 | #结束时间现在 11 | stop_time=`date +"%Y-%m-%d %H:%M:%S"` 12 | echo $stop_time 13 | cur_date="`date +%Y-%m-%d`" 14 | echo $cur_date 15 | #过滤出单位之间内的日志并统计最高ip数,请替换为你的日志路径!!!! 16 | tac $logfile/www.fun.log | awk -v st="$start_time" -v et="$stop_time" '{t=substr($2,RSTART+14,21);if(t>=st && t<=et) {print $0}}' | awk '{print $1}' | sort | uniq -c | sort -nr > $logfile/log_ip_top10 17 | ip_top=`cat $logfile/log_ip_top10 | head -1 | awk '{print $1}'` 18 | ip=`cat $logfile/log_ip_top10 | awk '{if($1>30)print $2}'` 19 | # 单位时间[1分钟]内单ip访问次数超过30次的ip记录入black.txt,这里大鸟为了测试设置了30,你需要改成其它的数字 20 | for line in $ip 21 | do 22 | echo $line >> $logfile/black.txt 23 | echo $line 24 | # 这里还可以执行CF的API来提交数据到CF防火墙 25 | done 26 | # 填Cloudflare Email邮箱 27 | CFEMAIL="" 28 | # 填Cloudflare API key 29 | CFAPIKEY="" 30 | # 填Cloudflare Zones ID 域名对应的ID 31 | ZONESID="" 32 | # /www/wwwlogs/black.txt存放恶意攻击的IP列表 33 | # IP一行一个。 34 | IPADDR=$(