-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.js
332 lines (289 loc) · 9.7 KB
/
cli.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
var tester = require('./main');
var fs = require('fs');
var https = require('https');
var crypto = require('crypto');
var VERSION = 4;
var remote = 'warg.ngrok.io';
var config = require('./config.json');
config.rateLimit = config.rateLimit || 95;
config.applist = config.applist || 'app-list.txt';
config.debug = config.debug || false;
function debug() {
if (config.debug) {
var args = [];
args[0] = '[debug]';
for (var i = 0; i < arguments.length; i++) args[i + 1] = arguments[i];
console.log.apply(console, args);
}
}
var appIDs = fs.readFileSync(config.applist).toString().replace(/\r/g, '').split('\n');
function checkPassword(password, callback) {
var results = [];
var queries = 0;
var elapsed = 0;
var rateLimited = false;
var left = [];
for (var i = 0; i < appIDs.length; i++) left[i] = appIDs[i];
console.log('== Checking password: ' + password);
console.log();
var intervalID = setInterval(function() {
elapsed++;
process.stdout.write('\x1b[1000D\x1b[K\x1b[A');
console.log(((appIDs.length - left.length) + '/' + appIDs.length + ' ').substr(0,11) + ' ' + (queries + 'q/s ').substr(0,8) + ' ' + (elapsed + 's ').substr(0,5) + ' ' + (rateLimited ? '! RATE LIMITED (waiting) !' : ''));
queries = 0;
if (left.length === 0) {
console.log('Done!');
clearInterval(intervalID);
return callback(results);
}
}, 1000);
function nextAppID(ignoreRateLimit, fromTimeout) {
if (left.length === 0) return;
if (queries > config.rateLimit) {
return setTimeout(function() {
nextAppID(ignoreRateLimit, false);
}, 50);
}
queries++;
if (rateLimited && !fromTimeout) {
return setTimeout(function() {
nextAppID(ignoreRateLimit, ignoreRateLimit);
}, 15000);
}
var appID = left[0];
left.splice(0, 1);
tester.tryPassword(password, appID, function(err, result) {
if (err) {
rateLimited = true;
left.splice(0, 0, appID);
} else {
rateLimited = false;
if (result) {
//process.stdout.write('\x07');
if (result.url) {
console.log('[found url] app=' + appID + ', password=' + password + ', url=' + result.url + '\n');
} else if (result.response) {
console.log('[found response] app=' + appID + ', password=' + password + ', response=' + result.response + '\n');
} else {
console.log('[found weird] app=' + appID + ', password=' + password + ', result=' + JSON.stringify(result) + '\n');
}
results.push({
appID: appID,
result: result
});
}
}
nextAppID(ignoreRateLimit);
});
}
for (var w = 0; w < 50; w++) nextAppID(w === 0);
}
function printHelp() {
console.log('== help');
console.log('Prints this message.');
console.log('== password <password>');
console.log('Check <password> against all app ids listed in a text file (default app-list.txt). Don\'t use quotes!');
console.log('== list');
console.log('Bruteforces all passwords in a text file (default custom-list.txt).');
console.log('== bot');
console.log('Automatically checks passwords.');
}
if (process.argv.length < 3 || process.argv[2] === 'help') {
printHelp();
} else if (process.argv[2] === 'password') {
if (process.argv.length < 3) return printHelp();
process.on('SIGINT', function() {
process.stdout.write('\n\r');
process.exit();
});
var password = process.argv.slice(3, process.argv.length).join(' ');
tester.tryWintercomic(password, function(err, winterResult) {
if (winterResult) {
if (winterResult.url) {
console.log('[wintercomic redirect] password=' + password + ', url=' + winterResult.url);
} else {
console.log('[wintercomic unusual] password=' + password + ', result:', winterResult);
}
}
checkPassword(password, function(result) {
process.exit();
});
});
}else if (process.argv[2] === 'list') {
fs.readFile('custom-list.txt', function(err, buffer) {
if (err) {
console.log('Error: custom-list.txt does not exist.');
return;
}
var text = buffer.toString().split('\n');
var out = 0;
checkList(0);
function checkList(i) {
if (i == text.length) {
if (out == text.length)
console.log('Error: custom-list.txt is empty.');
process.exit();
}
var password = text[i];
if (text[i] == '') {
out++;
checkList(i + 1);
} else
tester.tryWintercomic(password, function(err, winterResult) {
if (winterResult) {
if (winterResult.url) {
console.log('[wintercomic redirect] password=' + password + ', url=' + winterResult.url);
} else {
console.log('[wintercomic unusual] password=' + password + ', result:', winterResult);
}
}
checkPassword(password, function(result) {
checkList(i + 1);
});
});
}
});
} else if (process.argv[2] === 'bot') {
process.on('SIGINT', function() {
process.stdout.write('\n\r');
process.exit();
});
function postResults(resp, result) {
var req = https.request({
host: remote,
path: '/solve',
method: 'POST',
headers: {
'content-type': 'application/json'
}
}, function(res) {
res.on('data', function(data) {
req.response = (req.response || '') + data.toString();
}).on('end', function() {
try {
var a = JSON.parse(req.response);
if (a.status === 'success') {
console.log('Results posted.');
getNextPassword();
} else {
console.warn('Error posting results! Retrying in 10 seconds.');
console.log(req.response);
setTimeout(function() {
postResults(resp, result);
}, 10000);
}
} catch (e) {
console.log('Exception when posting results. Retrying in 10 seconds.', e);
console.log(req.response);
setTimeout(function() {
postResults(resp, result);
}, 10000);
}
});
});
req.on('error', function(err) {
console.log('Error when posting results. Retrying in 10 seconds.', err);
setTimeout(function() {
postResults(resp, result);
}, 10000);
});
req.write(JSON.stringify({
id: resp.id,
result: result
}));
req.end();
}
function getNextPassword() {
var req = https.request({
host: remote,
path: '/nextpassword?client=' + encodeURIComponent(VERSION) + '&applist=' + (crypto.createHash('md5').update(appIDs.join('\n')).digest('hex')),
headers: {
'content-type': 'application/json'
}
}, function(res) {
res.on('data', function(data) {
req.response = (req.response || '') + data.toString();
}).on('end', function() {
try {
var resp = JSON.parse(req.response);
var regexString = new RegExp("[<>\"'(){}]", "g"); // Regex check for XSS and SQL injection like strings
if (resp.status === 'success') {
var regexTest = regexString.test(resp.password);
//console.log(regexTest);
if(regexTest === false){
checkPassword(resp.password, function(result) {
if (resp.password.indexOf('/') !== -1) {
postResults(resp, result);
} else {
tester.tryWintercomic(resp.password, function(err, winterResult) {
if (winterResult) {
if (winterResult.url) {
console.log('[wintercomic redirect] password=' + resp.password + ', url=' + winterResult.url);
} else {
console.log('[wintercomic unusual] password=' + resp.password + ', result:', winterResult);
}
result.push(winterResult);
}
postResults(resp, result);
});
}
});
}else{
var results = [];
console.log("Received invalid password");
console.log(resp.password);
postResults(resp, results); // send back no response to remove the troll entry from the queue
}
}
else if (resp.status === 'queue_empty') {
console.log('No passwords to check. Retrying in 10 seconds.');
setTimeout(getNextPassword, 10000);
} else if (resp.status === 'invalid_applist') {
console.log('Invalid app list. Downloading new list from the server.');
var req2 = https.request({
host: remote,
path: '/res/app-list.txt'
}, function(res) {
res.on('data', function(data) {
req2.response = (req2.response || '') + data.toString();
});
res.on('end', function() {
var newName = 'app-list.' + (new Date().getTime()) + '.txt';
fs.renameSync(config.applist, newName);
fs.writeFile(config.applist, req2.response, function(err) {
appIDs = req2.response.replace(/\r/g, '').split('\n');
if (err) {
fs.renameSync(newName, config.applist);
console.log('Error writing new app list to disk. Skipping save.');
setTimeout(getNextPassword, 10000);
} else {
console.log('App list updated.');
setTimeout(getNextPassword, 10000);
}
});
});
});
req2.on('error', function(err) {
console.log('Error downloading new app list. Retrying in 10 seconds.', err);
setTimeout(getNextPassword, 10000);
});
req2.end();
} else {
console.log('Unknown response (retrying in 10 seconds):', resp);
setTimeout(getNextPassword, 10000);
}
} catch (e) {
console.log(req.response);
console.log('Exception when getting next password. Retrying in 10 seconds.', e);
setTimeout(getNextPassword, 10000);
}
});
});
req.on('error', function(err) {
console.log('Error when getting next password. Retrying in 10 seconds.', err);
setTimeout(getNextPassword, 10000);
});
req.end();
}
getNextPassword();
}