Skip to content

Commit 9ab9989

Browse files
authored
Merge pull request Pennyw0rth#914 from azoxlpf/fix/webdav-transport-errors
fix(webdav): handle transport errors and prevent session crash
2 parents a610ade + d4b91f7 commit 9ab9989

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

nxc/modules/webdav.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from impacket import nt_errors
44
from impacket.smb3structs import FILE_READ_DATA
55
from impacket.smbconnection import SessionError
6+
from impacket.nmb import NetBIOSError
7+
import contextlib
68

79

810
class NXCModule:
@@ -11,6 +13,7 @@ class NXCModule:
1113
DAV RPC Service pipe. This technique was first suggested by Lee Christensen (@tifkin_)
1214
1315
Module by Tobias Neitzel (@qtc_de)
16+
Modified by @azoxlpf to handle transport errors gracefully and avoid session crash
1417
"""
1518

1619
name = "webdav"
@@ -32,16 +35,18 @@ def on_login(self, context, connection):
3235
"""
3336
try:
3437
remote_file = RemoteFile(connection.conn, "DAV RPC Service", "IPC$", access=FILE_READ_DATA)
35-
3638
remote_file.open_file()
37-
remote_file.close()
3839

3940
context.log.highlight(self.output.format(connection.conn.getRemoteHost()))
40-
4141
except SessionError as e:
4242
if e.getErrorCode() == nt_errors.STATUS_OBJECT_NAME_NOT_FOUND:
43-
pass
43+
return
4444
elif e.getErrorCode() in nt_errors.ERROR_MESSAGES:
4545
context.log.fail(f"Error enumerating WebDAV: {e.getErrorString()[0]}", color="magenta")
4646
else:
47-
raise e
47+
context.log.debug(f"WebDAV SessionError (code={hex(e.getErrorCode())})")
48+
except (BrokenPipeError, ConnectionResetError, NetBIOSError, OSError) as e:
49+
context.log.debug(f"WebDAV check aborted due to transport error: {e.__class__.__name__}: {e}")
50+
finally:
51+
with contextlib.suppress(Exception):
52+
remote_file.close()

0 commit comments

Comments
 (0)