-
Notifications
You must be signed in to change notification settings - Fork 2
/
tlsmitm.js
115 lines (104 loc) · 5.25 KB
/
tlsmitm.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
//
// TLS MITM - an SSL relay for analyzing network communications
// Copyright (C) 2014 Josh Stone
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//
var fs = require('fs');
var tls = require('tls');
var out = require ("./out.js");
var relay = require("./relay.js");
var loggers = require("./loggers.js");
//
// This is a certificate that lasts for 10 years after 2014-07-11 for
// the FQDN of www.example.com. So, in other words, this should be
// an invalid cert for just about anything -- you can replace it with
// another cert if you like.
//
var options = {
key: "-----BEGIN RSA PRIVATE KEY-----\n"+
"MIIEowIBAAKCAQEAu6+3vSWAU6S1LlaQZe1tipdz/YZHMU3PQh/z4qCy18SAMGZs\n"+
"KjzZ80wip+qjXpEpOz4RuTCRAvcutStFocj7lMY1dSlhk5GcsyXPcm9UEGjhxtL0\n"+
"HzbU3r5K3/9jUaIX14z1mFUz/MpZRDW34zIJ54Pu8AAdUnJTvuGcFbuimrp3Fux9\n"+
"kNsu9txsoGDFEYD/QTqAaQL06I3iFtGU+F/yz+8AjgHdC97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4ZwVu6KauncW7H2Q2y723Gyg\n"+
"YMURgP9BOoBpAvTojeIW0ZT4X/LP7wCOAd0L3tOtjn41GYQYWDmdfmxq3rix+Gfm\n"+
"TiHsI7NNFiq30I5RN+LxVf+tpD9XJdjjORvOS9Rrr/5aZ8IXvypih+vyOOuoAsYO\n"+
"+aj41fY0brV4KKhkTbdS5EGe1lJXAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBAFnr\n"+
"unfExfdVmTtoEY5c/qbnFZXujcbaK27MnFXZ/vdhQnCYVOJgEjXLbRIwYgHQXgZz\n"+
"6Y2tmf1g0VwNDGVuor+lEiSUM/0QrnMdRvFja59Kc2Kr1PIQ+xwo6C0IFhyjArh6\n"+
"Gv6zPaPHhDgG3qq7lRBl0ZX50iqDRPeNU+WujGijT9B/G9SVCwrdqXwVQXoOP7d+\n"+
"LzVc1Ws1FIDUb1T3oqjF+gJNXgBPZK8yB6ta2LsqhGtnH6Pu5ec7E2KDe6Rp7Mtd\n"+
"CiG8RME2UaJxV24cxfu50yevsLaTyQ6no9o+pPV2XrfDGqKtHMOBYR+vKoU/mtBS\n"+
"dUjDQZMjn0l6MWBAaqg=\n"+
"-----END CERTIFICATE-----"
};
out.green("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
out.cyan (" Josh's TLS MitM Proxy - [email protected] - (C) 2014");
out.green("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
if(process.argv.length != 5) {
console.log("\n usage: tlsmitm.js <lport> <rhost> <rport>\n");
process.exit(1);
}
var lport = process.argv[2];
var rhost = process.argv[3];
var rport = process.argv[4];
out.red("Writing client comms to 'outclient.dat'");
out.red("Writing server comms to 'outserver.dat'");
var filer = new loggers.filer("output.dat");
var loglist = [filer.send, loggers.screen];
var logger = new Object();
logger.send = function(relay, direction, data) {
loglist.map(function(l) {
l(relay, direction, data);
});
}
relay.init(rhost, rport, logger);
var server = tls.createServer(options, relay.relay);
server.listen(lport, function() {
out.red('server bound to 0.0.0.0:'+lport);
});