Skip to content

Commit

Permalink
feat: chromium based decrypt linux
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Sep 30, 2023
1 parent f2d8146 commit dd304a4
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 45 deletions.
79 changes: 42 additions & 37 deletions rookie-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
[package]
name = "rookie"
version = "0.1.4"
edition = "2021"
description = "Load cookie from your web browsers"
license-file = "MIT-LICENSE.txt"
homepage = "https://crates.io/crates/rookie"
documentation = "https://docs.rs/rookie/"
repository = "https://github.com/thewh1teagle/rookie"
readme = "../README.md"
keywords = ["windows", "cookies", "rust", "web"]

[lib]
name = "rookie"
path = "src/lib.rs"

[[bin]]
name = "main"
path = "bin/main.rs"

[dependencies]
aes-gcm = "0.10.3"
rusqlite = { version = "0.29.0", features = ["bundled"] }
rust-ini = "0.19.0"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
url = "2.4.1"

[target.'cfg(unix)'.dependencies]
bcrypt-pbkdf = "0.10.0"

[target.'cfg(target_os = "macos")'.dependencies]
bcrypt-pbkdf = "0.10.0"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.51.1", features = ["Win32_Security_Cryptography", "Win32_Foundation"] }
base64 = "0.21.4"
[package]
name = "rookie"
version = "0.1.4"
edition = "2021"
description = "Load cookie from your web browsers"
license-file = "MIT-LICENSE.txt"
homepage = "https://crates.io/crates/rookie"
documentation = "https://docs.rs/rookie/"
repository = "https://github.com/thewh1teagle/rookie"
readme = "../README.md"
keywords = ["windows", "cookies", "rust", "web"]

[lib]
name = "rookie"
path = "src/lib.rs"

[[bin]]
name = "main"
path = "bin/main.rs"

[dependencies]
aes = "0.8.3"
aes-gcm = "0.10.3"
cbc = "0.1.2"
rusqlite = { version = "0.29.0", features = ["bundled"] }
rust-ini = "0.19.0"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"

url = "2.4.1"

[target.'cfg(unix)'.dependencies]
sha1 = "0.10.6"
pbkdf2 = "0.12.2"

[target.'cfg(target_os = "macos")'.dependencies]
sha1 = "0.10.6"
pbkdf2 = "0.12.2"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.51.1", features = ["Win32_Security_Cryptography", "Win32_Foundation"] }
base64 = "0.21.4"
4 changes: 3 additions & 1 deletion rookie-rs/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::path::PathBuf;

use rookie;

fn main() {
let cookies = rookie::brave(Some(vec!["github.com"])).unwrap();
let cookies = rookie::chromium_based(PathBuf::from("/home/user/snap/brave/285/.config/BraveSoftware/Brave-Browser/Local State"), PathBuf::from("/home/user/snap/brave/285/.config/BraveSoftware/Brave-Browser/Default/Cookies"), None).unwrap();
println!("{:?}", cookies);
}
5 changes: 5 additions & 0 deletions rookie-rs/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from browser_cookie3 import brave

key = "/home/user/snap/brave/285/.config/BraveSoftware/Brave-Browser/Local State"
db = "/home/user/snap/brave/285/.config/BraveSoftware/Brave-Browser/Default/Cookies"
cookies = brave(key_file=key, cookie_file=db)
60 changes: 53 additions & 7 deletions rookie-rs/src/chromium.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{path::PathBuf, fs, error::Error};
use serde_json;

#[cfg(target_os = "windows")]
use aes_gcm::{Aes256Gcm, Key,aead::{Aead, KeyInit, generic_array::GenericArray}};

use crate::enums::*;
Expand All @@ -9,8 +11,6 @@ use crate::sqlite;
#[cfg(target_os = "windows")]
use base64::{Engine as _, engine::general_purpose};

#[cfg(target_os = "linux")]
use bcrypt_pbkdf;



Expand All @@ -26,19 +26,36 @@ fn get_v10_key(key64: &str) -> Vec<u8> {


#[cfg(target_os = "linux")]
fn get_v10_key() -> Result<Vec<u8>, bcrypt_pbkdf::Error> {
let mut output = [0u8; 64];
bcrypt_pbkdf::bcrypt_pbkdf(b"peanuts", b"saltysalt", 1, output.as_mut())?;
fn get_v10_key() -> Result<Vec<u8>, Box<dyn std::error::Error>> {
use pbkdf2::pbkdf2_hmac;
use sha1::Sha1;

let mut output = [0u8; 16];
let salt = b"saltysalt";
let iterations = 1;
let password = b"peanuts";

pbkdf2_hmac::<Sha1>(password, salt, iterations, &mut output);
Ok(output.to_vec())
}



#[cfg(target_os = "macos")]
fn get_v10_key() -> Result<Vec<u8>, bcrypt_pbkdf::Error> {
let mut output = [0u8; 64];
bcrypt_pbkdf::bcrypt_pbkdf(b"peanuts", b"saltysalt", 1, output.as_mut())?;
use pbkdf2::pbkdf2_hmac;
use sha1::Sha1;

let mut output = [0u8; 16];
let salt = b"saltysalt";
let iterations = 1;
let password = b"peanuts";

pbkdf2_hmac::<Sha1>(password, salt, iterations, &mut output);
Ok(output.to_vec())
}

#[cfg(target_os = "windows")]
fn decrypt_encrypted_value(value: String, encrypted_value: &[u8], key: &[u8]) -> String {
let key_type = &encrypted_value[..3];
if !value.is_empty() || !(key_type == b"v11" || key_type == b"v10") { // unknown key_type or value isn't encrypted
Expand All @@ -57,6 +74,35 @@ fn decrypt_encrypted_value(value: String, encrypted_value: &[u8], key: &[u8]) ->
plaintext
}

#[cfg(target_os = "linux")]
fn decrypt_encrypted_value(value: String, encrypted_value: &[u8], key: &[u8]) -> String {
let key_type = &encrypted_value[..3];
if !value.is_empty() || !(key_type == b"v11" || key_type == b"v10") { // unknown key_type or value isn't encrypted
return value;
}
use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit};

type Aes128CbcDec = cbc::Decryptor<aes::Aes128>;


// Create an AES-128 cipher with the provided key.


let encrypted_value = & mut encrypted_value.to_owned()[3..];
let iv: [u8; 16] = [b' '; 16];

println!("{:?}", key);
let mut key_array: [u8;16] = [0;16];
key_array.copy_from_slice(&key[..16]);
let cipher = Aes128CbcDec::new(&key_array.into(), &iv.into());

let plaintext = cipher.decrypt_padded_mut::<Pkcs7>(encrypted_value).unwrap();


String::from_utf8(plaintext.to_vec()).unwrap()
}



fn query_cookies(v10_key: Vec<u8>, db_path: PathBuf, domains: Option<Vec<&str>>) -> Result<Vec<Cookie>, Box<dyn Error>> {
let connection = sqlite::connect(db_path);
Expand Down

0 comments on commit dd304a4

Please sign in to comment.