Skip to content

Commit 6eee13c

Browse files
committed
Initial release
0 parents  commit 6eee13c

File tree

103 files changed

+31450
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+31450
-0
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
.idea
3+
.dockerignore
4+
docker-compose.yml
5+
Dockerfile
6+
LICENSE
7+
README.md
8+
.env

.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MONGO_USER=2facesAdmin
2+
MONGO_PASSWORD=2facesPassword
3+
MONGO_DATABASE=2facesdb
4+
SERVER_PORT=9999
5+
SOCKET_MASTER_PORT=6969
6+
SOCKET_MASTER_PORT=6969
7+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.idea/

CryptoManager.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const crypto = require('crypto');
2+
3+
function aes256Encrypt(message, key, iv) {
4+
let ivBuffer = new Buffer.from(iv, 'base64');
5+
let keyBuffer = new Buffer.from(key, 'base64');
6+
7+
let cipher = crypto.createCipheriv('aes-256-cbc', keyBuffer, ivBuffer);
8+
let encrypted = cipher.update(message, 'utf8', 'base64');
9+
encrypted += cipher.final('base64');
10+
return encrypted;
11+
}
12+
13+
function aes256Decrypt(encrypted, key, iv) {
14+
let ivBuffer = new Buffer.from(iv, 'base64');
15+
let keyBuffer = new Buffer.from(key, 'base64');
16+
let encryptedBuffer = new Buffer.from(encrypted, 'base64');
17+
18+
let decipher = crypto.createDecipheriv('aes-256-cbc', keyBuffer, ivBuffer);
19+
let decrypted = decipher.update(encryptedBuffer);
20+
decrypted = Buffer.concat([decrypted, decipher.final()] );
21+
return decrypted.toString('utf-8');
22+
}
23+
24+
function sha256(message) {
25+
return crypto.createHash('sha256').update(message).digest('base64');
26+
}
27+
function md5(message) {
28+
return crypto.createHash('md5').update(message).digest('base64');
29+
}
30+
31+
function sha256File(filePath) {
32+
let stream = fs.ReadStream(filePath);
33+
return sha256(stream.toString());
34+
}
35+
36+
37+
module.exports = {
38+
aes256Encrypt,
39+
aes256Decrypt,
40+
sha256,
41+
md5
42+
};

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:latest
2+
# FROM openjdk:latest
3+
4+
WORKDIR /app
5+
6+
# Install app dependencies
7+
COPY package.json .
8+
COPY package-lock.json .
9+
RUN npm install && npm audit fix
10+
11+
# Bundle app source
12+
COPY . .
13+
14+
# API port
15+
EXPOSE 9999
16+
17+
# socker master port
18+
EXPOSE 6969
19+
# socket slave ports
20+
EXPOSE 52000-52500
21+
# socket slave ports
22+
EXPOSE 60000-60100
23+
CMD ["npm", "run", "start"]

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# LetsCompileServer
2+
3+
#
4+
### Docker
5+
6+
```
7+
docker-compose -d --build
8+
```
9+
10+
### NPM
11+
```
12+
npm start
13+
```
14+
15+
### API
16+
Endpoint | Method | Description
17+
------------ | ------------ | -------------
18+
/api/v.1.0/devices | GET | Content from cell 2
19+
/api/v.1.0/devices | POST | Content from cell 2
20+
/api/v.1.0/payloads | GET| Content in the second column
21+
/api/v.1.0/payloads | POST | Content in the second column
22+
/api/v.1.0/payloads | PUT | Content in the second column
23+
/api/v.1.0/payloads | DELETE | Content in the second column
24+
/api/v.1.0/attacks | GET | Content in the second column
25+
/api/v.1.0/attacks | POST Content in the second column
26+
/api/v.1.0/attacks | DELETE | Content in the second column

