i漂泊

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4667|回复: 0

PHP攻击网站防御代码-以及攻击代码反译

[复制链接]
TA的礼物信息
  • 收到:0
  • 送出:2
发表于 2013-3-11 14:54:25 | 显示全部楼层 |阅读模式
  1. <?php  
  2. //查询禁止IP  
  3. $ip =$_SERVER['REMOTE_ADDR'];  
  4. $fileht=".htaccess2";  
  5. if(!file_exists($fileht))file_put_contents($fileht,"");  
  6. $filehtarr=@file($fileht);  
  7. if(in_array($ip."\r\n",$filehtarr))die("Warning:"."
  8. "."Your IP address are forbided by some reason, IF you have any question Pls emill to shop@mydalle.com!");  

  9. //加入禁止IP  
  10. $time=time();  
  11. $fileforbid="log/forbidchk.dat";  
  12. if(file_exists($fileforbid))  
  13. { if($time-filemtime($fileforbid)>60)unlink($fileforbid);  
  14. else{  
  15. $fileforbidarr=@file($fileforbid);  
  16. if($ip==substr($fileforbidarr[0],0,strlen($ip)))  
  17. {  
  18. if($time-substr($fileforbidarr[1],0,strlen($time))>600)unlink($fileforbid);  
  19. elseif($fileforbidarr[2]>600){file_put_contents($fileht,$ip."\r\n",FILE_APPEND);unlink($fileforbid);}  
  20. else{$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);}  
  21. }  
  22. }  
  23. }  
  24. //防刷新  
  25. $str="";  
  26. $file="log/ipdate.dat";  
  27. if(!file_exists("log")&&!is_dir("log"))mkdir("log",0777);  
  28. if(!file_exists($file))file_put_contents($file,"");  
  29. $allowTime = 120;//防刷新时间  
  30. $allowNum=10;//防刷新次数  
  31. $uri=$_SERVER['REQUEST_URI'];  
  32. $checkip=md5($ip);  
  33. $checkuri=md5($uri);  
  34. $yesno=true;  
  35. $ipdate=@file($file);  
  36. foreach($ipdate as $k=>$v)  
  37. { $iptem=substr($v,0,32);  
  38. $uritem=substr($v,32,32);  
  39. $timetem=substr($v,64,10);  
  40. $numtem=substr($v,74);  
  41. if($time-$timetem<$allowTime){  
  42. if($iptem!=$checkip)$str.=$v;  
  43. else{  
  44. $yesno=false;  
  45. if($uritem!=$checkuri)$str.=$iptem.$checkuri.$time."1\r\n";  
  46. elseif($numtem<$allowNum)$str.=$iptem.$uritem.$timetem.($numtem+1)."\r\n";  
  47. else  
  48. {  
  49. if(!file_exists($fileforbid)){$addforbidarr=array($ip."\r\n",time()."\r\n",1);file_put_contents($fileforbid,$addforbidarr);}  
  50. file_put_contents("log/forbided_ip.log",$ip."--".date("Y-m-d H:i:s",time())."--".$uri."\r\n",FILE_APPEND);  
  51. $timepass=$timetem+$allowTime-$time;  
  52. die("Warning:"."
  53. "."Sorry,you are forbided by refreshing frequently too much, Pls wait for ".$timepass." seconds to continue!");  
  54. }  
  55. }  
  56. }  
  57. }  
  58. if($yesno) $str.=$checkip.$checkuri.$time."1\r\n";  
  59. file_put_contents($file,$str);  
  60. ?>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|IPiaoBo Inc. ( 渝ICP备17002826号 )

GMT+8, 2024-4-29 15:17 , Processed in 0.076965 second(s), 47 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表