Elffuss BraidHub

kikocis/osiris public

master · 3.8 KiBRawPermalink
1/**
2 * OSIRIS — Stealth Fetch Utility
3 * Generates randomized HTTP headers to distribute API requests
4 * across a pool of spoofed residential IP addresses and browser fingerprints.
5 */
6
7// Residential IP ranges (common ISP subnets globally)
8const IP_POOLS = [
9 // US Comcast
10 { base: [73, 15], range: [255, 255] },
11 { base: [98, 24], range: [255, 255] },
12 { base: [174, 51], range: [255, 255] },
13 // US AT&T
14 { base: [107, 77], range: [255, 255] },
15 { base: [166, 198], range: [255, 255] },
16 // US Verizon
17 { base: [71, 172], range: [255, 255] },
18 { base: [100, 0], range: [127, 255] },
19 // UK BT
20 { base: [86, 128], range: [127, 255] },
21 { base: [81, 132], range: [63, 255] },
22 // DE Telekom
23 { base: [91, 64], range: [63, 255] },
24 { base: [80, 128], range: [63, 255] },
25 // FR Orange
26 { base: [90, 0], range: [63, 255] },
27 { base: [86, 192], range: [63, 255] },
28 // IT Telecom Italia
29 { base: [79, 0], range: [63, 255] },
30 { base: [87, 0], range: [31, 255] },
31 // BR Vivo
32 { base: [177, 0], range: [127, 255] },
33 // AU Telstra
34 { base: [101, 160], range: [31, 255] },
35 // IN Jio
36 { base: [49, 32], range: [31, 255] },
37 // CA Rogers
38 { base: [99, 224], range: [31, 255] },
39];
40
41const USER_AGENTS = [
42 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
43 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
44 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0',
45 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15',
46 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
47 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
48 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Mobile/15E148 Safari/604.1',
49 'Mozilla/5.0 (iPad; CPU OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Mobile/15E148 Safari/604.1',
50 'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36',
51 'Mozilla/5.0 (Linux; Android 14; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36',
52];
53
54function randomInt(max: number): number {
55 return Math.floor(Math.random() * (max + 1));
56}
57
58function generateResidentialIP(): string {
59 const pool = IP_POOLS[randomInt(IP_POOLS.length - 1)];
60 const octet3 = pool.base[1] + randomInt(pool.range[0]);
61 const octet4 = randomInt(pool.range[1]);
62 return `${pool.base[0]}.${octet3}.${octet4 || 1}.${randomInt(254) + 1}`;
63}
64
65function randomUA(): string {
66 return USER_AGENTS[randomInt(USER_AGENTS.length - 1)];
67}
68
69/**
70 * Generate spoofed headers for a stealth fetch request.
71 * Merges with any existing headers you pass in.
72 */
73export function stealthHeaders(extraHeaders?: Record<string, string>): Record<string, string> {
74 const ip = generateResidentialIP();
75 return {
76 'User-Agent': randomUA(),
77 'Accept-Language': 'en-US,en;q=0.9',
78 ...extraHeaders,
79 };
80}
81
82/**
83 * Perform a fetch with stealth headers injected automatically.
84 * Drop-in replacement for global fetch() with identical signature.
85 */
86export async function stealthFetch(
87 url: string | URL | Request,
88 init?: RequestInit
89): Promise<Response> {
90 const headers = stealthHeaders(
91 init?.headers ? Object.fromEntries(
92 init.headers instanceof Headers
93 ? init.headers.entries()
94 : Array.isArray(init.headers)
95 ? init.headers
96 : Object.entries(init.headers)
97 ) : undefined
98 );
99
100 return fetch(url, {
101 ...init,
102 headers,
103 });
104}