Skip to content

Commit

Permalink
Gfs/#552 (#554)
Browse files Browse the repository at this point in the history
* Fix error when export monitoring

* Update dependencies

* Quit when no monitors are specified.

* Fix #552

* Fix using timestamps as default

* fix nbgv version

* Fix Cli Monitoring

* Update _ViewImports.cshtml
  • Loading branch information
gfs authored Oct 27, 2020
1 parent 90b9339 commit 839fa68
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 42 deletions.
8 changes: 0 additions & 8 deletions Cli/Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.14.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.31">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Lib\Lib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
Expand Down
15 changes: 9 additions & 6 deletions Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private static int RunExportMonitorCommand(ExportMonitorCommandOptions opts)

Log.Information("{0} {1}", Strings.Get("Exporting"), opts.RunId);

WriteMonitorJson(opts.RunId, (int)RESULT_TYPE.FILE, opts.OutputPath ?? "monitor.json");
WriteMonitorJson(opts.RunId, (int)RESULT_TYPE.FILE, opts.OutputPath ?? string.Empty);

return 0;
}
Expand All @@ -490,7 +490,7 @@ public static void WriteMonitorJson(string RunId, int ResultType, string OutputP
DefaultValueHandling = DefaultValueHandling.Ignore,
Converters = new List<JsonConverter>() { new StringEnumConverter() }
});
var output = new Dictionary<string, Object>();
var output = new Dictionary<string, object>();
output["results"] = records;
output["metadata"] = AsaHelpers.GenerateMetadata();
string path = Path.Combine(OutputPath, AsaHelpers.MakeValidFileName(RunId + "_Monitoring_" + ((RESULT_TYPE)ResultType).ToString() + ".json.txt"));
Expand Down Expand Up @@ -543,7 +543,10 @@ private static int RunMonitorCommand(MonitorCommandOptions opts)

if (opts.EnableFileSystemMonitor)
{
monitors.Add(new FileSystemMonitor(opts, x => DatabaseManager.WriteFileMonitor(x, opts.RunId)));
monitors.Add(new FileSystemMonitor(opts, x =>
{
DatabaseManager.WriteFileMonitor(x, opts.RunId);
}));
}

//if (opts.EnableRegistryMonitor)
Expand All @@ -554,8 +557,8 @@ private static int RunMonitorCommand(MonitorCommandOptions opts)

if (monitors.Count == 0)
{
Log.Warning(Strings.Get("Err_NoMonitors"));
returnValue = (int)ASA_ERROR.NO_COLLECTORS;
Log.Fatal(Strings.Get("Err_NoMonitors"));
return (int)ASA_ERROR.NO_COLLECTORS;
}

using var exitEvent = new ManualResetEvent(false);
Expand Down Expand Up @@ -761,7 +764,7 @@ public static ASA_ERROR RunGuiMonitorCommand(MonitorCommandOptions opts)
}
if (opts.EnableFileSystemMonitor)
{
monitors.Add(new FileSystemMonitor(opts, x => DatabaseManager.Write(x,opts.RunId)));
monitors.Add(new FileSystemMonitor(opts, x => DatabaseManager.WriteFileMonitor(x,opts.RunId)));
}

if (monitors.Count == 0)
Expand Down
4 changes: 1 addition & 3 deletions Cli/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@using AttackSurfaceAnalyzer
@using AttackSurfaceAnalyzer.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.ApplicationInsights.AspNetCore
@inject JavaScriptSnippet snippet
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.1.91</Version>
<Version>3.3.37</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
33 changes: 17 additions & 16 deletions Lib/Collectors/FileSystemCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ public class FileSystemCollector : BaseCollector

public static ConcurrentDictionary<string, uint> ClusterSizes { get; set; } = new ConcurrentDictionary<string, uint>();

public FileSystemCollector(CollectCommandOptions? opts = null, Action<CollectObject>? changeHandler = null) : base(opts, changeHandler) { }

public override bool CanRunOnPlatform()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}

public override void ExecuteInternal()
public FileSystemCollector(CollectCommandOptions? opts = null, Action<CollectObject>? changeHandler = null) : base(opts, changeHandler)
{
if (!string.IsNullOrEmpty(opts.SelectedDirectories))
{
Expand Down Expand Up @@ -68,7 +61,15 @@ public override void ExecuteInternal()
Roots.Add("/");
}
}
}

