-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (30 loc) · 866 Bytes
/
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
/* Can you find a vulnerability in this JavaScript code? */
const express = require("express");
const { execSync } = require("child_process");
const app = express();
/*
local ping check
*/
app.get("/", function(req, res) {
const ip_address = req.query.ip;
if(!ip_address){
res.send("?ip=[your_ip]");
return;
}
if(ip_address.length > 16){
res.send("Error! IP is too long.");
return;
}
if(/[!@#$%\^&*()\-_+=\[\] {}'";:,:?~\\]/.exec(ip_address)){
res.send("Error! Your request is filtered!");
return;
}
const cmd = "sh -c 'ping -c 1 " + ip_address + "' 2>&1 >/dev/null; true";
const stderr = execSync(cmd, {"timeout": 1000});
if(stderr != ""){
res.send("Error! " + stderr);
return;
}
res.send("Your IP is in a good state!");
});
app.listen(1337);