不過最近幾天突然糟糕了起來,有90%的攻擊已經沒法攔截,請看一天的統計:
| IP攻擊及開始時間 |
攻擊次數 |
地點 |
備忘 |
| 125.165.1.42--2010-11-19 02:02:19--/ |
10 |
印尼 |
|
| 125.165.26.186--2010-11-19 16:56:45--/ |
1846 |
印尼 |
|
| 151.51.238.254--2010-11-19 09:32:40--/ |
4581 |
意大利 |
|
| 151.76.40.182--2010-11-19 11:58:37--/ |
4763 |
意大利 羅馬 |
|
| 186.28.125.37--2010-11-19 11:19:22--/ |
170 |
哥倫比亞 |
|
| 186.28.131.122--2010-11-19 11:28:43--/ |
22 |
哥倫比亞 |
|
| 186.28.25.130--2010-11-19 11:30:20--/ |
1530 |
哥倫比亞 |
|
| 188.3.1.108--2010-11-19 02:48:28--/ |
1699 |
土耳其 |
|
| 188.3.1.18--2010-11-19 06:46:01--/ |
1358 |
土耳其 |
|
| 188.3.34.226--2010-11-19 17:07:02--/ |
1672 |
土耳其 |
|
| 190.24.50.228--2010-11-19 12:26:38--/ |
2038 |
哥倫比亞 |
|
| 190.24.83.82--2010-11-19 14:20:10--/ |
9169 |
哥倫比亞 |
|
| 190.25.30.213--2010-11-19 14:00:44--/ |
680 |
哥倫比亞 |
|
| 190.26.29.130--2010-11-19 13:33:11--/ |
510 |
哥倫比亞 |
|
| 190.27.115.101--2010-11-19 13:53:48--/ |
340 |
哥倫比亞 |
|
| 190.27.22.222--2010-11-19 12:16:02--/ |
340 |
哥倫比亞 |
|
| 201.244.113.165--2010-11-19 11:25:55--/ |
170 |
哥倫比亞 |
|
| 201.244.113.47--2010-11-19 11:24:56--/ |
147 |
哥倫比亞 |
|
| 201.244.115.156--2010-11-19 10:13:56--/ |
2031 |
哥倫比亞 |
|
| 201.244.119.228--2010-11-19 13:50:05--/ |
170 |
哥倫比亞 |
|
| 201.245.218.155--2010-11-19 13:30:30--/ |
21 |
哥倫比亞 |
|
| 212.156.185.122--2010-11-19 08:40:36--/ |
16158 |
土耳其 |
|
| 78.160.106.60--2010-11-19 03:31:12--/ |
340 |
土耳其 |
|
| 78.162.67.77--2010-11-19 04:26:24--/ |
3595 |
土耳其 |
程式已抓 |
| 78.175.64.173--2010-11-19 02:00:08--/ |
2877 |
土耳其 |
|
| 78.176.178.76--2010-11-19 06:12:05--/ |
2370 |
土耳其 |
|
| 78.177.2.86--2010-11-19 13:24:29--/ |
196 |
土耳其 |
|
| 78.181.76.51--2010-11-19 16:04:29--/ |
600 |
土耳其 |
|
| 78.184.145.63--2010-11-19 14:30:12--/ |
2542 |
土耳其 |
|
| 78.185.168.24--2010-11-19 09:02:52--/ |
3877 |
土耳其 |
|
| 78.190.79.225--2010-11-19 13:25:22--/ |
3300 |
土耳其 |
|
| 78.190.84.230--2010-11-19 06:51:33--/ |
2719 |
土耳其 |
|
| 78.191.149.47--2010-11-19 08:34:34--/ |
8783 |
土耳其 |
|
| 78.191.233.108--2010-11-19 05:10:48--/ |
340 |
土耳其 |
|
| 78.191.94.126--2010-11-19 04:34:26--/ |
3091 |
土耳其 |
|
| 85.104.231.74--2010-11-19 08:03:53--/ |
3500 |
土耳其 |
|
| 85.104.49.60--2010-11-19 04:47:12--/ |
1037 |
土耳其 |
|
| 85.106.123.116--2010-11-19 13:35:45--/ |
68 |
土耳其 |
|
| 88.224.255.96--2010-11-19 07:18:59--/ |
3903 |
土耳其 |
|
| 88.228.138.65--2010-11-19 02:12:31--/ |
396 |
土耳其 |
|
| 88.228.66.5--2010-11-19 10:44:26--/ |
2797 |
土耳其 |
|
| 88.229.12.40--2010-11-19 06:57:46--/ |
6792 |
土耳其 |
|
| 88.234.193.11--2010-11-19 08:25:42--/ |
5895 |
土耳其 |
|
| 88.236.78.79--2010-11-19 15:01:54--/ |
170 |
土耳其 |
|
| 88.238.26.12--2010-11-19 05:21:46--/ |
473 |
土耳其 |
|
| 88.238.26.154--2010-11-19 05:31:58--/ |
1683 |
土耳其 |
|
| 88.242.124.128--2010-11-19 06:53:56--/ |
8401 |
土耳其 |
|
| 88.242.65.61--2010-11-19 08:38:41--/ |
1204 |
土耳其 |
程式已抓 |
| 94.122.20.157--2010-11-19 09:53:39--/ |
1917 |
土耳其 美國 |
程式已抓 |
| 94.54.37.54--2010-11-19 02:44:07--/ |
1096 |
土耳其 美國 |
程式已抓 |
| 95.14.1.97--2010-11-19 08:30:10--/ |
167 |
土耳其 美國 |
|
| 95.15.248.177--2010-11-19 11:14:54--/ |
1454 |
土耳其 美國 |
程式已抓 |
| |
|
|
|
| 共125008次,快的15秒172次,只抓9266次。 |
|
|
|
這個表夠糟糕的了,我們網站一天被攻擊了12萬次之多,如果任由其亂來,會給網站的負擔帶來的網速影響是顯而易見的,該攻擊的特點是每當發起攻擊的時候都會由3-5個不同的IP同時以每秒3-5次的速度攻擊過來,合計起來每秒鐘就達9-25次,每過1-6小時換一次IP,而且IP和以前的記錄是不重複的。這樣,一來是網站記憶體會突然過大,亮燈;二來是給網路帶來很大的不穩定性。個別IP是封了一直存在的,我試過全部解鎖了,一解鎖就有好幾個IP同時進行攻擊,甚至會讓網站嚴重過載了幾分鐘。
現在,開始本期的話題,為什麼會擋不住新的攻擊了呢?經過研究,我發現那90%的IP採用了新的攻擊方案:已經智能的能攻擊2分鐘停5分鐘的輪流攻擊,由於我上次的程式參數設定為600秒/期的保守方案,所以,我把參數改為了120秒120次的新方案,錯殺率0.5%以內,經過log的對比,我可以分析出120秒120次錯殺是未曾試過的,120秒多1次也只是有一個運費頁面由於網路問題有個客戶重新整理多了1回,這是我們的交易背景原因不夠智能化居多。
最後,感謝大家的留言,你們的留言我都會思考的。不過,我這個程式只是個參考,因地制宜,也不是最好的,只能說是人性化的罷了。現在我把程式再發一遍,只改了時間次數參數,新的參數已經能100%抓住那些駭客IP,我實驗了兩天,抓了62個新IP,還是土耳其的居多。
網站防IP攻擊代碼(Anti-IP attack code website) ver2.0:
複製代碼 代碼如下:/*
*網站防IP攻擊代碼(Anti-IP attack code website)2010-11-20,Ver2.0
*Mydalle.com Anti-refresh mechanism
*design by www.mydalle.com
*/
<?php
//查詢禁止IP
$ip =$_SERVER['REMOTE_ADDR'];
$fileht=".htaccess2";
if(!file_exists($fileht))file_put_contents($fileht,"");
$filehtarr=@file($fileht);
if(in_array($ip."\r\n",$filehtarr))die("Warning:"."<br>"."Your IP address are forbided by Mydalle.com Anti-refresh mechanism, IF you have any question Pls emill to shop@mydalle.com!<br>(Mydalle.com Anti-refresh mechanism is to enable users to have a good shipping services, but there maybe some inevitable network problems in your IP address, so that you can mail to us to solve.)");
//加入禁止IP
$time=time();
$fileforbid="log/forbidchk.dat";
if(file_exists($fileforbid))
{ if($time-filemtime($fileforbid)>30)unlink($fileforbid);
else{
$fileforbidarr=@file($fileforbid);
if($ip==substr($fileforbidarr[0],0,strlen($ip)))
{
if($time-substr($fileforbidarr[1],0,strlen($time))>120)unlink($fileforbid);
elseif($fileforbidarr[2]>120){file_put_contents($fileht,$ip."\r\n",FILE_APPEND);unlink($fileforbid);}
else{$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);}
}
}
}
//防重新整理
$str="";
$file="log/ipdate.dat";
if(!file_exists("log")&&!is_dir("log"))mkdir("log",0777);
if(!file_exists($file))file_put_contents($file,"");
$allowTime = 60;//防重新整理時間
$allowNum=5;//防重新整理次數
$uri=$_SERVER['REQUEST_URI'];
$checkip=md5($ip);
$checkuri=md5($uri);
$yesno=true;
$ipdate=@file($file);
foreach($ipdate as $k=>$v)
{ $iptem=substr($v,0,32);
$uritem=substr($v,32,32);
$timetem=substr($v,64,10);
$numtem=substr($v,74);
if($time-$timetem<$allowTime){
if($iptem!=$checkip)$str.=$v;
else{
$yesno=false;
if($uritem!=$checkuri)$str.=$iptem.$checkuri.$time."1\r\n";
elseif($numtem<$allowNum)$str.=$iptem.$uritem.$timetem.($numtem+1)."\r\n";
else
{
if(!file_exists($fileforbid)){$addforbidarr=array($ip."\r\n",time()."\r\n",1);file_put_contents($fileforbid,$addforbidarr);}
file_put_contents("log/forbided_ip.log",$ip."--".date("Y-m-d H:i:s",time())."--".$uri."\r\n",FILE_APPEND);
$timepass=$timetem+$allowTime-$time;
die("Warning:"."<br>"."Pls don't refresh too frequently, and wait for ".$timepass." seconds to continue, IF not your IP address will be forbided automatic by Mydalle.com Anti-refresh mechanism!<br>(Mydalle.com Anti-refresh mechanism is to enable users to have a good shipping services, but there maybe some inevitable network problems in your IP address, so that you can mail to us to solve.)");
}
}
}
}
if($yesno) $str.=$checkip.$checkuri.$time."1\r\n";
file_put_contents($file,$str);
?>