| 
48 | 48 | use Scalar::Util qw(tainted);  | 
49 | 49 | use Term::ANSIColor;  | 
50 | 50 | 
 
  | 
51 |  | -my $VERSION="0.9.0";  | 
 | 51 | +my $VERSION="0.9.1";  | 
52 | 52 | my $verbose = 0;  | 
53 | 53 | my $debug = 0;  | 
 | 54 | +my $aggressive = 0;  | 
54 | 55 | my $global_fail_limit = 1000;     # no command line option yet  | 
55 | 56 | my $global_search_until_fail = 0; # no command line option yet  | 
56 | 57 | my $heighest_rid = 999999;  | 
 | 
174 | 175 |     -w wrkg   Specify workgroup manually (usually found automatically)  | 
175 | 176 |     -n        Do an nmblookup (similar to nbtstat)  | 
176 | 177 |     -v        Verbose.  Shows full commands being run (net, rpcclient, etc.)  | 
 | 178 | +    -A        Aggressive. Do write checks on shares etc  | 
177 | 179 | 
  | 
178 | 180 | RID cycling should extract a list of users from Windows \(or Samba\) hosts   | 
179 | 181 | which have RestrictAnonymous set to 1 \(Windows NT and 2000\), or \"Network   | 
 | 
210 | 212 | $ENV{'PATH'} =~ s/^\.://;  | 
211 | 213 | $ENV{'PATH'} =~ s/:\.//;  | 
212 | 214 | 
 
  | 
213 |  | -getopts('UMNSPGlLDu:dp:f:rR:s:k:vow:hnaiPK:', \%opts);  | 
 | 215 | +getopts('UMNSPGlLDu:dp:f:rR:s:k:vAow:hnaiPK:', \%opts);  | 
214 | 216 | 
 
  | 
215 | 217 | # Print help message if required  | 
216 | 218 | if ($opts{'h'}) {  | 
 | 
260 | 262 | $global_known_username_string = $opts{'k'} if $opts{'k'};  | 
261 | 263 | $global_workgroup      = $opts{'w'} if $opts{'w'};  | 
262 | 264 | $verbose               = $opts{'v'} if $opts{'v'};  | 
 | 265 | +$aggressive            = 1          if $opts{'A'};  | 
263 | 266 | $opts{'r'}             = 1          if $opts{'R'};  | 
264 | 267 | 
 
  | 
265 | 268 | $global_search_until_fail = 1 if defined($opts{'K'});  | 
@@ -691,33 +694,44 @@ sub enum_shares {  | 
691 | 694 | 			print_error("Can't understand response:\n");  | 
692 | 695 | 			print $output;  | 
693 | 696 | 		}  | 
694 |  | -		  | 
695 | 697 | 		if ($mapping_result eq "OK") {  | 
696 |  | -			# check for write access  | 
697 |  | -			my @chars = ("A".."Z", "a".."z", "0".."9");  | 
698 |  | -			my $random_string;  | 
699 |  | -			$random_string .= $chars[rand @chars] for 1..8;  | 
700 |  | -			  | 
701 |  | -			$command = "smbclient -W '$global_workgroup' //'$global_target'/'$share' -U'$global_username'\%'$global_password' -c 'mkdir $random_string' 2>&1";  | 
702 |  | -			print_verbose("Checking write access to share //$global_target/$share with command: $command\n") if $verbose;  | 
703 |  | -			$output = `$command` ;  | 
704 |  | -			if ($output =~ /NT_STATUS_ACCESS_DENIED making/) {  | 
705 |  | -				$writing_result="DENIED" ;  | 
706 |  | -			} elsif (length $output) {  | 
707 |  | -				# the command should not give any output, if something was output it's a failure  | 
708 |  | -				print error("Can't understand response:\n");  | 
709 |  | -				print $output;  | 
710 |  | -			} else {  | 
711 |  | -				$writing_result="OK"  | 
712 |  | -			}  | 
713 |  | -			if ($writing_result ne "DENIED") {  | 
714 |  | -				# remove the directory we created  | 
715 |  | -				$command = "smbclient -W '$global_workgroup' //'$global_target'/'$share' -U'$global_username'\%'$global_password' -c 'rmdir $random_string' 2>&1";  | 
716 |  | -				print_verbose("Removing created directory on share //$global_target/$share with command: $command\n") if $verbose;  | 
717 |  | -				$output=`$command` ;  | 
718 |  | -				if (length $output) {  | 
719 |  | -					print error("rmdir command returned the following:\n");  | 
720 |  | -					print $output ;  | 
 | 698 | +			if ($aggressive) {  | 
 | 699 | +				print "testing write access " . $share . "\n";  | 
 | 700 | +				# check for write access  | 
 | 701 | +				my @chars = ("A".."Z", "a".."z", "0".."9");  | 
 | 702 | +				my $random_string;  | 
 | 703 | +				$random_string .= $chars[rand @chars] for 1..8;  | 
 | 704 | +				  | 
 | 705 | +				$command = "smbclient -W '$global_workgroup' //'$global_target'/'$share' -U'$global_username'\%'$global_password' -c 'mkdir $random_string' 2>&1";  | 
 | 706 | +				print_verbose("Checking write access to share //$global_target/$share with command: $command\n") if $verbose;  | 
 | 707 | +				$output = `$command` ;  | 
 | 708 | +				if ($output =~ /NT_STATUS_ACCESS_DENIED making/) {  | 
 | 709 | +					$writing_result="DENIED" ;  | 
 | 710 | +				} elsif (length $output) {  | 
 | 711 | +					# the command should not give any output, if something was output maybe it's a failure  | 
 | 712 | +                			my $command2 = "smbclient -W '$global_workgroup' //'$global_target'/'$share' -U'$global_username'\%'$global_password' -c dir 2>&1";  | 
 | 713 | +                			print_verbose("Attempting check for directory $random_string on //$global_target/$share with command: $command2\n") if $verbose;  | 
 | 714 | +                			my $output2 = `$command2`;  | 
 | 715 | +					if ($output2 =~ /.*$random_string.*/) {  | 
 | 716 | +						$writing_result="OK";  | 
 | 717 | +					} else {  | 
 | 718 | +						print_error("Can't understand initial response:\n");  | 
 | 719 | +						print $output;  | 
 | 720 | +						print_error("Can't understand second response:\n");  | 
 | 721 | +						print $output2;  | 
 | 722 | +					}  | 
 | 723 | +				} else {  | 
 | 724 | +					$writing_result="OK";  | 
 | 725 | +				}  | 
 | 726 | +				if ($writing_result ne "DENIED") {  | 
 | 727 | +					# remove the directory we created  | 
 | 728 | +					$command = "smbclient -W '$global_workgroup' //'$global_target'/'$share' -U'$global_username'\%'$global_password' -c 'rmdir $random_string' 2>&1";  | 
 | 729 | +					print_verbose("Removing created directory on share //$global_target/$share with command: $command\n") if $verbose;  | 
 | 730 | +					$output=`$command` ;  | 
 | 731 | +					if (length $output) {  | 
 | 732 | +						print_error("rmdir command returned the following:\n");  | 
 | 733 | +						print $output ;  | 
 | 734 | +					}  | 
721 | 735 | 				}  | 
722 | 736 | 			}  | 
723 | 737 | 		}  | 
 | 
0 commit comments