Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -106,14 +106,25 @@ class TokenManager {
|
|
| 106 |
|
| 107 |
async updateTokens(response, isWaf = false) {
|
| 108 |
if (isWaf) {
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
if (wafToken) {
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
Tokens[currentIndex].aws_waf_token = wafToken;
|
| 115 |
-
|
|
|
|
| 116 |
}
|
|
|
|
| 117 |
await this.updateCacheTokens();
|
| 118 |
await this.updateRedisTokens();
|
| 119 |
} else {
|
|
@@ -133,6 +144,7 @@ class TokenManager {
|
|
| 133 |
console.log("更新缓存完毕");
|
| 134 |
}
|
| 135 |
}
|
|
|
|
| 136 |
currentIndex = (currentIndex + 1) % Tokens.length;
|
| 137 |
}
|
| 138 |
}
|
|
@@ -189,10 +201,15 @@ class Utils {
|
|
| 189 |
}
|
| 190 |
}
|
| 191 |
static async extractWaf() {
|
| 192 |
-
puppeteer.use(StealthPlugin())
|
| 193 |
const browser = await puppeteer.launch({
|
| 194 |
headless: true,
|
| 195 |
-
args: [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
executablePath: CONFIG.CHROME_PATH
|
| 197 |
});
|
| 198 |
|
|
@@ -201,28 +218,21 @@ class Utils {
|
|
| 201 |
await page.setExtraHTTPHeaders({
|
| 202 |
cookie: `pr_refresh_token=${Tokens[currentIndex].pr_refresh_token};idToken=${Tokens[currentIndex].idToken};aws-waf-token=${Tokens[currentIndex].aws_waf_token};cwr_s=${Tokens[currentIndex].cwr_s};cwr_u=${Utils.uuidv4()}`
|
| 203 |
});
|
| 204 |
-
await page.setUserAgent(
|
| 205 |
-
CONFIG.DEFAULT_HEADERS["User-Agent"]
|
| 206 |
-
)
|
| 207 |
|
| 208 |
-
//
|
| 209 |
page.on('response', async (response) => {
|
| 210 |
if (response.url().includes('aws-waf-challenge')) {
|
| 211 |
const screenshots = [];
|
| 212 |
-
|
| 213 |
-
// 截取验证图片
|
| 214 |
const challengeElements = await page.$$('.aws-waf-challenge');
|
| 215 |
for (const element of challengeElements) {
|
| 216 |
const screenshot = await element.screenshot({ encoding: 'base64' });
|
| 217 |
screenshots.push(`data:image/png;base64,${screenshot}`);
|
| 218 |
}
|
| 219 |
|
| 220 |
-
// 调用Capsolver
|
| 221 |
const solution = await this.solveAwsWaf(screenshots, 'aws:grid');
|
| 222 |
-
|
| 223 |
if (solution?.objects) {
|
| 224 |
console.log(`🎯 验证答案位置: ${solution.objects.join(', ')}`);
|
| 225 |
-
// 自动点击验证答案
|
| 226 |
await page.evaluate((objects) => {
|
| 227 |
document.querySelectorAll('.grid-item').forEach((el, index) => {
|
| 228 |
if (objects.includes(index)) el.click();
|
|
@@ -232,15 +242,21 @@ class Utils {
|
|
| 232 |
}
|
| 233 |
});
|
| 234 |
|
|
|
|
| 235 |
await page.goto(Tokens[currentIndex].refreshUrl, {
|
| 236 |
waitUntil: 'networkidle2',
|
| 237 |
timeout: 30000
|
| 238 |
});
|
| 239 |
|
| 240 |
-
//
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
cookie => cookie.name.toLowerCase() === 'aws-waf-token'
|
| 243 |
-
)
|
|
|
|
| 244 |
|
| 245 |
if (awsWafToken) {
|
| 246 |
console.log(`🔑 成功获取aws-waf-token | 长度: ${awsWafToken.length}字符`);
|
|
@@ -250,7 +266,6 @@ class Utils {
|
|
| 250 |
|
| 251 |
await browser.close();
|
| 252 |
return awsWafToken;
|
| 253 |
-
|
| 254 |
} catch (error) {
|
| 255 |
console.error('获取aws-waf-token出错:', error);
|
| 256 |
await browser.close();
|
|
|
|
| 106 |
|
| 107 |
async updateTokens(response, isWaf = false) {
|
| 108 |
if (isWaf) {
|
| 109 |
+
let wafToken = await Utils.extractWaf();
|
| 110 |
+
console.log("原aws-waf-token:", Tokens[currentIndex].aws_waf_token);
|
| 111 |
+
|
| 112 |
+
// 如果新 token 与旧 token 相同,等待后重试一次
|
| 113 |
+
if (wafToken === Tokens[currentIndex].aws_waf_token) {
|
| 114 |
+
console.log("⚠️ 更新后的aws-waf-token与现有token一致,等待后重试一次");
|
| 115 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 116 |
+
wafToken = await Utils.extractWaf();
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
if (wafToken) {
|
| 120 |
+
console.log("新获取的aws-waf-token:", wafToken);
|
| 121 |
+
if (wafToken !== Tokens[currentIndex].aws_waf_token) {
|
| 122 |
+
console.log("✅ 成功更新aws-waf-token | 新token长度:", wafToken.length);
|
| 123 |
Tokens[currentIndex].aws_waf_token = wafToken;
|
| 124 |
+
} else {
|
| 125 |
+
console.log("⚠️ 重试后aws-waf-token依旧与现有token一致");
|
| 126 |
}
|
| 127 |
+
// 更新内存缓存和Redis持久化
|
| 128 |
await this.updateCacheTokens();
|
| 129 |
await this.updateRedisTokens();
|
| 130 |
} else {
|
|
|
|
| 144 |
console.log("更新缓存完毕");
|
| 145 |
}
|
| 146 |
}
|
| 147 |
+
// 单账号场景下轮换仍然无副作用
|
| 148 |
currentIndex = (currentIndex + 1) % Tokens.length;
|
| 149 |
}
|
| 150 |
}
|
|
|
|
| 201 |
}
|
| 202 |
}
|
| 203 |
static async extractWaf() {
|
| 204 |
+
puppeteer.use(StealthPlugin());
|
| 205 |
const browser = await puppeteer.launch({
|
| 206 |
headless: true,
|
| 207 |
+
args: [
|
| 208 |
+
'--no-sandbox',
|
| 209 |
+
'--disable-setuid-sandbox',
|
| 210 |
+
'--disable-dev-shm-usage',
|
| 211 |
+
'--disable-gpu'
|
| 212 |
+
],
|
| 213 |
executablePath: CONFIG.CHROME_PATH
|
| 214 |
});
|
| 215 |
|
|
|
|
| 218 |
await page.setExtraHTTPHeaders({
|
| 219 |
cookie: `pr_refresh_token=${Tokens[currentIndex].pr_refresh_token};idToken=${Tokens[currentIndex].idToken};aws-waf-token=${Tokens[currentIndex].aws_waf_token};cwr_s=${Tokens[currentIndex].cwr_s};cwr_u=${Utils.uuidv4()}`
|
| 220 |
});
|
| 221 |
+
await page.setUserAgent(CONFIG.DEFAULT_HEADERS["User-Agent"]);
|
|
|
|
|
|
|
| 222 |
|
| 223 |
+
// 监听验证挑战事件,自动截屏并解决挑战
|
| 224 |
page.on('response', async (response) => {
|
| 225 |
if (response.url().includes('aws-waf-challenge')) {
|
| 226 |
const screenshots = [];
|
|
|
|
|
|
|
| 227 |
const challengeElements = await page.$$('.aws-waf-challenge');
|
| 228 |
for (const element of challengeElements) {
|
| 229 |
const screenshot = await element.screenshot({ encoding: 'base64' });
|
| 230 |
screenshots.push(`data:image/png;base64,${screenshot}`);
|
| 231 |
}
|
| 232 |
|
|
|
|
| 233 |
const solution = await this.solveAwsWaf(screenshots, 'aws:grid');
|
|
|
|
| 234 |
if (solution?.objects) {
|
| 235 |
console.log(`🎯 验证答案位置: ${solution.objects.join(', ')}`);
|
|
|
|
| 236 |
await page.evaluate((objects) => {
|
| 237 |
document.querySelectorAll('.grid-item').forEach((el, index) => {
|
| 238 |
if (objects.includes(index)) el.click();
|
|
|
|
| 242 |
}
|
| 243 |
});
|
| 244 |
|
| 245 |
+
// 进入验证页
|
| 246 |
await page.goto(Tokens[currentIndex].refreshUrl, {
|
| 247 |
waitUntil: 'networkidle2',
|
| 248 |
timeout: 30000
|
| 249 |
});
|
| 250 |
|
| 251 |
+
// 延长等待时间让挑战完成(根据实际情况可调整)
|
| 252 |
+
await page.waitForTimeout(5000);
|
| 253 |
+
|
| 254 |
+
// 再次等待,确保所有动态变动已结束
|
| 255 |
+
const cookies = await page.cookies();
|
| 256 |
+
const awsWafCookie = cookies.find(
|
| 257 |
cookie => cookie.name.toLowerCase() === 'aws-waf-token'
|
| 258 |
+
);
|
| 259 |
+
const awsWafToken = awsWafCookie ? awsWafCookie.value : null;
|
| 260 |
|
| 261 |
if (awsWafToken) {
|
| 262 |
console.log(`🔑 成功获取aws-waf-token | 长度: ${awsWafToken.length}字符`);
|
|
|
|
| 266 |
|
| 267 |
await browser.close();
|
| 268 |
return awsWafToken;
|
|
|
|
| 269 |
} catch (error) {
|
| 270 |
console.error('获取aws-waf-token出错:', error);
|
| 271 |
await browser.close();
|