From 61680c51bb26ca3d1288e2aad390c5683179de8b Mon Sep 17 00:00:00 2001 From: Gabe Stocco Date: Sun, 31 Mar 2019 14:34:38 -0700 Subject: [PATCH] Improve result output (#26) * Added a 'no results' status to the comparisons on the status page in GUI. * Adds summary file for cli collect output. If there are no results there is no output files so this clarifies why that would be the case. --- AttackSurfaceAnalyzer.sln | 5 ++--- Cli/Program.cs | 28 +++++++++++++++++++++------- Gui/wwwroot/js/Analyze.js | 14 ++++++++++++-- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/AttackSurfaceAnalyzer.sln b/AttackSurfaceAnalyzer.sln index 200abc132..15563cd89 100644 --- a/AttackSurfaceAnalyzer.sln +++ b/AttackSurfaceAnalyzer.sln @@ -2,11 +2,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27428.2037 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttackSurfaceAnalyzerGui", "Gui\AttackSurfaceAnalyzerGui.csproj", "{2B0AC364-0713-406C-8B07-795574F15EC6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AttackSurfaceAnalyzerGui", "Gui\AttackSurfaceAnalyzerGui.csproj", "{2B0AC364-0713-406C-8B07-795574F15EC6}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttackSurfaceAnalyzerLib", "Lib\AttackSurfaceAnalyzerLib.csproj", "{5069C7AB-2264-4768-AB42-358251B0863A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttackSurfaceAnalyzerCli", "Cli\AttackSurfaceAnalyzerCli.csproj", "{431FFEB4-57C2-4C5B-B329-DDF6ED229C3A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AttackSurfaceAnalyzerCli", "Cli\AttackSurfaceAnalyzerCli.csproj", "{431FFEB4-57C2-4C5B-B329-DDF6ED229C3A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0E30E3FA-AECD-4BF3-9EAA-9D6C16D5E991}" ProjectSection(SolutionItems) = preProject @@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CONTRIBUTING.md = CONTRIBUTING.md global.json = global.json LICENSE = LICENSE - NOTICE.txt = NOTICE.txt PRIVACY.md = PRIVACY.md README.md = README.md version.json = version.json diff --git a/Cli/Program.cs b/Cli/Program.cs index e8304dee5..a4a3945ba 100644 --- a/Cli/Program.cs +++ b/Cli/Program.cs @@ -249,11 +249,18 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId string GET_SERIALIZED_RESULTS = "select serialized from @table_name where row_key = @row_key and run_id = @run_id"; List ToExport = new List { (RESULT_TYPE)ResultType }; - + Dictionary actualExported = new Dictionary(); + JsonSerializer serializer = new JsonSerializer + { + Formatting = Formatting.Indented, + NullValueHandling = NullValueHandling.Ignore + }; if (ExportAll) { ToExport = new List { RESULT_TYPE.FILE, RESULT_TYPE.CERTIFICATE, RESULT_TYPE.PORT, RESULT_TYPE.REGISTRY, RESULT_TYPE.SERVICES, RESULT_TYPE.USER }; } + + foreach (RESULT_TYPE ExportType in ToExport) { List records = new List(); @@ -356,17 +363,13 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId records.Add(obj); } } + actualExported.Add(ExportType, records.Count()); + if (records.Count > 0) { //telemetry.GetMetric("ResultsExported").TrackValue(records.Count); - JsonSerializer serializer = new JsonSerializer - { - Formatting = Formatting.Indented, - NullValueHandling = NullValueHandling.Ignore - }; - serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); using (StreamWriter sw = new StreamWriter(Path.Combine(OutputPath, Helpers.MakeValidFileName(BaseId + "_vs_" + CompareId + "_" + ExportType.ToString() + ".json.txt")))) //lgtm[cs/path-injection] @@ -378,6 +381,17 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId } } } + + serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); + + using (StreamWriter sw = new StreamWriter(Path.Combine(OutputPath, Helpers.MakeValidFileName(BaseId + "_vs_" + CompareId + "_summary.json.txt")))) //lgtm[cs/path-injection] + { + using (JsonWriter writer = new JsonTextWriter(sw)) + { + serializer.Serialize(writer, actualExported); + } + } + } private static int RunExportMonitorCommand(ExportMonitorCommandOptions opts) diff --git a/Gui/wwwroot/js/Analyze.js b/Gui/wwwroot/js/Analyze.js index f0c63cb31..aab499bd8 100644 --- a/Gui/wwwroot/js/Analyze.js +++ b/Gui/wwwroot/js/Analyze.js @@ -190,12 +190,22 @@ function GetResultTypes() { function UpdateNumResults(total, offset, requested, actual) { $('#CountStatus').empty(); - $("#CountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records."); + if (actual == 0){ + $("#CountStatus").append("No difference detected."); + } + else{ + $("#CountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records."); + } } function UpdateMonitorNumResults(total, offset, requested, actual) { $('#MonitorCountStatus').empty(); - $("#MonitorCountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records."); + if (actual == 0){ + $("#CountStatus").append("No difference detected."); + } + else{ + $("#MonitorCountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records."); + } } function GetResults(type, offset, number) {