Skip to content

Commit 3fe32d6

Browse files
committed
add timeout to isdc function in case rpc is blocked
1 parent 31acd22 commit 3fe32d6

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

nxc/protocols/smb.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,27 @@ def generate_tgt(self):
664664
self.logger.fail(f"Failed to get TGT: {e}")
665665

666666
def is_host_dc(self):
667-
from impacket.dcerpc.v5 import nrpc, epm
667+
from impacket.dcerpc.v5 import transport, nrpc, epm
668+
import socket
669+
668670
self.logger.debug("Performing authentication attempts...")
669671
try:
670-
epm.hept_map(self.host, nrpc.MSRPC_UUID_NRPC, protocol="ncacn_ip_tcp")
672+
rpctransport = transport.DCERPCTransportFactory(f'ncacn_ip_tcp:{self.host}[135]')
673+
rpctransport.set_connect_timeout(5)
674+
675+
dce = rpctransport.get_dce_rpc()
676+
dce.connect()
677+
dce.bind(nrpc.MSRPC_UUID_NRPC)
678+
671679
self.isdc = True
680+
dce.disconnect()
672681
return True
673682
except DCERPCException:
674683
self.logger.debug("Error while connecting to host: DCERPCException, which means this is probably not a DC!")
684+
except socket.timeout:
685+
self.logger.debug("Timeout while connecting to host: likely not a DC or host is unreachable.")
686+
except Exception as e:
687+
self.logger.debug(f"Error while connecting to host: {e}")
675688
self.isdc = False
676689
return False
677690

0 commit comments

Comments
 (0)