268268 "STATUS_CONNECTION_DISCONNECTED"
269269 ]
270270
271- # Supported authentication methods
271+ # Supported authentication methods/protocols
272272AUTH_PASSWORD = "password"
273- AUTH_NTHASH = "nthash "
274- AUTH_KERBEROS = "kerberos "
273+ AUTH_NTLM = "NTLM "
274+ AUTH_KERBEROS = "Kerberos "
275275AUTH_NULL = "null"
276+ AUTH_GUEST = "guest"
276277
277278# Mapping from errno to string for socket errors we often come across
278279SOCKET_ERRORS = {
@@ -370,8 +371,8 @@ def __init__(self, host, credentials, port=None, tls=None, timeout=None, samba_c
370371 AUTH_NULL :False ,
371372 AUTH_PASSWORD :False ,
372373 AUTH_KERBEROS :False ,
373- AUTH_NTHASH :False ,
374- "random_user" :False ,
374+ AUTH_NTLM :False ,
375+ AUTH_GUEST :False ,
375376 }
376377
377378 result = self .valid_host (host )
@@ -432,7 +433,7 @@ def __init__(self, user='', pw='', domain='', ticket_file='', nthash='', local_a
432433 raise Exception (result .retmsg )
433434 if nthash and not user :
434435 raise Exception ("NT hash given (-H) without any user, please provide a username (-u)" )
435- self .auth_method = AUTH_NTHASH
436+ self .auth_method = AUTH_NTLM
436437 elif not user and not pw :
437438 self .auth_method = AUTH_NULL
438439 else :
@@ -1134,11 +1135,11 @@ def check_smb_dialects(self):
11341135### Session Checks
11351136
11361137class EnumSessions ():
1137- SESSION_USER = "user "
1138- SESSION_RANDOM = "random user "
1138+ SESSION_PASSWORD = "password "
1139+ SESSION_GUEST = "guest "
11391140 SESSION_NULL = "null"
11401141 SESSION_KERBEROS = "Kerberos"
1141- SESSION_NTHASH = "NT hash "
1142+ SESSION_NTLM = "NTLM "
11421143
11431144 def __init__ (self , target , creds ):
11441145
@@ -1156,12 +1157,12 @@ def run(self):
11561157 AUTH_NULL :False ,
11571158 AUTH_PASSWORD :False ,
11581159 AUTH_KERBEROS :False ,
1159- AUTH_NTHASH :False ,
1160- "random_user" :False ,
1160+ AUTH_NTLM :False ,
1161+ AUTH_GUEST :False ,
11611162 }
11621163
11631164 # Check null session
1164- print_info ("Check for null session" )
1165+ print_info ("Check for anonymous access ( null session) " )
11651166 null_session = self .check_session (Credentials ('' , '' , self .creds .domain ), self .SESSION_NULL )
11661167 if null_session .retval :
11671168 sessions [AUTH_NULL ] = True
@@ -1171,37 +1172,39 @@ def run(self):
11711172
11721173 # Check Kerberos session
11731174 if self .creds .ticket_file :
1174- print_info ("Check for Kerberos session " )
1175+ print_info ("Check for Kerberos authentication " )
11751176 kerberos_session = self .check_session (self .creds , self .SESSION_KERBEROS )
11761177 if kerberos_session .retval :
11771178 sessions [AUTH_KERBEROS ] = True
11781179 print_success (kerberos_session .retmsg )
11791180 else :
11801181 output = process_error (kerberos_session .retmsg , ["sessions" ], module_name , output )
1181- # Check NT hash session
1182+ # Check for NTLM authentication with user-provided NT hash
11821183 elif self .creds .nthash :
1183- print_info ("Check for NT hash session " )
1184- nthash_session = self .check_session (self .creds , self .SESSION_NTHASH )
1185- if nthash_session .retval :
1186- sessions [AUTH_NTHASH ] = True
1187- print_success (nthash_session .retmsg )
1184+ print_info ("Check for NTLM authentication " )
1185+ ntlm_session = self .check_session (self .creds , self .SESSION_NTLM )
1186+ if ntlm_session .retval :
1187+ sessions [AUTH_NTLM ] = True
1188+ print_success (ntlm_session .retmsg )
11881189 else :
1189- output = process_error (nthash_session .retmsg , ["sessions" ], module_name , output )
1190- # Check for user session
1190+ output = process_error (ntlm_session .retmsg , ["sessions" ], module_name , output )
1191+ # Check for password authentication
11911192 elif self .creds .user :
1192- print_info ("Check for user session " )
1193- user_session = self .check_session (self .creds , self .SESSION_USER )
1193+ print_info ("Check for password authentication " )
1194+ user_session = self .check_session (self .creds , self .SESSION_PASSWORD )
11941195 if user_session .retval :
11951196 sessions [AUTH_PASSWORD ] = True
11961197 print_success (user_session .retmsg )
11971198 else :
11981199 output = process_error (user_session .retmsg , ["sessions" ], module_name , output )
11991200
1200- # Check random user session
1201- print_info ("Check for random user" )
1202- user_session = self .check_session (Credentials (self .creds .random_user , self .creds .pw , self .creds .domain ), self .SESSION_RANDOM )
1201+ # Check for guest access via non-existing (i.e. random) user
1202+ # https://sensepost.com/blog/2024/guest-vs-null-session-on-windows/
1203+ # https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html#MAPTOGUEST
1204+ print_info ("Check for guest access" )
1205+ user_session = self .check_session (Credentials (self .creds .random_user , self .creds .pw , self .creds .domain ), self .SESSION_GUEST )
12031206 if user_session .retval :
1204- sessions ["random_user" ] = True
1207+ sessions [AUTH_GUEST ] = True
12051208 print_success (user_session .retmsg )
12061209 print_hint (f"Rerunning enumeration with user '{ self .creds .random_user } ' might give more results" )
12071210 else :
@@ -1210,8 +1213,8 @@ def run(self):
12101213 if sessions [AUTH_NULL ] or \
12111214 sessions [AUTH_PASSWORD ] or \
12121215 sessions [AUTH_KERBEROS ] or \
1213- sessions [AUTH_NTHASH ] or \
1214- sessions ["random_user" ]:
1216+ sessions [AUTH_NTLM ] or \
1217+ sessions [AUTH_GUEST ]:
12151218 sessions ["sessions_possible" ] = True
12161219 else :
12171220 process_error ("Sessions failed, neither null nor user sessions were possible" , ["sessions" ], module_name , output )
@@ -1246,10 +1249,10 @@ def check_session(self, creds, session_type):
12461249
12471250 if "case_sensitive" in result .retmsg :
12481251 if session_type == self .SESSION_KERBEROS :
1249- return Result (True , f"Server allows Kerberos session using '{ creds .ticket_file } '" )
1250- if session_type == self .SESSION_NTHASH :
1251- return Result (True , f"Server allows NT hash session using '{ creds .nthash } '" )
1252- return Result (True , f"Server allows session using username '{ creds .user } ', password '{ creds .pw } '" )
1252+ return Result (True , f"Server allows Kerberos authentication using ticket '{ creds .ticket_file } '" )
1253+ if session_type == self .SESSION_NTLM :
1254+ return Result (True , f"Server allows NTLM authentication using hash '{ creds .nthash } '" )
1255+ return Result (True , f"Server allows authentication via username '{ creds .user } ' and password '{ creds .pw } '" )
12531256 return Result (False , f"Could not establish session using '{ creds .user } ', password '{ creds .pw } '" )
12541257
12551258### Domain Information Enumeration via LDAP
0 commit comments