Skip to content

Commit

Permalink
Merge pull request rxwx#3 from mgeeky/master
Browse files Browse the repository at this point in the history
Added exception handling in case of a corrupted database exfiltrated.
  • Loading branch information
rxwx authored Jul 5, 2021
2 parents cfeb858 + 6ebff27 commit ebfc0ee
Showing 1 changed file with 97 additions and 10 deletions.
107 changes: 97 additions & 10 deletions ChloniumUI/ChloniumUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private void Import_Click(object sender, RoutedEventArgs e)

string backupFile;
List<Item> items = new List<Item>();
int count = 0;

switch (dbType)
{
Expand All @@ -109,6 +110,7 @@ private void Import_Click(object sender, RoutedEventArgs e)
{
c.encrypted_value = crypto.Encrypt(c.decrypted_value);
}
count = items.Count();
ImportCookies(items);
break;
case "logins":
Expand All @@ -123,12 +125,13 @@ private void Import_Click(object sender, RoutedEventArgs e)
{
i.password_value = crypto.Encrypt(i.decrypted_password_value);
}
count = items.Count();
ImportLogins(items);
break;
default:
return;
}
MessageBox.Show("Imported!");
MessageBox.Show($"Imported {count} {dbType}!");
}

private void File_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -227,6 +230,8 @@ private void ImportCookies(List<Item> items)
SQLiteCommand cmd = new SQLiteCommand("DELETE FROM cookies;", con);
cmd.ExecuteNonQuery();

int exceptionsCount = 0;

foreach (Cookie c in items)
{
cmd = new SQLiteCommand("INSERT INTO cookies (creation_utc, host_key, name, value, " +
Expand Down Expand Up @@ -257,7 +262,11 @@ private void ImportCookies(List<Item> items)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (exceptionsCount < 3)
{
MessageBox.Show(ex.Message);
exceptionsCount++;
}
}
}
}
Expand All @@ -272,6 +281,8 @@ private void ImportLogins(List<Item> items)
SQLiteCommand cmd = new SQLiteCommand("DELETE FROM logins;", con);
cmd.ExecuteNonQuery();

int exceptionsCount = 0;

foreach (Login c in items)
{
cmd = new SQLiteCommand("INSERT INTO logins (origin_url, action_url, username_element, username_value, " +
Expand Down Expand Up @@ -314,7 +325,11 @@ private void ImportLogins(List<Item> items)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (exceptionsCount < 3)
{
MessageBox.Show(ex.Message);
exceptionsCount++;
}
}
}
}
Expand All @@ -338,11 +353,34 @@ private List<Item> ExportCookies()
var cmd = new SQLiteCommand(stm, con);
SQLiteDataReader reader = cmd.ExecuteReader();

int exceptionsCount = 0;

if (reader.HasRows)
{
while (reader.Read())
bool ret = true;
int errCount = 0;

while (ret)
{
byte[] encrypted_value = (byte[])reader["encrypted_value"];
byte[] encrypted_value;
try
{
ret = reader.Read();
encrypted_value = (byte[])reader["encrypted_value"];
}
catch (Exception e)
{
errCount++;

if (errCount > 3)
{
MessageBox.Show("Some cookies could not be imported.", "Warning");
break;
}

continue;
}

byte[] decrypted_value = null;

if (encrypted_value[0] == 'v' && encrypted_value[1] == '1' && encrypted_value[2] == '0')
Expand All @@ -353,7 +391,11 @@ private List<Item> ExportCookies()
}
catch (Exception e)
{
MessageBox.Show(e.Message);
if (exceptionsCount < 3)
{
MessageBox.Show(e.Message);
exceptionsCount++;
}
continue;
}
}
Expand Down Expand Up @@ -389,7 +431,19 @@ private List<Item> ExportCookies()
{
Console.WriteLine("No rows found.");
}
reader.Close();

try
{
reader.Close();
}
catch (Exception e)
{ }

if(items.Count() == 0)
{
MessageBox.Show("No cookies were exported from specified input database!", "Error");
}

return items;
}

Expand All @@ -409,11 +463,34 @@ private List<Item> ExportLogins()
var cmd = new SQLiteCommand(stm, con);
SQLiteDataReader reader = cmd.ExecuteReader();

int exceptionsCount = 0;

if (reader.HasRows)
{
while (reader.Read())
bool ret = true;
int errCount = 0;

while (ret)
{
byte[] encrypted_value = (byte[])reader["password_value"];
byte[] encrypted_value;
try
{
ret = reader.Read();
encrypted_value = (byte[])reader["password_value"];
}
catch (Exception e)
{
errCount++;

if (errCount > 3)
{
MessageBox.Show("Some logins could not be imported.", "Warning");
break;
}

continue;
}

byte[] decrypted_value = null;

if (encrypted_value[0] == 'v' && encrypted_value[1] == '1' && encrypted_value[2] == '0')
Expand All @@ -424,7 +501,11 @@ private List<Item> ExportLogins()
}
catch (Exception e)
{
MessageBox.Show(e.Message);
if (exceptionsCount < 3)
{
MessageBox.Show(e.Message);
exceptionsCount++;
}
continue;
}
}
Expand Down Expand Up @@ -471,6 +552,12 @@ private List<Item> ExportLogins()
Console.WriteLine("No rows found.");
}
reader.Close();

if(items.Count() == 0)
{
MessageBox.Show("No logins were exported from specified input database!", "Error");
}

return items;
}

Expand Down

0 comments on commit ebfc0ee

Please sign in to comment.