-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_noexp.js
More file actions
96 lines (81 loc) · 2.57 KB
/
server_noexp.js
File metadata and controls
96 lines (81 loc) · 2.57 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
console.log('Server-side-noexp code running');
const {parse} = require('querystring');
const http = require('http');
const path = require('path');
const fs = require('fs');
var url = require("url");
const {spawn} = require('child_process');
const spawn1 = require('child_process').exec;
const requestHandler = (req, res) => {
fs.readFile("index_noexp.html",(err, data) => {
if(!err) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
}
});
if (/formrecv_post/i.test(req.url)) {
if (req.method == 'POST') {
let body = '';
req.on('data', chunk => {
body += chunk.toString(); // convert Buffer to string
});
req.on('end', () => {
console.log(parse(body));
console.log(parse(body).start);
res.end('Thank you for submitting Joyce Leung, your secret information will be revealed in no time');
});
} else {
res.end('Error!');
}
}
if (/python_run/i.test(req.url)) {
console.log('Now running the dangerous python script');
try {
const { spawn } = require('node:child_process');
// const ls = spawn('ls', ['-lh', '/usr']);
//
// ls.stdout.on('data', (data) => {
// console.log(`stdout: ${data}`);
// });
// __dirname + '/index.html'
// '/Users/chanyuyan/nodetest/test.py'
var python = spawn('python', ['/Users/chanyuyan/nodetest/test.py']);
// var python = spawn1('python', [__dirname + '/test.py']);
python.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
})
} catch (error) {
console.error(error);
} finally {
console.log('Not sure what happened');
}
}
//
// if (/josh/i.test(req.url)) {
// res.writeHead(200, {
// 'Content-Type': 'image/jpeg'
// });
// const image = path.join( path.dirname(require.main.filename), 'images', 'img1.jpeg' );
// const readStream = fs.createReadStream(image);
// return readStream.pipe(res);
// }
//
// if (/sam/i.test(req.url)) {
// res.writeHead(200, {
// 'Content-Type': 'text/html'
// });
// res.write('<a href="/josh/" download>Download</a>');
// return res.end();
// }
};
const server = http.createServer(requestHandler);
// server.on('request', (req, resp) => {
// if(req.url === '/' && req.method === 'GET') {
// data=fs.readFileSync(__dirname + '/index.html')
// resp.writeHead(200, {
// 'Content-Type': 'text/html',
// })
// return resp.end(data)
// }
// })
server.listen(8080, '192.168.1.127');