Skip to content

Commit

Permalink
Update filters.json for Windows files (#88)
Browse files Browse the repository at this point in the history
* Improvements to thread safety

* Ignore default location logfile

* Improve registry filters

* Update filters.json

* Revert inadvertant change to runid behavior

* Fix issue with provided paths to filter in directory walker
  • Loading branch information
gfs authored Apr 6, 2019
1 parent 7b54a24 commit 8a4885b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,4 @@ Application Insights/
*.sqlite-journal
Tools/
asa.sqlite
Cli/asa.log.txt
10 changes: 4 additions & 6 deletions Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,10 @@ public static int RunCollectCommand(CollectCommandOptions opts)
StartEvent.Add("Service", opts.EnableServiceCollector.ToString());

Telemetry.Client.TrackEvent("Begin collecting", StartEvent);

if (opts.RunId.Equals("Timestamp"))
{
opts.RunId = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}

if (opts.EnableFileSystemCollector || opts.EnableAllCollectors)
{
Expand Down Expand Up @@ -1093,11 +1096,6 @@ public static int RunCollectCommand(CollectCommandOptions opts)
Filter.LoadFilters(opts.FilterLocation);
DatabaseManager.SqliteFilename = opts.DatabaseFilename;

if (opts.RunId.Equals("Timestamp"))
{
opts.RunId = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}

if (opts.Overwrite)
{
DatabaseManager.DeleteRun(opts.RunId);
Expand Down
3 changes: 1 addition & 2 deletions Lib/Utils/DirectoryWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public static IEnumerable<FileSystemInfo> WalkDirectory(string root)
Log.Debug(e.Message);
continue;
}
string FullPath = String.Format("{0}{1}{2}", currentDir, Path.PathSeparator, file);
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "File", "Path", FullPath))
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "File", "Path", file))
{
continue;
}
Expand Down
30 changes: 27 additions & 3 deletions Lib/Utils/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,41 @@ public static bool IsFiltered(string Platform, string ScanType, string ItemType,
foreach (var filter in jFilters)
{
Log.Debug(filter.ToString());
filters.Add(new Regex(filter.ToString()));
try
{
filters.Add(new Regex(filter.ToString()));
}
catch (Exception e)
{
Log.Debug(e.GetType().ToString());
Log.Debug("Failed to make a regex from {0}", filter.ToString());
}
}
try
{
_filters.Add(key, filters);
}
catch (ArgumentException)
{
// We are running in parallel, its possible someone added it in between the original check and now. No problem here.
filters = _filters[key];
}
_filters.Add(key, filters);
Log.Warning("Successfully parsed {0} {1} {2} {3} {4}", Platform, ScanType, ItemType, Property, FilterType);
}
catch (NullReferenceException)
{
Log.Debug("Failed parsing {0} {1} {2} {3} {4} (no entry?)", Platform, ScanType, ItemType, Property, FilterType);
_filters.Add(key, new List<Regex>());
try
{
_filters.Add(key, new List<Regex>());
}
catch (ArgumentException)
{
// We are running in parallel, its possible someone added it in between the original check and now. No problem here.
}
return false;
}

}
catch (Exception e)
{
Expand Down
24 changes: 22 additions & 2 deletions filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,35 @@
"Registry": {
"Key": {
"Exclude": [
"HKEY_CLASSES_ROOT\\WOW6432Node\\Interface\\",
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\"
"^HKEY_CLASSES_ROOT\\\\WOW6432Node\\\\Interface$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\Control$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\DriverDatabase\\\\DriverPackages$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\Enum$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\Services\\\\DeviceAssociationService\\\\State\\\\Store$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\Services\\\\mpssvc\\\\Parameters$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\ControlSet001\\\\Enum$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\ControlSet001\\\\Control$",
"^HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\ControlSet001\\\\Services$"
]
},
"Hive": {
"Exclude": [
"ClassesRoot"
]
}
},
"File": {
"Path": {
"Exclude": [
"[A-Z]:\\\\pagefile.sys",
"[A-Z]:\\\\hiberfil.sys",
"[A-Z]:\\\\swapfile.sys",
"[A-Z]:\\\\Windows\\\\CSC",
"[A-Z]:\\\\Windows\\\\System32\\\\LogFiles\\\\WMI\\\\RTBackup",
"[A-Z]:\\\\Windows\\\\ServiceProfiles\\\\LocalService\\\\AppData\\\\Local\\\\Microsoft\\\\NGC"

]
}
}
}
},
Expand Down

0 comments on commit 8a4885b

Please sign in to comment.