Skip to content

Commit bde3ce2

Browse files
committed
Unify handling of legacy Samba versions
1 parent ee17f62 commit bde3ce2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

enum4linux-ng.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@
312312
KNOWN_USERNAMES = "administrator,guest,krbtgt,domain admins,root,bin,none"
313313
TIMEOUT = 5
314314

315-
# GLOBAL_VERBOSE and GLOBAL_COLORS should be the only variables which should be written to
315+
# GLOBAL_VERBOSE, GLOBAL_COLORS, GLOBAL_SAMBA_LEGACY should be the only variables which should be written to
316316
GLOBAL_VERBOSE = False
317317
GLOBAL_COLORS = True
318+
GLOBAL_SAMBA_LEGACY = False
318319

319320
class Colors:
320321
ansi_reset = '\033[0m'
@@ -496,10 +497,8 @@ def __init__(self, command, target, creds):
496497
self.env = os.environ.copy()
497498
self.env['KRB5CCNAME'] = self.creds.ticket_file
498499
# User and domain are taken from the ticket
499-
# Kerberos options differ between samba versions
500-
samba_version = re.match(r".*(\d+\.\d+\.\d+).*", check_output(["smbclient", "--version"]).decode()).group(1)
501-
samba_version = tuple(int(x) for x in samba_version.split('.'))
502-
if samba_version < (4, 15, 0):
500+
# Kerberos options differ between samba versions - TODO: Can be removed in the future
501+
if GLOBAL_SAMBA_LEGACY:
503502
self.exec += ['-k']
504503
else:
505504
self.exec += ['--use-krb5-ccache', self.creds.ticket_file]
@@ -3171,6 +3170,7 @@ def check_arguments():
31713170
'''
31723171

31733172
global GLOBAL_VERBOSE
3173+
global GLOBAL_SAMBA_LEGACY
31743174

31753175
parser = ArgumentParser(description="""This tool is a rewrite of Mark Lowe's enum4linux.pl, a tool for enumerating information from Windows and Samba systems.
31763176
It is mainly a wrapper around the Samba tools nmblookup, net, rpcclient and smbclient. Other than the original tool it allows to export enumeration results
@@ -3261,17 +3261,18 @@ def check_arguments():
32613261
raise RuntimeError("Timeout must be a valid integer in the range 1-600")
32623262
args.timeout = int(args.timeout)
32633263

3264+
# Perform Samba version checks - TODO: Can be removed in the future
3265+
samba_version = re.match(r".*(\d+\.\d+\.\d+).*", check_output(["smbclient", "--version"]).decode()).group(1)
3266+
samba_version = tuple(int(x) for x in samba_version.split('.'))
3267+
if samba_version < (4, 15, 0):
3268+
GLOBAL_SAMBA_LEGACY = True
3269+
32643270
# While smbclient and rpcclient support '--pw-nt-hash' the net command does not before Samba 4.15.
32653271
# In Samba 4.15 the commandline parser of the various tools were unified so that '--pw-nt-hash' works
32663272
# for this and later versions. An option would be to run the tool in a docker container like a recent
32673273
# Alpine Linux version.
3268-
if args.nthash and (args.Gm or args.C):
3269-
try:
3270-
output = check_output(['net','help'], shell=False, stderr=STDOUT)
3271-
except Exception as e:
3272-
output = str(e.output)
3273-
if '--pw-nt-hash' not in output:
3274-
raise RuntimeError("The -C and -Gm argument require Samba 4.15 or higher when used in combination with -H")
3274+
if GLOBAL_SAMBA_LEGACY and args.nthash and (args.Gm or args.C):
3275+
raise RuntimeError("The -C and -Gm argument require Samba 4.15 or higher when used in combination with -H")
32753276

32763277
return args
32773278

0 commit comments

Comments
 (0)