1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#!/usr/bin/perl
# this script is an example on how to make a HTTP request using libwhisker
$|++;
use LW2;
$TARGET=shift;
# check to make sure target is appropriate
if($TARGET!~m#^https*://#){
print "Usage: $0 http://target-host/url\n";
exit;
}
# $request contains the request values passed to libwhisker/server
# $response contains the response values received from libwhisker/server
my $request = LW2::http_new_request();
my $response = LW2::http_new_response();
# %jar will contain all our cookies
my $jar = LW2::cookie_new_jar();
# this is no longer needed, since http_new_request() calls it automatically
#LW2::http_init_request($request);
# set the target host and URI; uri_split() will handle all the SSL
# junk if the URL starts with https://, and also handle abnormal ports,
# setting the URI and parameters, etc.
LW2::uri_split($TARGET, $request);
# we can manually set/override values
#$request->{'whisker'}->{'host'}='www.example.com'; # 'localhost' is the default
#$request->{'whisker'}->{'uri'}="/index.html"; # '/' is the default
#$request->{'whisker'}->{'port'}=80; # port 80 is default
# example on how to enable SSL support
#
# Note: uri_split() will set these values automatically if it is passed
# a URL which starts with "https://"
#
#$request->{'whisker'}->{'port'}=443; # default SSL port
#$request->{'whisker'}->{'ssl'}=1; # tell libwhisker to use SSL
# Save the SSL server certificate information for viewing
$request->{'whisker'}->{'ssl_save_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::auth_set('basic',$request,'username','password');
#LW2::auth_set('basic-proxy',$request,'username','password');
#LW2::auth_set('ntlm',$request,'username','password');
#LW2::auth_set('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
if($request->{whisker}->{ssl}>0 &&
$request->{whisker}->{ssl_save_info}>0){
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";
}
# Uncomment following line to dump out the entire response hash
#print LW2::dump('response', $response);
}
# good practice to clean up our mess
LW2::http_reset();
|