-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (83 loc) · 2.28 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
"use strict";
const express = require("express");
const path = require("path");
const mysql = require('mysql');
const { exec } = require("child_process");
const app = express();
const PORT = process.env.PORT || 3000;
const pagesDir = path.join(__dirname, "public/");
let connection2 = mysql.createConnection({
host: 'localhost',
user: 'web2',
password: 'HyXrA56ESnzUKrW',
database: 'web2'
});
connection2.connect(function(err) {
if (err) {
return console.error('error: ' + err.message);
}
console.log('Web2 connected to the MySQL server.');
});
let connection3 = mysql.createConnection({
host: 'localhost',
user: 'web3',
password: 'wi8228Sc',
database: 'web3'
});
connection3.connect(function(err) {
if (err) {
return console.error('error: ' + err.message);
}
console.log('Web3 connected to the MySQL server.');
});
app.use(
express.static(path.join(__dirname, "public")),
express.urlencoded({ extended: true })
);
app.get("/1", (_, res) => {
return res.sendFile(path.join(pagesDir, "web1.html"));
});
app.get("/2", (_, res) => {
return res.sendFile(path.join(pagesDir, "web2.html"));
});
app.get("/3", (_, res) => {
return res.sendFile(path.join(pagesDir, "web3.html"));
});
app.post("/api", (req, res) => {
const ipAddress = req.body.ipaddress.replaceAll("'", "");
exec(`runuser -l web_user -c '/bin/rbash -r -c "ping -c 1 ${ipAddress}"'`,
(err, stdout, stderr) => {
if (err) {
return res.send(stderr);
} else {
return res.send(stdout);
}
});
});
app.post("/api2", (req, res) => {
const item = req.body.item;
connection2.query(`SELECT * FROM Products WHERE item_name LIKE "%${item}%";`, function (err, result, fields) {
if (err) {
console.error('error: ' + err.message);
return res.send(err.message);
} else {
return res.send(result);
}
});
});
app.post("/api3", (req, res) => {
const key = req.body.key;
connection3.query(`SELECT * FROM SECRETS WHERE name='flag' AND value='${key}';`, function (err, result, fields) {
if (err) {
return res.send(err);
} else {
if (result.length === 0) {
return res.send(`"${key}" is not the flag`)
} else {
return res.send(`"${key}" is the flag! Well done!`);
}
}
});
});
app.listen(3000);
console.log(`Listening on port ${PORT}`);