Skip to content

Commit

Permalink
Adds a command line option to exclude user provided directories (#559)
Browse files Browse the repository at this point in the history
* Adds Skip Directories support to 2.2

* Fix for skip

* Fix skipping sub directories of skipped directory
  • Loading branch information
gfs authored Nov 16, 2020
1 parent 5b77e9a commit efd3bdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Lib/Collectors/FileSystemCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public FileSystemCollector(CollectCommandOptions? opts = null, Action<CollectObj
{
Roots.Add(directory);
}
else
{
Log.Debug("Default settings skip directories /proc and /sys because they tend to have non-files which stall the collector.");
}
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand Down Expand Up @@ -137,15 +141,15 @@ void TryIterateOnDirectory(string Path)
Log.Verbose("Finished parsing {0}", Path);
}

foreach (var Root in Roots)
foreach (var Root in Roots.Where(x => !opts.SkipDirectories.Any(y => x.StartsWith(y))))
{
Log.Information("{0} root {1}", Strings.Get("Scanning"), Root);
var directories = Directory.EnumerateDirectories(Root, "*", new System.IO.EnumerationOptions()
{
ReturnSpecialDirectories = false,
IgnoreInaccessible = true,
RecurseSubdirectories = true
});
}).Where(x => !opts.SkipDirectories.Any(y => x.StartsWith(y)));

//First do root
TryIterateOnDirectory(Root);
Expand Down
4 changes: 4 additions & 0 deletions Lib/Objects/CommandOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using CommandLine;
using System.Collections.Generic;

namespace AttackSurfaceAnalyzer
{
Expand Down Expand Up @@ -137,6 +138,9 @@ public class CollectCommandOptions : CommandOptions
[Option("directories", Required = false, HelpText = "^ separated list of paths to scan with FileSystemCollector")]
public string? SelectedDirectories { get; set; }

[Option("skip-directories", Required = false, HelpText = ", separated list of paths to skip with FileSystemCollector", Separator = ',')]
public IEnumerable<string> SkipDirectories { get; set; } = new List<string>();

[Option("hives", Required = false, HelpText = "^ separated list of hives and subkeys to search.")]
public string? SelectedHives { get; set; }

Expand Down

0 comments on commit efd3bdf

Please sign in to comment.