Comprehensive SMB shares management class
| 16 | logger = logging.getLogger('NetworkHound.SMBSharesManager') |
| 17 | |
| 18 | class SMBSharesManager: |
| 19 | """Comprehensive SMB shares management class""" |
| 20 | |
| 21 | def __init__(self, timeout=5, max_threads=10, use_multiprocessing=False): |
| 22 | self.timeout = timeout |
| 23 | self.max_threads = max_threads |
| 24 | # Multiprocessing disabled - always use threading for stability |
| 25 | self.use_multiprocessing = False |
| 26 | |
| 27 | def discover_smb_shares(self, ip, port, username="", password="", domain="", ntlm_hash="", kerberos_ticket=""): |
| 28 | """Discover SMB shares on a specific IP:port""" |
| 29 | results = { |
| 30 | 'smb': { |
| 31 | 'status': False, |
| 32 | 'version': None, |
| 33 | 'shares': [], |
| 34 | 'domain': None, |
| 35 | 'server_name': None, |
| 36 | 'os': None, |
| 37 | 'error': None, |
| 38 | 'auth_required': False, |
| 39 | 'guest_access': False, |
| 40 | 'accessible_shares': [] |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | # Only test SMB ports |
| 45 | if port not in [139, 445]: |
| 46 | results['smb']['error'] = f"Port {port} is not an SMB port" |
| 47 | return results |
| 48 | |
| 49 | try: |
| 50 | # For Kerberos authentication, try to resolve IP to hostname for proper SPN |
| 51 | target_name = ip |
| 52 | if kerberos_ticket: |
| 53 | # Try common hostname patterns for domain controllers |
| 54 | potential_hostnames = [ |
| 55 | f"dc01.{domain}", |
| 56 | f"dc.{domain}", |
| 57 | f"dc1.{domain}", |
| 58 | f"hst1.{domain}", |
| 59 | f"hst2.{domain}", |
| 60 | f"hst3.{domain}", |
| 61 | f"host1.{domain}", |
| 62 | f"host2.{domain}", |
| 63 | f"host3.{domain}", |
| 64 | f"server.{domain}", |
| 65 | f"server1.{domain}", |
| 66 | f"server2.{domain}" |
| 67 | ] |
| 68 | |
| 69 | import socket |
| 70 | hostname_found = False |
| 71 | |
| 72 | # Try common DC hostnames first (more reliable than reverse DNS) |
| 73 | for potential_hostname in potential_hostnames: |
| 74 | try: |
| 75 | resolved_ip = socket.gethostbyname(potential_hostname) |
no outgoing calls
no test coverage detected