Skip to content

Commit

Permalink
feat: improve search paths
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Sep 30, 2023
1 parent 0afdb73 commit 23e8d2f
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 82 deletions.
85 changes: 43 additions & 42 deletions rookie-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
[package]
name = "rookie"
version = "0.1.5"
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"
[package]
name = "rookie"
version = "0.1.5"
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"
regex = "1.9.6"
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: 1 addition & 3 deletions rookie-rs/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::path::PathBuf;

use rookie;

fn main() {
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();
let cookies = rookie::chrome(None).unwrap();
println!("{:?}", cookies);
}
2 changes: 0 additions & 2 deletions rookie-rs/src/chromium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ fn decrypt_encrypted_value(value: String, encrypted_value: &[u8], key: &[u8]) ->
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());
Expand Down Expand Up @@ -119,7 +118,6 @@ fn decrypt_encrypted_value(value: String, encrypted_value: &[u8], key: &[u8]) ->
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());
Expand Down
8 changes: 4 additions & 4 deletions rookie-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ pub use enums::*;


pub fn firefox(domains: Option<Vec<&str>>) -> Result<Vec<Cookie>, Box<dyn Error>> {
let db_path = paths::find_firefox_paths();
let db_path = paths::find_firefox_paths()?;
firefox_based(db_path, domains)
}

pub fn chrome(domains: Option<Vec<&str>>) -> Result<Vec<Cookie>, Box<dyn Error>> {
let (key, db_path) = paths::find_chrome_paths();
let (key, db_path) = paths::find_chrome_paths()?;
chromium_based(key, db_path, domains)
}


pub fn brave(domains: Option<Vec<&str>>) -> Result<Vec<Cookie>, Box<dyn Error>> {
let (key, db_path) = paths::find_brave_paths();
let (key, db_path) = paths::find_brave_paths()?;
chromium_based(key, db_path, domains)
}

pub fn edge(domains: Option<Vec<&str>>) -> Result<Vec<Cookie>, Box<dyn Error>> {
let (key, db_path) = paths::find_edge_paths();
let (key, db_path) = paths::find_edge_paths()?;
chromium_based(key, db_path, domains)
}

123 changes: 92 additions & 31 deletions rookie-rs/src/paths.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,109 @@
use std::{env, path::{self, PathBuf}};
use std::{env, path::PathBuf};
use crate::mozilla::get_default_profile;
use regex::Regex;


#[cfg(target_os = "windows")]
const CHROME_PATHS: &'static [&'static str] = &[
"%LOCALAPPDATA%/Google/Chrome/User Data"
];

#[cfg(target_os = "windows")]
const BRAVE_PATHS: &'static [&'static str] = &[
"%LOCALAPPDATA%/BraveSoftware/Brave-Browser/User Data"
];

#[cfg(target_os = "windows")]
const EDGE_PATHS: &'static [&'static str] = &[
"%LOCALAPPDATA%/Microsoft/Edge/User Data"
];

#[cfg(target_os = "windows")]
const FIREFOX_PATHS: &'static [&'static str] = &[
"%APPDATA%/Mozilla/Firefox"
];




#[cfg(target_os = "windows")]
pub fn find_chrome_paths() -> (PathBuf, PathBuf) {
let appdata_path = env::var("APPDATA").unwrap();
let appdata_path = path::Path::new(appdata_path.as_str());
let user_data_path = appdata_path.join("../local/Google/Chrome/User Data");
let key_path = user_data_path.join("Local State");
let db_path = user_data_path.join("Default/Network/Cookies");
(key_path, db_path)
pub fn expand_path(path: &str) -> PathBuf {
// Define a regex pattern to match placeholders like %SOMETHING%
let re = Regex::new(r"%([^%]+)%").unwrap();

// Clone the input path for modification
let mut expanded_path = path.to_owned();

// Iterate over all matches of the regex pattern in the input path
for capture in re.captures_iter(&path) {
// Get the matched placeholder (e.g., "APPDATA" from "%APPDATA%")
let placeholder = &capture[1];

// Try to get the corresponding environment variable value
if let Ok(var_value) = env::var(placeholder) {
// Replace the placeholder with the environment variable value
expanded_path = expanded_path.replace(&capture[0], &var_value);
}
}

// Convert the expanded path to a PathBuf
let path_buf = PathBuf::from(expanded_path);

path_buf
}

#[cfg(target_os = "windows")]
pub fn find_chrome_paths() -> Result<(PathBuf, PathBuf), Box<dyn std::error::Error>> {
for path in CHROME_PATHS {
let user_data_path = expand_path(path);
let key_path = user_data_path.join("Local State");
let db_path = user_data_path.join("Default/Network/Cookies");
if db_path.exists() {
return Ok((key_path, db_path));
}
}
Err(("cant find any chrome cookies file").into())
}

#[cfg(target_os = "windows")]
pub fn find_brave_paths() -> (PathBuf, PathBuf) {
let appdata_path = env::var("APPDATA").unwrap();
let appdata_path = path::Path::new(appdata_path.as_str());

let user_data_path = appdata_path.join("../local/BraveSoftware/Brave-Browser/User Data");
let key_path = user_data_path.join("Local State");
let db_path = user_data_path.join("Default/Network/Cookies");
(key_path, db_path)
pub fn find_brave_paths() -> Result<(PathBuf, PathBuf), Box<dyn std::error::Error>> {
for path in BRAVE_PATHS {
let user_data_path = expand_path(path);
let key_path = user_data_path.join("Local State");
let db_path = user_data_path.join("Default/Network/Cookies");
if db_path.exists() {
return Ok((key_path, db_path));
}
}
Err(("cant find any brave cookies file").into())
}

#[cfg(target_os = "windows")]
pub fn find_edge_paths() -> (PathBuf, PathBuf) {
let appdata_path = env::var("APPDATA").unwrap();
let appdata_path = path::Path::new(appdata_path.as_str());

let user_data_path = appdata_path.join("../local/Microsoft/Edge/User Data");
let key_path = user_data_path.join("Local State");
let db_path = user_data_path.join("Default/Network/Cookies");
(key_path, db_path)
pub fn find_edge_paths() -> Result<(PathBuf, PathBuf), Box<dyn std::error::Error>> {
for path in EDGE_PATHS {
let user_data_path = expand_path(path);
let key_path = user_data_path.join("Local State");
let db_path = user_data_path.join("Default/Network/Cookies");
if db_path.exists() {
return Ok((key_path, db_path));
}
}
Err(("cant find any brave cookies file").into())
}


#[cfg(target_os = "windows")]
pub fn find_firefox_paths() -> PathBuf {
let appdata_path = env::var("APPDATA").unwrap();
let appdata_path = path::Path::new(appdata_path.as_str());
let profiles_path = appdata_path.join("Mozilla/Firefox/profiles.ini");
let default_profile = get_default_profile(profiles_path.as_path()).unwrap();
let db_path = appdata_path.join("Mozilla/Firefox/").join(default_profile).join("cookies.sqlite");
db_path
pub fn find_firefox_paths() -> Result<PathBuf, Box<dyn std::error::Error>> {
for path in FIREFOX_PATHS {
let firefox_path = expand_path(path);
let profiles_path = firefox_path.join("profiles.ini");
let default_profile = get_default_profile(profiles_path.as_path()).unwrap();
let db_path = firefox_path.join(default_profile).join("cookies.sqlite");
if db_path.exists() {
return Ok(db_path);
}
}
Err(("cant find any brave cookies file").into())
}

#[cfg(target_os = "linux")]
Expand Down

0 comments on commit 23e8d2f

Please sign in to comment.