Advertisement
atmoner

Basic RFI Protection

Oct 4th, 2011
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. <?php
  2. //// Copyright 2011-~ Muammer TURKMEN
  3. class rfistop{
  4.     public $silarray=array("php","txt","asp","aspx","html");
  5.     public $dizinarray=array("public_html","htdocs","httpdocs","httpsdocs");
  6.     public function rfidurdur($durdur="exit",$yapilacak="index.php"){
  7.         foreach($_REQUEST as $gelen=>$veri){
  8.             if(preg_match("#(./|http|.\\\)#si",$veri)){
  9.                 if($this->rfikontrol($veri)===false){
  10.                     switch($durdur){
  11.                         case "exit":
  12.                             exit();
  13.                         break;
  14.                         case "header":
  15.                             header("Location:".$yapilacak);
  16.                         break;
  17.                         case "custom":
  18.                             echo $yapilacak;
  19.                         break;
  20.  
  21.                     }
  22.                 }else{
  23.                     echo "tamam";
  24.                 }
  25.             }
  26.         }
  27.     }
  28.     private function rfikontrol($suzulecek){
  29.         if(preg_match("#http#si",$suzulecek)){
  30.             $urlal=array_reverse(explode("/",$suzulecek));
  31.             return $this->rfiuygunluk($urlal[0]);
  32.         }else{
  33.             if(preg_match("#(..\\\|../|.\\\|./)#si",$suzulecek)){
  34.                 $dizinust="";
  35.                 $ustsayi="";
  36.                 if(preg_match("#/#si",__FILE__)){
  37.                     $dizinbol=array_reverse(explode("/",__FILE__));
  38.                 }else{
  39.                     $dizinbol=array_reverse(explode("\\",__FILE__));
  40.                 }
  41.  
  42.                 foreach($this->dizinarray as $dizin){
  43.                     $sayi=array_search($dizin,$dizinbol);
  44.                     if($sayi>0){
  45.                         $dizinust=$sayi;
  46.                     }
  47.                 }
  48.                 $ustsayi+=substr_count($suzulecek,".\\");
  49.                 $ustsayi+=substr_count($suzulecek,"./");
  50.                 if($dizinust<$ustsayi){
  51.                     return false;
  52.                 }else{
  53.                     return true;
  54.                 }
  55.             }
  56.         }
  57.     }
  58.     private function rfiuygunluk($detect){
  59.         $uzanti=array_reverse(explode(".",$detect));
  60.         if(in_array($uzanti[0],$this->silarray)){
  61.             return false;
  62.         }else{
  63.             return true;
  64.         }
  65.     }
  66.  
  67. }
  68.  
  69. /*
  70. $test=new rfistop;        // New Class
  71. $deneme1->rfidurdur("custom","Stop Lamer <img src="http://atmoner.com/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley"> ");        . Add Custom Message
  72. $deneme1->rfidurdur(); or $deneme1->rfidurdur("exit"); Use command when locates error. default is exit();
  73. $deneme1->rfidurdur("header","deneme.php"); Send Attacker to defined page.
  74.  
  75. ****** when upload use $_FILES else will be caught to class. **********
  76. */
  77.  
  78. //// Copyright 2011-~ Muammer TURKMEN
  79. ?>
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement