• Publicidad

Duda con módulo HTTP::Proxy

Aquí encontrarás todo lo que sea específicamente acerca de módulos de Perl. Ya sea que estás compartiendo tu módulo, un manual o simplemente tienes una duda acerca de alguno.

Re: Duda con módulo HTTP::Proxy

Notapor BigBear » 2013-04-04 11:38 @526

¡Qué raro!, ahora de repente funciona, ayer no funcionó. Ahora sí funciona con el mismo código :?

Ahora estoy subiendo un archivo y necesito mostrar el "content" que volqué acá:

Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
[+] Proxy server Online in port 8080

soy el agente : Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.
0
$VAR1 = bless( {
                 '_protocol' => 'HTTP/1.1',
                 '_content' => '-----------------------------8283483225031
Content-Disposition: form-data; name="archivo"; filename="GFWLIVESetupLog.txt"
Content-Type: text/plain

  l i v e R e d i s t :   0
 G F W L C l i e n t :   0

-----------------------------8283483225031
Content-Disposition: form-data; name="destino"

C:/perl/test.txt
-----------------------------8283483225031--
',
                 '_uri' => bless( do{\(my $o = 'http://localhost/shell.php?uploa
d=')}, 'URI::http' ),
                 '_headers' => bless( {
                                        'user-agent' => 'Mozilla/5.0 (Windows NT
 5.1; rv:19.0) Gecko/20100101 Firefox/19.0',
                                        'accept' => 'text/html,application/xhtml
+xml,application/xml;q=0.9,*/*;q=0.8',
                                        'accept-language' => 'es-ar,es;q=0.8,en-
us;q=0.5,en;q=0.3',
                                        'cookie' => 'PHPSESSID=a8bkktvsripf6agpi
fnma61qq4',
                                        'content-length' => '378',
                                        'host' => 'localhost',
                                        'via' => '1.1 doddy-701c8cb49 (HTTP::Pro
xy/0.20)',
                                        'content-type' => 'multipart/form-data;
boundary=---------------------------8283483225031',
                                        'x-forwarded-for' => '127.0.0.1',
                                        'referer' => 'http://localhost/shell.php
?upload='
                                      }, 'HTTP::Headers' ),
                 '_method' => 'POST'
               }, 'HTTP::Request' );
 
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4


El código no cambió mucho:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. #A simple Proxy Server
  3. #Coded By Doddy H
  4. #ppm install http://theoryx5.uwinnipeg.ca/ppms/HTTP-Proxy.ppd
  5.  
  6. use HTTP::Proxy;
  7. use HTTP::Proxy::BodyFilter::simple;
  8. use HTTP::Proxy::BodyFilter::complete;
  9. use Data::Dumper;
  10.  
  11. my $port = "8080";
  12. my $logs = "logs.txt";
  13.  
  14. print "\n\n[+] Proxy server Online in port $port\n\n";
  15.  
  16. my $server = HTTP::Proxy->new(port=>$port);
  17. $server->host();
  18.  
  19. $server->push_filter(mime=>undef,response => HTTP::Proxy::BodyFilter::complete->new());
  20.  
  21. $server->push_filter(
  22. mime=>undef,
  23. request=>HTTP::Proxy::BodyFilter::simple->new(\&enable),
  24. response => HTTP::Proxy::BodyFilter::simple->new(\&enable2));
  25.  
  26. $server->start();
  27.  
  28. sub enable {
  29.  
  30. my @logs;
  31. my($a,$b,$c,$d,$e) = @_;
  32. my ($f,$g)=($c->header("cookie"),$c->header("x-requested-with"));
  33. my ($h,$i)=($c->header("content-type"),$c->header("content"));
  34.  
  35. print "soy el agente : ".$c->header("user-agent")."\n";
  36.  
  37. print Dumper $c;
  38.  
  39. savefile($logs,"\n[Peticion] : ".$c->method." ".$c->uri);
  40. savefile($logs,"[Cookie] : ".$f) if $f;
  41. savefile($logs,"[x-requested-with] : ".$g) if $g;
  42. savefile($logs,"[Content Type] : ".$h) if $h;
  43. savefile($logs,"[Content] : ".$i) if $i;
  44. savefile($logs,"");
  45.  
  46. }
  47.  
  48. sub enable2 {
  49. my ($j,$k,$l,$m,$n) = @_;
  50. savefile($logs,"\n\n[START]\n\n".$$k."\n\n[END]\n") if $$k ne "";
  51. }
  52.  
  53. sub savefile {
  54. open (SAVE,">>".$_[0]);
  55. print SAVE $_[1]."\n";
  56. close SAVE;
  57. }
  58.  
  59. # ¿ The End ?
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4


El problema es que no aparece nada.

¿ Qué hay que hacer en este caso ?
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Publicidad

Re: Duda con módulo HTTP::Proxy

Notapor explorer » 2013-04-04 16:00 @708

¿Te refieres a que no sale nada en los logs?

Es posible que el proxy no esté recibiendo ninguna petición... O que el sistema donde estés tiene instalado un cortafuegos o algo así, ocupando ese puerto.

A propósito, la línea 30, sobra (no hace nada).
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Duda con módulo HTTP::Proxy

Notapor BigBear » 2013-04-04 16:47 @741

Pero, ¿lo estoy haciendo bien?, porque en el volcado sí aparece la información y no tengo ningún firewall que bloquee ese puerto.
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: Duda con módulo HTTP::Proxy

Notapor explorer » 2013-04-04 20:53 @912

Pues no sé porque nunca me he puesto a hacer un proxy como este.

Si sale la información en el dump, es que va bien la cosa. Lo que dices que luego no funcionan los métodos para acceder a esa información, es lo raro. Según la documentación de HTTP::Request, que es el objeto que estás sacando, se deberían poder usar los métodos de acceso a la información.

Como es difícil hacer un depurado paso a paso de lo que está pasando, se me ocurre que una opción es la de poner print dentro del código del propio HTTP::Request, para que vaya informando de lo que va haciendo cuando llamamos, por ejemplo, a header(). Mejor dicho: es dentro del módulo HTTP::Headers donde está definido header():

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. sub header
  2. {
  3.     my $self = shift;
  4.     Carp::croak('Usage: $h->header($field, ...)') unless @_;
  5.     my(@old);
  6.     my %seen;
  7.     while (@_) {
  8.         my $field = shift;
  9.         my $op = @_ ? ($seen{lc($field)}++ ? 'PUSH' : 'SET') : 'GET';
  10.         @old = $self->_header($field, shift, $op);
  11.     }
  12.     return @old if wantarray;
  13.     return $old[0] if @old <= 1;
  14.     join(", ", @old);
  15. }
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
que a su vez llama a _header()...
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Duda con módulo HTTP::Proxy

Notapor BigBear » 2013-04-05 17:00 @750

¡Qué raro! Lo acabo de probar en Ubuntu 10.04 para ver si ese era el problema pero tiene el mismo problema: no muestra nada.
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: Duda con módulo HTTP::Proxy

Notapor explorer » 2013-04-05 17:05 @754

¿Para qué sirve la línea 19, la de HTTP::Proxy::BodyFilter::complete?
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Duda con módulo HTTP::Proxy

Notapor BigBear » 2013-04-05 17:28 @769

Genial, encontré la solución, ya casi termino. Solo me falta saber cómo cambiar el contenido de la linea $c->content;. Mira el código mejorado:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. #A simple Proxy Server
  3. #Coded By Doddy H
  4. #ppm install http://theoryx5.uwinnipeg.ca/ppms/HTTP-Proxy.ppd
  5.  
  6. use HTTP::Proxy;
  7. use HTTP::Proxy::BodyFilter::simple;
  8. use HTTP::Proxy::BodyFilter::complete;
  9. use Data::Dumper;
  10. use HTTP::Headers;
  11.  
  12. use HTTP::Proxy::HeaderFilter::simple;
  13.  
  14. my $port = "8080";
  15. my $logs = "logs.txt";
  16.  
  17. print "\n\n[+] Proxy server Online in port $port\n\n";
  18.  
  19. my $server = HTTP::Proxy->new(port=>$port);
  20. $server->host();
  21.  
  22. $server->push_filter(
  23. mime=>undef,
  24. request=>HTTP::Proxy::HeaderFilter::simple->new(\&enable),
  25. response => HTTP::Proxy::BodyFilter::complete->new(\&enable2),
  26.  
  27. );
  28.  
  29. $server->start();
  30.  
  31. sub enable {
  32.  
  33. my @logs;
  34. my($a,$b,$c,$d,$e) = @_;
  35. my ($f,$g)=($c->header("cookie"),$c->header("x-requested-with"));
  36. my ($h,$i)=($c->header("content-type"),$c->header("content"));
  37.  
  38. #my $j = $c->header("user-agent"=>"hola mundo");
  39. #print Dumper $c;
  40. #print "soy el agente : ".$c->header("user-agent")."\n";
  41.  
  42. system("cls");
  43.  
  44. print "\n--\n";
  45. print $c->content;
  46. print "\n--\n";
  47.  
  48. savefile($logs,"\n[Peticion] : ".$c->method." ".$c->uri);
  49. savefile($logs,"[Cookie] : ".$f) if $f;
  50. savefile($logs,"[x-requested-with] : ".$g) if $g;
  51. savefile($logs,"[Content Type] : ".$h) if $h;
  52. savefile($logs,"[Content] : ".$i) if $i;
  53. savefile($logs,"");
  54.  
  55. }
  56.  
  57. sub enable2 {
  58. my ($j,$k,$l,$m,$n) = @_;
  59.  
  60. savefile($logs,"\n\n[START]\n\n".$$k."\n\n[END]\n") if $$k ne "";
  61. }
  62.  
  63. sub savefile {
  64. open (SAVE,">>".$_[0]);
  65. print SAVE $_[1]."\n";
  66. close SAVE;
  67. }
  68.  
  69. # ¿ The End ?
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4


¿ Cómo tendría que cambiarlo ?

P.d.: intenté cambiarlo como lo hice con el 'useragent', pero no se puede.
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Anterior

Volver a Módulos

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 3 invitados