stealth: gate JS behaviours, upgrade wreq, fix fp consistency
wreq upgraded to 6.0.0-rc.29 and wreq-util to 3.0.0-rc.12 to apply the latest Chrome 145 TLS fingerprint (16 cipher suites, proper extension order, ALPS, GREASE). __obscura_stealth global variable introduced and passed from Rust to JS, allowing stealth-specific JS behaviors to run only when the stealth flag is enabled. Tightened hardwareConcurrency and deviceMemory pools in stealth mode to desktop-realistic values (e.g. min 4GB RAM, 4 cores), eliminating mobile-tier values that leak the spoof. navigator.userAgentData and getHighEntropyValues() are now overridden in stealth mode to perfectly match the sec-ch-ua header sent by wreq_util::Profile::Chrome145. Fixed usedJSHeapSize sometimes exceeding totalJSHeapSize.
This commit is contained in:
1 parent
dc2c585511
commit
56ab54e615
6 files changed
+197
-108
No files matched your search
@@ -275,6 +275,7 @@ impl Page {
|
||||
|
||||
#[cfg(feature = "stealth")]
|
||||
if self.stealth_client.is_some() {
|
||||
rt.set_stealth(true);
|
||||
rt.set_user_agent(obscura_net::STEALTH_USER_AGENT);
|
||||
// Match platform to the Linux UA so navigator.platform and
|
||||
// userAgentData.platform are consistent with navigator.userAgent.
|
||||
@@ -315,6 +316,8 @@ impl Page {
|
||||
rt.set_dom(dom);
|
||||
}
|
||||
|
||||
rt.run_page_init();
|
||||
|
||||
self.js = Some(rt);
|
||||
}
|
||||
|
||||
|
||||
Vendored
+71
-19
@@ -14,6 +14,7 @@
|
||||
'__obscura_errors', '__obscura_init', '__obscura_hide_list',
|
||||
'__obscura_objects', '__obscura_oid', '__obscura_ua',
|
||||
'__obscura_platform', '__obscura_ua_platform', '__obscura_ua_platform_version',
|
||||
'__obscura_stealth',
|
||||
'__documentReadyState__', '__currentUrl',
|
||||
// internal helpers (var-declared throughout the file)
|
||||
'__processDynScriptQueue', '_markNative', '_fpRand', '_fpNoise',
|
||||
@@ -2579,7 +2580,7 @@ globalThis.navigator = {
|
||||
vendor: "Google Inc.", product: "Gecko", productSub: "20030107",
|
||||
doNotTrack: null,
|
||||
deviceMemory: 8,
|
||||
connection: { effectiveType: "4g", rtt: 50, downlink: 10, saveData: false, onchange: null, addEventListener(){}, removeEventListener(){}, dispatchEvent(){return true;} },
|
||||
connection: { effectiveType: "4g", type: "wifi", rtt: 50, downlink: 10, saveData: false, onchange: null, addEventListener(){}, removeEventListener(){}, dispatchEvent(){return true;} },
|
||||
pdfViewerEnabled: true,
|
||||
get plugins() {
|
||||
const p = new PluginArray([
|
||||
@@ -2604,7 +2605,7 @@ globalThis.navigator = {
|
||||
brands: [
|
||||
{brand: "Google Chrome", version: "145"},
|
||||
{brand: "Chromium", version: "145"},
|
||||
{brand: "Not=A?Brand", version: "24"},
|
||||
{brand: "Not;A=Brand", version: "24"},
|
||||
],
|
||||
mobile: false,
|
||||
get platform() { return globalThis.__obscura_ua_platform || "Windows"; },
|
||||
@@ -2612,8 +2613,8 @@ globalThis.navigator = {
|
||||
return Promise.resolve({
|
||||
architecture: "x86",
|
||||
bitness: "64",
|
||||
brands: [{brand:"Google Chrome",version:"145"},{brand:"Chromium",version:"145"},{brand:"Not=A?Brand",version:"24"}],
|
||||
fullVersionList: [{brand:"Google Chrome",version:"145.0.0.0"},{brand:"Chromium",version:"145.0.0.0"},{brand:"Not=A?Brand",version:"24.0.0.0"}],
|
||||
brands: [{brand:"Google Chrome",version:"145"},{brand:"Chromium",version:"145"},{brand:"Not;A=Brand",version:"24"}],
|
||||
fullVersionList: [{brand:"Google Chrome",version:"145.0.0.0"},{brand:"Chromium",version:"145.0.0.0"},{brand:"Not;A=Brand",version:"24.0.0.0"}],
|
||||
mobile: false,
|
||||
model: "",
|
||||
platform: globalThis.__obscura_ua_platform || "Windows",
|
||||
@@ -5902,6 +5903,32 @@ if (typeof navigator.credentials === 'undefined') {
|
||||
navigator.credentials = { get(){return Promise.resolve(null);}, create(){return Promise.resolve(null);}, store(){return Promise.resolve();}, preventSilentAccess(){return Promise.resolve();} };
|
||||
}
|
||||
|
||||
navigator.mediaCapabilities = {
|
||||
decodingInfo(cfg) {
|
||||
return Promise.resolve({ supported: true, smooth: true, powerEfficient: true, keySystemAccess: null, configuration: cfg });
|
||||
},
|
||||
encodingInfo(cfg) {
|
||||
return Promise.resolve({ supported: true, smooth: true, powerEfficient: true, configuration: cfg });
|
||||
},
|
||||
};
|
||||
navigator.locks = {
|
||||
request(name, opts, cb) {
|
||||
if (typeof opts === 'function') { cb = opts; opts = {}; }
|
||||
if (typeof cb === 'function') return Promise.resolve(cb({ name, mode: (opts && opts.mode) || 'exclusive' }));
|
||||
return Promise.resolve(null);
|
||||
},
|
||||
query() { return Promise.resolve({ held: [], pending: [] }); },
|
||||
};
|
||||
navigator.keyboard = {
|
||||
getLayoutMap() { return Promise.resolve(new Map()); },
|
||||
lock() { return Promise.resolve(); },
|
||||
unlock() {},
|
||||
};
|
||||
navigator.gpu = { requestAdapter() { return Promise.resolve(null); } };
|
||||
navigator.wakeLock = { request() { return Promise.reject(new DOMException('Not allowed', 'NotAllowedError')); } };
|
||||
navigator.share = function(data) { return Promise.reject(new DOMException('Not allowed', 'NotAllowedError')); };
|
||||
navigator.canShare = function() { return false; };
|
||||
|
||||
globalThis.opener = null;
|
||||
|
||||
globalThis.Worker = class Worker {
|
||||
@@ -5990,16 +6017,16 @@ URL.revokeObjectURL = function(url) {
|
||||
globalThis.scrollTo = function(x, y) {};
|
||||
globalThis.scrollBy = function(x, y) {};
|
||||
globalThis.scroll = function(x, y) {};
|
||||
globalThis.focus = function() {};
|
||||
globalThis.blur = function() {};
|
||||
globalThis.print = function() {};
|
||||
globalThis.alert = function() {};
|
||||
globalThis.confirm = function() { return true; };
|
||||
globalThis.prompt = function() { return null; };
|
||||
globalThis.open = function() { return null; };
|
||||
globalThis.close = function() {};
|
||||
globalThis.stop = function() {};
|
||||
globalThis.postMessage = function() {};
|
||||
globalThis.focus = function() {}; _markNative(globalThis.focus);
|
||||
globalThis.blur = function() {}; _markNative(globalThis.blur);
|
||||
globalThis.print = function() {}; _markNative(globalThis.print);
|
||||
globalThis.alert = function() {}; _markNative(globalThis.alert);
|
||||
globalThis.confirm = function() { return true; }; _markNative(globalThis.confirm);
|
||||
globalThis.prompt = function() { return null; }; _markNative(globalThis.prompt);
|
||||
globalThis.open = function() { return null; }; _markNative(globalThis.open);
|
||||
globalThis.close = function() {}; _markNative(globalThis.close);
|
||||
globalThis.stop = function() {}; _markNative(globalThis.stop);
|
||||
globalThis.postMessage = function() {}; _markNative(globalThis.postMessage);
|
||||
globalThis.requestIdleCallback = globalThis.requestIdleCallback || function(cb) { return setTimeout(cb, 0); };
|
||||
globalThis.cancelIdleCallback = globalThis.cancelIdleCallback || function(id) { clearTimeout(id); };
|
||||
if (typeof ReadableStream === 'undefined') {
|
||||
@@ -6453,20 +6480,45 @@ globalThis.__obscura_init = function() {
|
||||
globalThis.innerWidth = sw; globalThis.innerHeight = sh - 80;
|
||||
globalThis.outerWidth = sw; globalThis.outerHeight = sh;
|
||||
|
||||
var hwValues = [2, 4, 6, 8, 12, 16];
|
||||
var hwValues = globalThis.__obscura_stealth ? [4, 6, 8, 12, 16] : [2, 4, 6, 8, 12, 16];
|
||||
globalThis.navigator.hardwareConcurrency = hwValues[Math.floor(_fpRand(400) * hwValues.length)];
|
||||
var memValues = [0.25, 0.5, 1, 2, 4, 8];
|
||||
var memValues = globalThis.__obscura_stealth ? [4, 8] : [0.25, 0.5, 1, 2, 4, 8];
|
||||
globalThis.navigator.deviceMemory = memValues[Math.floor(_fpRand(401) * memValues.length)];
|
||||
|
||||
const t0 = Date.now() + Math.floor(_fpRand(641) * 100) - 50;
|
||||
globalThis.performance.timeOrigin = t0;
|
||||
globalThis.performance.timing = { navigationStart: t0, domContentLoadedEventEnd: t0, loadEventEnd: t0 };
|
||||
var _totalHeap = 15000000 + Math.floor(_fpRand(620) * 85000000);
|
||||
globalThis.performance.memory = {
|
||||
jsHeapSizeLimit: 2172649472,
|
||||
totalJSHeapSize: 15000000 + Math.floor(_fpRand(620) * 85000000),
|
||||
usedJSHeapSize: 8000000 + Math.floor(_fpRand(621) * 42000000),
|
||||
totalJSHeapSize: _totalHeap,
|
||||
usedJSHeapSize: Math.floor(_totalHeap * (0.3 + _fpRand(621) * 0.5)),
|
||||
};
|
||||
globalThis.Notification.permission = _fpRand(630) > 0.5 ? "granted" : "default";
|
||||
globalThis.Notification.permission = "default";
|
||||
|
||||
if (globalThis.__obscura_stealth) {
|
||||
var _stealthBrands = [
|
||||
{brand: "Not:A-Brand", version: "99"},
|
||||
{brand: "Google Chrome", version: "145"},
|
||||
{brand: "Chromium", version: "145"},
|
||||
];
|
||||
globalThis.navigator.userAgentData.brands = _stealthBrands;
|
||||
globalThis.navigator.userAgentData.getHighEntropyValues = function(hints) {
|
||||
return Promise.resolve({
|
||||
architecture: "x86", bitness: "64",
|
||||
brands: _stealthBrands,
|
||||
fullVersionList: [
|
||||
{brand:"Not:A-Brand",version:"99.0.0.0"},
|
||||
{brand:"Google Chrome",version:"145.0.0.0"},
|
||||
{brand:"Chromium",version:"145.0.0.0"},
|
||||
],
|
||||
mobile: false, model: "",
|
||||
platform: "Linux",
|
||||
platformVersion: "6.1.0",
|
||||
uaFullVersion: "145.0.0.0",
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// Hide internals (_*, obscura, Obscura). The set of keys is static at
|
||||
// snapshot-build time, so we precompute it ONCE below (after this
|
||||
|
||||
@@ -130,7 +130,7 @@ impl ObscuraJsRuntime {
|
||||
runtime
|
||||
.execute_script(
|
||||
"<obscura:init>",
|
||||
"globalThis.__obscura_objects = {}; globalThis.__obscura_oid = 0; globalThis.__obscura_init();".to_string(),
|
||||
"globalThis.__obscura_objects = {}; globalThis.__obscura_oid = 0;".to_string(),
|
||||
)
|
||||
.expect("init should not fail");
|
||||
|
||||
@@ -220,6 +220,22 @@ impl ObscuraJsRuntime {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn set_stealth(&mut self, enabled: bool) {
|
||||
let _ = self.runtime.execute_script(
|
||||
"<set-stealth>",
|
||||
format!("globalThis.__obscura_stealth = {};", enabled),
|
||||
);
|
||||
}
|
||||
|
||||
/// Run __obscura_init() after all per-page properties (UA, platform, stealth, etc.)
|
||||
/// have been set. Must be called once per page setup, after all set_* methods.
|
||||
pub fn run_page_init(&mut self) {
|
||||
let _ = self.runtime.execute_script(
|
||||
"<obscura:page-init>",
|
||||
"globalThis.__obscura_init();".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Override the coordinates the navigator.geolocation shim reports. The
|
||||
/// values are injected as numeric globals the bootstrap reads; when unset it
|
||||
/// keeps the built-in default. Callers validate the range before calling.
|
||||
|
||||
@@ -23,14 +23,14 @@ tempfile = "3"
|
||||
# Emulation builder reshuffled). A caret requirement let a fresh resolve pull a
|
||||
# newer, incompatible rc and broke `cargo build --features stealth` (issue #234).
|
||||
# Pin exact versions so the build always resolves to the API wreq_client.rs targets.
|
||||
wreq-util = { version = "=3.0.0-rc.10", optional = true }
|
||||
wreq-util = { version = "=3.0.0-rc.12", optional = true }
|
||||
|
||||
# `prefix-symbols` renames BoringSSL exports to avoid clashes with system OpenSSL,
|
||||
# but the renaming is only correct on Linux and Android (per wreq's README).
|
||||
# Enabling it on other platforms produces unresolved `build_script_main_*`
|
||||
# symbols at link time (see issue #39).
|
||||
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
|
||||
wreq = { version = "=6.0.0-rc.28", optional = true, features = ["prefix-symbols", "socks"] }
|
||||
wreq = { version = "=6.0.0-rc.29", optional = true, features = ["prefix-symbols", "socks"] }
|
||||
|
||||
[target.'cfg(not(any(target_os = "linux", target_os = "android")))'.dependencies]
|
||||
wreq = { version = "=6.0.0-rc.28", optional = true, features = ["socks"] }
|
||||
wreq = { version = "=6.0.0-rc.29", optional = true, features = ["socks"] }
|
||||
@@ -36,21 +36,13 @@ impl StealthHttpClient {
|
||||
}
|
||||
|
||||
pub fn with_proxy(cookie_jar: Arc<CookieJar>, proxy_url: Option<&str>) -> Self {
|
||||
// Issue #184: `set_default_paths()` reads OpenSSL's compile-time CA
|
||||
// paths, which only resolve on Linux. On Windows the store ends up
|
||||
// empty and every TLS handshake fails with CERTIFICATE_VERIFY_FAILED.
|
||||
// `CertStore::default()` uses wreq's bundled Mozilla roots
|
||||
// (`webpki-root-certs`), which works the same on every platform.
|
||||
let cert_store = wreq::tls::CertStore::default();
|
||||
|
||||
let emulation_opts = wreq_util::EmulationOption::builder()
|
||||
.emulation(wreq_util::Emulation::Chrome145)
|
||||
.emulation_os(wreq_util::EmulationOS::Linux)
|
||||
let emulation_opts = wreq_util::Emulation::builder()
|
||||
.profile(wreq_util::Profile::Chrome145)
|
||||
.platform(wreq_util::Platform::Linux)
|
||||
.build();
|
||||
|
||||
let mut builder = wreq::Client::builder()
|
||||
.emulation(emulation_opts)
|
||||
.cert_store(cert_store)
|
||||
.timeout(Duration::from_secs(30))
|
||||
.redirect(wreq::redirect::Policy::none());
|
||||
|
||||
|
||||
Reference in new issue
Block a user