Skip to content

Commit 14b1bc6

Browse files
committed
add more resiliant check on dc in case rpc is filtered
1 parent 3fe32d6 commit 14b1bc6

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

nxc/protocols/smb.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,32 @@ def generate_tgt(self):
663663
except Exception as e:
664664
self.logger.fail(f"Failed to get TGT: {e}")
665665

666-
def is_host_dc(self):
667-
from impacket.dcerpc.v5 import transport, nrpc, epm
666+
def check_dc_ports(self, timeout=2):
667+
"""Check multiple DC-specific ports in case first check fails"""
668668
import socket
669+
dc_ports = [88, 389, 636, 3268] # Kerberos, LDAP, LDAPS, Global Catalog
670+
open_ports = 0
671+
672+
for port in dc_ports:
673+
try:
674+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
675+
sock.settimeout(timeout)
676+
result = sock.connect_ex((self.host, port))
677+
if result == 0:
678+
self.logger.debug(f"Port {port} is open on {self.host}")
679+
open_ports += 1
680+
sock.close()
681+
except Exception:
682+
pass
683+
# If 3 or more DC ports are open, likely a DC
684+
return open_ports >= 3
685+
686+
def is_host_dc(self):
687+
from impacket.dcerpc.v5 import transport, nrpc
669688

670689
self.logger.debug("Performing authentication attempts...")
671690
try:
672-
rpctransport = transport.DCERPCTransportFactory(f'ncacn_ip_tcp:{self.host}[135]')
691+
rpctransport = transport.DCERPCTransportFactory(f"ncacn_ip_tcp:{self.host}[135]")
673692
rpctransport.set_connect_timeout(5)
674693

675694
dce = rpctransport.get_dce_rpc()
@@ -681,10 +700,15 @@ def is_host_dc(self):
681700
return True
682701
except DCERPCException:
683702
self.logger.debug("Error while connecting to host: DCERPCException, which means this is probably not a DC!")
684-
except socket.timeout:
703+
except TimeoutError:
685704
self.logger.debug("Timeout while connecting to host: likely not a DC or host is unreachable.")
686705
except Exception as e:
687706
self.logger.debug(f"Error while connecting to host: {e}")
707+
708+
if self.check_dc_ports():
709+
self.logger.debug("Host appears to be a DC (multiple DC ports open)")
710+
self.isdc = True
711+
return True
688712
self.isdc = False
689713
return False
690714

0 commit comments

Comments
 (0)