Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Output.cshtml and Filter.json as resources in the binary #159

Merged
merged 4 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions Cli/AttackSurfaceAnalyzerCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lib\AttackSurfaceAnalyzerLib.csproj" />
<Content Include="Output\Output.cshtml" CopyToPublishDirectory="PreserveNewest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Output\Output.cshtml" CopyToPublishDirectory="PreserveNewest">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<Content Include="..\LICENSE.txt">
<Link>LICENSE.txt</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -41,10 +41,9 @@
<Link>README.md</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\filters.json">
<EmbeddedResource Include="..\filters.json">
<Link>filters.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Remove="asa.sqlite" />
Expand Down
25 changes: 20 additions & 5 deletions Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ public class CollectCommandOptions
[Option("match-run-id", Required = false, HelpText = "Match the collectors used on another run id")]
public string MatchedCollectorId { get; set; }

[Option("filter", Required = false, HelpText = "Provide a JSON filter file.", Default = "filters.json")]
[Option("filter", Required = false, HelpText = "Provide a JSON filter file.", Default = "Use embedded filters.")]
public string FilterLocation { get; set; }

[Option(HelpText = "Disables the embedded filters.")]
public bool NoFilters { get; set; }

[Option('h',"gather-hashes", Required = false, HelpText = "Hashes every file when using the File Collector. May dramatically increase run time of the scan.")]
public bool GatherHashes { get; set; }

Expand Down Expand Up @@ -1200,8 +1203,18 @@ public static int RunCollectCommand(CollectCommandOptions opts)
Log.Warning(Strings.Get("Err_NoCollectors"));
return -1;
}

Filter.LoadFilters(opts.FilterLocation);
Log.Information(opts.FilterLocation);
if (!opts.NoFilters)
{
if (opts.FilterLocation.Equals("Use embedded filters."))
{
Filter.LoadEmbeddedFilters();
}
else
{
Filter.LoadFilters(opts.FilterLocation);
}
}
DatabaseManager.SqliteFilename = opts.DatabaseFilename;

if (opts.Overwrite)
Expand Down Expand Up @@ -1378,11 +1391,13 @@ private static int RunCompareCommand(CompareCommandOptions opts)
var results = CompareRuns(opts);

var engine = new RazorLightEngineBuilder()
.UseFilesystemProject(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))
.UseEmbeddedResourcesProject(typeof(AttackSurfaceAnalyzerCLI))
.UseMemoryCachingProvider()
.Build();

var result = engine.CompileRenderAsync("Output" + Path.DirectorySeparatorChar + "Output.cshtml", results).Result;
var assembly = Assembly.GetExecutingAssembly();

var result = engine.CompileRenderAsync("Output.Output.cshtml", results).Result;
File.WriteAllText($"{opts.OutputBaseFilename}.html", result);
Log.Information(Strings.Get("OutputWrittenTo"), opts.OutputBaseFilename + ".html");

Expand Down
2 changes: 1 addition & 1 deletion Cli/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
<data name="NoMonitorRuns" xml:space="preserve">
<value>There were no monitor runs in the database.</value>
</data>
<data name="FirstRunListRunsError" xml:space="preserve">
<data name="FirstRunListRunsError" xml:space="preserve">
<value>This appears to be the first run with database {0}. There are no runs to list.</value>
</data>
</root>
6 changes: 1 addition & 5 deletions Gui/AttackSurfaceAnalyzerGui.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
<PropertyGroup>
<Authors>Microsoft Corporation</Authors>
Expand Down Expand Up @@ -28,10 +28,6 @@
<ProjectReference Include="..\Lib\AttackSurfaceAnalyzerLib.csproj" />
<ProjectReference Include="..\Cli\AttackSurfaceAnalyzerCli.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\js\min\" />
<Folder Include="wwwroot\css\min\" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Gui/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using AttackSurfaceAnalyzer.Utils;
using ElectronNET.API;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
Expand Down
7 changes: 6 additions & 1 deletion Gui/wwwroot/American-English.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"%ReadyToBeginCollection": "<i>Ready to begin collection.</i>",
"%Showing": "Showing ",
"%Results": " Results",
"%TotalRecords": " total records."
"%TotalRecords": " total records.",
"%Created": "Created",
"%Deleted": "Deleted",
"%Modified": "Modified",
"%Renamed": "Renamed",
"%InvalidChange": "Invalid Change Type"
}
}
9 changes: 8 additions & 1 deletion Gui/wwwroot/js/Analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ ResultTypeGroup.change(function () {
}
});

var ExportQuantityGroup = $('input[type=radio][name=ExportQuantity]');
ExportQuantityGroup.change(function () {
$("#ExportResultsButton").attr('disabled', false);
})



$('#SelectedBaseRunId').change(function () { ResetResults(); } );
$('#SelectedCompareRunId').change(function () { ResetResults(); } );

Expand Down Expand Up @@ -135,7 +142,7 @@ function GetComparators() {
icon = '<i class="far fa-check-circle" style="color:green"></i> ';
}
else if (value === RUN_STATUS.NOT_STARTED) {
icon = '<i class="fas fa-pause"></i> ';
icon = '<i class="fas fa-cog"></i> ';
}
else if (value === RUN_STATUS.NO_RESULTS) {
icon = '<i class="fas fa-level-down-alt"></i> ';
Expand Down
2 changes: 2 additions & 0 deletions Gui/wwwroot/lib/jquery.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Lib/AttackSurfaceAnalyzerLib.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand Down Expand Up @@ -66,6 +66,7 @@ This NuGet contains the AttackSurfaceAnalyzer Library, which is used by the CLI
<PackageReference Include="Nerdbank.GitVersioning" Version="2.3.138" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\filters.json" Link="filters.json" />
<Content Include="..\LICENSE.txt">
<Link>LICENSE.txt</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
41 changes: 39 additions & 2 deletions Lib/Utils/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using Serilog;
using System.Reflection;

namespace AttackSurfaceAnalyzer.Utils
{
Expand Down Expand Up @@ -152,6 +151,44 @@ public static void DumpFilters()
}
}

public static void LoadEmbeddedFilters()
{
try
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "AttackSurfaceAnalyzer.filters.json";

using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader streamreader = new StreamReader(stream))
using (JsonTextReader reader = new JsonTextReader(streamreader))
{
config = (JObject)JToken.ReadFrom(reader);
Log.Information("{0} {1}", Strings.Get("LoadedFilters"), "Embedded");
DumpFilters();
}
if (config == null)
{
Log.Debug("Out of entries");
}
}
catch (FileNotFoundException)
{
//That's fine, we just don't have any filters to load
config = null;
Log.Debug("{0} is missing (filter configuration file)", "Embedded");

return;
}
catch (NullReferenceException)
{
config = null;
Log.Debug("{0} is missing (filter configuration file)", "Embedded");

return;

}
}

public static void LoadFilters(string filterLoc = "filters.json")
{
try
Expand Down