/// <summary> /// Print target's SMB shares and their ACL /// </summary> /// <param name="hostname"></param> public static void PreviewHostShares(string hostname) { List <SMBShareACL> sharesACL = ShareACLUtils.GetSharesACL(GetNetShare.EnumNetShares(hostname)); foreach (SMBShareACL shareACL in sharesACL) { ShareACLUtils.PrintShareAccesses(shareACL); } }
/// <summary> /// Scan host's SMB shares /// </summary> /// <param name="hostname">Target to scan.</param> /// <returns></returns> public static SMBHost ScanHost(string hostname) { SMBHost result = new SMBHost(); SMBScanResult currentResult; HostShare[] hostShares; IPAddress ip = null; result.scanRecursiveLevel = Config.RecursiveLevel; result.hostname = hostname; try { ip = IPAddress.Parse(hostname); result.ip = ip.ToString(); } catch (FormatException) { if ((Config.TryResolveHostName && !TryResolveHostName(hostname))) { Console.WriteLine("[-][" + DateTime.Now.ToString() + "] Could not resolve " + hostname); return(result); } result.ip = ""; } // Get target's shares try { if (Config.Debug) { Console.WriteLine("[*][" + DateTime.Now.ToString() + "] Getting " + hostname + " shares ..."); } hostShares = GetNetShare.EnumNetShares(hostname); } catch (Exception e) { if (Config.Debug) { Console.WriteLine("[-][" + DateTime.Now.ToString() + "] Error on enumerating " + hostname + " shares (" + e.ToString() + ")."); } return(result); } List <SMBShareACL> sharesACL = ShareACLUtils.GetSharesACL(hostShares); // Iterate over target's shares foreach (SMBShareACL shareACL in sharesACL) { // Create SMBScanResult object for every shareInfo currentResult = new SMBScanResult { shareACL = shareACL, shareSubDirectories = new Dictionary <string, ScanDirectoryResult>() }; // if the shareInfo is not IPC$ or a printer, do a recursive scan on the subdirectories if (IsRecursivelyScannable(currentResult.shareACL.share)) { currentResult.shareSubDirectories = ScanShareDirectory(shareACL.share.ToString(), Config.RecursiveLevel).shareDirectorySubDirectories; } result.hostSharesScanResult.Add(shareACL.share.shareInfo.shi1_netname, currentResult); } return(result); }