-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathautoReverseCaptcha.js
More file actions
202 lines (171 loc) · 6.02 KB
/
autoReverseCaptcha.js
File metadata and controls
202 lines (171 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// @ts-check
import { traverse, types } from '@babel/core';
import { generate } from '@babel/generator';
import parser from '@babel/parser';
import axios from 'axios';
import fs from 'fs/promises';
import { JSDOM } from 'jsdom';
import { Script } from 'vm';
import {
analyzeFunctionCalls,
convertComputedToProperty,
extractIIFEBody,
inlineImmutableBindings,
removeExcessiveParseIntFunctions,
removeIntermediateFunctions,
} from './utils.js';
(async () => {
const appId = 'PXzC5j78di';
const url = `https://captcha.hsprotect.net/${appId}/captcha.js`;
/** @type {string} */
let originalScript = '';
try {
const response = await axios.get(url);
originalScript = response.data;
} catch (error) {
console.error('Error fetching the script:', error);
return;
}
const ast = parser.parse(originalScript);
// Traverse the AST to find and replace function calls
inlineImmutableBindings(ast);
const fnCalls = analyzeFunctionCalls(ast);
fnCalls.forEach((elem) => {
const { path, fnFinalCallString } = elem;
if (fnFinalCallString) {
path.replaceWithSourceString(fnFinalCallString);
}
});
// Remove intermediate functions that are not used
removeIntermediateFunctions(ast, fnCalls);
// Extract the body of the IIFE and execute it in a JSDOM context
const iifeBodyResult = extractIIFEBody(ast);
const jsdom = new JSDOM(
`
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HUMAN Iframe Page</title>
<style>
#px-captcha {
text-align: center;
margin: auto;
}
</style>
</head>
<body>
<div id="px-captcha"></div>
<script>
'use strict';
var c = '';
function y(t) {
return t
.substring(1)
.split('&')
.reduce(function (t, n) {
try {
var e = n.split('='),
o = e[0],
c = e[1];
t[o] = decodeURIComponent(c);
} catch (t) {}
return t;
}, {});
}
function h() {
c = y(window.location.search);
c.app_id = '${appId}';
c.session_id = '6ee4f253d917a777f9c1bb93f9de737a';
window._pxAppId = c.app_id || null;
window._pxParam1 = c.session_id || null;
window._pxOnCaptchaSuccess = function () {};
}
function _() {
h();
}
_();
</script>
</body>
</html>
`,
{
runScripts: 'dangerously',
}
);
const script = new Script(iifeBodyResult?.code || '');
// Execute the IIFE body in jsdom context
try {
script.runInContext(jsdom.getInternalVMContext());
} catch (err) {}
// run the IIFE body in a JSDOM context
const { window } = jsdom;
fnCalls.forEach((elem) => {
const { path, fnFinalCallString } = elem;
if (fnFinalCallString) {
const result = window.eval(fnFinalCallString);
// console.log(`Function call replaced: ${fnFinalCallString} => ${result}`);
path.replaceWith(types.stringLiteral(result));
}
});
// const chatCodeAtResults = findCharCodeAtCalls(ast);
let replacedAttempts = 0;
for (;;) {
const replaceResults = [];
traverse(ast, {
CallExpression(path) {
const node = path.node;
if (node.arguments.length !== 1 || !types.isStringLiteral(node.arguments[0])) {
return;
}
const functionName = node.callee.name;
if (!functionName || ['atob', 'parseInt'].includes(functionName)) return;
// FIXME: handle the case where the function name is a single character
if (functionName.length === 1) {
// console.log(`Found function call: ${functionName}`);
const stringArg = node.arguments[0].value;
try {
const stringResult = window.u(stringArg);
if (stringResult !== stringArg) {
replaceResults.push({
path,
stringResult,
});
}
} catch (err) {}
} else {
// console.log(`Found function call: ${functionName} with argument: ${node.arguments[0].value}`);
}
},
});
if (replaceResults.length === 0) {
++replacedAttempts;
if (replacedAttempts === 3) {
break;
}
continue;
}
replacedAttempts = 0;
replaceResults.forEach((result) => {
const { path, stringResult } = result;
path.replaceWith(types.stringLiteral(stringResult));
});
}
// Convert computed properties to regular properties
convertComputedToProperty(ast);
// Remove excessive parseInt functions
removeExcessiveParseIntFunctions(ast);
// generate the modified script from the AST
const modifiedScript = generate(ast, { retainLines: false }).code;
// Save the modified script to a file
const outputPath = './captcha.transformed.js';
const prettier = await import('prettier');
const prettierConfig = await prettier.resolveConfig(outputPath);
const formatted = await prettier.format(modifiedScript, {
...prettierConfig,
filepath: outputPath,
});
await fs.writeFile(outputPath, formatted, 'utf-8');
})();