GeminiBot
commited on
Commit
·
387c337
1
Parent(s):
2e170a0
Reinforce JSDOM browser simulation to solve challenge
Browse files- src/duckai.ts +31 -3
src/duckai.ts
CHANGED
|
@@ -6,20 +6,48 @@ export class DuckAI {
|
|
| 6 |
private async solveChallenge(vqdHash: string, ua: string): Promise<string> {
|
| 7 |
try {
|
| 8 |
const jsScript = Buffer.from(vqdHash, 'base64').toString('utf-8');
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
dom.window.top.__DDG_BE_VERSION__ = 1;
|
| 11 |
dom.window.top.__DDG_FE_CHAT_HASH__ = 1;
|
| 12 |
|
|
|
|
| 13 |
const result = await dom.window.eval(jsScript) as any;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
result.client_hashes[0] = ua;
|
| 15 |
result.client_hashes = result.client_hashes.map((t: string) => {
|
| 16 |
const hash = createHash('sha256');
|
| 17 |
hash.update(t);
|
| 18 |
return hash.digest('base64');
|
| 19 |
});
|
|
|
|
| 20 |
return btoa(JSON.stringify(result));
|
| 21 |
} catch (e: any) {
|
| 22 |
-
throw new Error(
|
| 23 |
}
|
| 24 |
}
|
| 25 |
|
|
@@ -78,4 +106,4 @@ export class DuckAI {
|
|
| 78 |
return `⚠️ Ошибка бэкенда: ${error.message}`;
|
| 79 |
}
|
| 80 |
}
|
| 81 |
-
}
|
|
|
|
| 6 |
private async solveChallenge(vqdHash: string, ua: string): Promise<string> {
|
| 7 |
try {
|
| 8 |
const jsScript = Buffer.from(vqdHash, 'base64').toString('utf-8');
|
| 9 |
+
|
| 10 |
+
// Создаем максимально детальную симуляцию браузера
|
| 11 |
+
const dom = new JSDOM(`<!DOCTYPE html><html><head></head><body><div id="app"></div></body></html>`, {
|
| 12 |
+
url: "https://duckduckgo.com/",
|
| 13 |
+
referrer: "https://duckduckgo.com/",
|
| 14 |
+
contentType: "text/html",
|
| 15 |
+
runScripts: "dangerously",
|
| 16 |
+
resources: "usable"
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
// Эмулируем Navigator и другие свойства
|
| 20 |
+
Object.defineProperty(dom.window, 'navigator', {
|
| 21 |
+
value: {
|
| 22 |
+
userAgent: ua,
|
| 23 |
+
platform: 'Win32',
|
| 24 |
+
languages: ['en-US', 'en'],
|
| 25 |
+
deviceMemory: 8,
|
| 26 |
+
hardwareConcurrency: 8
|
| 27 |
+
}
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
// Установка обязательных переменных DDG
|
| 31 |
dom.window.top.__DDG_BE_VERSION__ = 1;
|
| 32 |
dom.window.top.__DDG_FE_CHAT_HASH__ = 1;
|
| 33 |
|
| 34 |
+
// Выполняем скрипт
|
| 35 |
const result = await dom.window.eval(jsScript) as any;
|
| 36 |
+
|
| 37 |
+
if (!result || !result.client_hashes) {
|
| 38 |
+
throw new Error("Challenge script returned invalid result");
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
result.client_hashes[0] = ua;
|
| 42 |
result.client_hashes = result.client_hashes.map((t: string) => {
|
| 43 |
const hash = createHash('sha256');
|
| 44 |
hash.update(t);
|
| 45 |
return hash.digest('base64');
|
| 46 |
});
|
| 47 |
+
|
| 48 |
return btoa(JSON.stringify(result));
|
| 49 |
} catch (e: any) {
|
| 50 |
+
throw new Error(`Challenge Solver Error: ${e.message}`);
|
| 51 |
}
|
| 52 |
}
|
| 53 |
|
|
|
|
| 106 |
return `⚠️ Ошибка бэкенда: ${error.message}`;
|
| 107 |
}
|
| 108 |
}
|
| 109 |
+
}
|