MCPcopy Create free account
hub / github.com/MorDavid/NetworkHound / _resolve_dc_hostname

Method _resolve_dc_hostname

NetworkHound.py:257–357  ·  view source on GitHub ↗

Try to resolve DC IP to NetBIOS hostname for proper Kerberos SPN Tries multiple methods: 1. SMB connection (TCP 445/139) - most reliable with proxychains 2. DNS PTR query (TCP if available) 3. nmblookup (UDP 137) - fallback

(self, ip_address)

Source from the content-addressed store, hash-verified

255 self.entries = [] # Store last search results
256
257 def _resolve_dc_hostname(self, ip_address):
258 """Try to resolve DC IP to NetBIOS hostname for proper Kerberos SPN
259
260 Tries multiple methods:
261 1. SMB connection (TCP 445/139) - most reliable with proxychains
262 2. DNS PTR query (TCP if available)
263 3. nmblookup (UDP 137) - fallback
264 """
265
266 # Method 1: SMB Connection (TCP - works with proxychains!)
267 try:
268 from impacket.smbconnection import SMBConnection
269 logger.debug(f"Trying SMB connection to {ip_address} for name resolution...")
270
271 # Try anonymous SMB connection
272 smb = SMBConnection(ip_address, ip_address, timeout=10)
273 try:
274 smb.login('', '') # Anonymous/null session
275 except:
276 # If anonymous fails, that's OK - we might still get the name
277 pass
278
279 server_name = smb.getServerName()
280 if server_name and server_name != ip_address:
281 logger.debug(f"SMB resolved {ip_address} -> {server_name}")
282 try:
283 smb.logoff()
284 except:
285 pass
286 return server_name
287
288 try:
289 smb.logoff()
290 except:
291 pass
292
293 except Exception as e:
294 logger.debug(f"SMB name resolution failed: {e}")
295
296 # Method 2: DNS PTR query (TCP)
297 try:
298 import dns.resolver
299 import dns.reversename
300 import dns.query
301 import dns.message
302
303 logger.debug(f"Trying DNS PTR query for {ip_address}...")
304
305 # Create reverse DNS name
306 addr = dns.reversename.from_address(ip_address)
307
308 # Use DC/target as DNS server (more appropriate for internal network)
309 dns_server = self.impacket_auth.target if hasattr(self, 'impacket_auth') else ip_address
310
311 # Try TCP first (works better with proxychains)
312 try:
313 query = dns.message.make_query(addr, 'PTR')
314 response = dns.query.tcp(query, dns_server, timeout=5)

Callers 2

searchMethod · 0.95

Calls 1

loginMethod · 0.80

Tested by

no test coverage detected