elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Duda curl y buffer php
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Duda curl y buffer php  (Leído 1,719 veces)
MetaNoia

Desconectado Desconectado

Mensajes: 33



Ver Perfil WWW
Duda curl y buffer php
« en: 1 Marzo 2020, 21:28 pm »

Muy buenas, he conseguido mediante la librería de curl en php pintar los directorios encontrados dado un dominio de forma dinámica mediante el buffer de php, ya que sino lo haces así tienes que esperar a que se procesen todas las peticiones para que te pinte los resultados.

El código que muestro a continuación funciona a la perfección pero lo he estado intentando pasar a programación POO y no los pinta de forma dinámica, ¿alguien sabe a que se debe?

Buffer php => https://www.php.net/manual/en/function.ob-start.php


Código en programacion estructurada como prueba de concepto
Código
  1. <?php
  2. $lista = file_get_contents('lista.txt');
  3. $directorios = explode("\n" , $lista);
  4.  
  5. foreach($directorios as $dir)
  6.        $list[] = trim("http://www.google.com/".$dir);
  7.  
  8. echo "<pre>";
  9. echo "Loading ...";
  10. $directorios = array();
  11. $rolling_window = 100;
  12. $rolling_window = (count($list) < $rolling_window) ? count($list) : $rolling_window;
  13. $master = curl_multi_init();
  14. $curl_arr = array();
  15. $std_options = array
  16. (
  17.    CURLOPT_RETURNTRANSFER => true,
  18.   CURLOPT_FOLLOWLOCATION => true,
  19.    CURLOPT_USERAGENT => 'DHunter');
  20. $options = $std_options;
  21. for ($i = 0; $i < $rolling_window; $i++)
  22. {
  23.    $ch = curl_init();
  24.    $options[CURLOPT_URL] = $list[$i];
  25.    curl_setopt($ch, CURLOPT_HEADER, 0);
  26.    curl_setopt($ch, CURLOPT_PROGRESSFUNCTION,'progress');
  27.    curl_setopt($ch, CURLOPT_NOPROGRESS, false);
  28.    curl_setopt_array($ch,$options);
  29.    curl_multi_add_handle($master, $ch);
  30. }
  31. $i = 0;
  32. do
  33. {
  34.  while(($execrun = curl_multi_exec($master, $running)) == CURLM_CALL_MULTI_PERFORM);
  35.  if($execrun != CURLM_OK)
  36.      break;
  37.  while($done = curl_multi_info_read($master))
  38.  {
  39.      $info = curl_getinfo($done['handle']);
  40.      if ($info['http_code'] == 200)
  41.      {
  42.          $directorios[] = $info['url'];
  43.          $i++;
  44.          echo  $info['url']."<br>";
  45.       }
  46.      $output = curl_multi_getcontent($done['handle']);
  47.      $ch = curl_init();
  48.      curl_setopt($ch, CURLOPT_PROGRESSFUNCTION,'progress');
  49.      curl_setopt($ch, CURLOPT_HEADER, 0);
  50.      curl_setopt($ch, CURLOPT_NOPROGRESS, false);
  51.      curl_setopt_array($ch,$options);
  52.      curl_multi_add_handle($master, $ch);
  53.      curl_multi_remove_handle($master, $done['handle']);
  54.      $options[CURLOPT_URL] = $list[$i++];
  55.  }
  56. }while ($running);
  57. echo "<br>Done";
  58.  
  59. function progress()
  60. {
  61.    ob_flush();
  62.    flush();
  63. }
  64.  


