bobocup commited on
Commit
e341326
·
verified ·
1 Parent(s): b65bb2a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +76 -20
index.js CHANGED
@@ -18,7 +18,8 @@ const CONFIG = {
18
  BASE_URL: process.env.DENO_URL || "https://partyrock.aws/stream/getCompletion",//如果需要多号循环,需要设置你自己的denourl
19
  API_KEY: process.env.API_KEY || "sk-123456",//自定义你自己的认证密钥,记得修改
20
  RedisUrl: process.env.RedisUrl,
21
- RedisToken: process.env.RedisToken
 
22
  },
23
  SERVER: {
24
  PORT: process.env.PORT || 3000,
@@ -149,18 +150,50 @@ class Utils {
149
  return type[Math.floor(Math.random() * type.length)]
150
  }
151
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  static async extractWaf() {
153
  puppeteer.use(StealthPlugin())
154
  const browser = await puppeteer.launch({
155
  headless: true,
156
- args: [
157
- '--no-sandbox',
158
- '--disable-setuid-sandbox',
159
- '--disable-dev-shm-usage',
160
- '--disable-gpu'
161
- ],
162
  executablePath: CONFIG.CHROME_PATH
163
  });
 
164
  try {
165
  const page = await browser.newPage();
166
  await page.setExtraHTTPHeaders({
@@ -169,32 +202,55 @@ class Utils {
169
  await page.setUserAgent(
170
  CONFIG.DEFAULT_HEADERS["User-Agent"]
171
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  await page.goto(Tokens[currentIndex].refreshUrl, {
173
  waitUntil: 'networkidle2',
174
  timeout: 30000
175
  });
176
- await page.evaluate(() => {
177
- // 随机滚动
178
- window.scrollBy(0, Math.random() * 500)
179
- })
180
- await page.evaluate(() => {
181
- return new Promise(resolve => setTimeout(resolve, 2000))
182
- })
183
- // 直接从页面 cookies 中提取 aws-waf-token
184
  const awsWafToken = (await page.cookies()).find(
185
  cookie => cookie.name.toLowerCase() === 'aws-waf-token'
186
  )?.value;
187
 
188
  if (awsWafToken) {
189
- await browser.close();
190
- return awsWafToken;
191
  } else {
192
- await browser.close();
193
- return null;
194
  }
195
 
 
 
 
196
  } catch (error) {
197
- console.error('获取 aws-waf-token 出错:', error);
198
  await browser.close();
199
  return null;
200
  }
 
18
  BASE_URL: process.env.DENO_URL || "https://partyrock.aws/stream/getCompletion",//如果需要多号循环,需要设置你自己的denourl
19
  API_KEY: process.env.API_KEY || "sk-123456",//自定义你自己的认证密钥,记得修改
20
  RedisUrl: process.env.RedisUrl,
21
+ RedisToken: process.env.RedisToken,
22
+ CAPSOLVER_KEY: process.env.CAPSOLVER_KEY // 完全从环境变量读取
23
  },
24
  SERVER: {
25
  PORT: process.env.PORT || 3000,
 
150
  return type[Math.floor(Math.random() * type.length)]
151
  }
152
  }
153
+ static async solveAwsWaf(images, questionType = 'aws:grid') {
154
+ try {
155
+ console.log(`开始Capsolver验证 (类型: ${questionType}), 图片数量: ${images.length}`);
156
+
157
+ const response = await fetch('https://api.capsolver.com/createTask', {
158
+ method: 'POST',
159
+ headers: {
160
+ 'Content-Type': 'application/json',
161
+ },
162
+ body: JSON.stringify({
163
+ clientKey: CONFIG.API.CAPSOLVER_KEY,
164
+ task: {
165
+ type: 'AwsWafClassification',
166
+ websiteURL: Tokens[currentIndex].refreshUrl,
167
+ images: images,
168
+ question: questionType
169
+ }
170
+ })
171
+ });
172
+
173
+ const data = await response.json();
174
+ if (data.errorId === 0) {
175
+ if (data.status === 'ready') {
176
+ console.log(`✅ Capsolver验证成功 | 任务ID: ${data.taskId} | 使用图片: ${images.length}张`);
177
+ return data.solution;
178
+ }
179
+ console.log(`⏳ Capsolver处理中 | 任务ID: ${data.taskId} | 状态: ${data.status}`);
180
+ } else {
181
+ console.error(`❌ Capsolver错误 | 代码: ${data.errorCode} | 描述: ${data.errorDescription}`);
182
+ }
183
+ return null;
184
+ } catch (error) {
185
+ console.error('Capsolver请求失败:', error);
186
+ return null;
187
+ }
188
+ }
189
  static async extractWaf() {
190
  puppeteer.use(StealthPlugin())
191
  const browser = await puppeteer.launch({
192
  headless: true,
193
+ args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-gpu'],
 
 
 
 
 
194
  executablePath: CONFIG.CHROME_PATH
195
  });
196
+
197
  try {
198
  const page = await browser.newPage();
199
  await page.setExtraHTTPHeaders({
 
202
  await page.setUserAgent(
203
  CONFIG.DEFAULT_HEADERS["User-Agent"]
204
  )
205
+
206
+ // 监听验证挑战
207
+ page.on('response', async (response) => {
208
+ if (response.url().includes('aws-waf-challenge')) {
209
+ const screenshots = [];
210
+
211
+ // 截取验证图片
212
+ const challengeElements = await page.$$('.aws-waf-challenge');
213
+ for (const element of challengeElements) {
214
+ const screenshot = await element.screenshot({ encoding: 'base64' });
215
+ screenshots.push(`data:image/png;base64,${screenshot}`);
216
+ }
217
+
218
+ // 调用Capsolver
219
+ const solution = await this.solveAwsWaf(screenshots, 'aws:grid');
220
+
221
+ if (solution?.objects) {
222
+ console.log(`🎯 验证答案位置: ${solution.objects.join(', ')}`);
223
+ // 自动点击验证答案
224
+ await page.evaluate((objects) => {
225
+ document.querySelectorAll('.grid-item').forEach((el, index) => {
226
+ if (objects.includes(index)) el.click();
227
+ });
228
+ }, solution.objects);
229
+ }
230
+ }
231
+ });
232
+
233
  await page.goto(Tokens[currentIndex].refreshUrl, {
234
  waitUntil: 'networkidle2',
235
  timeout: 30000
236
  });
237
+
238
+ // 获取最终token
 
 
 
 
 
 
239
  const awsWafToken = (await page.cookies()).find(
240
  cookie => cookie.name.toLowerCase() === 'aws-waf-token'
241
  )?.value;
242
 
243
  if (awsWafToken) {
244
+ console.log(`🔑 成功获取aws-waf-token | 长度: ${awsWafToken.length}字符`);
 
245
  } else {
246
+ console.error('❌ 获取aws-waf-token失败');
 
247
  }
248
 
249
+ await browser.close();
250
+ return awsWafToken;
251
+
252
  } catch (error) {
253
+ console.error('获取aws-waf-token出错:', error);
254
  await browser.close();
255
  return null;
256
  }