Last active
August 6, 2019 08:22
-
-
Save lesstif/547410a609de4e11345304fbc38c49ee to your computer and use it in GitHub Desktop.
to extract malicious web request client ip and add into nginx blacl list file.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TMP1=/tmp/tmp-black-list | |
NGINX_LOG=/var/log/nginx/error.log | |
grep '.php\|.cfg' ${NGINX_LOG} | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | sort | uniq | awk '{print "deny "$0";"}' > ${TMP1} | |
## copy original block ips file | |
D=$(date '+%Y-%m-%d') | |
BACKUP=/tmp/blockips-${D}.conf | |
BLOCKIPS=/etc/nginx/blockips.conf | |
cp ${BLOCKIPS} ${BACKUP} | |
## merge 2 files while removing duplicates | |
## https://unix.stackexchange.com/questions/50103/merge-two-lists-while-removing-duplicates | |
sort -u ${TMP1} ${BACKUP} > ${BLOCKIPS} | |
nginx -t | |
if [ $? == 0 ];then | |
systemctl restart nginx; | |
else | |
echo "nginx -t failed"; | |
fi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
## do something... | |
### add this | |
include /etc/nginx/blockips.conf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment