色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php防攻擊代碼升級(jí)版

不過最近幾天突然糟糕了起來,有90%的攻擊已經(jīng)沒法攔截,請(qǐng)看下圖一天的統(tǒng)計(jì):
IP攻擊及開始時(shí)間攻擊次數(shù)地點(diǎn)備注
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土耳其 美國(guó)程序已抓
94.54.37.54--2010-11-19 02:44:07--/1096土耳其 美國(guó)程序已抓
95.14.1.97--2010-11-19 08:30:10--/167土耳其 美國(guó) 
95.15.248.177--2010-11-19 11:14:54--/1454土耳其 美國(guó)程序已抓
    
共125008次,快的15秒172次,只抓9266次。   

這個(gè)表夠糟糕的了,我們網(wǎng)站一天被攻擊了12萬次之多,如果任由其亂來,會(huì)給網(wǎng)站的負(fù)擔(dān)帶來的網(wǎng)速影響是顯而易見的,該攻擊的特點(diǎn)是每當(dāng)發(fā)起攻擊的時(shí)候都會(huì)由3-5個(gè)不同的IP同時(shí)以每秒3-5次的速度攻擊過來,合計(jì)起來每秒鐘就達(dá)9-25次,每過1-6小時(shí)換一次IP,而且IP和以前的記錄是不重復(fù)的。這樣,一來是網(wǎng)站內(nèi)存會(huì)突然過大,亮燈;二來是給網(wǎng)絡(luò)帶來很大的不穩(wěn)定性。個(gè)別IP是封了一直存在的,我試過全部解封了,一解封就有好幾個(gè)IP同時(shí)進(jìn)行攻擊,甚至?xí)尵W(wǎng)站嚴(yán)重過載了幾分鐘。

現(xiàn)在,開始本期的話題,為什么會(huì)擋不住新的攻擊了呢?經(jīng)過研究,我發(fā)現(xiàn)那90%的IP采用了新的攻擊方案:已經(jīng)智能的能攻擊2分鐘停5分鐘的輪流攻擊,由于我上次的程序參數(shù)設(shè)置為600秒/期的保守方案,所以,我把參數(shù)改為了120秒120次的新方案,錯(cuò)殺率0.5%以內(nèi),經(jīng)過log的對(duì)比,我可以分析出120秒120次錯(cuò)殺是未曾試過的,120秒多1次也只是有一個(gè)運(yùn)費(fèi)頁面由于網(wǎng)絡(luò)問題有個(gè)客戶刷新多了1回,這是我們的交易后臺(tái)的原因不夠智能化居多。

最后,感謝大家的留言,你們的留言我都會(huì)思考的。不過,我這個(gè)程序只是個(gè)參考,因地制宜,也不是最好的,只能說是人性化的罷了。現(xiàn)在我把程序再發(fā)一遍,只改了時(shí)間次數(shù)參數(shù),新的參數(shù)已經(jīng)能100%抓住那些黑客IP,我試驗(yàn)了兩天,抓了62個(gè)新IP,還是土耳其的居多。

網(wǎng)站防IP攻擊代碼(Anti-IP attack code website) ver2.0:
復(fù)制代碼 代碼如下:
/*
*網(wǎng)站防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;//防刷新時(shí)間
$allowNum=5;//防刷新次數(shù)
$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);
?>

php技術(shù)php防攻擊代碼升級(jí)版,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 茂名市| 炉霍县| 博白县| 阿克苏市| 永吉县| 长治市| 孟村| 韩城市| 大竹县| 六安市| 普定县| 金乡县| 高邑县| 昌图县| 长丰县| 界首市| 县级市| 晋州市| 阿合奇县| 略阳县| 白河县| 金湖县| 北碚区| 天峻县| 昌邑市| 砀山县| 衡阳市| 棋牌| 驻马店市| 乌兰浩特市| 阿瓦提县| 济阳县| 大竹县| 富裕县| 收藏| 美姑县| 西吉县| 邵东县| 三河市| 双流县| 马尔康县|