Skip to content

Commit

Permalink
Address Roslyn Warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
gfs committed Feb 18, 2020
2 parents 90300c2 + b65c47b commit 8cd7799
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ dotnet_diagnostic.CA1307.severity = none

# CA1031: General Exceptions
dotnet_diagnostic.CA1031.severity = none

# CA1707: Remove the underscores from type name AttackSurfaceAnalyzer.Types.RUN_TYPE.
dotnet_diagnostic.CA1707.severity = none

# CA2227: Collection properties should be read only
dotnet_diagnostic.CA2227.severity = none
2 changes: 1 addition & 1 deletion Asa/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
RequestPath = new PathString("")
});
}
catch(Exception e)
catch(Exception)
{
Log.Debug("Had an issue setting static file path. Reverting to default.");
app.UseStaticFiles();
Expand Down
2 changes: 1 addition & 1 deletion Lib/Collectors/WindowsFileSystemUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static Signature GetSignatureStatus(string Path)
var sig = new Signature(authenticodeInfo);
return sig;
}
catch(Exception e)
catch(Exception)
{
}
return null;
Expand Down
18 changes: 9 additions & 9 deletions Lib/Objects/FileMonitorObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ namespace AttackSurfaceAnalyzer.Objects
{
public class FileMonitorObject : CollectObject
{
public string Path;
public string OldPath;
public string Name;
public string OldName;
public CHANGE_TYPE ChangeType;
public string ExtendedResults;
public string NotifyFilters;
public string Serialized;
public string Timestamp;
public string Path { get; set; }
public string OldPath { get; set; }
public string Name { get; set; }
public string OldName { get; set; }
public CHANGE_TYPE ChangeType { get; set; }
public string ExtendedResults { get; set; }
public string NotifyFilters { get; set; }
public string Serialized { get; set; }
public string Timestamp { get; set; }

public override string Identity
{
Expand Down
12 changes: 6 additions & 6 deletions Lib/Objects/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace AttackSurfaceAnalyzer.Objects
{
public class Run
{
public RUN_TYPE Type;
public string RunId;
public string Timestamp;
public string Version;
public string Platform;
public Dictionary<RESULT_TYPE, bool> ResultTypes;
public RUN_TYPE Type { get; set; }
public string RunId { get; set; }
public string Timestamp { get; set; }
public string Version { get; set; }
public string Platform { get; set; }
public Dictionary<RESULT_TYPE, bool> ResultTypes { get; set; }
}
}
2 changes: 1 addition & 1 deletion Lib/Objects/SerializableCertificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SerializableCertificate
{
public SerializableCertificate (X509Certificate2 certificate)
{
Thumbprint = certificate.Thumbprint;
Thumbprint = certificate?.Thumbprint;
Subject = certificate.Subject;
PublicKey = certificate.PublicKey.EncodedKeyValue.Format(true);
NotAfter = certificate.NotAfter;
Expand Down
23 changes: 14 additions & 9 deletions Lib/Utils/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ public static class DatabaseManager
private const string UPDATE_TELEMETRY = "replace into persisted_settings values ('telemetry_opt_out',@TelemetryOptOut)"; //lgtm [cs/literal-as-local]
private const string CHECK_TELEMETRY = "select value from persisted_settings where setting='telemetry_opt_out'";

private const string SQL_TRUNCATE = "delete from file_system_monitored where run_id=@run_id";
private const string SQL_INSERT = "insert into file_system_monitored (run_id, row_key, timestamp, change_type, path, old_path, name, old_name, extended_results, notify_filters, serialized) values (@run_id, @row_key, @timestamp, @change_type, @path, @old_path, @name, @old_name, @extended_results, @notify_filters, @serialized)";

private const string PRAGMAS = "PRAGMA main.auto_vacuum = 0; PRAGMA main.synchronous = OFF; PRAGMA main.journal_mode = DELETE;";

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 string UPDATE_RUN_IN_RESULT_TABLE = "update results set status = @status where (base_run_id = @base_run_id and compare_run_id = @compare_run_id)";

private const string SQL_GET_RUN = "select run_id from runs where run_id=@run_id";

private const string GET_COMPARISON_RESULTS = "select * from findings where comparison_id = @comparison_id and result_type=@result_type order by level des;";
private const string GET_SERIALIZED_RESULTS = "select change_type, Serialized from file_system_monitored where run_id = @run_id";
Expand All @@ -92,7 +90,6 @@ public static class DatabaseManager
private const string SQL_QUERY_ANALYZED = "select * from results where status = @status"; //lgtm [cs/literal-as-local]

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"; //lgtm [cs/literal-as-local]
private const string INSERT_RUN = "insert into runs (run_id, file_system, ports, users, services, registry, certificates, type, timestamp, version, platform) values (@run_id, @file_system, @ports, @users, @services, @registry, @certificates, @type, @timestamp, @version, @platform)"; //lgtm [cs/literal-as-local]
private const string SQL_GET_RESULT_TYPES = "select * from runs where run_id = @base_run_id or run_id = @compare_run_id"; //lgtm [cs/literal-as-local]

private const string GET_MONITOR_RESULTS = "select * from file_system_monitored where run_id=@run_id order by timestamp limit @offset,@limit;"; //lgtm [cs/literal-as-local]
Expand Down Expand Up @@ -217,12 +214,12 @@ public static bool Setup(string filename = null)
return false;
}

public static List<DataRunModel> GetResultModels(RUN_STATUS cOMPLETED)
public static List<DataRunModel> GetResultModels(RUN_STATUS runStatus)
{
var output = new List<DataRunModel>();
using (var cmd = new SqliteCommand(SQL_QUERY_ANALYZED, Connection, Transaction))
{
cmd.Parameters.AddWithValue("@status", RUN_STATUS.COMPLETED);
cmd.Parameters.AddWithValue("@status", runStatus);

using (var reader = cmd.ExecuteReader())
{
Expand Down Expand Up @@ -478,6 +475,10 @@ public static void BeginTransaction()

public static void InsertRun(string runId, Dictionary<RESULT_TYPE, bool> dictionary)
{
if (dictionary == null)
{
return;
}
string INSERT_RUN = "insert into runs (run_id, file_system, ports, users, services, registry, certificates, firewall, comobjects, eventlogs, type, timestamp, version, platform) values (@run_id, @file_system, @ports, @users, @services, @registry, @certificates, @firewall, @comobjects, @eventlogs, @type, @timestamp, @version, @platform)";

using var cmd = new SqliteCommand(INSERT_RUN, Connection, Transaction);
Expand Down Expand Up @@ -753,13 +754,17 @@ public static void SetOptOut(bool OptOut)
}
}

public static void WriteFileMonitor(FileMonitorObject obj, string RunId)
public static void WriteFileMonitor(FileMonitorObject fmo, string RunId)
{
if (fmo == null)
{
return;
}
using var cmd = new SqliteCommand(SQL_INSERT, Connection, Transaction);
cmd.Parameters.AddWithValue("@run_id", RunId);
cmd.Parameters.AddWithValue("@path", obj.Path);
cmd.Parameters.AddWithValue("@timestamp", obj.Timestamp);
cmd.Parameters.AddWithValue("@serialized", JsonConvert.SerializeObject(obj));
cmd.Parameters.AddWithValue("@path", fmo.Path);
cmd.Parameters.AddWithValue("@timestamp", fmo.Timestamp);
cmd.Parameters.AddWithValue("@serialized", JsonConvert.SerializeObject(fmo));

cmd.ExecuteNonQuery();
}
Expand Down

0 comments on commit 8cd7799

Please sign in to comment.