public override bool CanRunOnPlatform()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}

public override void ExecuteInternal()
{
void TryIterateOnDirectory(string Path)
{
try
Expand Down Expand Up @@ -188,14 +189,14 @@ private FileSystemObject FileEntryToFileSystemObject(FileEntry fileEntry)
return fso;
}

/// <summary>
/// Converts a FileSystemInfo into a FileSystemObject by reading in data about the file
/// </summary>
/// <param name="fileInfo">A reference to a file on disk.</param>
/// <param name="downloadCloud">If the file is hosted in the cloud, the user has the option to include cloud files or not.</param>
/// <param name="includeContentHash">If we should generate a hash of the file.</param>
/// <returns></returns>
public FileSystemObject FilePathToFileSystemObject(string path)
/// <summary>
/// Converts a FileSystemInfo into a FileSystemObject by reading in data about the file
/// </summary>
/// <param name="fileInfo">A reference to a file on disk.</param>
/// <param name="downloadCloud">If the file is hosted in the cloud, the user has the option to include cloud files or not.</param>
/// <param name="includeContentHash">If we should generate a hash of the file.</param>
/// <returns></returns>
public FileSystemObject FilePathToFileSystemObject(string path)
{
FileSystemObject obj = new FileSystemObject(path);

Expand Down
10 changes: 5 additions & 5 deletions Lib/Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="CompareNETObjects" Version="4.66.0" />
<PackageReference Include="CompareNETObjects" Version="4.67.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.1.7" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.1.9" />
<PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="7.0.3" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.3" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.1" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
Expand All @@ -59,14 +59,14 @@
<PackageReference Include="System.Net.Security" Version="4.3.2" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.31">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="WindowsFirewallHelper" Version="2.0.2.29-beta1" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="sqlite" Version="3.13.0" />
<PackageReference Include="PeNet" Version="2.4.0" />
<PackageReference Include="PeNet" Version="2.4.2" />
<PackageReference Include="Microsoft.CST.MultiExtractor" Version="0.1.194" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lib/Objects/CommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public class CollectCommandOptions : CommandOptions
[Verb("monitor", HelpText = "Continue running and monitor activity")]
public class MonitorCommandOptions : CommandOptions
{
[Option(HelpText = "Identifies which run this is. Monitor output can be combined with collect output, but doesn't need to be compared.", Default = "Timestamp")]
[Option(HelpText = "Identifies which run this is. Monitor output can be combined with collect output, but doesn't need to be compared.")]
public string? RunId { get; set; }

[Option('f', "file-system", Required = false, HelpText = "Enable the file system monitor. Unless -d is specified will monitor the entire file system.")]
Expand Down
3 changes: 1 addition & 2 deletions Lib/Utils/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ public static List<FileMonitorEvent> GetSerializedMonitorResults(string runId)
if (reader["serialized"].ToString() is string serialized)
{
obj = JsonConvert.DeserializeObject<FileMonitorEvent>(serialized);
obj.ChangeType = (CHANGE_TYPE)int.Parse(reader["change_type"].ToString() ?? "0", CultureInfo.InvariantCulture);
records.Add(obj);
}
}
Expand Down Expand Up @@ -990,7 +989,7 @@ public static void WriteFileMonitor(FileMonitorObject fmo, string RunId)
private const string GET_RESULT_COUNT_MONITORED = "select count(*) from file_system_monitored where run_id=@run_id;";

private const string GET_RUNS = "select run_id from runs order by ROWID desc;";
private const string GET_SERIALIZED_RESULTS = "select change_type, Serialized from file_system_monitored where run_id = @run_id";
private const string GET_SERIALIZED_RESULTS = "select serialized from file_system_monitored where run_id = @run_id";
private const string INSERT_RUN_INTO_RESULT_TABLE_SQL = "insert into results (base_run_id, compare_run_id, status) values (@base_run_id, @compare_run_id, @status);";
private const int SCHEMA_VERSION = 10;
private const string SQL_CHECK_IF_COMPARISON_PREVIOUSLY_COMPLETED = "select * from results where base_run_id=@base_run_id and compare_run_id=@compare_run_id";
Expand Down

0 comments on commit 839fa68

Please sign in to comment.