• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

Fake a browser, using LWP module.

Hi, i need to be able to fake a browser post to a php script.
I want to fake a post to, http://www.hooya.com/sendsms.php3. But i have faild. whats wrong with this?

#!/usr/bin/perl

use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use LWP::UserAgent;


$cookie = new HTTP::Cookies( ignore_discard => 1 );
$ua = new LWP::UserAgent;
$ua->cookie_jar( $cookie );
$ua->agent("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)");

$myparams{"network"} = "0046703";
$myparams{"cb"} = "ON";
$myparams{"Anzahl"} = "119";
$myparams{"textarea"} = "Jag testar!";
$myparams{"gsm"} = "512221";

my $req = POST 'http://www.hooya.com/sendsms.php3', [ %myparams ];
   $req->push_header(HTTP_REFERER => 'http://www.hooya.com');

$page = $ua->request($req)->as_string;

open OUT,">hooya_log.txt" or die;
print OUT "$page\n";
close OUT;

print $page;

The server, www.hooya.com respons to my post is :

HTTP/1.1 302 (Found) Moved Temporarily
Connection: close
Date: Thu, 17 Feb 2000 20:42:27 GMT
Location: http://www.hooya.com
Server: Apache/1.2.6 Debian/GNU
Content-Type: text/html
Client-Date: Thu, 17 Feb 2000 20:43:23 GMT
Client-Peer: 195.100.21.240:80
Title: 302 Moved Temporarily

<HTML><HEAD>
<TITLE>302 Moved Temporarily</TITLE>
</HEAD><BODY>
<H1>Moved Temporarily</H1>
The document has moved <A HREF="http://www.hooya.com">here</A>.<P>
</BODY></HTML>

Plz help.

Thanxs a lot

/Hansen
0
mysig
Asked:
mysig
1 Solution
 
maneshrCommented:
try this.... it works....


==========hooya.pl
#!/usr/local/bin/perl -I/home/webuser/manesh

require LWP;
require URI::URL;

use strict;
use CGI;

my($hdr,$server_response);
my($statement_URL)="http://www.hooya.com/sendsms.php3";

#my($query)=new CGI;

## Right now the values are hard-coded
$hdr="network=0046703&cb=ON&Anzahl=130&textarea=Jag&gsm=512221";

$server_response=&browse($statement_URL,$hdr,3);   ## Fire the URL

print "Content-type: text/html\n\n";

print "$server_response";
   
sub browse(){
   my($statement_URL,$hdr,$page_no)=@_;
   my($content_type,$method);

   $content_type="application/x-www-form-urlencoded";

   $method="GET";

   my($headers)= new HTTP::Headers
     'Content-Type'   =>  $content_type,
     'MIME-Version'   =>  '1.0',
     'Date'           =>  HTTP::Date::time2str(time),
     'Accept'         =>  'text/html';

   my($ua)= new LWP::UserAgent;

   $ua->agent("Mozilla/4.7 [en] (WinNT; U)"); # Define env variable - HTTP_USER
_AGENT

   my($url)= new URI::URL($statement_URL);
   my($request)= new HTTP::Request($method, $url, $headers,$hdr);

   my($response)= $ua->request($request);

   my($reply);

   if ($response->is_success){
      $reply=$response->content;
   }else{
      $reply=$response->error_as_HTML();
   }
   return $reply;
}
0
 
mysigAuthor Commented:
It worked with som modifications,

$method="POST";

And under my($headers) i add the following:
'Referer'  =>  'http://www.hooya.com/';

Post it as an answer and i will give u your points.
0
 
maneshrCommented:
gotcha!! the resulting output has a small piece of javascript code that checks the no of frames and redirects to home page is the no of frames are not 3.

you can add a small piece of PERL code after line 21 to eliminate that problem too.

@page=split(/\n/,$server_response);

foreach(@page){
  ## here search and remove the javascript code.
}

====================hooya.pl
   +1   #!/usr/local/bin/perl -I/home/webuser/manesh
    +2
    +3   require LWP;
    +4   require URI::URL;
    +5
    +6   use strict;
    +7   use CGI;
    +8
    +9   my($hdr,$server_response);
   +10   my($statement_URL)="http://www.hooya.com/sendsms.php3";
   +11
   +12   #my($query)=new CGI;
   +13
   +14   ## Right now the values are hard-coded
   +15   $hdr="network=0046703&cb=ON&Anzahl=130&textarea=Jag&gsm=512221";
   +16
   +17   $server_response=&browse($statement_URL,$hdr,3);   ## Fire the URL
   +18
   +19   print "Content-type: text/html\n\n";
   +20
   +21   print "$server_response";
   +22
   +23   sub browse(){
   +24      my($statement_URL,$hdr,$page_no)=@_;
   +25      my($content_type,$method);
   +26
   +27      $content_type="application/x-www-form-urlencoded";
   +28
   +29      $method="POST";
   +30
   +31      my($headers)= new HTTP::Headers
   +32        'Content-Type'   =>  $content_type,
   +33        'MIME-Version'   =>  '1.0',
   +34        'Date'           =>  HTTP::Date::time2str(time),
   +35        'Accept'         =>  'text/html',
   +36        'Referer'        =>  'http://www.hooya.com/';
   +37
   +38      my($ua)= new LWP::UserAgent;
   +39
   +40      $ua->agent("Mozilla/4.7 [en] (WinNT; U)"); # Define env variable -
HTTP_USER_AGENT
   +41
   +42      my($url)= new URI::URL($statement_URL);
   +43      my($request)= new HTTP::Request($method, $url, $headers,$hdr);
   +44
   +45      my($response)= $ua->request($request);
   +46
   +47      my($reply);
   +48
   +49      if ($response->is_success){
   +50         $reply=$response->content;
   +51      }else{
   +52         $reply=$response->error_as_HTML();
   +53      }
   +54      return $reply;
   +55   }
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
jasoncolsonCommented:
I'm looking for an ISP that has the LWP module installed.  Any suggestions, guys?
0
 
ozoCommented:
You might install it yourself.
0
 
fpoyavoCommented:
Hi,

This line : my($statement_URL)="http://www.hooya.com/sendsms.php3">http://www.hooya.com/sendsms.php3";

gives error : bareword found ......near //www ????

How to fix it ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now