-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
122 lines (104 loc) · 3.06 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// khai báo require module evilscan
var evilscan = require('evilscan')
// khai báo require module express
, express = require('express');
// khởi tạo ứng dụng express
var app = express();
// read file
var readline = require('readline');
var fileName = 'req-res_out.txt';
var http = require('http')
, url = require('url')
, fs = require('fs')
, USERNAME = '/huyttq/'
, layout = '/layouts'
, device = '/accessories/0x0000'
, group = '/groups'
, preset = '/presets'
, event = '/events';
var flgInit = true;
var LineArr = fs.readFileSync(fileName)
.toString()
.split("\n");
function sleep(mili){
var start = new Date().getTime();
for(;;){
if((new Date().getTime() - start) > mili){
break;
}
}
}
// ứng dụng port-scanning tự giới thiệu về mình
app.get(/.*$/, function(req, res){
if (req.method == 'POST') {
console.log("Receive Req: Type = Post");
var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
if(body == '{"pass":"a"}' ||body == 'pass=a' ){
console.log("++++");
console.log(body);
res.statusCode = 200;
sleep(1000);
res.end();
}
else{
console.log("----");
console.log(body);
res.statusCode = 404;
sleep(1000);
res.end();
}
});
}else if (req.url.indexOf(USERNAME) == -1) {
console.log("Receive Req: Type = GET");
if (flgInit) {
flgInit = false;
for (i in LineArr) {
console.log(LineArr[i]);
}
console.log("------------READ DATABASE SUCCESSFULL------------");
}
var str_Req = req.url;
urlSubReq = str_Req;
console.log('<<<<<' + urlSubReq);
sleep(1000);
res.writeHead(200, {
'Content-Type': 'application/json'
});
if (urlSubReq.indexOf('/0x') > -1) {
//Detail OR get all devices
console.log('Response for ' + urlSubReq);
// res detail
for (i = 0; i < LineArr.length; i++) {
if (LineArr[i].indexOf(urlSubReq) > -1) {
console.log('Res line ' + (i + 2))
console.log('>>>>>' + LineArr[i + 1]);
res.write(LineArr[i + 1]);
break;
}
}
} else {
// main page
console.log('Response for ' + urlSubReq);
for (i = 0; i < LineArr.length; i++) {
if ((LineArr[i].indexOf(urlSubReq) > -1) && (LineArr[i].indexOf('0x') == -1)) {
console.log('Res line ' + (i + 2))
console.log('>>>>>' + LineArr[i + 1]);
res.write(LineArr[i + 1]);
break;
}
}
}
res.end();
} else {
console.log('user fail');
res.statusCode = 404;
res.end();
}
});
var HTTP_PORT = process.env.PORT || 3000;
app.listen(HTTP_PORT);
console.log('port-scanning application listening at 0.0.0.0:' + HTTP_PORT);