diff --git a/Cargo.lock b/Cargo.lock index 1181c97..24390be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -621,7 +621,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "ua_generator" -version = "0.4.2" +version = "0.5.0" dependencies = [ "fastrand", "serde", diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 1ec425c..3ddc407 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -5,7 +5,7 @@ publish = false edition = "2021" [dependencies] -ua_generator = { version = "^0.4.0", path = "../ua_generator" } +ua_generator = { version = "^0.5.0", path = "../ua_generator" } criterion = { version = "0.3.5", features = ["html_reports"] } [[bench]] diff --git a/ua_generator/Cargo.toml b/ua_generator/Cargo.toml index c83a9f7..6db6e8c 100644 --- a/ua_generator/Cargo.toml +++ b/ua_generator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ua_generator" -version = "0.4.2" +version = "0.5.0" edition = "2018" authors = ["j-mendez "] description = "Random User Agent Spoofer in Rust." diff --git a/ua_generator/build.rs b/ua_generator/build.rs index 2ee4abb..5c8058b 100644 --- a/ua_generator/build.rs +++ b/ua_generator/build.rs @@ -109,6 +109,34 @@ pub fn agents() -> [&'static str; 9] {{ ); fs::write(&dest_path, agents).unwrap(); + + // Build a list of valid chrome user-agents to use for chrome only browsers. + let chrome_agent_list: Vec = + match get(&format!("{base_api}?chrome=true&list=true")) + .set("apikey", &token) + .call() + { + Ok(req) => { + let req: Vec = req + .into_json() + .expect("Authorization not granted! Make sure to set a valid API key."); + req + } + Err(e) => { + panic!("{:?}", e) + } + }; + let dest_path = Path::new(&"./src").join("chrome_ua_list.rs"); + let mut chrome_devices = format!("/// List of real Chrome User-Agents.\n Duplicates may be stored to increase chances of getting the most relevant agent.\npub const STATIC_CHROME_AGENTS: &'static [&'static str; {}] = &[\n", chrome_agent_list.len()); + + for device in chrome_agent_list { + chrome_devices.push_str(&format!(" \"{}\",\n", device.agent)); + } + + chrome_devices.push_str("];"); + + fs::write(dest_path, chrome_devices).unwrap(); + println!("cargo:rerun-if-changed=build.rs"); } diff --git a/ua_generator/src/chrome_ua_list.rs b/ua_generator/src/chrome_ua_list.rs new file mode 100644 index 0000000..46e2c8c --- /dev/null +++ b/ua_generator/src/chrome_ua_list.rs @@ -0,0 +1,23 @@ +/// List of real Chrome User-Agents. +pub const STATIC_CHROME_AGENTS: &'static [&'static str; 20] = &[ + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36", + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", +]; \ No newline at end of file diff --git a/ua_generator/src/lib.rs b/ua_generator/src/lib.rs index 4330480..29d3b3e 100644 --- a/ua_generator/src/lib.rs +++ b/ua_generator/src/lib.rs @@ -20,5 +20,7 @@ pub mod ua; /// Auto generated latest User Agents for windows, mac, linux, and android. pub mod ua_list; +/// Auto generated list of real Chrome User Agents. +pub mod chrome_ua_list; pub extern crate fastrand; diff --git a/ua_generator/src/ua.rs b/ua_generator/src/ua.rs index 4e4acf0..b8813d1 100644 --- a/ua_generator/src/ua.rs +++ b/ua_generator/src/ua.rs @@ -1,4 +1,6 @@ pub use crate::ua_list::STATIC_AGENTS; +pub use crate::chrome_ua_list::STATIC_CHROME_AGENTS; + use fastrand; use std::collections::HashMap; use std::rc::Rc; @@ -8,6 +10,11 @@ pub fn spoof_ua() -> &'static str { STATIC_AGENTS[fastrand::usize(..STATIC_AGENTS.len())] } +/// Get a random UA from a static precompiled list. +pub fn spoof_chrome_ua() -> &'static str { + STATIC_CHROME_AGENTS[fastrand::usize(..STATIC_CHROME_AGENTS.len())] +} + /// Structure to manage a dynamic list of User-Agents, with quick lookup capabilities. #[derive(Default, Clone)] pub struct UserAgents { diff --git a/ua_generator/src/ua_list.rs b/ua_generator/src/ua_list.rs index e5ce2cb..94abedd 100644 --- a/ua_generator/src/ua_list.rs +++ b/ua_generator/src/ua_list.rs @@ -2,9 +2,9 @@ pub const STATIC_AGENTS: &'static [&'static str; 9] = &[ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", "Mozilla/5.0 (Android 12; Tablet; rv:110.0) Gecko/110.0 Firefox/110.0", - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", "Mozilla/5.0 (Android 12; Tablet; rv:110.0) Gecko/110.0 Firefox/110.0", "Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0",