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

Fixes #117 #147

Merged
merged 1 commit into from
Apr 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 60 additions & 32 deletions Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ public static class AttackSurfaceAnalyzerCLI

static void Main(string[] args)
{
Logger.Setup();
#if DEBUG
Logger.Setup(true,false);
#else
Logger.Setup(false,false);
#endif
Strings.Setup();

string version = (Assembly
Expand Down Expand Up @@ -252,21 +256,41 @@ private static int RunConfigCommand(ConfigCommandOptions opts)
{
while (reader.Read())
{
string output = String.Format("{0} {1} {2} {3}",
reader["timestamp"].ToString(),
reader["version"].ToString(),
reader["type"].ToString(),
reader["run_id"].ToString());
Log.Information(output);
output = String.Format("{0} {1} {2} {3} {4} {5}",
(int.Parse(reader["file_system"].ToString()) != 0) ? "FILES" : "",
(int.Parse(reader["ports"].ToString()) != 0) ? "PORTS" : "",
(int.Parse(reader["users"].ToString()) != 0) ? "USERS" : "",
(int.Parse(reader["services"].ToString()) != 0) ? "SERVICES" : "",
(int.Parse(reader["certificates"].ToString()) != 0) ? "CERTIFICATES" : "",
(int.Parse(reader["registry"].ToString()) != 0) ? "REGISTRY" : "");
Log.Information(output);

Log.Information("RunId:{2} Timestamp:{0} AsaVersion:{1} ",
reader["timestamp"],
reader["version"],
reader["run_id"]);
List<RESULT_TYPE> resultTypes = new List<RESULT_TYPE>();
if (int.Parse(reader["file_system"].ToString()) != 0)
{
resultTypes.Add(RESULT_TYPE.FILE);
}
if (int.Parse(reader["ports"].ToString()) != 0)
{
resultTypes.Add(RESULT_TYPE.PORT);
}
if (int.Parse(reader["users"].ToString()) != 0)
{
resultTypes.Add(RESULT_TYPE.USER);
}
if (int.Parse(reader["services"].ToString()) != 0)
{
resultTypes.Add(RESULT_TYPE.SERVICES);
}
if (int.Parse(reader["certificates"].ToString()) != 0)
{
resultTypes.Add(RESULT_TYPE.CERTIFICATE);
}
if (int.Parse(reader["registry"].ToString()) != 0)
{
resultTypes.Add(RESULT_TYPE.REGISTRY);
}

foreach (RESULT_TYPE type in resultTypes)
{
int num = DatabaseManager.GetNumResults(type, reader["run_id"].ToString());
Log.Information("{0} : {1}", type, num);
}
}
}
}
Expand Down Expand Up @@ -415,33 +439,37 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId
string BaseString = "";
CHANGE_TYPE ChangeType = (CHANGE_TYPE)int.Parse(reader["change_type"].ToString());

if (ChangeType == CHANGE_TYPE.CREATED || ChangeType == CHANGE_TYPE.MODIFIED)
using (var inner_cmd = new SqliteCommand(GET_SERIALIZED_RESULTS.Replace("@table_name", Helpers.ResultTypeToTableName(ExportType)), DatabaseManager.Connection))
{
var inner_cmd = new SqliteCommand(GET_SERIALIZED_RESULTS.Replace("@table_name", Helpers.ResultTypeToTableName(ExportType)), DatabaseManager.Connection);
inner_cmd.Parameters.AddWithValue("@run_id", reader["compare_run_id"].ToString());
inner_cmd.Parameters.AddWithValue("@row_key", reader["compare_row_key"].ToString());
using (var inner_reader = inner_cmd.ExecuteReader())
if (ChangeType == CHANGE_TYPE.CREATED || ChangeType == CHANGE_TYPE.MODIFIED)
{
while (inner_reader.Read())
inner_cmd.Parameters.Clear();
inner_cmd.Parameters.AddWithValue("@run_id", reader["compare_run_id"].ToString());
inner_cmd.Parameters.AddWithValue("@row_key", reader["compare_row_key"].ToString());
using (var inner_reader = inner_cmd.ExecuteReader())
{
CompareString = inner_reader["serialized"].ToString();
while (inner_reader.Read())
{
CompareString = inner_reader["serialized"].ToString();
}
}
}
}
if (ChangeType == CHANGE_TYPE.DELETED || ChangeType == CHANGE_TYPE.MODIFIED)
{
var inner_cmd = new SqliteCommand(GET_SERIALIZED_RESULTS.Replace("@table_name", Helpers.ResultTypeToTableName(ExportType)), DatabaseManager.Connection);
inner_cmd.Parameters.AddWithValue("@run_id", reader["base_run_id"].ToString());
inner_cmd.Parameters.AddWithValue("@row_key", reader["base_row_key"].ToString());
using (var inner_reader = inner_cmd.ExecuteReader())
if (ChangeType == CHANGE_TYPE.DELETED || ChangeType == CHANGE_TYPE.MODIFIED)
{
while (inner_reader.Read())
inner_cmd.Parameters.Clear();
inner_cmd.Parameters.AddWithValue("@run_id", reader["base_run_id"].ToString());
inner_cmd.Parameters.AddWithValue("@row_key", reader["base_row_key"].ToString());
using (var inner_reader = inner_cmd.ExecuteReader())
{
BaseString = inner_reader["serialized"].ToString();
while (inner_reader.Read())
{
BaseString = inner_reader["serialized"].ToString();
}
}
}
}


CompareResult obj;
switch (ExportType)
{
Expand Down
Loading