コード例 #1
0
ファイル: SharesScanner.cs プロジェクト: H0K5/SharesMapper
        /// <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;
                }
            }
        }
コード例 #2
0
ファイル: SharesScanner.cs プロジェクト: H0K5/SharesMapper
        /// <summary>
        /// Fetch ACL of directory and his subdirectories recursively and append them to the Evolution list
        /// </summary>
        /// <param name="scanDirectoryResults"></param>
        public static void ReScanScanDirectoryResults(Dictionary <string, ScanDirectoryResult> scanDirectoryResults, int subRecursiveLevel = 0)
        {
            foreach (ScanDirectoryResult scanDirectoryResult in scanDirectoryResults.Values)
            {
                scanDirectoryResult.shareDirectoryACL.AddDirectoryACL(ShareACLUtils.GetShareACL(scanDirectoryResult.shareDirectoryACL.shareDirectory));
                if (scanDirectoryResult.shareDirectorySubDirectories.Count > 0)
                {
                    ReScanScanDirectoryResults(scanDirectoryResult.shareDirectorySubDirectories, subRecursiveLevel - 1);
                }

                if (subRecursiveLevel > 0)
                {
                    // Get current directory subdirectories and check if there are new ones
                    foreach (string subDirectory in GetSubDirectories(scanDirectoryResult.shareDirectoryACL.shareDirectory))
                    {
                        if (!scanDirectoryResult.shareDirectorySubDirectories.ContainsKey(subDirectory.Split('\\').Last()))
                        {
                            scanDirectoryResult.shareDirectorySubDirectories.Add(subDirectory.Split('\\').Last(), ScanShareDirectory(subDirectory, subRecursiveLevel - 1));
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: SharesScanner.cs プロジェクト: H0K5/SharesMapper
        /// <summary>
        /// Fetch the ACL of a share (and his subdirectories) and append them to the evolution list
        /// </summary>
        /// <param name="scanResult"></param>
        public static void ReScanSMBScanResult(SMBScanResult scanResult)
        {
            scanResult.shareACL.AddShareACL(ShareACLUtils.GetShareACL(scanResult.shareACL.share.ToString()));

            if (scanResult.shareSubDirectories.Count > 0)
            {
                ReScanScanDirectoryResults(scanResult.shareSubDirectories, Config.ScanForNewSharesRecusiveLevel - 1);
            }


            if (Config.ScanForNewSharesRecusiveLevel > 0 && IsRecursivelyScannable(scanResult.shareACL.share))
            {
                // Get share subdirectories and check if there are new ones
                foreach (string subDirectory in GetSubDirectories(scanResult.shareACL.share.ToString()))
                {
                    if (!scanResult.shareSubDirectories.ContainsKey(subDirectory.Split('\\').Last()))
                    {
                        // If so, then perform a scan on the new subdirectories
                        scanResult.shareSubDirectories.Add(subDirectory, ScanShareDirectory(subDirectory, Config.ScanForNewSharesRecusiveLevel - 1));
                    }
                }
            }
        }