通过Nginx日志分析 反爬虫抓取用户cookie id

#!/bin/bash
cat /dev/null >/tmp/1234.txt
#十分钟前的时间格式
old_time=`date -d "10 minute ago" -R |awk '{ print $5 }'`
#当前的时间格式
TIME=`date -R |awk '{ print $5 }'`
Month=`date -R |awk '{ print $2"/"$3"/"$4 }'`
logs_path="/var/log/nginx/"
tmp_dir="/tmp"
#session---userID
URL="http://127.0.0.1:9180/user/getUserInfo?zbUserKey="
cat $logs_path/www.test.com_access.log |grep -v '1.2.3.4'|grep "$Month"| sed -n "/$old_time/,/$TIME/p" | awk '{print $NF}' | sort |uniq -c | sort -rn |grep -v '"-"'|awk '{if($1>100) print $0}' >

for ID in $(cat /tmp/seID.txt|awk '{print $2}' |sed 's/"//g')
do
#用户id
UIDS=`curl $URL$ID -s|awk -F ":" '{print $5}'|awk -F "," '{print $1}'| sort | uniq -c| sort -rn |awk '{print $2}'`
cok=`cat $tmp_dir/seID.txt|grep "$ID"|awk '{print $1}' `
UIDC=`curl $URL$ID -s|awk -F ":" '{print $5}'|awk -F "," '{print $1}'| sort | uniq -c| sort -rn |awk '{print $1}' `
#用户cookie
if [ $UIDC == "1" ]; then
UIDC="$cok"
echo "当前cookie是: $ID 单重复次数: $cok 用户ID是: $UIDS 单重复次数: $UIDC" >> $tmp_dir/1234.txt
else
echo "当前cookie是: $ID 单重复次数: $cok 用户ID是: $UIDS 单重复次数: $UIDC" >> $tmp_dir/1234.txt
fi
#相用户ID
done
xtid=`cat $tmp_dir/1234.txt | awk '{print $6}' |sort |uniq -c | sort -rn |awk '{if($1>2) print $0}'|grep -v '"No'``
if [ ! -n "$xtid" ]; then
xtid=0
cok_sum=0
else
cok_sum=` cat $tmp_dir/1234.txt |grep "$xtid"|awk '{sum += $4};END {print sum}'`
fi
#相id相加cooki总和
echo 一样id: $xtid 相id相加cooki总和:$cok_sum
#done

qywx() {
webhook='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=*********************'
if [ "$?" -eq 0 ]; then
curl $webhook
-H 'Content-Type: application/json'
-d "
{"msgtype": "text",
"text": {
"content": "注意有爬虫! n 当前cookie是: $ID n 单重复次数: $cok n 单重复次数: $UIDS n 单重复次数: $UIDC n 相同id: $xtid n 相同id相加cooki总和:$cok_sum "
}
}"
else
break
fi
}
#qywx

/usr/bin/python3.6 /data/scripts/qywx.py $ID $cok $UIDS $UIDC $xtid $cok_sum

执行结果:

通过Nginx日志分析 反爬虫抓取用户cookie id

发表评论

相关文章