33from impacket import nt_errors
44from impacket .smb3structs import FILE_READ_DATA
55from impacket .smbconnection import SessionError
6+ from impacket .nmb import NetBIOSError
67
78
89class NXCModule :
@@ -11,6 +12,7 @@ class NXCModule:
1112 DAV RPC Service pipe. This technique was first suggested by Lee Christensen (@tifkin_)
1213
1314 Module by Tobias Neitzel (@qtc_de)
15+ Modified by @azoxlpf to handle transport errors gracefully and avoid session crash
1416 """
1517
1618 name = "webdav"
@@ -30,18 +32,36 @@ def on_login(self, context, connection):
3032 Check whether the 'DAV RPC Service' pipe exists within the 'IPC$' share. This indicates
3133 that the WebClient service is running on the target.
3234 """
35+ remote_file = None
36+
3337 try :
34- remote_file = RemoteFile (connection .conn , "DAV RPC Service" , "IPC$" , access = FILE_READ_DATA )
38+ if not getattr (connection , "username" , None ) and not getattr (connection , "password" , None ):
39+ context .log .debug ("WebDAV skipped: unauthenticated/null session (IPC$ likely denied)." )
40+ return
3541
42+ remote_file = RemoteFile (connection .conn , "DAV RPC Service" , "IPC$" , access = FILE_READ_DATA )
3643 remote_file .open_file ()
37- remote_file .close ()
3844
3945 context .log .highlight (self .output .format (connection .conn .getRemoteHost ()))
4046
4147 except SessionError as e :
4248 if e .getErrorCode () == nt_errors .STATUS_OBJECT_NAME_NOT_FOUND :
43- pass
44- elif e .getErrorCode () in nt_errors .ERROR_MESSAGES :
49+ return
50+
51+ if e .getErrorCode () in nt_errors .ERROR_MESSAGES :
4552 context .log .fail (f"Error enumerating WebDAV: { e .getErrorString ()[0 ]} " , color = "magenta" )
46- else :
47- raise e
53+ return
54+
55+ context .log .debug (f"WebDAV SessionError (code={ hex (e .getErrorCode ())} )" )
56+ return
57+
58+ except (BrokenPipeError , ConnectionResetError , NetBIOSError , OSError ) as e :
59+ context .log .debug (f"WebDAV check aborted due to transport error: { e .__class__ .__name__ } : { e } " )
60+ return
61+
62+ finally :
63+ if remote_file is not None :
64+ try :
65+ remote_file .close ()
66+ except Exception :
67+ pass
0 commit comments