forked from sebastienvercammen/ptc-acc-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
428 lines (377 loc) · 16.4 KB
/
index.js
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
/*jshint sub:true*/
// Requires
var Nightmare = require('nightmare');
var nicknames = require('./nicknames.json');
var fs = require('fs');
var request = require('request');
// Settings
var debug = false;
var showWindow = true;
// Start Config File Imports
var configFile = require('./config');
var start = configFile.startNum;
var end = configFile.endNum;
var useNicknamesFile = configFile.nicknameFile;
var useRandomPassword = configFile.randomPassword;
var screenshotResult = configFile.screenshotResult;
var screenshotFail = configFile.screenshotOnFailure;
var username = configFile.username;
var password = configFile.password;
var email_user = configFile.emailUser;
var email_domain = configFile.emailDomain;
var lat = configFile.latitude;
var lon = configFile.longitude;
var country = configFile.country;
var useAutoCatcha = configFile.useAutoCatcha;
var captchaApiKey = configFile.captchaApiKey;
// End Config File Imports
if (useAutoCatcha)
showWindow = false;
// argv parse
var argv = require('minimist')(process.argv.slice(2));
if (argv['h']) {
console.log("usage: index.js [-h] [-u USERNAME] [-s START] [-e END]");
console.log("");
console.log("An automation script based on Nightmare.js.");
console.log("Can create any number of Nintendo Pokémon Trainer Club accounts,");
console.log("with a single e-mail address.");
console.log("");
console.log("optional arguments:");
console.log(" -u The username used.");
console.log(" -s Starting number.");
console.log(" -e Ending number.");
process.exit();
}
if (argv['u']) {
username = argv['u'];
}
if (argv['s']) {
start = argv['s'];
}
if (argv['e']) {
end = argv['e'];
}
var outputFile = "PogoPlayer/accounts.csv"; // File which will contain the generated "username password" combinations.
var outputFormat = "ptc,%NICK%,%PASS%,%LAT%,%LON%,%UN%\r\n"; // Format used to save the account data in outputFile. Supports %NICK%, %PASS%.
var screenshotFolder = "output/screenshots/";
// App data
var url_ptc = "https://club.pokemon.com/us/pokemon-trainer-club/sign-up/";
var useragent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36";
var symbols = ["#", "?", "!", "@", "$", "%", "^", "&", ">", "<", "+", "`", "*", "(", ")", "-", "[", "]"];
var nightmare_opts = {
show: showWindow,
waitTimeout: 10000,
gotoTimeout: 5000,
loadTimeout: 5000
};
// Prints nice little message
console.log("ptc-acc-gen v2.8.0 by Sébastien Vercammen and Frost The Fox (and Github contribs)");
// Settings check
if (!useNicknamesFile && (username + end).length > 16) {
console.log("Error: length of username + number can't be longer than 16 characters.");
console.log("Please use a shorter nickname.");
process.exit();
}
if ((email_user + '+' + username + end + '@' + email_domain).length > 75) {
console.log("Error: length of e-mail address including the + trick can't be longer than 75 characters.");
console.log("Please use a shorter e-mail address and/or nickname.");
process.exit();
}
if (!useRandomPassword && (password.length > 15 || !containsSymbol(password) || !containsUppercase(password))) {
console.log("Error: length of password can't be longer than 15 characters, requires a symbol and uppercase characters.");
process.exit();
}
// LETSAHGO
var nightmare = Nightmare(nightmare_opts);
nightmare.useragent(useragent);
createAccount(start);
// Helpers
function containsUppercase(txt) {
return txt.toLowerCase() !== txt;
}
function containsSymbol(txt) {
return symbols.some(function(s) { return txt.indexOf(s) > -1; });
}
function handleError(err) {
if (debug) {
console.log("[DEBUG] Error:" + JSON.stringify(err));
}
return err;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomNumbers(length) {
return Math.random().toString().substr(2, length);
}
function getRandomSymbols(length) {
var str = "";
for (var i = 0; i < length; i++) {
str += symbols[getRandomInt(0, symbols.length - 1)];
}
return str;
}
function randomPassword() {
// Your password must include upper and lower case letters, numbers and symbols (such as #?!@$%%^&><+`*()-])
return (Math.random().toString(36)+'00000000000000000').slice(2, 8) + getRandomNumbers(3) + getRandomSymbols(3) + "ABC";
}
function prepareNightmare(nightmare) {
nightmare.useragent(useragent);
}
// Pages
function createAccount(ctr) {
console.log("Creating account " + ctr + " of " + end);
// Launch instance
handleFirstPage(ctr);
}
// First page
function handleFirstPage(ctr) {
if (debug) {
console.log("[DEBUG] Handle first page #" + ctr);
}
nightmare.goto(url_ptc)
.evaluate(evaluateDobPage)
.then(function(validated) {
if (!validated) {
// Missing form data, loop over itself
console.log("[" + ctr + "] Servers are acting up... Trying again.");
return function() {
nightmare.wait(500).refresh().wait();
handleFirstPage(ctr);
};
} else {
return function() {
fillFirstPage(ctr);
};
}
})
.then(function(next) {
// Handle next step: either a loop to first page in case of error, or form fill on success
return next();
})
.catch(handleError)
.then(function(err) {
if (typeof err !== "undefined") {
return handleFirstPage(ctr);
}
});
}
function fillFirstPage(ctr) {
if (debug) {
console.log("[DEBUG] Fill first page #" + ctr);
}
nightmare.evaluate(function(data) {
var dob = new Date((new Date()).getTime() - (Math.random() * (new Date()).getTime()) - 18 * 365 * 24 * 60 * 60 * 1000);
document.getElementById("id_dob").value = dob.getFullYear() + "-" + (dob.getMonth() + 1) + "-" + dob.getDate();
var els = document.getElementsByName("country");
for (var i = 0; i < els.length; i++) {
els[i].value = data.country;
}
return document.getElementById("id_dob").value;
}, {
country: country
})
.click("form[name='verify-age'] [type=submit]")
.wait("#id_username")
.then(function() {
handleSignupPage(ctr);
})
.catch(handleError)
.then(function(err) {
if (typeof err !== "undefined") {
return handleFirstPage(ctr);
}
});
}
// Signup page
function handleSignupPage(ctr) {
if (debug) {
console.log("[DEBUG] Handle second page #" + ctr);
}
nightmare.evaluate(evaluateSignupPage)
.then(function(validated) {
if (!validated) {
// Missing form data, loop over itself
console.log("[" + ctr + "] Servers are acting up... Trying again.");
return function() {
nightmare.wait(500).refresh().wait();
handleFirstPage(ctr);
};
} else {
return function() {
fillSignupPage(ctr);
};
}
}).then(function(next) {
// Handle next step: either a loop to first page in case of error, or form fill on success
return next();
})
.catch(handleError)
.then(function(err) {
if (typeof err !== "undefined") {
return handleSignupPage(ctr);
}
});
}
function fillSignupPage(ctr) {
if (debug) {
console.log("[DEBUG] Fill signup page #" + ctr);
}
var _pass = password;
var _nick = username + ctr;
if (useRandomPassword) {
_pass = randomPassword();
}
// Use nicknames list, or (username + number) combo?
if (useNicknamesFile) {
// Make sure we have a nickname left
if (nicknames.length < 1) {
throw Error("We're out of nicknames to use!");
}
// Get the first nickname off the list & use it
_nick = nicknames.shift();
}
// Fill it all in
if (useAutoCatcha) {
nightmare.evaluate(function(data) {
document.getElementById("id_password").value = data.pass;
document.getElementById("id_confirm_password").value = data.pass;
document.getElementById("id_email").value = data.email_user === "" ? data.nick + "@" + data.email_domain : data.email_user + "+" + data.nick + "@" + data.email_domain;
document.getElementById("id_confirm_email").value = data.email_user === "" ? data.nick + "@" + data.email_domain : data.email_user + "+" + data.nick + "@" + data.email_domain;
document.getElementById("id_screen_name").value = data.nick;
document.getElementById("id_username").value = data.nick;
window.scrollTo(0, document.body.scrollHeight);
}, {
"pass": _pass,
"nick": _nick,
"email_user": email_user,
"email_domain": email_domain
})
.check("#id_terms");
nightmare.evaluate(function() {
return document.getElementsByClassName("g-recaptcha")[0].getAttribute('data-sitekey');
}).then(function(result) {
console.log("Start recaptcha solving");
request('http://2captcha.com/in.php?key=' + captchaApiKey + '&method=userrecaptcha&googlekey=' + result + '&pageurl=club.pokemon.com', function(error, response, body) {
if (error) throw error;
var checkCaptcha = function() {
request('http://2captcha.com/res.php?key=' + captchaApiKey + '&action=get&id=' + body.substring(3), function(error, response, body) {
if (error) throw error;
if (body.substring(0, 2) == "OK") {
var captchaValidation = body.substring(3);
nightmare.evaluate(function(data) {
document.getElementById("g-recaptcha-response").value = data.captchaValidation;
}, {
captchaValidation: captchaValidation
})
.click('.button-green[value=" Continue"]')
.then(function() {
nightmare.wait(function() {
return (document.getElementById("signup-signin") !== null || document.getElementById("btn-reset") !== null || document.body.textContent.indexOf("That username already exists") > -1);
})
.evaluate(function() {
return (document.body.textContent.indexOf("Hello! Thank you for creating an account!") > -1);
})
.then(function(success) {
if (success) {
// Log it in the file of used nicknames
var content = outputFormat.replace('%NICK%', _nick).replace('%PASS%', _pass).replace('%LAT%', lat).replace('%LON%', lon).replace('%UN%', _nick);
fs.appendFile(outputFile, content, function(err) {
if (err) throw err;
});
} else {
console.log("[x] Failed username " + _nick);
}
if ((success && screenshotResult) || screenshotFail) {
// Screenshot
nightmare.screenshot(screenshotFolder + _nick + ".png");
}
// Next one, or stop
if (ctr < end) {
return function() {
createAccount(ctr + 1);
};
} else {
return nightmare.end();
}
}).then(function(next) {
return next();
}).catch(handleError)
.then(function(err) {
if (typeof err !== "undefined") {
return handleSignupPage(ctr);
}
});
});
} else {
// Not ready yet...
setTimeout(checkCaptcha, 2000);
}
});
};
setTimeout(checkCaptcha, 2000);
});
});
} else {
nightmare.evaluate(function(data) {
document.getElementById("id_password").value = data.pass;
document.getElementById("id_confirm_password").value = data.pass;
document.getElementById("id_email").value = data.email_user === "" ? data.nick + "@" + data.email_domain : data.email_user + "+" + data.nick + "@" + data.email_domain;
document.getElementById("id_confirm_email").value = data.email_user === "" ? data.nick + "@" + data.email_domain : data.email_user + "+" + data.nick + "@" + data.email_domain;
document.getElementById("id_screen_name").value = data.nick;
document.getElementById("id_username").value = data.nick;
window.scrollTo(0, document.body.scrollHeight);
}, {
"pass": _pass,
"nick": _nick,
"email_user": email_user,
"email_domain": email_domain
})
.check("#id_terms")
.wait(function() {
return (document.getElementById("signup-signin") !== null || document.getElementById("btn-reset") !== null || document.body.textContent.indexOf("That username already exists") > -1);
})
.evaluate(function() {
return (document.body.textContent.indexOf("Hello! Thank you for creating an account!") > -1);
})
.then(function(success) {
if (success) {
// Log it in the file of used nicknames
var content = outputFormat.replace('%NICK%', _nick).replace('%PASS%', _pass).replace('%LAT%', lat).replace('%LON%', lon).replace('%UN%', _nick);
fs.appendFile(outputFile, content, function(err) {
if (err) throw err;
});
} else {
console.log("[x] Failed username " + _nick);
}
if ((success && screenshotResult) || screenshotFail) {
// Screenshot
nightmare.screenshot(screenshotFolder + _nick + ".png");
}
// Next one, or stop
if (ctr < end) {
return function() {
createAccount(ctr + 1);
};
} else {
return nightmare.end();
}
}).then(function(next) {
return next();
}).catch(handleError)
.then(function(err) {
if (typeof err !== "undefined") {
return handleSignupPage(ctr);
}
});
}
}
// Evaluations
function evaluateDobPage() {
var dob_value = document.getElementById("id_dob");
return ((document.title === "The Official Pokémon Website | Pokemon.com") && (dob_value !== null));
}
function evaluateSignupPage() {
var username_field = document.getElementById("id_username");
return ((document.title === "The Official Pokémon Website | Pokemon.com") && (username_field !== null));
}