From 3fe32d6530a3eeefec9d88ffcb07bb291b6ee224 Mon Sep 17 00:00:00 2001 From: mpgn <5891788+mpgn@users.noreply.github.com> Date: Sun, 15 Jun 2025 22:39:43 +0200 Subject: [PATCH] add timeout to isdc function in case rpc is blocked --- nxc/protocols/smb.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nxc/protocols/smb.py b/nxc/protocols/smb.py index 325da7f4..fbf6f8dc 100755 --- a/nxc/protocols/smb.py +++ b/nxc/protocols/smb.py @@ -664,14 +664,27 @@ class smb(connection): self.logger.fail(f"Failed to get TGT: {e}") def is_host_dc(self): - from impacket.dcerpc.v5 import nrpc, epm + from impacket.dcerpc.v5 import transport, nrpc, epm + import socket + self.logger.debug("Performing authentication attempts...") try: - epm.hept_map(self.host, nrpc.MSRPC_UUID_NRPC, protocol="ncacn_ip_tcp") + rpctransport = transport.DCERPCTransportFactory(f'ncacn_ip_tcp:{self.host}[135]') + rpctransport.set_connect_timeout(5) + + dce = rpctransport.get_dce_rpc() + dce.connect() + dce.bind(nrpc.MSRPC_UUID_NRPC) + self.isdc = True + dce.disconnect() return True except DCERPCException: self.logger.debug("Error while connecting to host: DCERPCException, which means this is probably not a DC!") + except socket.timeout: + self.logger.debug("Timeout while connecting to host: likely not a DC or host is unreachable.") + except Exception as e: + self.logger.debug(f"Error while connecting to host: {e}") self.isdc = False return False