Skip to content

Commit bfd014f

Browse files
committed
catch BrokenPipe and transport errors to prevent session crash
1 parent a610ade commit bfd014f

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

nxc/modules/ntlm_reflection.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from impacket.dcerpc.v5.rpcrt import RPC_C_AUTHN_GSS_NEGOTIATE
44
from impacket.smbconnection import SessionError
55
from nxc.helpers.misc import CATEGORY
6+
from impacket.nmb import NetBIOSError
67

78

89
class NXCModule:
910
# https://www.synacktiv.com/en/publications/ntlm-reflection-is-dead-long-live-ntlm-reflection-an-in-depth-analysis-of-cve-2025
11+
# Modified by azoxlpf to handle BrokenPipe/transport errors gracefully
1012
name = "ntlm_reflection"
1113
description = "Attempt to check if the OS is vulnerable to CVE-2025-33073 (NTLM Reflection attack)"
1214
supported_protocols = ["smb"]
@@ -76,21 +78,27 @@ def on_login(self, context, connection):
7678
self.context.log.info(f"RemoteRegistry is probably deactivated: {e}")
7779
else:
7880
self.context.log.debug(f"Unexpected error: {e}")
81+
except (BrokenPipeError, ConnectionResetError, NetBIOSError, OSError) as e:
82+
context.log.debug(f"ntlm_reflection: DCERPC transport error: {e.__class__.__name__}: {e}")
7983

8084
def trigger_winreg(self, connection, context):
8185
# Original idea from https://twitter.com/splinter_code/status/1715876413474025704
8286
# Basically triggers the RemoteRegistry to start without admin privs
83-
tid = connection.connectTree("IPC$")
8487
try:
85-
connection.openFile(
86-
tid,
87-
r"\winreg",
88-
0x12019F,
89-
creationOption=0x40,
90-
fileAttributes=0x80,
91-
)
92-
except SessionError as e:
93-
# STATUS_PIPE_NOT_AVAILABLE error is expected
94-
context.log.debug(str(e))
95-
# Give remote registry time to start
96-
time.sleep(1)
88+
tid = connection.connectTree("IPC$")
89+
try:
90+
connection.openFile(
91+
tid,
92+
r"\winreg",
93+
0x12019F,
94+
creationOption=0x40,
95+
fileAttributes=0x80,
96+
)
97+
except SessionError as e:
98+
# STATUS_PIPE_NOT_AVAILABLE error is expected
99+
context.log.debug(str(e))
100+
# Give remote registry time to start
101+
time.sleep(1)
102+
return True
103+
except (SessionError, BrokenPipeError, ConnectionResetError, NetBIOSError, OSError):
104+
return False

0 commit comments

Comments
 (0)