api/routes.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
module.exports = (app, socketManager) => {
2+
const BASE_API_URL = "/api";
3+
const API_VERSION_1_0 = '/v1.0';
4+
5+
const deviceManager = require('./v1.0/deviceManager');
6+
7+
const payloads = require('../database/models/payload');
8+
const attacks = require('../database/models/attackResult');
9+
10+
app.get(BASE_API_URL + API_VERSION_1_0 + "/devices", (req, res) => {
11+
deviceManager.showAllDevices(socketManager)
12+
.then((ok) => {
13+
res.json(ok);
14+
}).catch((error) => {
15+
res.status(error.status).json({error: error.message});
16+
});
17+
});
18+
19+
app.post(BASE_API_URL + API_VERSION_1_0 + "/devices", (req, res) => {
20+
const device = req.body.device;
21+
const payload_id = req.body.payload_id;
22+
23+
deviceManager.triggerDevice(socketManager, device, payload_id)
24+
.then((ok) => {
25+
res.json(ok);
26+
}).catch((error) => {
27+
res.status(error.status).json({error: error.message});
28+
});
29+
});
30+
31+
32+
app.get(BASE_API_URL + API_VERSION_1_0 + "/payloads", (req, res) => {
33+
const payload_id = req.query.payload_id;
34+
if(payload_id) {
35+
payloads.readOneById(payload_id)
36+
.then((payload) => {
37+
if(payload) {
38+
res.json(payload);
39+
} else {
40+
res.status(404).json({error: "payload not found"});
41+
}
42+
43+
}).catch((error) => {
44+
res.status(error.status).json({error: error.message});
45+
});
46+
} else {
47+
payloads.readAll()
48+
.then((payloads) => {
49+
res.json(payloads);
50+
}).catch((error) => {
51+
res.status(error.status).json({error: error.message});
52+
});
53+
}
54+
});
55+
56+
app.post(BASE_API_URL + API_VERSION_1_0 + "/payloads", (req, res) => {
57+
payloads.create(req.body)
58+
.then((payloads) => {
59+
res.json(payloads);
60+
}).catch((error) => {
61+
res.status(500).json({
62+
error: error
63+
});
64+
});
65+
});
66+
67+
app.delete(BASE_API_URL + API_VERSION_1_0 + "/payloads", (req, res) => {
68+
const payload_id = req.query.payload_id;
69+
payloads.deleteOne(payload_id)
70+
.then((payloads) => {
71+
res.json(payloads);
72+
}).catch((error) => {
73+
res.status(error.status).json({error: error.message});
74+
});
75+
});
76+
77+
app.put(BASE_API_URL + API_VERSION_1_0 + "/payloads", (req, res) => {
78+
const payload_id = req.query.payload_id;
79+
payloads.updateOne(payload_id, req.body)
80+
.then((payloads) => {
81+
res.json(payloads);
82+
}).catch((error) => {
83+
res.status(error.status).json({error: error.message});
84+
});
85+
});
86+
87+
88+
app.get(BASE_API_URL + API_VERSION_1_0 + "/attacks", (req, res) => {
89+
const attack_id = req.query.attack_id;
90+
if(attack_id) {
91+
attacks.readOneById(attack_id)
92+
.then( (attack) => {
93+
if (attack) {
94+
res.json(attack);
95+
} else {
96+
res.status(404).json({error: "payload not found"});
97+
}
98+
}).catch((error) => {
99+
res.status(error.status).json({error: error.message});
100+
});
101+
} else {
102+
attacks.readAll()
103+
.then((attacks) => {
104+
res.json(attacks);
105+
}).catch((error) => {
106+
res.status(error.status).json({error: error.message});
107+
});
108+
}
109+
});
110+
111+
app.post(BASE_API_URL + API_VERSION_1_0 + "/attacks", (req, res) => {
112+
attacks.create(req.body)
113+
.then( (attacks) => {
114+
res.json(attacks);
115+
}).catch((error) => {
116+
res.status(500).json({
117+
error: error
118+
});
119+
});
120+
});
121+
122+
app.delete(BASE_API_URL + API_VERSION_1_0 + "/attacks", (req, res) => {
123+
const attack_id = req.query.attack_id;
124+
payloads.deleteOne(attack_id)
125+
.then((attack) => {
126+
res.json(attack);
127+
}).catch((error) => {
128+
res.status(error.status).json({error: error.message});
129+
});
130+
});
131+
132+
133+
app.post(BASE_API_URL + API_VERSION_1_0 + "/build-apk", (req, res) => {
134+
if (req.files && req.files.apk) {
135+
let apkFile = req.files.apk;
136+
137+
//Use the mv() method to place the file in upload directory (i.e. "uploads")
138+
avatar.mv('./uploads/' + apkFile.name);
139+
140+
const spawn = require("child_process").spawn;
141+
const pythonProcess = spawn('python',["path/to/script.py", "child_process"]);
142+
pythonProcess.stdout.on('data', (data) => {
143+
// Do something with the data returned from python script
144+
});
145+
}
146+
});
147+
148+
/** NOT FOUND FALL-BACK **/
149+
app.get('*', (req, res) => {
150+
console.log('GET fall back');
151+
res.status(404).json({message : "not found on this server"});
152+
});
153+
app.post('*', (req, res) => {
154+
console.log('POST fall back');
155+
res.status(404).json({message : "not found on this server"});
156+
});
157+
app.delete('*', (req, res) => {
158+
console.log('DELETE fall back');
159+
res.status(404).json({message : "not found on this server"});
160+
});
161+
app.put('*', (req, res) => {
162+
console.log('PUT fall back');
163+
res.status(404).json({message : "not found on this server"});
164+
});
165+
};

0 commit comments

Comments
 (0)