Example #1
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            if (!ImportExportCheck())
            {
                return;
            }

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

            // initialize AES
            var crypto = new AesCrypto(browser.localState);

            string backupFile = String.Format("Cookies_{0}.bak", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));

            File.Copy(browser.cookieFile, backupFile, true);

            List <Cookie> items = ExportItems();

            // re-encrypt all items
            foreach (Cookie c in items)
            {
                c.encrypted_value = crypto.Encrypt(c.decrypted_value);
            }
            ImportItems(items);
            MessageBox.Show("Imported!");
        }
Example #2
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            if (!ImportExportCheck())
            {
                return;
            }

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

            // initialize AES
            var crypto = new AesCrypto(browser.LocalState);

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

            switch (dbType)
            {
            case "cookies":
                backupFile = String.Format("{0}_{1}.bak", Path.GetFileName(browser.CookieFile),
                                           DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
                File.Copy(browser.CookieFile, backupFile, true);
                items = ExportCookies();

                // re-encrypt all items
                foreach (Cookie c in items)
                {
                    c.encrypted_value = crypto.Encrypt(c.decrypted_value);
                }
                count = items.Count();
                ImportCookies(items);
                break;

            case "logins":
                backupFile = String.Format("{0}_{1}.bak", Path.GetFileName(browser.LoginFile),
                                           DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
                File.Copy(browser.LoginFile, backupFile, true);

                items = ExportLogins();

                // re-encrypt all items
                foreach (Login i in items)
                {
                    i.password_value = crypto.Encrypt(i.decrypted_password_value);
                }
                count = items.Count();
                ImportLogins(items);
                break;

            default:
                return;
            }
            MessageBox.Show($"Imported {count} {dbType}!");
        }
Example #3
0
        private List <Item> ExportLogins()
        {
            List <Item> items = new List <Item>();

            // initialize AES
            var crypto = new AesCrypto(Convert.FromBase64String(MasterKeyText.Text));

            // open the Cookie db
            string cs  = string.Format("Data Source={0};", this.inputFile);
            string stm = "SELECT * FROM logins ORDER BY origin_url;";
            var    con = new SQLiteConnection(cs);

            con.Open();

            var cmd = new SQLiteCommand(stm, con);
            SQLiteDataReader reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    byte[] encrypted_value = (byte[])reader["password_value"];
                    byte[] decrypted_value = null;

                    if (encrypted_value[0] == 'v' && encrypted_value[1] == '1' && encrypted_value[2] == '0')
                    {
                        try
                        {
                            decrypted_value = crypto.Decrypt(encrypted_value);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            continue;
                        }
                    }
                    else
                    {
                        // TODO: we could extract DPAPI keys too maybe
                        continue;
                    }

                    Login login = new Login
                    {
                        origin_url          = reader.GetString(0),
                        action_url          = reader.GetString(1),
                        username_element    = reader.GetString(2),
                        username_value      = reader.GetString(3),
                        password_element    = reader.GetString(4),
                        password_value      = encrypted_value,
                        submit_element      = reader.GetString(6),
                        signon_realm        = reader.GetString(7),
                        date_created        = reader.GetInt32(8),
                        blacklisted_by_user = reader.GetInt32(9),
                        scheme                   = reader.GetInt32(10),
                        password_type            = reader.GetInt32(11),
                        times_used               = reader.GetInt32(12),
                        form_data                = (byte[])reader["form_data"],
                        date_synced              = reader.GetInt32(14),
                        display_name             = reader.GetString(15),
                        icon_url                 = reader.GetString(16),
                        federation_url           = reader.GetString(17),
                        skip_zero_click          = reader.GetInt32(18),
                        generation_upload_status = reader.GetInt32(19),
                        possible_username_pairs  = (byte[])reader["possible_username_pairs"],
                        id                       = reader.GetInt32(21),
                        date_last_used           = reader.GetInt32(22),
                        moving_blocked_for       = (byte[])reader["moving_blocked_for"],
                        decrypted_password_value = decrypted_value
                    };
                    items.Add(login);
                }
            }
            else
            {
                Console.WriteLine("No rows found.");
            }
            reader.Close();
            return(items);
        }
Example #4
0
        private List <Item> ExportCookies()
        {
            List <Item> items = new List <Item>();

            // initialize AES
            var crypto = new AesCrypto(Convert.FromBase64String(MasterKeyText.Text));

            // open the Cookie db
            string cs  = string.Format("Data Source={0};", this.inputFile);
            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, " +
                         "samesite, source_scheme FROM cookies ORDER BY host_key;";
            var con = new SQLiteConnection(cs);

            con.Open();

            var cmd = new SQLiteCommand(stm, con);
            SQLiteDataReader reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    byte[] encrypted_value = (byte[])reader["encrypted_value"];
                    byte[] decrypted_value = null;

                    if (encrypted_value[0] == 'v' && encrypted_value[1] == '1' && encrypted_value[2] == '0')
                    {
                        try
                        {
                            decrypted_value = crypto.Decrypt(encrypted_value);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            continue;
                        }
                    }
                    else
                    {
                        // TODO: we could extract DPAPI keys too maybe
                        continue;
                    }

                    var cookie = new Cookie
                    {
                        creation_utc    = reader.GetInt64(0),
                        host_key        = reader.GetString(1),
                        name            = reader.GetString(2),
                        value           = reader.GetString(3),
                        path            = reader.GetString(4),
                        expires_utc     = reader.GetInt64(5),
                        is_secure       = reader.GetBoolean(6),
                        is_httponly     = reader.GetBoolean(7),
                        last_access_utc = reader.GetInt64(8),
                        has_expires     = reader.GetBoolean(9),
                        is_persistent   = reader.GetBoolean(10),
                        priority        = reader.GetInt16(11),
                        encrypted_value = encrypted_value,
                        samesite        = reader.GetBoolean(13),
                        source_scheme   = reader.GetInt16(14),
                        decrypted_value = decrypted_value
                    };
                    items.Add(cookie);
                }
            }
            else
            {
                Console.WriteLine("No rows found.");
            }
            reader.Close();
            return(items);
        }