-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
130 lines (106 loc) · 3.7 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
/***
* _
* | |
* _ _ ___ ___ _ __ ______ ___ ___ __ _ _ __ ___| |__
* | | | / __|/ _ \ '__|______/ __|/ _ \/ _` | '__/ __| '_ \
* | |_| \__ \ __/ | \__ \ __/ (_| | | | (__| | | |
* \__,_|___/\___|_| |___/\___|\__,_|_| \___|_| |_|
*
* by quantiom
*/
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const { cleanList, usernameFound } = require('./functions');
const { ArgumentParser } = require('argparse');
const rp = require('request-promise');
const colors = require('colors'); // console colors
const fs = require('fs');
let siteList = require('./sites.json');
if (isMainThread) {
// add arguments
siteList = cleanList(siteList);
const parser = new ArgumentParser({
version: '1.0.0',
addHelp: true,
description: 'User search',
});
parser.addArgument(['-username', '-u'], {
help: 'The username to search for.',
required: true,
});
parser.addArgument(['-results', '-r'], {
help: 'The results folder directory.',
defaultValue: './results',
});
parser.addArgument(['-threads', '-t'], {
help: 'How many threads to use.',
defaultValue: 1
});
const { username, results, threads } = parser.parseArgs();
console.log(`${'Searching for: '.brightRed.bold}${username.white.bold}${'...'.brightRed}\n`);
const remainder = Object.keys(siteList).length % threads;
const perThread = (Object.keys(siteList).length - remainder) / threads;
let curIdx = 0;
let hits = [];
let threadsThatSentMessage = 0;
for (let i = 0; i < threads; i++) {
let lastThread = i == threads - 1;
let amount = lastThread ? perThread + parseInt(remainder) : perThread;
let worker = new Worker(__filename, {
workerData: { amount, curIdx, username }
});
worker.on('message', (message) => {
hits = [...hits, ...message];
threadsThatSentMessage++;
if (threadsThatSentMessage == threads) {
console.log(`${'\nUsername found on '.white}${hits.length.toString().brightRed} ${'sites'.white}`);
const fileName = `${username}-${Date.now()}`;
fs.writeFileSync(`${results}/${fileName}.txt`, hits.join('\n'), 'utf8');
console.log(`${'Saved hits to '}${`results/${fileName}.txt`}`);
process.exit();
}
});
curIdx += amount;
}
} else {
let hits = [];
let username = workerData.username;
(async () => {
for (let i = workerData.curIdx; i < parseInt(workerData.curIdx + workerData.amount); i++) {
let _site = Object.entries(siteList)[i][0];
let site = Object.entries(siteList)[i][1];
if (site.regexCheck && !username.match(site.regexCheck)) {
console.log(`${'[x]'.yellow} ${`Invalid username format for ${_site}.`.white.bold}`);
continue;
}
try {
await rp({
uri: site.url.replace('{}', username),
resolveWithFullResponse: true,
method: 'GET',
timeout: 2500,
})
.then(res => {
if (!res || !res.body) return;
if (usernameFound(site, res)) {
console.log(`${'[x]'.green} ${`Username found on ${_site}.`.white.bold}`);
hits.push(site.url.replace('{}', username));
} else {
console.log(`${'[x]'.red} ${`Username not found on ${_site}.`.white.bold}`);
}
})
.catch(err => {
if (!err.response || !err.response.body) return;
if (usernameFound(site, err, true)) {
console.log(`${'[x]'.green} ${`Username found on ${_site}.`.white.bold}`);
hits.push(site.url.replace('{}', username));
} else {
console.log(`${'[x]'.red} ${`Username not found on ${_site}.`.white.bold}`);
}
});
} catch (e) {
console.log(`${'[x]'.red} An error occured: ${e}`);
}
}
parentPort.postMessage(hits);
})();
}