-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
230 lines (196 loc) · 7.14 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
const axios = require('axios');
const puppeteer = require('puppeteer');
const fs = require("fs");
const inquirer = require("inquirer");
const chalk = require("chalk");
const error = chalk.bold.red;
const warning = chalk.bold.keyword('orange');
const log = console.log;
const {
discord_password,
discord_user,
server_name
} = require('./config');
const port = 1337;
const DISCORD_APP_URL = "https://discordapp.com/app";
const MEME_API = "https://some-random-api.ml/meme"; // Not being used for now
//const RANDOM_WORDAPI_KEY = 'NW8TVMH0'; // not being used for now
axios.interceptors.request.use(function (config) {
config.metadata = {
startTime: new Date()
}
return config;
}, function (error) {
return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
response.config.metadata.endTime = new Date()
response.duration = response.config.metadata.endTime - response.config.metadata.startTime
return response;
}, function (error) {
error.config.metadata.endTime = new Date();
error.duration = error.config.metadata.endTime - error.config.metadata.startTime;
return Promise.reject(error);
});
(async () => {
const response = await axios.get(`http://localhost:${port}/json/version`);
if (response.status !== 200) {
log(error(`[!] CHECK IF YOUR CHROME/CHROMIUM IS REALLY LISTENING ON PORT ${port}`));
} else {
log(chalk.bold.green(`[+] Got Response from http://localhost:${port}/json/version`));
}
const {
webSocketDebuggerUrl
} = response.data;
log(chalk.blue(`[?] Got webSocketDebuggerUrl: ${webSocketDebuggerUrl}`));
const browser = await puppeteer.connect({
browserWSEndpoint: webSocketDebuggerUrl,
defaultViewport: null
});
log(chalk.bold.green(`[+] Connected to chrome instance`));
const page = await browser.newPage();
await page.setViewport({
width: 1300,
height: 1100
});
await page.goto(DISCORD_APP_URL);
if (page.url() === "https://discordapp.com/login") {
log(chalk.blue(`[INFO] Got redirect to https://discordapp.com/login`));
log(chalk.bold.blue(`[+] Attempting login with given credentials`));
await page.waitForSelector('[type="email"]');
await page.evaluate(() => document.querySelector('[type="email"]').value = "");
await page.focus('[type="email"]');
await page.keyboard.type(discord_user.toString(), {
delay: 100
});
await page.waitForSelector('[type="password"]');
await page.evaluate(() => document.querySelector('[type="password"]').value = "");
await page.focus('[type="password"]')
await page.keyboard.type(discord_password.toString(), {
delay: 100
});
await Promise.all([
page.keyboard.press('Enter'),
page.waitForNavigation()
]);
log(page.url());
if (page.url() !== "https://discordapp.com/login") {
log(chalk.bold.green(`[+] Login Successfull!`));
} else {
log(error(`[!] Login failed, Exiting now...!`));
// eslint-disable-next-line no-undef
process.exit(1);
}
}
await page.waitForSelector(`a[aria-label="${server_name}"]`);
await page.evaluate(({
server_name
}) => document.querySelector(`a[aria-label="${server_name}"]`).click(), {
server_name
});
await autoScroll(page);
await page.waitFor(() => document.querySelectorAll('.containerDefault-1ZnADq').length);
const channels__ = await page.evaluate(() => {
let channels = document.querySelectorAll('.containerDefault-1ZnADq .name-3_Dsmg');
let chans = Array();
for (let i = 0; i < channels.length; i++) {
if (!channels[i].previousSibling.hasAttribute('name')) {
chans.push(channels[i].innerHTML);
}
}
return chans;
});
await page.setViewport({
width: 1300,
height: 768
});
let flood__channel_ = "";
await inquirer
.prompt([{
type: 'checkbox',
name: 'channel',
message: 'Which channel you want to flood? (only first choice will be considerated)',
choices: channels__,
default: "general",
}, ])
.then(answers => {
flood__channel_ = answers.channel[0];
});
log(chalk.bold.white('[+] Selected channel: ' + chalk.bold.red(`${flood__channel_}`)));
await page.evaluate(({
flood__channel_
}) => {
let channels = document.querySelectorAll('.containerDefault-1ZnADq .name-3_Dsmg');
for (let i = 0; i < channels.length; i++) {
if (channels[i].innerHTML == flood__channel_) {
channels[i].click();
}
}
}, {
flood__channel_
});
await page.waitForSelector('textarea');
await page.focus('textarea');
log(warning(`[+] Starting channel flood.`));
try {
// read contents of the file
const data = fs.readFileSync('mr_robot.txt', 'UTF-8');
const lines = data.split(/\r?\n/);
let n_lines = 1;
for (let l_indx = 0; l_indx < lines.length; l_indx++) {
let message_length = 0
await page.keyboard.type('`' + lines[l_indx] + '`', {
delay: 50
});
await page.keyboard.press('Enter');
message_length += lines[l_indx].length
log(`[+] Sent ${n_lines} Mr.Robot messages to channel ${flood__channel_}`);
await page.keyboard.type('!clear 1', {
delay: 50
});
await page.keyboard.press('Enter');
message_length += '!clear 1'.length
n_lines++;
await sleep(60 * 1000 - message_length * 50);
}
/* let meme = await axios.get(MEME_API);
let message_length = 0
await page.keyboard.type('`' + meme.data.caption + '`', {
delay: 50
});
await page.keyboard.press('Enter');
message_length += meme.data.caption.length;
await page.keyboard.type(meme.data.image, {
delay: 50
});
await page.keyboard.press('Enter');
message_length += meme.data.image.length
log(`[+] Sent ${n_memes} memes to channel ${flood__channel_}`);
await sleep(60 * 1000 - meme.duration - message_length * 50);
n_memes++
*/
} catch (err) {
log(error(err.toString()));
}
})();
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function autoScroll(page) {
await page.evaluate(async () => {
// eslint-disable-next-line no-unused-vars
await new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 1000;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 100);
});
});
}