· 4 years ago · Apr 15, 2021, 11:30 PM
1const puppeteer = require('puppeteer-extra');
2// add stealth plugin and use defaults (all evasion techniques)
3const StealthPlugin = require('puppeteer-extra-plugin-stealth')
4puppeteer.use(StealthPlugin())
5async function createRunescapeAccount(email, password, proxy) {
6 email = email || generateEmail();
7 password = password || generatePassword();
8
9 console.log('Starting the creation of account:', email);
10 console.log('password:', password);
11
12 const args = [
13 '--incognito',
14 ];
15 if(proxy) {
16 console.log(`Adding socks5 proxy ${proxy.host}:${proxy.port}...`)
17 args.push(`--proxy-server=socks5://${proxy.host}:${proxy.port}`)
18 }
19 console.log("Launching browser...")
20 const browser = await puppeteer.launch({
21 headless: false,
22 executablePath: "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe",
23 args,
24 });
25 const page = await browser.newPage();
26 page.deleteCookie();
27 page.setCacheEnabled(false);
28 //await page.setRequestInterception(true);
29
30 if(proxy) {
31 console.log('authenticating proxy...')
32 await page.authenticate({
33 username: proxy.username,
34 password: proxy.password,
35 });
36 }
37
38 console.log("Going to runescape create account page...")
39 await page.goto('https://secure.runescape.com/m=account-creation/create_account');
40 // await page.goto('https://www.expressvpn.com/what-is-my-ip');
41
42 // Wait for the page to be completely loaded before trying to type
43 await asyncTimeout(3000);
44 let frameElement, emailInputElement;
45 while(!frameElement && !emailInputElement) {
46 frameElement = await page.$('#main-iframe');
47 emailInputElement = await page.$('#create-email');
48 }
49 let frame;
50 if(frameElement) {
51 console.log('had frame element')
52 frame = await frameElement.contentFrame();
53 }
54 if(frame) {
55 // const title = await frame.$('#imperva_title');
56 const title = await frame.$eval('#imperva_title', el => el.innerText);
57 if(title && title.toLowerCase().includes('additional security')) {
58 console.log("waiting for the captcha to be finished...")
59 await page.waitForSelector('#create-email', {timeout: 45000}),
60 await asyncTimeout(1000);
61 }
62 }
63 await asyncTimeout(generateRandom(2500, 5000));
64 // Enter in random details for the user
65 await page.type('#create-email', email);
66 await page.type('#create-password', password);
67 await asyncTimeout(generateRandom(1000, 1500));
68
69 await page.type('.m-date-entry__day-field', `${generateRandom(1, 28)}`);
70 await asyncTimeout(generateRandom(1000, 1500));
71 await page.type('.m-date-entry__month-field', `${generateRandom(1, 12)}`);
72 await asyncTimeout(generateRandom(1000, 1500));
73 await page.type('.m-date-entry__year-field', `${generateRandom(1980, 2002)}`);
74 await asyncTimeout(generateRandom(1000, 1500));
75
76 const foundCookieBtn = await page.$('.a-button.c-cookie-consent__dismiss');
77 if(foundCookieBtn) {
78 await page.click('.a-button.c-cookie-consent__dismiss');
79 await page.waitForSelector('.a-button.c-cookie-consent__dismiss', { timeout: 5000, hidden: true })
80 }
81
82 console.log("Submitting form....")
83 const submit = await page.click('#create-submit');
84 console.log('submit was', submit);
85 await page.waitForSelector('#create-submit', { timeout: 15000, hidden: true })
86 // Wait for the success page to load
87 await asyncTimeout(generateRandom(500, 1500));
88 // Close the current page
89 await page.close();
90
91 console.log("Succesfully created account with info:", {
92 email,
93 password
94 });
95 return {
96 email,
97 password
98 }
99}
100module.exports.createRunescapeAccount = createRunescapeAccount;
101
102
103/// utils below
104
105const { UbuntuSetup } = require('./VpsSetup/Ubuntu/UbuntuSetup');
106const util = require('util');
107const exec = util.promisify(require('child_process').exec);
108
109module.exports.asyncTimeout = async function asyncTimeout(time) {
110 return new Promise((resolve => {
111 setTimeout(() => {
112 return resolve();
113 }, time)
114 }))
115}
116
117function setupFactory() {
118 return new UbuntuSetup();
119}
120module.exports.setupFactory = setupFactory;
121
122function formatHttpsGithubRepoName(url, username, password) {
123 if(url.includes(username) && url.includes(password)) {
124 return url;
125 }
126 return url.slice(0, 8) + username + ":" + password + "@" + url.slice(8, url.length);
127}
128module.exports.formatHttpsGithubRepoName = formatHttpsGithubRepoName;
129
130function formatGitRepoName(url, username, password) {
131 const isHttps = url.slice(0, 5) === 'https';
132 if(isHttps) {
133 if(url.slice(8, 19) === 'github.com/') {
134 return formatHttpsGithubRepoName(url, username, password);
135 }
136 }
137 return url;
138}
139module.exports.formatGitRepoName = formatGitRepoName;
140
141
142/**
143 * Generate a random number between two given interval bounds.
144 * @param {number} min
145 * @param {number} max
146 */
147function generateRandom(min, max) {
148 return Math.floor(Math.random() * (max - min + 1) + min);
149}
150module.exports.generateRandom = generateRandom
151
152async function runCommand(command) {
153 const { stdout, stderr, error } = await exec(command);
154 return stdout;
155}
156module.exports.runCommand = runCommand;
157
158// list of all the known email providers
159const EMAIL_PROVIDERS = [
160 'gmail.com',
161];
162
163/**
164 * Generate a random display name. Always
165 * 12 characters to maximize the chance to avoid
166 * duplicates.
167 */
168module.exports.generateDisplayName = function generateDisplayName() {
169 return generateString(12);
170}
171
172/**
173 * Generate a random string of a given length.
174 * @param {number} length the length of the string
175 */
176function generateString(length) {
177 var text = "";
178 const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
179
180 for (var i = 0; i < length; i++)
181 text += possible.charAt(Math.floor(Math.random() * possible.length));
182
183 return text;
184}
185
186/**
187 * Generate a random age between 19 and 30 years.
188 */
189module.exports.generateAge = function generateAge() {
190 return Math.floor(Math.random() * (40 - 18 + 1) + 18) + ""; // generate age 18-40
191}
192
193
194
195/**
196 * Generate a random email that includes a
197 * randomly generated string for the username and
198 * a random provider from a given list.
199 */
200module.exports.generateEmail = function generateEmail() {
201 const header = generateString(Math.floor(Math.random() * (13 - 8 + 1) + 8)); // random string with # chars 5-10
202 const provider = EMAIL_PROVIDERS[Math.floor(Math.random() * EMAIL_PROVIDERS.length)];
203
204 return `${header}@${provider}`;
205}
206
207/**
208 * Generate a random password that contains
209 * 8-15 random characters.
210 */
211module.exports.generatePassword = function generatePassword() {
212 return generateString(Math.floor(Math.random() * (15 - 10 + 1) + 10)) // random string with # chars 8-15
213}
214