-
Notifications
You must be signed in to change notification settings - Fork 0
/
engageup.ts
634 lines (497 loc) · 24.5 KB
/
engageup.ts
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
console.log('test')
let totalCreated = 0;
import puppeteer from 'puppeteer-extra'
import userAgent from 'user-agents'
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import fs from 'fs/promises'
import { getTextFromAudio, solve } from './solver.js';
import { Browser, HTTPRequest, ResponseForRequest } from 'puppeteer';
// import Rotator from './ProxyRotater.ts';
let usernames = await getUsernames()
let overrides: Map<string, Partial<ResponseForRequest>> = new Map();
import {
proxyRequest,
} from 'puppeteer-proxy';
const args = {
email: '[email protected]',
password: 'jfoiwljf2sdFJ9',
createUsername() {
return `${usernames[Math.floor(Math.random() * usernames.length)]}1`
},
}
puppeteer.use(StealthPlugin())
async function newBrowser(proxyUrl) {
return await puppeteer.launch({
args: [
`--proxy-server=${proxyUrl}`,
// '--proxy-server=socks5://127.0.0.1:9050',
'--no-sandbox', '--allow-external-pages',
'--allow-third-party-modules',
'--data-reduction-proxy-http-proxies',
'--disable-web-security',
'--enable-automation',
'--disable-features=IsolateOrigins,site-per-process,SitePerProcess',
'--flag-switches-begin --disable-site-isolation-trials --flag-switches-end', '--disable-features=IsolateOrigins,site-per-process',],
// executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
// executablePath: '/usr/bin/chromium',
headless: false, timeout: 0,
waitForInitialPage: true,
defaultViewport: { width: 800 + Math.round(Math.random() * 100), height: 600 + Math.round(Math.random() * 100), isMobile: true },
devtools: true,
});
}
async function getUsernames() {
let usernames = (await fs.readFile('usernames.txt')).toString();
return usernames.split('\n')
}
async function fetchInterceptedRequest(interceptedRequest: HTTPRequest) {
if(interceptedRequest.url().includes('engageub')) {
console.log('YIPPEEE IM A BIG GREEN LEPRACHAUN!!!');
console.log(interceptedRequest,interceptedRequest.hasPostData(),interceptedRequest.postData(),)
}
let fetchOptions: RequestInit = {
headers: interceptedRequest.headers(),
method: interceptedRequest.method(),
}
if (interceptedRequest.hasPostData()) fetchOptions.body = interceptedRequest.postData(); // todo make be proxy instead
console.log('fetching with options', fetchOptions)
let response = await fetch(interceptedRequest.url(), fetchOptions)
console.log(response)
if (response.ok) {
// console.log('overriding success');
// console.log(response)
let responseObj = { ...response } // allow body to be editable
// response.body = JSON.stringify(response.text)
if (response.body) responseObj.body = await streamToBuffer(response.body)
// if(response.body) responseObj.body = await streamToString(response.body)
// console.log('new body', responseObj.body)
// console.log(response);
if (responseObj) {
console.log('overriding ' + interceptedRequest.url())
interceptedRequest.respond(responseObj)
} else {
interceptedRequest.continue();
}
return responseObj
} else {
interceptedRequest.continue();
return false;
}
}
import { sleep, streamToBuffer, streamToString } from './utils.ts'
function createAccount(browser: Browser, username?, p?): Promise<void | null | { success?: boolean, username?: string, password?: string, info?: string, error?: any, }> {
let inputtedUsername = username;
let generate = false;
if (!username) generate = true;
return new Promise(async res => {
try {
browser.on('close', () => { res({ info: 'browser closed' }) })
// let page = (await browser.pages())[0]
let page = await browser.newPage()
await page.setUserAgent(userAgent.random().toString())
// page.bringToFront();
await page.setRequestInterception(true);
page.on('request', async interceptedRequest => {
console.log(interceptedRequest.url())
// handle ones that you want to proxy through vanilla network
if (
interceptedRequest.url().includes('engageub')
// || interceptedRequest.url().includes('recaptcha__en.js')
|| (interceptedRequest.url().includes('www.googletagmanager.com') && interceptedRequest.method().toLowerCase()=='get')
|| interceptedRequest.url().includes('www.recaptcha.net/recaptcha/api.js')
// || interceptedRequest.url().includes('www.google.com/js/')
// || interceptedRequest.url().includes('www.recaptcha.net/recaptcha/api2')
// || interceptedRequest.url().includes('www.googletagmanager.com')
// || interceptedRequest.url().includes('www.googletagmanager.com')
// || interceptedRequest.url().includes('www.googletagmanager.com/gtag')
// || interceptedRequest.url().includes('www.googletagmanager.com/gtm')
) {
let result = await fetchInterceptedRequest(interceptedRequest);
} else
if (overrides.has(interceptedRequest.url())) {
interceptedRequest.respond(overrides.get(interceptedRequest.url())!);
} else if (
(
(interceptedRequest.url().includes('scratch.mit.edu') && new URL(interceptedRequest.url()).pathname.slice(-5).includes('.'))
|| interceptedRequest.url() == ('https://scratch.mit.edu/join')
|| interceptedRequest.url().includes('scratch.mit.edu/session')
|| interceptedRequest.url().includes('gstatic.com')
// || interceptedRequest.url().includes('engageub.pythonanywhere.com')
)
&& interceptedRequest.method().toLowerCase() == 'get'
) { // test if is filename
let responseObj = await fetchInterceptedRequest(interceptedRequest);
if (responseObj) {
overrides.set(interceptedRequest.url(), responseObj); // test types
return;
} else {
console.log('whomp whomp')
}
} else {
// interceptedRequest.
interceptedRequest.continue();
// await sleep(1000)
let response = interceptedRequest.responseForRequest()
console.log(response)
}
});
// await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36')
page.setDefaultNavigationTimeout(1000 * 40)
page.setDefaultTimeout(1000 * 120)
console.log('loading page')
page.evaluate(getTextFromAudio);
let navPromise = page.waitForNavigation({ waitUntil: 'load', timeout: 1000 * 39 })
await page.goto('https://scratch.mit.edu/join')
await navPromise
console.log('page loaded!')
if (!p) p = args.password;
console.log('inputting fields, waiting for password')
await page.waitForSelector('#password')
await page.type('#password', p)
await page.type('#passwordConfirm', p)
console.log('inputted password')
let total = 0
while (true) { // loop in case username exists
if (total > 10) { res({ info: 'username recreate loop' }); return; }
total++;
console.log('creating new username')
if (generate) {
console.log('yes making new', total)
inputtedUsername = args.createUsername();
console.log(inputtedUsername)
}
// await page.waitForNavigation({waitUntil: 'networkidle2'})
// page.evaluate(()=>{alert('okay')})
await page.type('#username', inputtedUsername);
await page.click('[type="submit"]');
let elem = await Promise.race([page.waitForSelector('#country'), page.waitForSelector('.validation-error')])
if (await elem?.evaluate(e => e.classList.contains('validation-error')) == false) { break }
const inputValue = await page.$eval('#username', el => (el as HTMLInputElement).value);
// focus on the input field
await page.click('#username');
for (let i = 0; i < inputValue.length; i++) {
await page.keyboard.press('Backspace');
}
console.log('that didnt work, making new')
await sleep(500)
}
await page.select('#country', 'United States')
await page.click('[type="submit"]');
await page.waitForSelector('#birth_month')
await page.select('#birth_month', 'May')
await page.select('#birth_year', String(Math.round(1980 + 40 * Math.random())))
await page.click('[type="submit"]');
await page.waitForSelector('#GenderRadioOptionPreferNot')
await page.click('#GenderRadioOptionPreferNot')
await page.click('[type="submit"]');
page.waitForSelector('.registration-error-msg', { timeout: 1000 * 600 }).then((err) => {
// console.log('GOOGLE error message!!!')
res({ success: false, username: inputtedUsername, password: p, info: 'captchaload' });
})
await page.waitForSelector('#email')
await page.type('#email', args.email)
console.log('done. waiting for submit button')
await sleep(100)
await page.waitForSelector('[type="submit"][content="Create Your Account"]:has(.next-step-title)')
// console.log('found')
await page.click('[type="submit"]');
console.log('clicked, waiting for google')
await Promise.all([(
(async () => {
sleep(1000 * 60);
})()
,
(async () => {
try {
await page.waitForSelector('iframe[title="recaptcha challenge expires in two minutes"]');
// console.log('found iframe')
let title = await page.evaluate(() => { return (document.querySelector('iframe[title="recaptcha challenge expires in two minutes"]') as HTMLIFrameElement)?.title }) as string;
console.log('title', title)
let frames = await page.frames();
// console.log(frames.length, await Promise.all(frames.map(frame => frame)));
{
(async () => {
// blocks until element shows up
let item = await (await (await page.waitForSelector('iframe[src*="api2/bframe"]'))?.contentFrame())?.waitForSelector('.rc-doscaptcha-body-text');
// when error element shows up, say so
res({ success: false, username: inputtedUsername, password: p, info: 'googleknows' })
})();
}
// page.evaluate(() => {
// return new Promise(async res => {
// console.log('test')
// function ifqSelector(selector) {
// // @ts-ignore
// return document.querySelector('iframe[src*="api2/bframe"]')?.contentWindow?.document?.querySelector?.(selector)
// }
// function sleep(m) { return new Promise(r => setTimeout(r, m)) }
// while (true) {
// let isThing = ifqSelector('.rc-doscaptcha-body-text')?.innerText?.includes?.('protect')
// await sleep(1000);
// console.log('going again')
// if (isThing) {
// console.log('it knew!')
// res(true)
// break;
// }
// }
// })
// }).then(ress => {
// console.log('google knows:', ress);
// res({ success: false, username, password: p })
// })
sleep(1000 * 10).then(() => { page.evaluate(solve); })
sleep(1000 * 20).then(() => { page.evaluate(solve); })
sleep(1000 * 40).then(() => { page.evaluate(solve); })
await sleep(1000);
await page.evaluate(solve);
await Promise.race([page.waitForSelector('.welcome-step-image', { timeout: 1000 * 600 }), sleep(1000 * 15)]);
if ((await page.waitForSelector('.welcome-step-image'))) {
console.log('success!!')
res({ success: true, username: inputtedUsername, password: p })
page.close();
} else {
console.log('so close, no success')
res({ success: false, username: inputtedUsername, password: p })
page.close();
}
// await sleep(1000 * 1000)
// for (let frame of frames) {
// // let thisTitle = await frame.evaluate((f)=>f)
// let thisTitle = frame.url
// console.log(thisTitle);
// if(thisTitle==title) {
// console.log('got frame', frame.title)
// // await page.evaluate(()=>alert('solving'))
// // await frame.page().evaluate(solve);
// // await frame.waitForNavigation({ waitUntil: 'load' })
// // await frame.waitForSelector('.rc-button.goog-inline-block.rc-button-audio')
// await frame.waitForSelector('.rc-button-audio')
// console.log('solving in 100 ms')
// await sleep(100)
// await page.evaluate(solve);
// console.log('done');
// res();
// return;
// }
// }
} catch (e) {
// console.error(e)
page.close();
}
})())])
res({ info: 'timed out waiting for captcha to appear and solve' });
page.close();
} catch (e) {
// console.error(e);
res({ error: e });
}
})
}
async function createAccountAndStoreCredentials(browser, username?, p?) {
let res = await createAccount(browser, username, p);
if (res?.success) {
totalCreated++;
if (!res.username || !res.password) return;
await storeDeets(res.username, res.password)
}
console.log('total created:', totalCreated)
return res;
}
function storeDeets(u: string, p: string) {
return fs.writeFile(`./accounts/${u}.json`, JSON.stringify({
token: null,
username: u,
password: p,
}));
}
// let usernames = await getUsernames()
// let username = `${usernames[Math.floor(Math.random() * usernames.length)]}1`
// let password = '3uiwefhjskd'
// createAccount(username, password)
// page.do('create an account') // does it conciously the first time, then saves steps to quickly reproduce.
// app with interface where people can select folders to pull from and then ask the ai to complete a certain task
import { emailLoop } from './email/emailServer.ts'
async function startEmailResponding() {
// emailLoop();
}
// let pr = new Rotator();
const INTERVAL = 1000 * 8;
const MAX_TABS = 2;
const MAX_ERRORS_IN_ROW_NON_GOOGLE = 5;
const MAX_GOOGLE_KNOWS_IN_ROW = 3;
async function doCreates(browser: Browser) {
// let answer = await createAccountAndStoreCredentials();
// if (answer?.success) {
if (true) {
// console.log('IT WAS A SUCCESS!')
console.log('starting up the factory!')
let errorCount = 0;
let errorCountInRowNonGoogle = 2;
let callitoff = false;
let googleKnowsInRow = 0;
let numTabs = 0
while (true) {
if (callitoff || errorCountInRowNonGoogle > MAX_ERRORS_IN_ROW_NON_GOOGLE || googleKnowsInRow >= MAX_GOOGLE_KNOWS_IN_ROW) break;
await sleep(INTERVAL);
while (numTabs >= MAX_TABS) { await sleep(100) }
console.log('sleep over')
if (callitoff || errorCountInRowNonGoogle > MAX_ERRORS_IN_ROW_NON_GOOGLE || googleKnowsInRow >= MAX_GOOGLE_KNOWS_IN_ROW) break;
numTabs++;
{
(async () => {
try {
let resp = await createAccountAndStoreCredentials(browser);
console.log(resp)
numTabs--;
if (resp?.success) {
googleKnowsInRow = 0;
errorCountInRowNonGoogle = 0;
} else {
if (resp?.info == 'googleknows') {
googleKnowsInRow++;
errorCountInRowNonGoogle++;
} else if (resp?.info == 'captchaload') {
callitoff = true;
errorCountInRowNonGoogle++;
} else if (resp?.info == 'username recreate loop') {
callitoff = true;
console.log('calling it off because couldnt connect')
} else {
console.log('non google error')
// callitoff = true;
errorCountInRowNonGoogle++;
}
errorCount++;
}
} catch (e) {
console.error('error', e)
errorCount++;
numTabs--;
// callitoff = true;
}
})()
}
}
console.log('loop broken [callitoff,errCount,errCountInRowNonGoogle,googleKnowsInRow,numTabs]', callitoff, errorCount, errorCountInRowNonGoogle, googleKnowsInRow, numTabs)
} // make more. until not success
}
async function doItWithProxy(proxyUrl) {
let browser;
try {
// await newBrowser('http://assortedgummies.uk.to:6969')
// await newBrowser('http://173.249.60.246:14344')
// await newBrowser('http://152.53.19.8:3128')
// await newBrowser('socks5://45.77.222.98:10312')
totalNumberOfBrowsersOpen++;
console.log('initting browser')
browser = await newBrowser(proxyUrl);
console.log('browser initted')
await doCreates(browser)
console.log('DONE creating')
} catch (e) {
console.log('ERROR')
console.error(e)
totalNumberOfBrowsersOpen--;
await browser.close();
browser.process()?.kill()
return;
} finally {
totalNumberOfBrowsersOpen--;
await browser.close();
browser.process()?.kill()
}
}
const TOTAL_BROWSERS_AT_ONCE = 1;
let totalNumberOfBrowsersOpen = 0;
async function go() {
while (true) {
console.log('waiting', totalNumberOfBrowsersOpen)
while (totalNumberOfBrowsersOpen >= TOTAL_BROWSERS_AT_ONCE) { await sleep(1000) }
console.log('starting up', totalNumberOfBrowsersOpen)
doItWithProxy(await pr.getCurrentProxyUrl())
await pr.rotate()
await sleep(1000);
}
}
process.on('uncaughtException', function (err) {
console.error(err);
// console.log("Node NOT Exiting...");
});
process.stdin.resume(); // so the program will not close instantly
import { spawn } from 'child_process'
import { error } from 'console';
async function exitHandler(options, exitCode) {
if (options.cleanup) {
console.log('killing chromium instances and waiting 5 seconds...');
spawn('pkill chromium');
await sleep(1000 * 5);
console.log('done waiting')
}
if (exitCode || exitCode === 0) console.log(exitCode);
if (options.exit) process.exit();
}
// do something when app is closing
process.on('exit', exitHandler.bind(null, { cleanup: true }));
// catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, { exit: true, cleanup: true }));
// catches "kill pid" (for example: nodemon restart)
process.on('SIGUSR1', exitHandler.bind(null, { exit: true, cleanup: true }));
process.on('SIGUSR2', exitHandler.bind(null, { exit: true, cleanup: true }));
// catches uncaught exceptions
// go();
let browser = await newBrowser('http://193.138.178.6:8282');
let page = await browser.newPage()
await page.setUserAgent(userAgent.random().toString())
// page.bringToFront();
await page.setRequestInterception(true);
page.on('request', async interceptedRequest => {
console.log(interceptedRequest.url())
// handle ones that you want to proxy through vanilla network
if (
interceptedRequest.url().includes('engageub')
// || interceptedRequest.url().includes('recaptcha__en.js')
|| (interceptedRequest.url().includes('www.googletagmanager.com') && interceptedRequest.method().toLowerCase()=='get')
|| interceptedRequest.url().includes('www.recaptcha.net/recaptcha/api.js')
// || interceptedRequest.url().includes('www.google.com/js/')
// || interceptedRequest.url().includes('www.recaptcha.net/recaptcha/api2')
// || interceptedRequest.url().includes('www.googletagmanager.com')
// || interceptedRequest.url().includes('www.googletagmanager.com')
// || interceptedRequest.url().includes('www.googletagmanager.com/gtag')
// || interceptedRequest.url().includes('www.googletagmanager.com/gtm')
) {
let result = await fetchInterceptedRequest(interceptedRequest);
} else
if (overrides.has(interceptedRequest.url())) {
interceptedRequest.respond(overrides.get(interceptedRequest.url())!);
} else if (
(
(interceptedRequest.url().includes('scratch.mit.edu') && new URL(interceptedRequest.url()).pathname.slice(-5).includes('.'))
|| interceptedRequest.url() == ('https://scratch.mit.edu/join')
|| interceptedRequest.url().includes('scratch.mit.edu/session')
|| interceptedRequest.url().includes('gstatic.com')
// || interceptedRequest.url().includes('engageub.pythonanywhere.com')
)
&& interceptedRequest.method().toLowerCase() == 'get'
) { // test if is filename
let responseObj = await fetchInterceptedRequest(interceptedRequest);
if (responseObj) {
overrides.set(interceptedRequest.url(), responseObj); // test types
return;
} else {
console.log('whomp whomp')
}
} else {
// interceptedRequest.
interceptedRequest.continue();
// await sleep(1000)
let response = interceptedRequest.responseForRequest()
console.log(response)
}
});
await page.goto('https://www.google.com/recaptcha/api2/demo');
// await page.waitForNavigation();
// await page.waitForNetworkIdle();
await sleep(7*1000)
console.log('solving')
await page.evaluate(solve);