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

Class ImpacketLDAPWrapper

NetworkHound.py:249–1262  ·  view source on GitHub ↗

Wrapper class to make ImpacketAuth compatible with ldap3 connection interface

Source from the content-addressed store, hash-verified

247# connect_to_dc function removed - using only impacket
248
249class ImpacketLDAPWrapper:
250 """Wrapper class to make ImpacketAuth compatible with ldap3 connection interface"""
251
252 def __init__(self, impacket_auth):
253 self.impacket_auth = impacket_auth
254 self.is_impacket = True
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)

Callers 1

connect_with_impacketFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected