Nginx Log found a large number of malicious IP automatically added firewall script

Source: Internet
Author: User

#!/bin/bash #_日志位置_log_path="/data0/nginx/weblogs/" #_日志文件名称_log_filename="Access_blog.kinggoo.com.log" #_要被屏蔽的ip访问端口, default_port="a"_nginx_deny="/opt/webserver/nginx/conf/deny.conf"_nginx_bin="/opt/webserver/nginx/sbin/nginx"_logfilepath=${_log_path}${_log_filename} #初始化被禁ip变量_drop_ip="" #检测文件Test-e ${_nginx_deny} ||Touch ${_nginx_deny}  for_drop_ipinch $(Tail-n50000"${_logfilepath}" |awk' {print $1,$12} ' |grep-I-v-E"google|yahoo|baidu|msnbot| feedsky|sogou| WordPress " |awk' {print '} '|Sort|Uniq-C|Sort-RN|awk' {if ($1>1000) print ' " $" "} ' );  Dogrep-Q"${_drop_ip}" ${_nginx_deny} &&eg=1 ||eg=0 ; if (( ${eg}==0 )); ThenEcho"Deny ${_drop_ip};" >> ${_nginx_deny} ${_nginx_bin} -s Reload iptables-I INPUT-p TCP--Dport ${_port} -S ${_drop_ip} -J DROP Echo">>>>> ' Date ' +%y-%m-%d%h%m%s"-found attack source address, ${_drop_ip} " >> /tmp/Nginx_deny.Log;Echo"Iptables-i input-p tcp--dport ${_port}-S ${_DROP_IP}-j Drop" >> /tmp/Nginx_deny.Logfi  Done

Nginx Log found a large number of malicious IP automatically added firewall script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.