Skip to content

Commit 1de6e86

Browse files
Tim BrownTim Brown
Tim Brown
authored and
Tim Brown
committed
Hid writable shares sheck being -A flag to ensure no change to default behaviour
Fixed check for writable shares to cope with Samba being chatty
1 parent 1c7d0c8 commit 1de6e86

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

CHANGELOG

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2021-06-28 Enum4Linux v0.9.1
2+
3+
* Cleaned up CHANGELOG.
4+
* Thanks to DidierA.
5+
* Added check for writable shares.
6+
* Hid writable shares sheck being -A flag to ensure no change to default behaviour.
7+
* Fixed check for writable shares to cope with Samba being chatty.
8+
19
2021-04-10 Enum4Linux v0.9.0
210

311
* Thanks to jtpereyda, logicsec, mrefish, Kawsay, NoxNoctis,

enum4linux.pl

+42-28
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
use Scalar::Util qw(tainted);
4949
use Term::ANSIColor;
5050

51-
my $VERSION="0.9.0";
51+
my $VERSION="0.9.1";
5252
my $verbose = 0;
5353
my $debug = 0;
54+
my $aggressive = 0;
5455
my $global_fail_limit = 1000; # no command line option yet
5556
my $global_search_until_fail = 0; # no command line option yet
5657
my $heighest_rid = 999999;
@@ -174,6 +175,7 @@
174175
-w wrkg Specify workgroup manually (usually found automatically)
175176
-n Do an nmblookup (similar to nbtstat)
176177
-v Verbose. Shows full commands being run (net, rpcclient, etc.)
178+
-A Aggressive. Do write checks on shares etc
177179
178180
RID cycling should extract a list of users from Windows \(or Samba\) hosts
179181
which have RestrictAnonymous set to 1 \(Windows NT and 2000\), or \"Network
@@ -210,7 +212,7 @@
210212
$ENV{'PATH'} =~ s/^\.://;
211213
$ENV{'PATH'} =~ s/:\.//;
212214

213-
getopts('UMNSPGlLDu:dp:f:rR:s:k:vow:hnaiPK:', \%opts);
215+
getopts('UMNSPGlLDu:dp:f:rR:s:k:vAow:hnaiPK:', \%opts);
214216

215217
# Print help message if required
216218
if ($opts{'h'}) {
@@ -260,6 +262,7 @@
260262
$global_known_username_string = $opts{'k'} if $opts{'k'};
261263
$global_workgroup = $opts{'w'} if $opts{'w'};
262264
$verbose = $opts{'v'} if $opts{'v'};
265+
$aggressive = 1 if $opts{'A'};
263266
$opts{'r'} = 1 if $opts{'R'};
264267

265268
$global_search_until_fail = 1 if defined($opts{'K'});
@@ -691,33 +694,44 @@ sub enum_shares {
691694
print_error("Can't understand response:\n");
692695
print $output;
693696
}
694-
695697
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+
}
721735
}
722736
}
723737
}

0 commit comments

Comments
 (0)