forked from jeremylvln/DOHA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
227 lines (176 loc) · 5.02 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
/**
* Copyright © 2016 Jérémy L. (BlueSlime)
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file or http://www.wtfpl.net/
* for more details.
*/
var fs = require('fs');
var restify = require('restify');
var request = require('request');
var low = require('lowdb');
var db = low('db.json', {
storage: require('lowdb/lib/file-async')
});
db.defaults({ players: [] }).value();
var config = require('./config.json');
/**
* MCLeaks's API related
*/
function getAPIAddress(callback) {
request({
url: 'https://api.mcleaks.net/authenticator.php',
json: true,
proxy: config.proxy
}, function (err, res, body) {
if (err || !body.serverip) {
console.log('Failed to retreive the MCLeaks\'s fake login server!');
console.log(err);
process.exit(1);
}
else {
callback(body.serverip);
}
});
}
function getAltStatus(target, alt, callback) {
request({
url: 'https://' + target + '/authenticate',
method: 'post',
body: {
username: alt,
password: randomString(12)
},
rejectUnhauthorized: false,
strictSSL: false,
json: true,
proxy: config.proxy
}, function (err, res, body) {
if (err) {
callback(err);
}
else if (body.error) {
callback(body.errorMessage);
}
else {
callback(null, body.availableProfiles[0].name);
}
});
}
/*
* Utils
*/
function randomString(length) {
var text = "";
var dictionnary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++)
text += dictionnary.charAt(Math.floor(Math.random() * dictionnary.length));
return text;
}
function getIPAddressFromRequest(req) {
return req.headers['x-forwarded-for'] || req.connection.remoteAddress;
}
function getUUIDWithDash(uuid) {
return uuid.replace(/([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)/, '$1-$2-$3-$4-$5');
}
function getUUIDWithName(name, callback) {
request({
url: 'https://api.mojang.com/profiles/minecraft',
method: 'post',
body: [
name
],
json: true
}, function (err, res, body) {
if (err) {
callback(err);
}
else {
callback(null, getUUIDWithDash(body[0].id));
}
});
}
/*
* Bot related
*/
getAPIAddress(function (target) {
var server = restify.createServer();
server.get('/api/ban/:alt', function (req, res, next) {
if (req.params.alt.length != 16) {
res.send(400, {
status: 'error',
error: 'The ALT-Token has to be 16 chars long!'
});
}
else {
getAltStatus(target, req.params.alt, function (err, name) {
if (err) {
console.log('Failed to retreive ALT-Token status: ' + err + ' (from ' + getIPAddressFromRequest(req) + ')');
res.send(500, {
status: 'error',
error: err
});
}
else {
getUUIDWithName(name, function (err, uuid) {
if (err) {
console.log('Failed to retreive the UUID according to the ALT-Token: ' + err + ' (from' + getIPAddressFromRequest(req) + ')');
res.send(500, {
status: 'error',
error: err
});
}
else {
var isPresent = db.get('players').find(function (o) {
return o == uuid;
}).value();
if (isPresent) {
console.log('Already in the database: ' + uuid + ' (ALT-Token: ' + req.params.alt + ') (from ' + getIPAddressFromRequest(req) + ')');
res.send(304, {
status: 'already',
error: 'This hacked account is already in the database!'
});
}
else {
db.get('players').push(uuid).value();
console.log('Added in the database: ' + uuid + ' (ALT-Token: ' + req.params.alt + ') (from ' + getIPAddressFromRequest(req) + ')');
res.send(201, {
status: 'ok',
player: {
name: name,
uuid: uuid
}
});
}
}
});
}
});
}
next();
});
server.get('/api/check/:uuid', function (req, res, next) {
var isExisting = db.get('players').find(function (o) {
return o == req.params.uuid;
}).value();
res.send(200, {
exists: (isExisting ? 'true' : 'false')
});
next();
});
server.get('/api/stats', function (req, res, next) {
res.send(200, {
players: db.get('players').size().value()
});
next();
});
server.get(/.*/, restify.serveStatic({
'directory': './docs/',
'default': 'index.html'
}));
server.use(restify.queryParser());
server.listen(6450, function () {
console.log('Target is: ' + target);
console.log('%s listening at %s', server.name, server.url);
});
});