Skip to content

Instantly share code, notes, and snippets.

@cmlh
Created August 25, 2013 23:22
Show Gist options
  • Save cmlh/6336922 to your computer and use it in GitHub Desktop.
Save cmlh/6336922 to your computer and use it in GitHub Desktop.
use LW2;
%request = ();
%response = ();
LW2::http_init_request(\%request);
$request{'whisker'}->{'host'} = "www.victim.com";
use LW2;
$request = LW2::http_new_request(host=>'www.victim.com', uri =>'/');
$response = LW2::http_new_response();
#Define the modules that we intend to use.
use strict;
use LW2;
use Getopt::Std;
#Define hashes for our command line options, request
#information and response information.
my (%opts, %request, %response, $headers_array, $header);
getopts('h:m:', \%opts);
#Initialize all the request variables. Some of these we will overwrite.
LW2::http_init_request(\%request);
if (!(defined($opts{h}))) {
die "You must specify a host to scan.\n";
}
if (defined($opts{m})) {
if ($opts{m} =~ /OPTIONS|HEAD|GET/) {
$request{'whisker'}->{'method'} = $opts{m};
} else {
die "You can only use OPTIONS, HEAD or GET for the method.\n";
}
}
##start making requests
#Set the host that we want to scan
$request{'whisker'}->{'host'} = $opts{h};
#Make RFC compliant
LW2::http_fixup_request(\%request);
#Do the actual scan.
if(LW2::http_do_request(\%request,\%response)){
##error handling
print 'ERROR: ', $response{'whisker'}->{'error'}, "\n";
print $response{'whisker'}->{'data'}, "\n";
} else {
##show results
#Get the information out of the anonymous array.
#'$headers_array' is a reference.
$headers_array = $response{'whisker'}->{'header_order'};
print "HTTP " ,$response{'whisker'}->{'version'}, "\t";
print $response{'whisker'}->{'code'} , "\n";
foreach $header (@$headers_array) {
print "$header";
print "\t$response{$header}\n";
}
}
#Define the modules that we intend to use.
use strict;
use LW2;
use Getopt::Std;
#Define hashes for our command line options,
#request information and response information.
my (%opts, %request, %response, $headers_array, $header);
##note the additions of 'd' for data and 'u' as
##the option for the URI, below
getopts('dh:m:u:', \%opts);
#Initialize all the request variables. Some of these we will overwrite.
LW2::http_init_request(\%request);
if (!(defined($opts{h}))) {
die "You must specify a host to scan.\n";
}
if (defined($opts{m})) {
if ($opts{m} =~ /OPTIONS|HEAD|GET/) {
$request{'whisker'}->{'method'} = $opts{m};
} else {
die "You can only use OPTIONS, HEAD or GET for the method.\n";
}
}
##now set URI if passed on command line
if (defined($opts{u})) {
$request{'whisker'}->{'uri'} = $opts{u};
}
#Set the host that we want to scan
$request{'whisker'}->{'host'} = $opts{h};
#Make RFC compliant
LW2::http_fixup_request(\%request);
#Do the actual scan.
if(LW2::http_do_request(\%request,\%response)){
print 'ERROR: ', $response{'whisker'}->{'error'}, "\n";
print $response{'whisker'}->{'data'}, "\n";
} else {
#Get the information out of the anonymous array.
#'$headers_array' is a reference.
$headers_array = $response{'whisker'}->{'header_order'};
print "\n\n";
print "HTTP " ,$response{'whisker'}->{'version'}, "\t";
print $response{'whisker'}->{'code'} , "\n";
foreach $header (@$headers_array) {
print "$header";
print "\t$response{$header}\n";
}
##if 'd' is passed, print some data
if (defined($opts{d})) {
print "\n\n-----------------------------
-----------------------------\n\n";
print $response{'whisker'}->{'data'} , "\n";
}
}
#Define the modules that we intend to use.
use strict;
use LW2;
use Getopt::Std;
#Define hashes for our command line options, request
#information, response information and cookies.
my (%opts, %request, %response, , %jar, $headers_array, $header);
##note the addition of 'U' and 'D' as options
getopts('dh:m:u:U:D:', \%opts);
#Initialize all the request variables. Some of these we will overwrite.
LW2::http_init_request(\%request);
if (!(defined($opts{h}))) {
die "You must specify a host to scan.\n";
}
if (defined($opts{m})) {
##defaults to GET if we need to POST
if ($opts{m} =~ /OPTIONS|HEAD|GET/) {
$request{'whisker'}->{'method'} = $opts{m};
}
}
if (defined($opts{u})) {
##don't set URI if method is POST
$request{'whisker'}->{'uri'} = $opts{u} unless ($opts{m} eq "POST");
}
##now set user-agent based on 'U' option
##'F', 'I' or 'N' for Firefox/IE/Netscape
##as explained in the text
if (defined($opts{U})) {
if ($opts{U} eq "F") {
$request{'User-Agent'} =
"Mozilla/5.0 (Windows; U; Windows NT 5.1;
en-US; rv:1.7) Gecko/20040614 Firefox/0.9";
} elsif ($opts{U} eq "I") {
$request{'User-Agent'} =
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
} elsif ($opts{U} eq "N") {
$request{'User-Agent'} =
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
Gecko/20030624 Netscape/7.1 (ax)";
} else {
die "You did not specify a supported \'User-Agent\'.\n";
}
}
#Set the host that we want to scan
$request{'whisker'}->{'host'} = $opts{h};
#Make RFC compliant
LW2::http_fixup_request(\%request);
#Do the actual scan.
H_REQUEST:
if(LW2::http_do_request(\%request,\%response)){
print 'ERROR: ', $response{'whisker'}->{'error'}, "\n";
print $response{'whisker'}->{'data'}, "\n";
} else {
##else preserve cookie info for our next request
LW2::cookie_read(\%jar, \%response);
#Get the information out of the anonymous array.
#'$headers_array' is a reference.
$headers_array = $response{'whisker'}->{'header_order'};
print "\n\n";
print "HTTP " ,$response{'whisker'}->{'version'}, "\t";
print $response{'whisker'}->{'code'} , "\n";
foreach $header (@$headers_array) {
print "$header";
print "\t$response{$header}\n";
}
if (defined($opts{d})) {
print "\n\n----------------------------------
------------------------\n\n";
print $response{'whisker'}->{'data'} , "\n";
}
if ($opts{m} eq "POST") {
LW2::cookie_write(\%jar, \%request);
$request{'whisker'}->{'method'} = "POST";
$request{'whisker'}->{'uri'} = $opts{u};
$request{'whisker'}->{'data'} = $opts{d };
LW2::http_fixup_request(\%request);
$opts{d} = undef;
$opts{m} = undef;
goto H_REQUEST;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment