-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasp-auditor.pl
6642 lines (5226 loc) · 184 KB
/
asp-auditor.pl
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
my $VERSION="[ASP Auditor v2.2]";
# ASP Auditor [BETA]
# Author david.kierznowski_at_gmail.com
# http://michaeldaw.org
#
# purpose: Look for common misconfigurations and information leaks in
# ASP.NET applications.
#
# usage: Run with no arguments for usage instructions.
#
# Changelog:
# --v2.2-- 20/Apr/07
# * Added additional support for Anti-XSS Validation detection.
# * Added ASP Source Directory Leak Check
# * Added Apr/07 ASP.NET XSS Detection
#
# --v2.1-- 25/Sep/06
# * GET /Trace.axd often leaks ASP.NET version when other methods fail.
# * Fixed "?" bug in JavaScript Validate test
# * Added Version into usage()
#
# --v2.0-- 16/Sep/06
# * Version plugin allowing specific ASP.NET versioning.
# * Version brute force capabilities using JavaScript validate
# directories.
# * Check if global ASP.NET validate is being used.
# * Added brute force function and option in usage()
#
# This tool is based on H D Moore's Dot Net Application Scanner
# Author: H D Moore <hdm@digitaloffense.net>
# url: http://www.digitaloffense.net/index.html?section=TOOLS
#
# This script includes libwhisker v1.6
# libwhisker copyright 2000,2001,2002 rfp.labs
# see comments after "package LW" for full headers
#
$|++;
use FindBin qw{$Bin};
##
# use strict; # the embedded libwhisker breaks this :(
##
##( Initialize Variables
my (%hin, %hout, %jar, %options);
my (@sorted, @unsorted, $prevkey);
##( Parse Arguments
my $target = shift() || usage();
my $bf = shift();
if ($target !~ /(^http:\/\/|^https:\/\/)/)
{
print STDERR "[*] Please specify the complete URL (ex: http://www.site.int/)\n\n";
exit(0);
}
my @target_vals = LW::utils_split_uri($target);
if ($target_vals[1] !~ /(^http$|^https$)/)
{
print STDERR "[*] Only http and https URL's are supported.\n";
usage();
}
##( Create HIN
my $hin = ConfigureRequest (@target_vals);
$hin->{'Content-type'} = "application/x-www-form-urlencoded";
$hin->{'Accept-Charset'} = "iso-8859-1,*,utf-8";
$hin->{'Accept'} = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*";
$hin->{'Accept-Language'} = "en";
$hin->{'Referer'} = $target;
$hin->{'User-Agent'} = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
##( Start Execution
# ASP Versions for use in fingerprint function
my %aspver = (
"1.0.2204.21" => "Version 1.0 Public Beta 1 Nov 2000 ",
"1.0.2914.16" => "Version 1.0 Public Beta 2 Jun 2001 ",
"1.0.3512.0" => "Version 1.0 Pre-release RC3 (Visual Studio.NET 2002 RC3)",
"1.0.3705.0" => "Version 1.0 RTM (Visual Studio.NET 2002) Feb 2002 ",
"1.0.3705.209" => "Version 1.0 SP1 Mar 2002 ",
"1.0.3705.288" => "Version 1.0 SP2 Aug 2002 ",
"1.0.3705.6018" => "Version 1.0 SP3 Aug 2004",
"1.1.4322.510" => "Version 1.1 Final Beta Oct 2002 ",
"1.1.4322.573" => "Version 1.1 RTM (Visual Studio.NET 2003 / Windows Server 2003) Feb 2003 ",
"1.1.4322.2032" => "Version 1.1 SP1 Aug 2004",
"1.1.4322.2300" => "Version 1.1 Post-SP1 (Windows Server 2003 SP1) Mar 2005",
"1.2.21213.-1" => "Version 1.2 (Whidbey pre-Alpha build) ",
"1.2.30703.27" => "Version 1.2 (Whidbey Alpha, PDC 2004) Nov 2003 ",
"2.0.40301.9" => "Version 2.0 (Whidbey CTP, WinHEC 2004) Mar 2004 ",
"2.0.40426.16" => "Version 2.0 (Whidbey CTP, TechEd US 2004) May 2004",
"2.0.40607.16" => "Version 2.0 (Visual Studio.NET 2005 Beta 1, TechEd Europe 2004) Jun 2004",
"2.0.40607.42" => "Version 2.0 (SQL Server Yukon Beta 2) Jul 2004",
"2.0.40607.85" => "Version 2.0 (Visual Studio.NET 2005 Beta 1, Team System Refresh) Aug 2004 ",
"2.0.40903.0" => "Version 2.0 (Whidbey CTP, Visual Studio Express) Oct 2004",
"2.0.41115.19" => "Version 2.0 (Visual Studio.NET 2005 Beta 1, Team System Refresh) Dec 2004",
"2.0.50110.28" => "Version 2.0 (Visual Studio.NET 2005 CTP, Professional Edition) Feb 2005",
"2.0.50215.44" => "Version 2.0 (Visual Studio.NET 2005 Beta 2, Visual Studio Express Beta 2) Apr 2005",
"2.0.50601.0" => "Version 2.0 (Visual Studio.NET 2005 CTP) Jun 2005",
"2.0.50215.322" => "Version 2.0 (Beta 2, WinFX) Sep 2005",
"2.0.50727.07" => "Version 2.0 (Visual Studio.NET 2005 CTP) Aug 2005",
"2.0.50727.26" => "Version 2.0 (Visual Studio.NET 2005 RC / SQL Server 2005 CTP) Sep 2005",
"2.0.50727.42" => "Version 2.0 RTM (Visual Studio.NET 2005 RTM / SQL Server 2005 RTM) Nov 2005",
);
# end of aspver hash
print STDERR "[*] Sending initial probe request...\n";
my $init_req = 0;
while ($init_req < 2)
{
# perform a normal GET request to the target URL
$hin->{'whisker'}->{'method'} = "GET";
SendRequest($hin, \%hout);
# process the response message
LW::cookie_read(\%jar, \%hout);
foreach my $c (keys(%jar))
{
if ($jar{$c}->[0] eq '')
{
# blank value, often this cookie is set to a null value on the
# login page of an asp.net app using Forms Authentication, so
# we should save this for future attacks
push @{$options{"AuthCookies"}}, $c;
print STDERR "[*] Possible authentication cookie: $c\n";
}
}
# look for the asp.net session handler cookie
if ($jar{"ASP.Net_Session"}) { $options{"Sessions"}++ }
# Save the asp.net version number if it is available
if ($hout{"X-AspNet-Version"}) { $options{"ADNVersion"} = $hout{"X-AspNet-Version"} }
# Save the server name while we are at it
if ($hout{"Server"}) { $options{"Server"} = $hout{"Server"} }
if ($hout{'whisker'}->{'data'} =~ m/\_\_VIEWSTATE\" value=\"([^\"]*)\" \/\>/)
{
my $VSR = LW::decode_base64($1);
$options{"ViewState"}++;
if ($VSR =~ m/^t<(.[0-9]{4,15});/) { $options{"VSPageID"} = $1 }
}
if ($hout{'whisker'}->{'code'} == 302 && $hout{'whisker'}->{'data'} =~ m/href=\'([^\']*)/)
{
my $loc = $1;
$hin->{'whisker'}->{'uri'} = $loc;
print STDERR "[*] Recieved a redirect response to $loc...\n";
if ($loc =~ m/\/\((.{1,32})\)\//)
{
$options{"CookielessSessions"}++;
$options{"CookielessSessionValue"} = $1;
}
# give it one more change to give us a real page
$init_req++;
} else {
# the first request was just fine, exit the loop
$init_req+=2;
}
}
# test the View State
if ($options{"ViewState"} && $options{"VSPageID"})
{
print STDERR "[*] Testing the View State...\n";
# send a request with an invalid (null key) ViewState
$hin->{'whisker'}->{'method'} = "POST";
$hin->{'whisker'}->{'data'} = '__VIEWSTATE=' . LW::encode_str2uri(LW::encode_base64("t<" . $options{"VSPageID"} . ";t<p<l<;>;l<187;>>;;>;>"));
SendRequest($hin, \%hout);
if ($hout{'whisker'}->{'code'} == 302)
{
$options{"CustomErrors"} = "On";
if ($hout{'whisker'}->{'data'} =~ m/href=\'(.*)\?aspxerrorpath=/)
{
$options{"ErrorHandler"} = $1;
}
}
if ($hout{'whisker'}->{'data'} =~ /viewable on remote machines/)
{
$options{"CustomErrors"} = "RemoteOnly";
}
if ($hout{'whisker'}->{'data'} =~ /the view.*state is invalid for this page/i)
{
$options{"CustomErrors"} = "Off";
$options{"ViewStateMac"} = "True";
}
# newer versions of asp.net do not allow the MAC to be disabled
if ($hout{'whisker'}->{'data'} =~ /key cannot be null or empty/i)
{
$options{"CustomErrors"} = "Off";
$options{"ViewStateMac"} = "False";
}
}
my $orig_uri = $hin->{'whisker'}->{'uri'};
# request a non-existent file and parse the error message
# the aspxerrorpath argument prevents us from being redirected
# and shows us the application name and directory for the url
# some systems also disclose the drive path in HTML comments (stack trace)
print STDERR "[*] Sending path discovery request...\n";
my $fake_uri = $orig_uri;
my $fake_asp = "FAQ$$.aspx";
if ($fake_uri =~ m/(.*)\//) { $fake_uri = $1 }
$fake_uri .= "/$fake_asp?aspxerrorpath=/";
$hin->{'whisker'}->{'uri'} = $fake_uri;
$hin->{'whisker'}->{'method'} = "GET";
SendRequest($hin, \%hout);
$hin->{'whisker'}->{'uri'} = $orig_uri;
if ($hout{'whisker'}->{'data'} =~ m/Server Error in \'(.*)\' Application/) { $options{"Application"} = $1 }
if ($hout{'whisker'}->{'data'} =~ m/FileNotFoundException.*([A-Z]:.*)\\$fake_asp/i) { $options{"FilePath"} = $1 }
# this version is more granular than the one provided by the http header
if ($hout{'whisker'}->{'data'} =~ m/ASP.NET Version:([0-9].*)/) { $options{"ADNVersion"} = $1 }
# Requesting <script>...</script> will cause .NET validate to cry
# if enabled.
print STDERR "[*] Sending ASP.NET validate discovery request...\n";
my $fake_uri = $orig_uri;
# This is not really required.
#my $fake_asp = "FAQ$$.aspx?<script>FAQ$$</script>";
my $fake_asp = "?<script>alert(1)</script>";
if ($fake_uri =~ m/(.*)\//) { $fake_uri = $1 }
$fake_uri .= "/$fake_asp";
$hin->{'whisker'}->{'uri'} = $fake_uri;
$hin->{'whisker'}->{'method'} = "GET";
SendRequest($hin, \%hout);
$hin->{'whisker'}->{'uri'} = $orig_uri;
if ($hout{'whisker'}->{'data'} =~ m/for security reasons|A potentially dangerous/) { $options{"ASPValidate"} = "ASP.NET Anti-XSS Library Enabled." }
if ($hout{'whisker'}->{'data'} =~ m/(c:\\windows.*)\<b/i) { $options{"ASPDirLeak"} = "Source File Dir Leak: $1" }
print STDERR "[*] Sending ASP.NET Apr/07 XSS Check\n";
my $fake_uri = $orig_uri;
my $fake_asp = "?<//STYLE=x:e/**/xpression(alert('asp-audit'))>";
if ($fake_uri =~ m/(.*)\//) { $fake_uri = $1 }
$fake_uri .= "/$fake_asp";
#print $fake_uri;
$hin->{'whisker'}->{'uri'} = $fake_uri;
$hin->{'whisker'}->{'method'} = "GET";
SendRequest($hin, \%hout);
$hin->{'whisker'}->{'uri'} = $orig_uri;
# Not testing a great deal.
# we send: <//STYLE=x:e/**/xpression(alert('asp-audit'))>
if ($hout{'whisker'}->{'data'} =~ m/\<\/\/STYLE=x.*asp-audit/) {
$options{"ASPXSSBypass1"} = "ASP XSS Bypass 1 Successful (http://michaeldaw.org/news/news-030407/)" }
# determine if tracing is enabled by sending a request for
# trace.axd in the application root and parsing the response.
print STDERR "[*] Sending application trace request...\n";
if (! $options{"Application"})
{
$fake_uri = $orig_uri;
if ($fake_uri =~ m/(.*)\//) { $fake_uri = $1 }
$fake_uri .= "/trace.axd";
} else {
$fake_uri = $options{"Application"} . "/trace.axd";
if ($options{"CookielessSessions"})
{
$fake_uri = "/(" . $options{"CookielessSessionValue"} . ")$fake_uri";
}
}
$fake_uri =~ s/\/\//\//;
$hin->{'whisker'}->{'uri'} = $fake_uri;
$hin->{'whisker'}->{'method'} = "GET";
SendRequest($hin, \%hout);
$hin->{'whisker'}->{'uri'} = $orig_uri;
if ($hout{'whisker'}->{'data'} =~ m/Server Error in \'(.*)\' Application/) { $options{"Application"} = $1 }
if ($hout{'whisker'}->{'data'} =~ /viewable on remote machines/) { $options{"AppTrace"} = "LocalOnly" }
if ($hout{'whisker'}->{'data'} =~ /Application Trace/) { $options{"AppTrace"} = "Enabled" }
# DK: Added 25/Sep/06. Grab ADN Version if its available - this often works when other tests fail.
if (! $options{"ADNVersion"} && $hout{"X-AspNet-Version"}) { $options{"ADNVersion"} = $hout{"X-AspNet-Version"} }
if ($hout{'whisker'}->{'data'} =~ m/ASP.NET Version:([0-9].*)/) { $options{"ADNVersion"} = $1 }
# request a .REM extension with a file name consisting of
# the DOS 'NUL' special device name and parse the response
if ((! $options{"CustomErrors"} || ! $options{"ADNVersion"}) )
{
print STDERR "[*] Sending null remoter service request...\n";
if (! $options{"Application"})
{
$fake_uri = $orig_uri;
if ($fake_uri =~ m/(.*)\//) { $fake_uri = $1 }
$fake_uri .= "/NUL.REM";
} else {
$fake_uri = $options{"Application"} . "/NUL.REM";
if ($options{"CookielessSessions"})
{
$fake_uri = "/(" . $options{"CookielessSessionValue"} . ")$fake_uri";
}
}
$fake_uri =~ s/\/\//\//;
$hin->{'whisker'}->{'uri'} = $fake_uri;
$hin->{'whisker'}->{'method'} = "GET";
SendRequest($hin, \%hout);
$hin->{'whisker'}->{'uri'} = $orig_uri;
# <= windows 2000
if ($hout{'whisker'}->{'data'} =~ m/be viewed by browsers running on the local server/i) { $options{"CustomErrors"} = "On" }
# >= windows 2003
if ($hout{'whisker'}->{'data'} =~ m/get more info turn on customErrors/i) { $options{"CustomErrors"} = "On" }
# <= windows 2000 customErrors=Off
if ($hout{'whisker'}->{'data'} =~ m/invalid file name for monitoring/i) { $options{"CustomErrors"} = "Off" }
if ($hout{'whisker'}->{'data'} =~ m/System.ArgumentNullException/i) { $options{"CustomErrors"} = "Off" }
#if ($hout{'whisker'}->{'data'} =~ m/No receiver registered/i) { $options{"CustomErrors"} = "Unknown" }
# Save the asp.net version number if it is available
if (! $options{"ADNVersion"} && $hout{"X-AspNet-Version"}) { $options{"ADNVersion"} = $hout{"X-AspNet-Version"} }
if ($hout{'whisker'}->{'data'} =~ m/ASP.NET Version:([0-9].*)/) { $options{"ADNVersion"} = $1 }
# print $hout{'whisker'}->{'data'};
}
# generate the report
print "\n[ .NET Configuration Analysis ]\n\n";
foreach (keys(%options))
{
print " " . (" " x (13 - length($_))) . $_ . "\t-> " . $options{$_} . "\n";
}
# Match ADNVersion with aspver hash
if ($options{"ADNVersion"}) {
# Credits to MacGyveR (macgyver@thedumbterminal.co.uk) for multi-platform chomp.
# This confuzzled me for almost an hour.
$options{"ADNVersion"} =~ s/\n|\r$//g;
my $ADN = $options{"ADNVersion"};
print "\n";
while ( my ($version, $data) = each(%aspver) )
{
# print $version . " " . $ADN . "\n";
if ($version =~ /$ADN/)
{
print "\tmatches\t-> $version $data\n";
}
}
}
print "\n";
if ($bf =~ /-bf/) {
# JavaScript validate brute force version check.
print STDERR "[*] Sending brute force discovery requests...\n";
# Get rid of duplicate asp vers
while ( my ($key, $value) = each(%aspver) )
{
if ($key =~ /(\d)\.(\d)\.(\d+)/)
{
my $key = $1 . $2 . $3;
push (@unsorted, $key);
push (@unsorted, "\n");
}
}
foreach my $key (sort { $a <=> $b } @unsorted)
{
push (@sorted, $key . "\n") unless ($key =~ /$prevkey/);
$prevkey = $key;
}
# print @sorted;
foreach my $line (@sorted) {
if ($line =~ /(\d)(\d)(\d+)/)
{
my $newver = $1 . "_" . $2 . "_" . $3;
my $bf_uri = $orig_uri;
if ($bf_uri =~ m/(.*)\//) { $bf_uri = $1 }
$bf_uri .= "/aspnet_client/system_web/$newver";
$hin->{'whisker'}->{'uri'} = $bf_uri;
$hin->{'whisker'}->{'method'} = "GET";
SendRequest($hin, \%hout);
$hin->{'whisker'}->{'uri'} = $orig_uri;
if ($hout{'whisker'}->{'data'} =~ /Virtual Directory|has moved (.*)\d{1}.\d{1}.\d+/) { $options{"JSValidate"} = "1" } else { $options{"JSValidate"} = 0}
# print $hout{'whisker'}->{'data'};
$newver =~ s/\_/\./g;
# print $options{"JSValidate"} . "\n";
print "\tFound -> $bf_uri \n" if ($options{"JSValidate"} =~ /1/);
}
}
}
# disconnect the session
LW::http_reset();
##( All Done, Exit
exit(0);
##( Begin Subroutines
#
#
sub usage
{
print "\n$VERSION\n";
print "Usage: $0 [http://target/app/file.aspx] (opts)
(opts)
-bf brute force ASP.NET version using JS Validate
directories.\n\n";
exit(1);
}
sub CheckLW {
# require libwhisker-1.6 or newer
if ($LW::VERSION =~ /^(0|1\.[0-5]$)/) {
print STDERR "Error: Please upgrade to libwhisker 1.6 or newer.\n";
exit(1);
}
}
sub SendRequest {
my ($hin, $hout) = @_;
LW::http_fixup_request($hin);
if (LW::http_do_request($hin,$hout)) {
print 'ERROR: ', $hout{'whisker'}->{'error'}, "\n";
print $hout{'whisker'}->{'data'}, "\n";
exit(0);
} else {
return $hout;
}
}
sub ConfigureRequest {
my @target_vals = @_;
my %hin = ();
my $hin = \%hin;
LW::http_init_request($hin);
##( Set the URI
$hin{'whisker'}->{'uri'} = $target_vals[0];
##( Set the Host
$hin{'whisker'}->{'host'} = $target_vals[2];
##( Set the Port
$hin{'whisker'}->{'port'} = $target_vals[3];
##( Configure SSL and Default Port
if ($target_vals[1] eq "https")
{
$hin{'whisker'}->{'ssl'} = 1;
$hin{'whisker'}->{'save_ssl_info'} = 1;
if ( ($target_vals[3] + 0 ) == 0) { $hin{'whisker'}->{'port'} = 443; }
} else {
if ( ($target_vals[3] + 0 ) == 0) { $hin{'whisker'}->{'port'} = 80; }
}
##( Configure HTTP Authentication
if ($target_vals[6] && $target_vals[7])
{
LW::auth_set_header('basic', \%hin, $target_vals[6], $target_vals[7]);
}
return $hin;
}
# libwhisker v1.6
# libwhisker is a collection of routines used by whisker
#
# libwhisker copyright 2000,2001,2002 rfp.labs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# More information can be found at http://www.wiretrip.net/rfp/
# Libwhisker mailing list and resources are also available at
# http://sourceforge.net/projects/whisker/
#
package LW;
use 5.004;
$LW::VERSION = "1.6";
####### external module tests ###################################
BEGIN
{
## LW module manager stuff ##
%LW::available = ();
$LW::LW_HAS_SOCKET = 0;
$LW::LW_HAS_SSL = 0;
$LW::LW_SSL_LIB = 0;
$LW::LW_NONBLOCK_CONNECT = 0;
## binary helper - may contain functions substituted further down ##
eval "use LW::bin"; # do we have libwhisker binary helpers?
if ($@) { $LW::available{'LW::bin'} = $LW::bin::VERSION; }
## encode subpackage ##
eval "require MIME::Base64";
if ($@)
{
*encode_base64 = \&encode_base64_perl;
*decode_base64 = \&decode_base64_perl;
}
else
{
# MIME::Base64 typically has faster C versions
$LW::available{'mime::base64'} = $MIME::Base64::VERSION;
*encode_base64 = \&MIME::Base64::encode_base64;
*decode_base64 = \&MIME::Base64::decode_base64;
}
## md5 subpackage ##
eval "require MD5";
if ( !$@ ) { $LW::available{'md5'} = $MD5::VERSION; }
## http subpackage ##
eval "use Socket"; # do we have socket support?
if ($@) { $LW::LW_HAS_SOCKET = 0; }
else
{
$LW::LW_HAS_SOCKET = 1;
$LW::available{'socket'} = $Socket::VERSION;
}
if ($LW::LW_HAS_SOCKET)
{
eval "use Net::SSLeay"; # do we have SSL support?
if ($@) { $LW::LW_HAS_SSL = 0; }
else
{
$LW::LW_HAS_SSL = 1;
$LW::LW_SSL_LIB = 1;
$LW::available{'net::ssleay'} = $Net::SSLeay::VERSION;
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();
}
if ( !$LW::LW_HAS_SSL )
{
eval "use Net::SSL"; # different SSL lib
if ($@) { $LW::LW_HAS_SSL = 0; }
else
{
$LW::LW_HAS_SSL = 1;
$LW::LW_SSL_LIB = 2;
$LW::available{'net::ssl'} = $Net::SSL::VERSION;
}
}
## non-blocking IO ##
if ( $^O !~ /Win32/ )
{
eval "use POSIX qw(:errno_h :fcntl_h)"; # better
if ( !$@ )
{
$LW::LW_NONBLOCK_CONNECT = 1;
}
}
} # if($LW_HAS_SOCKET)
} # BEGIN
####### package variables #######################################
## crawl subpackage ##
%LW::crawl_config = (
'save_cookies' => 0,
'reuse_cookies' => 1,
'save_offsites' => 0,
'follow_moves' => 1,
'url_limit' => 1000,
'use_params' => 0,
'params_double_record' => 0,
'skip_ext' => '.gif .jpg .gz .mp3 .swf .zip ',
'save_skipped' => 0,
'save_referrers' => 0,
'do_head' => 0,
'callback' => 0,
'slashdot_bug' => 1,
'normalize_uri' => 1,
'source_callback' => 0
);
@LW::crawl_urls = ();
%LW::crawl_server_tags = ();
%LW::crawl_referrers = ();
%LW::crawl_offsites = ();
%LW::crawl_cookies = ();
%LW::crawl_forms = ();
%LW::crawl_temp = ();
# this idea/structure was taken from HTML::LinkExtor.pm,
# copyright 2000 Gisle Aas and Michael A. Chase
%LW::crawl_linktags = (
'a' => 'href',
'applet' => [qw(codebase archive code)],
'area' => 'href',
'base' => 'href',
'bgsound' => 'src',
'blockquote' => 'cite',
'body' => 'background',
'del' => 'cite',
'embed' => [qw(src pluginspage)],
'form' => 'action',
'frame' => [qw(src longdesc)],
'iframe' => [qw(src longdesc)],
'ilayer' => 'background',
'img' => [qw(src lowsrc longdesc usemap)],
'input' => [qw(src usemap)],
'ins' => 'cite',
'isindex' => 'action',
'head' => 'profile',
'layer' => [qw(background src)],
'link' => 'href',
'object' => [qw(codebase data archive usemap)],
'q' => 'cite',
'script' => 'src',
'table' => 'background',
'td' => 'background',
'th' => 'background',
'xmp' => 'href',
);
## forms subpackage ##
@LW::forms_found = ();
%LW::forms_current = ();
## http subpackage ##
my $SOCKSTATE = 0;
my $TIMEOUT = 10; # default
my ( $STATS_REQS, $STATS_SYNS ) = ( 0, 0 );
my ( $LAST_HOST, $LAST_INET_ATON, $LAST_SSL ) = ( '', '', 0 );
my ( $OUTGOING_QUEUE, $INCOMING_QUEUE ) = ( '', '' );
my ( $SSL_CTX, $SSL_THINGY );
my %http_host_cache = ();
# order is following:
# [0] - SOCKET
# [1] - $SOCKSTATE
# [2] - INET_ATON
# [3] - $SSL_CTX
# [4] - $SSL_THINGY
# [5] - $OUTGOING_QUEUE
# [6] - $INCOMING_QUEUE
# [7] - $STATS_SYNS
# [8] - $STATS_REQS
my $Z; # array ref to current host specs
=pod
=head1 ++ Sub package: anti-ids
The anti-ids sub package implements management routines for various
rewriting/encoding in order to evade intrusion detection systems.
=cut
########################################################################
=pod
=head1 - Function: LW::anti_ids
Params: \%hin, $modes
Return: nothing
LW::anti_ids computes the proper anti-ids encoding/tricks specified by
$modes, and sets up %hin in order to use those tricks. Valid modes
are (the mode numbers are the same as those found in whisker 1.4):
1 - Encode some of the characters via normal URL encoding
2 - Insert directory self-references (/./)
3 - Premature URL ending (make it appear the request line is done)
4 - Prepend a long random string in the form of "/string/../URL"
5 - Add a fake URL parameter
6 - Use a tab instead of a space as a request spacer
7 - Change the case of the URL around (works against Windows and Novell)
8 - Change normal seperators ('/') to Windows version ('\')
9 - Session splicing (sending data in multiple packets)
You can set multiple modes by setting the string to contain all the modes
desired; i.e. $modes="146" will use modes 1, 4, and 6.
=cut
sub anti_ids
{
my ( $rhin, $modes ) = ( shift, shift );
my ( @T, $x, $c, $s, $y );
my $ENCODED = 0;
my $W = $$rhin{'whisker'};
return if ( !( defined $rhin && ref($rhin) ) );
# in case they didn't do it already
$$rhin{'whisker'}->{'uri_orig'} = $$rhin{'whisker'}->{'uri'};
# note: order is important!
# mode 9 - session splicing
if ( $modes =~ /9/ )
{
$$rhin{'whisker'}->{'ids_session_splice'} = 1;
}
# mode 4 - prepend long random string
if ( $modes =~ /4/ )
{
$s = '';
if ( $$W{'uri'} =~ m#^/# )
{
$y = &utils_randstr;
$s .= $y while ( length($s) < 512 );
$$W{'uri'} = "/$s/.." . $$W{'uri'};
}
}
# mode 7 - (windows) random case sensitivity
if ( $modes =~ /7/ )
{
@T = split( //, $$W{'uri'} );
for ( $x = 0 ; $x < ( scalar @T ) ; $x++ )
{
if ( ( rand() * 2 ) % 2 == 1 )
{
$T[$x] = uc( $T[$x] );
}
}
$$W{'uri'} = join( '', @T );
}
# mode 2 - directory self-reference (/./)
if ( $modes =~ /2/ )
{
$$W{'uri'} =~ s#/#/./#g;
}
# mode 8 - windows directory separator (\)
if ( $modes =~ /8/ )
{
$$W{'uri'} =~ s#/#\\#g;
$$W{'uri'} =~ s#^\\#/#;
$$W{'uri'} =~ s#^(http|file|ftp|nntp|news|telnet):\\#$1://#;
$$W{'uri'} =~ s#\\$#/#;
}
# mode 1 - random URI (non-UTF8) encoding
if ( $modes =~ /1/ )
{
if ( $ENCODED == 0 )
{
$$W{'uri'} = encode_str2ruri( $$W{'uri'} );
$ENCODED = 1;
}
}
# mode 5 - fake parameter
if ( $modes =~ /5/ )
{
( $s, $y ) = ( &utils_randstr, &utils_randstr );
$$W{'uri'} = "/$s.html%3f$y=/../$$W{'uri'}";
}
# mode 3 - premature URL ending
if ( $modes =~ /3/ )
{
$s = &utils_randstr;
$$W{'uri'} = "/%20HTTP/1.1%0D%0A%Accept%3A%20$s/../..$$W{'uri'}";
}
# mode 6 - TAB as request spacer
if ( $modes =~ /6/ )
{
$$W{'req_spacer'} = "\t";
}
} # end anti_ids
=pod
=head1 ++ Sub package: auth
The auth sub package implements HTTP authentication routines.
=cut
########################################################################
=pod
=head1 - Function: LW::auth_brute_force
Params: $auth_method, \%hin, $user, \@passwords [, $domain]
Return: $first_valid_password, undef if error/none found
Perform a HTTP authentication brute force against a server (host and URI
defined in %hin). It will try every password in the password array for
the given user. The first password (in conjunction with the given user)
that doesn't return HTTP 401 is returned (and the brute force is stopped
at that point). $domain is optional, and is only used for NTLM auth.
=cut
sub auth_brute_force
{
my ( $auth_method, $hrin, $user, $pwordref, $dom ) = @_;
my ( $P, %hout );
return undef if ( !defined $auth_method || length($auth_method) == 0 );
return undef if ( !defined $user || length($user) == 0 );
return undef if ( !( defined $hrin && ref($hrin) ) );
return undef if ( !( defined $pwordref && ref($pwordref) ) );
map {
( $P = $_ ) =~ tr/\r\n//d;
auth_set_header( $auth_method, $hrin, $user, $P, $dom );
return undef if ( http_do_request( $hrin, \%hout ) );
return $P if ( $hout{'whisker'}->{'http_resp'} ne 401 );
} @$pwordref;
return undef;
}
########################################################################
=pod
=head1 - Function: LW::auth_set_header
Params: $auth_method, \%hin, $user, $password [, $domain]
Return: nothing (modifies %hin)
Set the appropriate authentication header in %hin.
NOTE: right now only BASIC and NTLM are supported.
=cut
sub auth_set_header
{
my ( $method, $href, $user, $pass, $domain ) = ( lc(shift), @_ );
return if ( !( defined $href && ref($href) ) );
return if ( !defined $user || !defined $pass );
if ( $method eq 'basic' )
{
$$href{'Authorization'} =
'Basic ' . encode_base64( $user . ':' . $pass, '' );
}
if ( $method eq 'proxy-basic' )
{
$$href{'Proxy-Authorization'} =
'Basic ' . encode_base64( $user . ':' . $pass, '' );
}
if ( $method eq 'ntlm' )
{
my $o = ntlm_new( $user, $pass, $domain );
$$href{'whisker'}->{'ntlm_obj'} = $o;
$$href{'whisker'}->{'ntlm_step'} = 0;
$$href{'Authorization'} = 'NTLM ' . ntlm_client($o);
}
}
########################################################################
=pod
=head1 - Function: LW::do_auth
Params: $auth_method, \%hin, $user, $password [, $domain]
Return: nothing (modifies %hin)
This is an alias for auth_set_header().
=cut
sub do_auth
{
goto &auth_set_header;
}
=pod
=head1 ++ Sub package: bruteurl
The bruteurl sub package is used to perform a brute-force of HTTP
requests on an array of string components.
=cut
=pod
=head1 - Function: LW::bruteurl
Params: \%hin, $pre, $post, \@values_in, \@values_out
Return: Nothing (adds to @out)