Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Perform new scan on host
        /// </summary>
        /// <param name="host"></param>
        public static void ReScanHost(SMBHost host)
        {
            HostShare[]   hostShares;
            List <string> discoveredHostShares;
            SMBScanResult currentResult;

            // If the recursive level is not set in the Config class, we use the level used for the first scan
            if (Config.ScanForNewSharesRecusiveLevel == -1)
            {
                Config.ScanForNewSharesRecusiveLevel = host.scanRecursiveLevel;
            }

            foreach (SMBScanResult scanResult in host.hostSharesScanResult.Values)
            {
                ReScanSMBScanResult(scanResult);
            }

            // Check whether the scan will be performed on discovered shares only or try to identify new shares.
            // The discovery operation includes only the scanned hosts. To add new hosts you should use AppendHosts method.
            if (Config.ScanForNewShares)
            {
                hostShares = GetNetShare.EnumNetShares(host.hostname);
                if (host.hostSharesScanResult.Count > 0)
                {
                    discoveredHostShares = host.hostSharesScanResult.Keys.ToList();
                    foreach (HostShare hostShare in hostShares)
                    {
                        if (!discoveredHostShares.Contains(hostShare.shareInfo.shi1_netname))
                        {
                            currentResult = new SMBScanResult {
                                shareACL = ShareACLUtils.GetShareACL(hostShare), shareSubDirectories = new Dictionary <string, ScanDirectoryResult>()
                            };
                            if (IsRecursivelyScannable(currentResult.shareACL.share))
                            {
                                currentResult.shareSubDirectories = ScanShareDirectory(hostShare.ToString(), Config.ScanForNewSharesRecusiveLevel).shareDirectorySubDirectories;
                            }
                            host.hostSharesScanResult.Add(hostShare.shareInfo.shi1_netname, currentResult);
                        }
                    }
                }
                else
                {
                    host.hostSharesScanResult = ScanHost(host.hostname).hostSharesScanResult;
                }
            }
        }
Beispiel #3
0
        /// <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);
        }