不管肉鸡,还是代理,CC识别就封杀!
这几天的心得,汇成代码。
PYTHON版,我编的。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os,sys,time
import commands,logging
#以下为手工命令时的动作
#time format 17/Oct/2014:10:00:00
#time format Sat Oct 18 12:35:43 2014
#awk '$4>"[17/Oct/2014:14:00:00"&&$4<"[17/Oct/2014:14:02:00"' xxx.log|awk '{a[$7]++}END{for(i in a)print a[i],i}'|sort -n|tail -n 10|column -t | 500
#awk '$4>"[17/Oct/2014:14:00:00"&&$4<"[17/Oct/2014:14:02:00"' xxx.log|grep 'uc_server/images/noavatar_small.gif'|awk '{a[$1]++}END{for(i in a)print a[i],i}'|sort -n|tail -n 10|column -t | 100
#定义预警触发时的CC访问数及IP访问CC网址的次数
urlAlert = 500
ipAlert = 50
print 'urlAler is:',urlAlert, ', ipAlert is:', ipAlert
#定义LOG文件地址
logPath = "xxx.log"
#120秒的处理间隔
endtime = time.time()
strEndTime = time.ctime(endtime).split()
strBeginTime = time.ctime(endtime-120).split()
#规整格式,使PYTHON时间格式对应NGINX的日志时间格式
endTime = "%s/%s/%s:%s"%(strEndTime[2],strEndTime[1],strEndTime[4],strEndTime[3])
beginTime = "%s/%s/%s:%s"%(strBeginTime[2],strBeginTime[1],strBeginTime[4],strBeginTime[3])
#LOGGIN记录功能
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='XXX.log',
filemode='a')
#通用的命令处理函数
def exec_Cmd(Cmd):
(status,output) = commands.getstatusoutput(Cmd)
try:
if int(status) == 0:
print Cmd + " is OK!"
logging.info(Cmd + " ---is OK!")
return output
else:
logging.info(Cmd + " cant't finish...")
print Cmd + " can't finish...."
sys.exit(1)
except:
logging.info(Cmd + " is Wrong")
print Cmd + " is Wrong!"
sys.exit(1)
#获取最可能的CC的URL列表
def CCDef_url():
global urlAlert, logPath, beginTime, endTime
#封装BASH SHELL命令,搜索日志为当前时间前两分钟内,也可以用TAIL -F,省时间,AWK语法我有些搞不懂,运维兄弟提供
urlCmd = "awk '$4>\"[" + beginTime + "\"&&$4<\"[" + endTime + "\"' " + logPath + "|awk '{a[$7]++}END{for(i in a)print a[i],i}'|sort -n|tail -n 10|column -t"
urlOutput = exec_Cmd(urlCmd)
urlList = []
#规范输出格式并获取大于预警的URL地址列表
for line in (urlOutput.split('\n')):
urlCountList = line.split()
if int(urlCountList[0]) > urlAlert:
urlList.append(urlCountList[1])
#logging.info("cc's url is:", urlCountList[1])
return urlList
#获取访问过这些URL的IP地址列表
def CCDef_ip(urlList):
global ipAlert, logPath, beginTime, endTime
ipList = []
for url in urlList:
#更改一下AWK,获取
ipCmd = "awk '$4>\"[" + beginTime + "\"&&$4<\"[" + endTime + "\"' " + logPath + "|grep " + url + "|awk '{a[$1]++}END{for(i in a)print a[i],i}'|sort -n|tail -n 10|column -t"
ipOutput = exec_Cmd(ipCmd)
#规范输出格式并获取大于预警的IP地址列表
for line in (ipOutput.split('\n')):
ipCountList = line.split()
if int(ipCountList[0]) > ipAlert:
ipList.append(ipCountList[1])
#logging.info("cc's url is:", urlCountList[1])
return ipList
#将最可以疑的攻击IP加入防火墙
def dropIptables(ipList):
drop_ip_list = []
#先列出已有的IPTABLES的IP,达到过滤,去重的目的
iptablesOutput = exec_Cmd('iptables -vnL')
for line in iptablesOutput.split('\n'):
line = line.split()
if not line[0].isdigit():
continue
drop_ip_list.append(line[7])
for ip in ipList:
if ip in drop_ip_list:
continue
dropCmd = "iptables -I INPUT -s " + ip + " -j DROP"
print dropCmd
#干之!!!
exec_Cmd(dropCmd)
def main():
urlList = CCDef_url()
ipList = CCDef_ip(urlList)
print ipList
dropIptables(ipList)
pass
if __name__=="__main__":
main()
BASH SHELL版,运维兄弟写的,真的省好多行。要好好攻一下SHELL脚本了。
#!/bin/bash
#while true
#do
tail -f XXX.log > url.txt &
echo "wait 120s"
sleep 120s
`ps -ef | grep "tail -f" | grep -v grep | awk '{print $2}' | xargs` > /dev/null
one=` url.txt | awk '{print $4}'`
two=` url.txt | awk '{print $4}'`
#|column -t
url_max=`|column -t | awk '{if ($1 > 500) print $2}' | xargs`
echo $url_max >> url.log
for i in $url_max
do
ipaddress=`|column -t | awk '{if ($1 > 100) print $2}'|xargs`
for ip in $ipaddress
do
iptables -L -n | grep "$ip"
]
then
echo $ip >> url.log
iptables -I INPUT -s $ip -j DROP
fi
done
done
#done
不管肉鸡,还是代理,CC识别就封杀!的更多相关文章
- 核武器代理CC工具V3.42最新版本!
软件说明 !!!有新版本更新,请移步到更新地址:https://www.cnblogs.com/cnhacker/p/10878688.html ########################### ...
- DDOS工具合集---CC 2.0(僵尸网络proxy,单一url,可设置cookie,refer),传奇克星(代理+单一url,可设置cookie),NetBot_Attacker网络僵尸1.0(僵尸网络,HTTP NO-Cache Get攻击模式,CC攻击,HTTP空GET请求攻击),傀儡僵尸VIP1.4版(僵尸网络,动态单一url)、上兴网络僵尸2.3、中国制造网络僵尸、安全基地网络僵尸==
DDOS工具合集 from:https://blog.csdn.net/chinafe/article/details/74928587 CC 著名的DDOS CC工具,效果非常好!CC 2.0使用了 ...
- cc攻击技术
攻击者借助代理服务器生成指向受害主机的合法请求,实现DOS,和伪装就叫:cc(ChallengeCollapsar). CC主要是用来攻击页面的.大家都有这样的经历,就是在访问论坛时,如果这个论坛比较 ...
- 如何防范CC攻击
服务器如何防范CC攻击CC攻击是DDOS(分布式拒绝服务)的一种,相比其它的DDOS攻击CC似乎更有技术含量一些.这种攻击你见不到虚假IP,见不到特别大的异常流量,但造成服务器无法进行正常连接,听说一 ...
- CC攻击网站和游戏如何针对性预防?
1:CC攻击原理 CC = Challenge Collapsar,其前身名为Fatboy攻击,是利用不断对网站发送连接请求致 使形成拒绝服务的目的, CC攻击是DDOS(分布式拒绝服务)的一种,相比 ...
- CC攻击原理及防范方法和如何防范CC攻击
一. CC攻击的原理: CC攻击的原理就是攻击者控制某些主机不停地发大量数据包给对方服务器造成服务器资源耗尽,一直到宕机崩溃.CC主要是用来消耗服务器资源的,每个人都有这样的体验:当一个网页访问的人数 ...
- CC攻击原理及防范方法
一. CC攻击的原理: CC攻击的原理就是攻击者控制某些主机不停地发大量数据包给对方服务器造成服务器资源耗尽,一直到宕机崩溃.CC主要是用来消耗服务器资源的,每个人都有这样的体验:当一个网页访问的人数 ...
- trackingjs+websocket+百度人脸识别API,实现人脸签到
在公司做了个年会的签到.抽奖系统.用java web做的,用公司的办公app扫二维码码即可签到,扫完码就在大屏幕上显示这个人的照片.之后领导让我改得高大上一点,用人脸识别来签到,就把扫二维码的步骤改成 ...
- Nginx防御CC攻击
CC攻击可以归为DDoS攻击的一种.他们之间都原理都是一样的,即发送大量的请求数据来导致服务器拒绝服务,是一种连接攻击.CC攻击又可分为代理CC攻击,和肉鸡CC攻击.代理CC攻击是黑客借助代理服务器生 ...
随机推荐
- 关于NAT穿透的一些理解
前些天在知乎回答了一个智能家居远程控制方面的问题,感觉自己对无公网IP地址环境下的穿透问题有些了解.昨天同事拿来一个网络摄像头,安装在ADSL路由器上网的环境下,可以远程查看视频,效果还挺不错,问我厂 ...
- jquery获取表格中特定列
jQuery().text() 如果有一个表格,我们要用jquery获取特定列,则需要修改列的索引值就好了,此句代码获取的是页面的第10列
- C#中判断字符串是否中文的方法
public bool IsChinaString(string CString) { bool BoolValue = false; ; i < CString.Length; i++) { ...
- HAVING 子句 (SQL Server Compact)
MSDN官方文献 原文地址:http://technet.microsoft.com/zh-cn/library/ms173260.aspx
- 护肤品总结 Skin Care (1)
很久没有更博了,最近过年在家,就写些生活上面的总结吧- 从护肤品开始,接下来陆陆续续会有化妆品,北美生活购物等. 因为是学生党,所以此帖中的东西基本都是价钱适中.因为经常买买买,所以用的好的坏的都会在 ...
- GF(2^8)乘法优化
利用指数表和对数表,实现GF(2^8)的乘法优化. 首先利用简单的基础的GF(2^8)乘法,构造指数表和对数表.在这里选取生成元3. 指数表exp[i] = 3^i,对数表log[i] = log3( ...
- 近 100 个 Linux 常用命令大全
1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a 列出包括.a开头的隐藏文件的所有文件 -A 通-a,但不列出"."和".." -l 列出 ...
- sqlyog v11.24注册码
ccbfc13e-c31d-42ce-8939-3c7e63ed5417 a56ea5da-f30b-4fb1-8a05-95f346a9b20b a0fe8645-3916-45d4-9976- ...
- 【C#基础】HTTP发送POST二进制数据
//postdata为数组的请求方式 public byte[] POST(string Url, byte[] byteRequest) { byte[] responsebody; HttpWeb ...
- [Angular 2] Filter items with a custom search Pipe in Angular 2
This lessons implements the Search Pipe with a new SearchBox component so you can search through eac ...