Esta es la version de POO que no pinta los resultados de forma dinamica:
Clase BruterDirectory
Código
  1. <?php
  2.    class BruterDirectory extends Bruter
  3.    {
  4.        private $directories;
  5.        private $domain;
  6.        public $handle;
  7.  
  8.        public function __construct($domain,$list)
  9.        {
  10.            parent::__construct($list);
  11.            $this -> domain = $domain;
  12.            $this -> directories = array();
  13.        }
  14.  
  15.       public function doSearch()
  16.       {
  17.           ob_implicit_flush(true);
  18.           ob_end_flush();
  19.           ob_start();
  20.           echo "<pre>";
  21.           echo "Loading ...";
  22.           ob_flush();
  23.           flush();
  24.             $directorios = array();
  25.             $rolling_window = 100;
  26.             $rolling_window = (count($this -> list) < $rolling_window) ? count($this -> list) : $rolling_window;
  27.             $master = curl_multi_init();
  28.             $curl_arr = array();
  29.             $std_options = array
  30.             (
  31.                 CURLOPT_RETURNTRANSFER => true,
  32.                 CURLOPT_FOLLOWLOCATION => true,
  33.                 //CURLOPT_MAXREDIRS => 2,
  34.                 CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Windows; Windows10_64bits; rv:72.0) Gecko/20100101 Firefox/72.0');
  35.             $options = $std_options;
  36.             for ($i = 0; $i < $rolling_window; $i++)
  37.             {
  38.               $ch = curl_init();
  39.               $options[CURLOPT_URL] = $this -> list[$i];
  40.               curl_setopt($ch, CURLOPT_HEADER, 0);
  41.               curl_setopt($ch, CURLOPT_PROGRESSFUNCTION,array($this, 'progress'));
  42.               curl_setopt($ch, CURLOPT_NOPROGRESS, false);
  43.               curl_setopt_array($ch,$options);
  44.               curl_multi_add_handle($master, $ch);
  45.             }
  46.             $i = 0;
  47.             do
  48.             {
  49.               while(($execrun = curl_multi_exec($master, $running)) == CURLM_CALL_MULTI_PERFORM);
  50.               if($execrun != CURLM_OK)
  51.                   break;
  52.               while($done = curl_multi_info_read($master))
  53.               {
  54.                   $info = curl_getinfo($done['handle']);
  55.                   if ($info['http_code'] == 200)
  56.                   {
  57.                       $directorios[] = $info['url'];
  58.                       $i++;
  59.                       echo  $info['http_code']."<br>";
  60.                    }
  61.                   $output = curl_multi_getcontent($done['handle']);
  62.                   $ch = curl_init();
  63.                   curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, array($this, 'progress'));
  64.                   curl_setopt($ch, CURLOPT_HEADER, 0);
  65.                   curl_setopt($ch, CURLOPT_NOPROGRESS, false);
  66.                   curl_setopt_array($ch,$options);
  67.                   curl_multi_add_handle($master, $ch);
  68.                   curl_multi_remove_handle($master, $done['handle']);
  69.                   $options[CURLOPT_URL] = $this -> list[$i++];
  70.               }
  71.           }while ($running);
  72.         curl_multi_close($master);
  73.         echo "<br>Done";
  74.         return $directorios;
  75.       }
  76.  
  77.       public function progress()
  78.       {
  79.           ob_flush();
  80.           flush();
  81.       }
  82.  

Y la llamada al metodo "doSearch" en el fichero main.php
Código
  1. $domain="http://www.google.com";
  2. $list = file_get_contents('lista.txt');
  3. $directorios = explode("\n" , $list);
  4. foreach($directorios as $dir)
  5.        $urls[] = trim($domain.$dir);
  6. $bruterDir = new BruterDirectory($domain,$urls);
  7. dirs = $bruterDir -> doSearch();
  8.  

Cualquier sugerencia es bienvenida.


En línea

Código:
<?php
       header("Location: TheHackerWay");
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Duda sobre legalidad de utilizacion de CURL
PHP
JungleBoogie 2 2,465 Último mensaje 6 Febrero 2011, 19:01 pm
por JungleBoogie
duda con buffer de cin
Programación C/C++
david_tosc90 1 1,572 Último mensaje 17 Abril 2014, 23:54 pm
por rir3760
Duda sobre curl
Programación C/C++
Drewermerc 2 1,785 Último mensaje 4 Junio 2014, 20:14 pm
por Drewermerc
Hacer cURL en respuesta de cURL para posterior scraping.
PHP
goditozor 3 4,532 Último mensaje 1 Septiembre 2014, 20:32 pm
por WHK
[DUDA] cURL subir imagen
PHP
Shell Root 3 2,581 Último mensaje 9 Septiembre 2015, 19:42 pm
por MinusFour
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines