XWorm
XWorm

Reputation: 197

Cant make an SSL request with perl

Here is my code

use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use LWP::Protocol::https;
use strict;
use warnings;
use CACertOrg::CA;


my $URL="https://ta.example.co.il/f5-w-687474703a2f2f746573742e636c616c6e65742e636f2e696c$$/toolsandforms/specialissearch/policysearch/Pages/default.aspx";
my $UA = LWP::UserAgent->new();

my $xml = <<XMLREQUEST;

__SPSCEditMenu=true
XMLREQUEST

$UA->ssl_opts(
     SSL_verify_mode   => 'SSL_VERIFY_NONE',
);

my $req =HTTP::Request::Common::POST("$URL",
   Content_type=>'form-data',
   Content =>$xml
);

$req->header('Cookie' =>q( Cookie: TIN=294000; LastMRH_Session=ca480946; MRHSession=7e53c7507df395d38a2eb230ca480946; F5_ST=1382338632c900c100c1382338632c604800c600c; MRHSequence=1382338609),
             'DNT'=>'1',
             'Referer'=> 'https://ta.example.co.il/f5-w-687474703a2f2f746573742e636c616c6e65742e636f2e696c$$/testing/notificationsandalerts/Pages/Default.aspx?txtTabID=0&txtType=1',
             'User-Agent'=>'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; EIE10;HEILMSN',
             'Content-Type'=>'application/x-www-form-urlencoded');


my $response=$UA->request($req);

if ($response->is_success) {
  print $response->decoded_content;  
}
else {
  die $response->status_line;  
}

I get this error in eclipse.

write failed: at C:/Perl/lib/LWP/Protocol/http.pm line 356. 500 write failed: at C:/Perl/Workplace/P1/SimpleCSRF.pl line 41.

Why is it failed to write? It is a simple request to an ssl page? How can I enable more verbose debugging to see what is being returned?

I also tried with SSL easy and I get 302 response each time.

use strict;

use warnings; use Net::SSLeay qw(get_https post_https sslcat make_headers make_form);

my $head=<<HEADREQUEST;
           Host: ta.example.co.il
            Connection: keep-alive
            Content-Length: 154768
            Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
            Origin: https://ta.example.co.il
            User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
            Content-Type: application/x-www-form-urlencoded
            Referer: https://ta.example.co.il/f5-w-687474703a2f2f746573742e636c616c6e65742e636f2e696c$$/testing/notificationsandalerts/Pages/Default.aspx?txtTabID=0&txtType=1
            Accept-Encoding: gzip,deflate,sdch
            Accept-Language: en,en-US;q=0.8
            Cookie: TIN=15000; LastMRH_Session=8acc0244; MRHSession=f5d160f7be2a40e290cd37f38acc0244; MRHSequence=1382340967; F5_ST=1382340968c900c100c1382340968c604800c600c
HEADREQUEST

my $body=<<BODY;
AGRkZAIDDc_46c9_9a5a_167e29fefb40%24txtCSRFValidation=&ctl00%24SPWebPartManager1%24g_137a0e02_1a49_45df_a17f_45dd7b48cbca%24txtCSRFValidation=
BODY
my $url='/f5-w-687474703a2f2f746573742e636c616c6e65742e636f2e696c$$/testing/notificationsandalerts/Pages/Default.aspx?txtTabID=0&txtType=1 ';
my ($page, $response, %reply_headers)= post_https('ta.example.co.il', 443, $url, $head,$body );


     print $response;

Upvotes: 0

Views: 1921

Answers (1)

user1126070
user1126070

Reputation: 5069

What versions are you using from each of the modules? Which perl version are you using?

Did they installed well?

If it helps, there are ppm packages for both Net::SSLeay at the sisyphusion repo (and probably elsewhere, too):

ppm install http://www.sisyphusion.tk/ppm/Net-SSLeay.ppd

I used this code, and it was worked.

use LWP::UserAgent;
use HTTP::Request::Common;

use Data::Dumper;


local $ENV{'HTTPS_DEBUG'} = 1; # Will show SSL assertions

my $URL="https://www.google.com/";
my $UA = LWP::UserAgent->new();

my $xml = <<XMLREQUEST;

__SPSCEditMenu=true
XMLREQUEST

$UA->ssl_opts(
     SSL_verify_mode   => 'SSL_VERIFY_NONE',
);

my $req =HTTP::Request::Common::POST("$URL",
   Content_type=>'form-data',
   Content =>$xml
);

$req->header('Cookie' =>q( Cookie: TIN=294000; LastMRH_Session=ca480946; MRHSession=7e53c7507df395d38a2eb230ca480946; F5_ST=1382338632c900c100c1382338632c604800c600c; MRHSequence=1382338609),
             'DNT'=>'1',
             'Referer'=> 'https://google.co.uk',
             'User-Agent'=>'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; EIE10;HEILMSN',
             'Content-Type'=>'application/x-www-form-urlencoded');

print Dumper($req);

Upvotes: 0

Related Questions