#!/usr/bin/perl # this script is an example on how to make a HTTP request using libwhisker $|++; use LW2; $TARGET=shift; # %request contains the request values passed to libwhisker/server # %response contains the response values received from libwhisker/server # %jar contains all our cookies my (%request, %response, %jar); # this sets up some standard values in the given hash LW2::http_init_request(\%request); # set the target host and URI $request{'whisker'}->{'host'}=$TARGET; $request{'whisker'}->{'uri'}="/index.html"; # $request{'whisker'}->{'port'}=80; # port 80 is default # SSL support seems ok, but still reserves the right to be buggy #$request{'whisker'}->{'port'}=443; #$request{'whisker'}->{'ssl'}=1; #$request{'whisker'}->{'save_ssl_info'}=1; # proxy support # $request{'whisker'}->{'proxy_host'}='localhost'; # $request{'whisker'}->{'proxy_port'}=8080; # anti-IDS # $request{'whisker'}->{'anti_ids'}='12345'; # values are the modes # basic auth #LW2::do_auth('basic',\%request,'username','password'); #LW2::do_auth('basic-proxy',\%request,'username','password'); #LW2::do_auth('ntlm',\%request,'username','password'); #LW2::do_auth('ntlm',\%request,'username','password','domain'); # special function to tweak the request to make sure it's valid HTTP # (not required if you set it all manually, but it never hurts) LW2::http_fixup_request(\%request); # if there's any cookies in the %jar, then set them as appropriate # LW2::cookie_write(\%jar,\%request); # actually make the request (and get response) if(LW2::http_do_request(\%request,\%response)){ print 'ERROR: ', $response{'whisker'}->{'error'}, "\n"; print $response{'whisker'}->{'data'}, "\n"; } else { # save any cookies sent to us into our %jar # LW2::cookie_read(\%jar,\%response); print $response{'whisker'}->{'code'}, "\n"; # HTTP return code print $response{'Server'}, "\n"; # Server banner # Uncomment following line if you want to see resulting HTML data # print $response{'whisker'}->{'data'}, "\n"; # If we wanted to save the SSL info (only works with Net::SSLeay) if(defined $request{whisker}->{save_ssl_info}){ print 'SSL cipher: ', $response{whisker}->{ssl_cipher},"\n"; print "Server cert:\n\t", $response{whisker}->{ssl_cert_subject},"\n"; print "Cert issuer:\n\t", $response{whisker}->{ssl_cert_issuer},"\n"; } } # good practice to clean up our mess &LW2::http_reset;