Skip to content

Commit

Permalink
Add support for other Chromium based browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
rxwx committed Sep 3, 2020
1 parent f25186f commit 81b99f0
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 25 deletions.
41 changes: 41 additions & 0 deletions Chlonium/Browsers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;

namespace Chlonium
{
class Browsers
{
public class BrowserConfig
{
public string browserName { get; set; }
public string processName { get; set; }
public string cookieFile { get; set; }
public string localState { get; set; }
}

public static List<BrowserConfig> browserConfigs = new List<BrowserConfig>
{
new BrowserConfig
{
browserName = "Chrome",
processName = "chrome",
cookieFile = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies", Environment.GetEnvironmentVariable("USERPROFILE")),
localState = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data", Environment.GetEnvironmentVariable("USERPROFILE"))
},
new BrowserConfig
{
browserName = "Edge (Chromium)",
processName = "msedge",
cookieFile = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies", Environment.GetEnvironmentVariable("USERPROFILE")),
localState = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data", Environment.GetEnvironmentVariable("USERPROFILE"))
},
new BrowserConfig
{
browserName = "Vivaldi",
processName = "vivaldi",
cookieFile = string.Format("{0}\\AppData\\Local\\Vivaldi\\User Data\\Default\\Cookies", Environment.GetEnvironmentVariable("USERPROFILE")),
localState = string.Format("{0}\\AppData\\Local\\Vivaldi\\User Data", Environment.GetEnvironmentVariable("USERPROFILE"))
},
};
}
}
1 change: 1 addition & 0 deletions Chlonium/Chlonium.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AesCrypto.cs" />
<Compile Include="Browsers.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions ChloniumUI/ChloniumUI/AesCrypto.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using PInvoke;
using System.IO;
using System.Windows;
using static PInvoke.BCrypt;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
Expand All @@ -11,21 +12,21 @@ class AesCrypto
{
private static readonly Random rand = new Random();

public static readonly byte[] prefix = { 0x76, 0x31, 0x30 };
private static readonly byte[] prefix = { 0x76, 0x31, 0x30 };

public static readonly int PREFIX_SIZE = "v10".Length;
private static readonly int PREFIX_SIZE = prefix.Length;

private static readonly int NONCE_SIZE = 12;

private static readonly int TAG_SIZE = 16;

private readonly string profilePath;
private readonly string localStatePath;

private byte[] key;

public AesCrypto(string profilePath)
public AesCrypto(string localStatePath)
{
this.profilePath = profilePath;
this.localStatePath = localStatePath;
InitDecryptor();
}

Expand All @@ -48,16 +49,15 @@ private static byte[] SubArray(byte[] data, int index, int length)

public byte[] GetEncryptionKey()
{
string localStatePath = profilePath + "\\Local State";
byte[] encryptedKey;
string localState = File.ReadAllText(localStatePath);
string localState = File.ReadAllText(this.localStatePath);

// Read encrypted Masterkey
Regex r = new Regex("encrypted_key\":\"([A-Za-z0-9+\\/]+)\"", RegexOptions.IgnoreCase);
Regex r = new Regex("encrypted_key\":\"([a-z0-9+\\/=]+)\"", RegexOptions.IgnoreCase);

if (!r.IsMatch(localState))
{
Console.WriteLine("[X] Couldn't find encrypted_key");
MessageBox.Show("Couldn't find encrypted key", "Error");
return null;
}

Expand Down
41 changes: 41 additions & 0 deletions ChloniumUI/ChloniumUI/Browsers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;

namespace ChloniumUI
{
class Browsers
{
public class BrowserConfig
{
public string browserName { get; set; }
public string processName { get; set; }
public string cookieFile { get; set; }
public string localState { get; set; }
}

public static List<BrowserConfig> browserConfigs = new List<BrowserConfig>
{
new BrowserConfig
{
browserName = "Chrome",
processName = "chrome",
cookieFile = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies", Environment.GetEnvironmentVariable("USERPROFILE")),
localState = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data\\Local State", Environment.GetEnvironmentVariable("USERPROFILE"))
},
new BrowserConfig
{
browserName = "Edge (Chromium)",
processName = "msedge",
cookieFile = string.Format("{0}\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default\\Cookies", Environment.GetEnvironmentVariable("USERPROFILE")),
localState = string.Format("{0}\\AppData\\Local\\Microsoft\\Edge\\User Data\\Local State", Environment.GetEnvironmentVariable("USERPROFILE"))
},
new BrowserConfig
{
browserName = "Vivaldi",
processName = "vivaldi",
cookieFile = string.Format("{0}\\AppData\\Local\\Vivaldi\\User Data\\Default\\Cookies", Environment.GetEnvironmentVariable("USERPROFILE")),
localState = string.Format("{0}\\AppData\\Local\\Vivaldi\\User Data\\Local State", Environment.GetEnvironmentVariable("USERPROFILE"))
},
};
}
}
1 change: 1 addition & 0 deletions ChloniumUI/ChloniumUI/ChloniumUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Browsers.cs" />
<Compile Include="Cookie.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
Expand Down
12 changes: 7 additions & 5 deletions ChloniumUI/ChloniumUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ChloniumUI"
mc:Ignorable="d"
ResizeMode="NoResize" Title="ChloniumUI v0.1" Height="186.563" Width="693.125">
ResizeMode="NoResize" Title="ChloniumUI v0.1" Height="209.884" Width="676.801">
<Grid Background="Black">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="67*"/>
<ColumnDefinition Width="749*"/>
</Grid.ColumnDefinitions>
<TextBox Name="MasterKeyText" MaxLength="50" HorizontalAlignment="Left" Height="23" Margin="23,27,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="502" Grid.Column="1"/>
<TextBlock Foreground="White" HorizontalAlignment="Left" Margin="14,27,0,0" TextWrapping="Wrap" Text="Master Key:" VerticalAlignment="Top" Grid.ColumnSpan="2" Height="20" Width="66"/>
<TextBlock Foreground="White" HorizontalAlignment="Left" Margin="14,30,0,0" TextWrapping="Wrap" Text="Master Key" VerticalAlignment="Top" Grid.ColumnSpan="2" Height="20" Width="66"/>
<Button Foreground="White" Background="Black" Content="Check" HorizontalAlignment="Left" Margin="530,27,0,0" VerticalAlignment="Top" Width="75" Grid.Column="1" Height="23" Click="MasterKeyCheck_Click"/>
<TextBox Name="TextBox_CookieFile" HorizontalAlignment="Left" Height="23" Margin="23,63,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="502" Grid.Column="1"/>
<TextBlock Foreground="White" HorizontalAlignment="Left" Margin="14,66,0,0" TextWrapping="Wrap" Text="Cookie File:" VerticalAlignment="Top" Grid.ColumnSpan="2" Height="20" Width="66"/>
<TextBlock Foreground="White" HorizontalAlignment="Left" Margin="12,66,0,0" TextWrapping="Wrap" Text="Cookie File" VerticalAlignment="Top" Grid.ColumnSpan="2" Height="20" Width="66"/>
<Button Foreground="White" Background="Black" Content="Browse.." HorizontalAlignment="Left" Margin="530,63,0,0" VerticalAlignment="Top" Width="75" Grid.Column="1" Height="23" Click="CookieFile_Click"/>
<Button Foreground="White" Background="Black" Content="Export to Text File" Grid.Column="1" HorizontalAlignment="Left" Margin="117.5,108,0,0" VerticalAlignment="Top" Width="142" Height="32" Click="Export_Click"/>
<Button Foreground="White" Background="Black" Content="Import to Chrome" Grid.Column="1" HorizontalAlignment="Left" Margin="283.5,108,0,0" VerticalAlignment="Top" Width="140" Height="32" Click="Import_Click"/>
<Button Foreground="White" Background="Black" Content="Export to Text File" Grid.Column="1" HorizontalAlignment="Left" Margin="115.5,140,0,0" VerticalAlignment="Top" Width="142" Height="32" Click="Export_Click"/>
<Button Foreground="White" Background="Black" Content="Import Cookies" Grid.Column="1" HorizontalAlignment="Left" Margin="281.5,140,0,0" VerticalAlignment="Top" Width="140" Height="32" Click="Import_Click"/>
<TextBlock Foreground="White" HorizontalAlignment="Left" Margin="14,102,0,0" TextWrapping="Wrap" Text="Browser" VerticalAlignment="Top" Grid.ColumnSpan="2" Height="20" Width="66"/>
<ComboBox DisplayMemberPath="browserName" Name="ComboBox" Grid.Column="1" HorizontalAlignment="Left" Margin="23,102,0,0" VerticalAlignment="Top" Width="502" SelectionChanged="ComboBox_SelectionChanged" />

</Grid>
</Window>
34 changes: 23 additions & 11 deletions ChloniumUI/ChloniumUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Data.SQLite;
using System.Diagnostics;
using static ChloniumUI.Browsers;

namespace ChloniumUI
{
Expand All @@ -17,14 +18,24 @@ public partial class MainWindow : Window
{
private string cookieFile = String.Empty;

private BrowserConfig browser = null;

public MainWindow()
{
InitializeComponent();

foreach (var browser in browserConfigs)
{
if (File.Exists(browser.cookieFile))
{
ComboBox.Items.Add(browser);
}
}
}

private bool ImportExportCheck()
{
if (String.IsNullOrEmpty(cookieFile) || !File.Exists(cookieFile))
if (String.IsNullOrEmpty(browser.cookieFile) || !File.Exists(browser.cookieFile))
{
MessageBox.Show("Enter a valid cookie file path");
return false;
Expand Down Expand Up @@ -63,19 +74,17 @@ private void Import_Click(object sender, RoutedEventArgs e)
return;

// kill chrome if it's running
if (Process.GetProcessesByName("chrome").Length > 0)
if (Process.GetProcessesByName(browser.processName).Length > 0)
{
MessageBox.Show("Chrome is running. Please close it first", "Error");
MessageBox.Show($"{browser.processName} is running. Please close it first", "Error");
return;
}

// initialize AES
string userLocalstatePath = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data", Environment.GetEnvironmentVariable("USERPROFILE"));
var crypto = new AesCrypto(userLocalstatePath);
var crypto = new AesCrypto(browser.localState);

string cookieFile = string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies", Environment.GetEnvironmentVariable("USERPROFILE"));
string backupFile = String.Format("Cookies_{0}.bak", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
File.Copy(cookieFile, backupFile, true);
File.Copy(browser.cookieFile, backupFile, true);

List<Cookie> items = ExportItems();

Expand Down Expand Up @@ -145,9 +154,7 @@ private void Export_Click(object sender, RoutedEventArgs e)
private void ImportItems(List<Cookie> items)
{
// SCARY STUFF!! Make sure we take a backup
string cs = string.Format("Data Source={0};",
string.Format("{0}\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies",
Environment.GetEnvironmentVariable("USERPROFILE")));
string cs = string.Format("Data Source={0};", browser.cookieFile);

var con = new SQLiteConnection(cs);
con.Open();
Expand Down Expand Up @@ -197,7 +204,7 @@ private List<Cookie> ExportItems()
var crypto = new AesCrypto(Convert.FromBase64String(MasterKeyText.Text));

// open the Cookie db
string cs = string.Format("Data Source={0};", cookieFile);
string cs = string.Format("Data Source={0};", this.cookieFile);
string stm = "SELECT creation_utc, host_key, name, value, " +
"path, expires_utc, is_secure, is_httponly, last_access_utc, " +
"has_expires, is_persistent, priority, encrypted_value, " +
Expand Down Expand Up @@ -262,5 +269,10 @@ private List<Cookie> ExportItems()
reader.Close();
return items;
}

private void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
this.browser = (BrowserConfig)ComboBox.SelectedItem;
}
}
}

0 comments on commit 81b99f0

Please sign in to comment.