davechri 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of davechri might be problematic. Click here for more details.
- package/README.md +277 -0
- package/bin/proxyall +5 -0
- package/build/app.js +89 -0
- package/build/app.js.map +1 -0
- package/build/common/Message.js +34 -0
- package/build/common/Message.js.map +1 -0
- package/build/common/ProxyConfig.js +27 -0
- package/build/common/ProxyConfig.js.map +1 -0
- package/build/node-http-mitm-proxy/.gitattributes +2 -0
- package/build/node-http-mitm-proxy/.travis.yml +10 -0
- package/build/node-http-mitm-proxy/README.md +539 -0
- package/build/node-http-mitm-proxy/bin/mitm-proxy.js +36 -0
- package/build/node-http-mitm-proxy/examples/forwardHttps.js +62 -0
- package/build/node-http-mitm-proxy/examples/modifyGoogle.js +44 -0
- package/build/node-http-mitm-proxy/examples/onCertificateMissing.js +30 -0
- package/build/node-http-mitm-proxy/examples/onCertificateRequired.js +23 -0
- package/build/node-http-mitm-proxy/examples/preventRequest.js +20 -0
- package/build/node-http-mitm-proxy/examples/processFullResponseBody.js +36 -0
- package/build/node-http-mitm-proxy/examples/removeProxyToServerContentLength.js +17 -0
- package/build/node-http-mitm-proxy/examples/websocket.js +31 -0
- package/build/node-http-mitm-proxy/examples/wildcard.js +17 -0
- package/build/node-http-mitm-proxy/index.d.ts +233 -0
- package/build/node-http-mitm-proxy/index.js +3 -0
- package/build/node-http-mitm-proxy/lib/ca.js +245 -0
- package/build/node-http-mitm-proxy/lib/middleware/gunzip.js +19 -0
- package/build/node-http-mitm-proxy/lib/middleware/wildcard.js +22 -0
- package/build/node-http-mitm-proxy/lib/proxy.js +1137 -0
- package/build/node-http-mitm-proxy/package-lock.json +1406 -0
- package/build/node-http-mitm-proxy/package.json +45 -0
- package/build/node-http-mitm-proxy/test/01_proxy.js +449 -0
- package/build/node-http-mitm-proxy/test/www/1024.bin +64 -0
- package/build/node-http-mitm-proxy/test/wwwA/1024.bin +64 -0
- package/build/node-http-mitm-proxy/test/wwwA/example.com.html +8 -0
- package/build/node-http-mitm-proxy/test/wwwA/index.html +0 -0
- package/build/node-http-mitm-proxy/test/wwwB/1024.bin +64 -0
- package/build/node-http-mitm-proxy/test/wwwB/index.html +0 -0
- package/build/private/keys/README.md +2 -0
- package/build/private/keys/server.crt +20 -0
- package/build/private/keys/server.key +28 -0
- package/build/private/keys/ssl.conf +25 -0
- package/build/server/src/Global.js +38 -0
- package/build/server/src/Global.js.map +1 -0
- package/build/server/src/Http2Proxy.js +197 -0
- package/build/server/src/Http2Proxy.js.map +1 -0
- package/build/server/src/HttpMessage.js +99 -0
- package/build/server/src/HttpMessage.js.map +1 -0
- package/build/server/src/HttpProxy.js +196 -0
- package/build/server/src/HttpProxy.js.map +1 -0
- package/build/server/src/HttpsProxy.js +110 -0
- package/build/server/src/HttpsProxy.js.map +1 -0
- package/build/server/src/LogProxy.js +115 -0
- package/build/server/src/LogProxy.js.map +1 -0
- package/build/server/src/Paths.js +28 -0
- package/build/server/src/Paths.js.map +1 -0
- package/build/server/src/Ping.js +21 -0
- package/build/server/src/Ping.js.map +1 -0
- package/build/server/src/ProxyAllApp.js +70 -0
- package/build/server/src/ProxyAllApp.js.map +1 -0
- package/build/server/src/Resend.js +89 -0
- package/build/server/src/Resend.js.map +1 -0
- package/build/server/src/SocketIoManager.js +312 -0
- package/build/server/src/SocketIoManager.js.map +1 -0
- package/build/server/src/SocketMessage.js +68 -0
- package/build/server/src/SocketMessage.js.map +1 -0
- package/build/server/src/TcpProxy.js +202 -0
- package/build/server/src/TcpProxy.js.map +1 -0
- package/build/server/src/formatters/HexFormatter.js +33 -0
- package/build/server/src/formatters/HexFormatter.js.map +1 -0
- package/build/server/src/formatters/MongoFormatter.js +97 -0
- package/build/server/src/formatters/MongoFormatter.js.map +1 -0
- package/build/server/src/formatters/MongoOpCode.js +51 -0
- package/build/server/src/formatters/MongoOpCode.js.map +1 -0
- package/build/server/src/formatters/RedisFormatter.js +25 -0
- package/build/server/src/formatters/RedisFormatter.js.map +1 -0
- package/build/server/src/formatters/SqlCommand.js +111 -0
- package/build/server/src/formatters/SqlCommand.js.map +1 -0
- package/build/server/src/formatters/SqlFormatter.js +150 -0
- package/build/server/src/formatters/SqlFormatter.js.map +1 -0
- package/client/README.md +46 -0
- package/client/build/asset-manifest.json +26 -0
- package/client/build/favicon.ico +0 -0
- package/client/build/index.html +1 -0
- package/client/build/manifest.json +8 -0
- package/client/build/robots.txt +3 -0
- package/client/build/static/css/2.bbde182e.chunk.css +12 -0
- package/client/build/static/css/2.bbde182e.chunk.css.map +1 -0
- package/client/build/static/css/main.5bf489b2.chunk.css +2 -0
- package/client/build/static/css/main.5bf489b2.chunk.css.map +1 -0
- package/client/build/static/js/2.ba308ba1.chunk.js +3 -0
- package/client/build/static/js/2.ba308ba1.chunk.js.LICENSE.txt +100 -0
- package/client/build/static/js/2.ba308ba1.chunk.js.map +1 -0
- package/client/build/static/js/3.7073b0d8.chunk.js +2 -0
- package/client/build/static/js/3.7073b0d8.chunk.js.map +1 -0
- package/client/build/static/js/main.494a7501.chunk.js +2 -0
- package/client/build/static/js/main.494a7501.chunk.js.map +1 -0
- package/client/build/static/js/runtime-main.00264969.js +2 -0
- package/client/build/static/js/runtime-main.00264969.js.map +1 -0
- package/client/build/static/media/fa-brands-400.2285773e.woff +0 -0
- package/client/build/static/media/fa-brands-400.23f19bb0.eot +0 -0
- package/client/build/static/media/fa-brands-400.2f517e09.svg +3717 -0
- package/client/build/static/media/fa-brands-400.527940b1.ttf +0 -0
- package/client/build/static/media/fa-brands-400.d878b0a6.woff2 +0 -0
- package/client/build/static/media/fa-regular-400.4689f52c.svg +801 -0
- package/client/build/static/media/fa-regular-400.491974d1.ttf +0 -0
- package/client/build/static/media/fa-regular-400.77206a6b.eot +0 -0
- package/client/build/static/media/fa-regular-400.7a333762.woff2 +0 -0
- package/client/build/static/media/fa-regular-400.bb58e57c.woff +0 -0
- package/client/build/static/media/fa-solid-900.1551f4f6.woff2 +0 -0
- package/client/build/static/media/fa-solid-900.7a8b4f13.svg +5034 -0
- package/client/build/static/media/fa-solid-900.9bbb245e.eot +0 -0
- package/client/build/static/media/fa-solid-900.be9ee23c.ttf +0 -0
- package/client/build/static/media/fa-solid-900.eeccf4f6.woff +0 -0
- package/package.json +80 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var port = 8081;
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
var Proxy = require('../');
|
|
7
|
+
var proxy = Proxy();
|
|
8
|
+
|
|
9
|
+
proxy.onError(function(ctx, err, errorKind) {
|
|
10
|
+
// ctx may be null
|
|
11
|
+
var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : '';
|
|
12
|
+
console.error(errorKind + ' on ' + url + ':', err);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
proxy.onCertificateMissing = function(ctx, files, callback) {
|
|
16
|
+
console.log('Looking for "%s" certificates', ctx.hostname);
|
|
17
|
+
console.log('"%s" missing', ctx.files.keyFile);
|
|
18
|
+
console.log('"%s" missing', ctx.files.certFile);
|
|
19
|
+
|
|
20
|
+
// Here you have the last chance to provide certificate files data
|
|
21
|
+
// A tipical use case would be creating them on the fly
|
|
22
|
+
//
|
|
23
|
+
// return callback(null, {
|
|
24
|
+
// key: keyFileData,
|
|
25
|
+
// cert: certFileData
|
|
26
|
+
// });
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
proxy.listen({ port: port });
|
|
30
|
+
console.log('listening on ' + port);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var port = 8081;
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
var Proxy = require('../');
|
|
7
|
+
var proxy = Proxy();
|
|
8
|
+
|
|
9
|
+
proxy.onError(function(ctx, err, errorKind) {
|
|
10
|
+
// ctx may be null
|
|
11
|
+
var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : '';
|
|
12
|
+
console.error(errorKind + ' on ' + url + ':', err);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
proxy.onCertificateRequired = function(hostname, callback) {
|
|
16
|
+
return callback(null, {
|
|
17
|
+
keyFile: path.resolve('/ca/certs/', hostname + '.key'),
|
|
18
|
+
certFile: path.resolve('/ca/certs/', hostname + '.crt')
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
proxy.listen({ port: port });
|
|
23
|
+
console.log('listening on ' + port);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var port = 8081;
|
|
4
|
+
|
|
5
|
+
var Proxy = require('../');
|
|
6
|
+
var proxy = Proxy();
|
|
7
|
+
|
|
8
|
+
proxy.onError(function(ctx, err, errorKind) {
|
|
9
|
+
// ctx may be null
|
|
10
|
+
var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : '';
|
|
11
|
+
console.error(errorKind + ' on ' + url + ':', err);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
proxy.onRequest(function(ctx, callback) {
|
|
15
|
+
ctx.proxyToClientResponse.end('Hacked, you cannot proceed to the website');
|
|
16
|
+
// no callback() so proxy request is not sent to the server
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
proxy.listen({ port: port });
|
|
20
|
+
console.log('listening on ' + port);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var port = 8081;
|
|
4
|
+
|
|
5
|
+
var Proxy = require('../');
|
|
6
|
+
var proxy = Proxy();
|
|
7
|
+
|
|
8
|
+
proxy.onError(function(ctx, err, errorKind) {
|
|
9
|
+
// ctx may be null
|
|
10
|
+
var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : '';
|
|
11
|
+
console.error(errorKind + ' on ' + url + ':', err);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
proxy.use(Proxy.gunzip);
|
|
15
|
+
|
|
16
|
+
proxy.onRequest(function(ctx, callback) {
|
|
17
|
+
var chunks = [];
|
|
18
|
+
ctx.onResponseData(function(ctx, chunk, callback) {
|
|
19
|
+
chunks.push(chunk);
|
|
20
|
+
return callback(null, null); // don't write chunks to client response
|
|
21
|
+
});
|
|
22
|
+
ctx.onResponseEnd(function(ctx, callback) {
|
|
23
|
+
var body = Buffer.concat(chunks);
|
|
24
|
+
if(ctx.serverToProxyResponse.headers['content-type'] && ctx.serverToProxyResponse.headers['content-type'].indexOf('text/html') === 0) {
|
|
25
|
+
body = body.toString().replace(/Lucky/g, 'Sexy');
|
|
26
|
+
}
|
|
27
|
+
ctx.proxyToClientResponse.write(body);
|
|
28
|
+
return callback();
|
|
29
|
+
});
|
|
30
|
+
callback();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
proxy.listen({ port: port });
|
|
36
|
+
console.log('listening on ' + port);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var port = 8081;
|
|
4
|
+
|
|
5
|
+
var Proxy = require('../');
|
|
6
|
+
var proxy = Proxy();
|
|
7
|
+
|
|
8
|
+
proxy.onRequest(function(ctx, callback) {
|
|
9
|
+
if('content-length' in ctx.proxyToServerRequestOptions.headers) {
|
|
10
|
+
console.log(`found "content-length" header in request to "${ctx.proxyToServerRequestOptions.host}${ctx.proxyToServerRequestOptions.path}". Removing.`);
|
|
11
|
+
delete ctx.proxyToServerRequestOptions.headers['content-length'];
|
|
12
|
+
}
|
|
13
|
+
callback();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
proxy.listen({ port: port });
|
|
17
|
+
console.log('listening on ' + port);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var port = 8081;
|
|
4
|
+
|
|
5
|
+
var Proxy = require('../');
|
|
6
|
+
var proxy = Proxy();
|
|
7
|
+
|
|
8
|
+
proxy.onError(function(ctx, err, errorKind) {
|
|
9
|
+
// ctx may be null
|
|
10
|
+
var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : '';
|
|
11
|
+
console.error(errorKind + ' on ' + url + ':', err);
|
|
12
|
+
});
|
|
13
|
+
proxy.onWebSocketConnection(function(ctx, callback) {
|
|
14
|
+
console.log('WEBSOCKET CONNECT:', ctx.clientToProxyWebSocket.upgradeReq.url);
|
|
15
|
+
return callback();
|
|
16
|
+
});
|
|
17
|
+
proxy.onWebSocketFrame(function(ctx, type, fromServer, message, flags, callback) {
|
|
18
|
+
console.log('WEBSOCKET FRAME ' + type + ' received from ' + (fromServer ? 'server' : 'client'), ctx.clientToProxyWebSocket.upgradeReq.url, message);
|
|
19
|
+
if (message) var hackedMessage = message.replace(/Rock it/ig, 'Hack it');
|
|
20
|
+
return callback(null, message, flags);
|
|
21
|
+
});
|
|
22
|
+
proxy.onWebSocketError(function(ctx, err) {
|
|
23
|
+
console.log('WEBSOCKET ERROR ', ctx.clientToProxyWebSocket.upgradeReq.url, err);
|
|
24
|
+
});
|
|
25
|
+
proxy.onWebSocketClose(function(ctx, code, message, callback) {
|
|
26
|
+
console.log('WEBSOCKET CLOSED BY '+(ctx.closedByServer ? 'SERVER' : 'CLIENT'), ctx.clientToProxyWebSocket.upgradeReq.url, code, message);
|
|
27
|
+
callback(null, code, message);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
proxy.listen({ port: port });
|
|
31
|
+
console.log('listening on ' + port);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var port = 8081;
|
|
4
|
+
|
|
5
|
+
var Proxy = require('../');
|
|
6
|
+
var proxy = Proxy();
|
|
7
|
+
|
|
8
|
+
proxy.use(Proxy.wildcard);
|
|
9
|
+
|
|
10
|
+
proxy.onError(function(ctx, err, errorKind) {
|
|
11
|
+
// ctx may be null
|
|
12
|
+
var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : '';
|
|
13
|
+
console.error(errorKind + ' on ' + url + ':', err);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
proxy.listen({ port: port });
|
|
17
|
+
console.log('listening on ' + port);
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
//definitions by jason swearingen. jasons aat novaleaf doot coom. for node-htt-mitm-proxy v0.5.2.
|
|
2
|
+
|
|
3
|
+
import http = require("http");
|
|
4
|
+
import https = require("https");
|
|
5
|
+
import net = require("net");
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
declare namespace HttpMitmProxy {
|
|
9
|
+
export interface IProxyStatic {
|
|
10
|
+
(): IProxy;
|
|
11
|
+
/** mod to pass to the use() function: Gunzip response filter (uncompress gzipped content before onResponseData and compress back after)*/
|
|
12
|
+
gunzip: any;
|
|
13
|
+
/** mod to pass to the use() function: Generates wilcard certificates by default (so less certificates are generated)*/
|
|
14
|
+
wildcard: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IProxyOptions {
|
|
18
|
+
/**port - The port or named socket to listen on (default: 8080).*/
|
|
19
|
+
port?: number;
|
|
20
|
+
/**host - The hostname or local address to listen on.*/
|
|
21
|
+
host?: string;
|
|
22
|
+
/** - Path to the certificates cache directory (default: process.cwd() + '/.http-mitm-proxy')*/
|
|
23
|
+
sslCaDir?: string;
|
|
24
|
+
/** - enable HTTP persistent connection*/
|
|
25
|
+
keepAlive?: boolean;
|
|
26
|
+
/** - The number of milliseconds of inactivity before a socket is presumed to have timed out. Defaults to no timeout. */
|
|
27
|
+
timeout?: number;
|
|
28
|
+
/** - The http.Agent to use when making http requests. Useful for chaining proxys. (default: internal Agent) */
|
|
29
|
+
httpAgent?: http.Agent;
|
|
30
|
+
/** - The https.Agent to use when making https requests. Useful for chaining proxys. (default: internal Agent) */
|
|
31
|
+
httpsAgent?: https.Agent;
|
|
32
|
+
/** - force use of SNI by the client. Allow node-http-mitm-proxy to handle all HTTPS requests with a single internal server. */
|
|
33
|
+
forceSNI?: boolean;
|
|
34
|
+
/** - The port or named socket for https server to listen on. (forceSNI must be enabled) */
|
|
35
|
+
httpsPort?: number;
|
|
36
|
+
/** - Setting this option will remove the content-length from the proxy to server request, forcing chunked encoding */
|
|
37
|
+
forceChunkedRequest?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type IProxy = ICallbacks & {
|
|
41
|
+
/** Starts the proxy listening on the given port.. example: proxy.listen({ port: 80 }); */
|
|
42
|
+
listen(/** An object with the following options: */ options?: IProxyOptions, callback?: Function): void;
|
|
43
|
+
/** proxy.close
|
|
44
|
+
Stops the proxy listening.
|
|
45
|
+
|
|
46
|
+
Example
|
|
47
|
+
|
|
48
|
+
proxy.close(); */
|
|
49
|
+
close(): void;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
onCertificateRequired(hostname: string, callback: (error: Error | undefined, certDetails: { keyFile: string; certFile: string; hosts: string[]; }) => void): void;
|
|
53
|
+
onCertificateMissing(ctx: IContext, files: any, callback: (error: Error | undefined, certDetails: { keyFileData: string; certFileData: string; hosts: string[]; }) => void): void;
|
|
54
|
+
|
|
55
|
+
//undocumented helpers
|
|
56
|
+
onConnect(fcn: (req: http.IncomingMessage, socket: net.Socket, head: any, callback: (error?: Error) => void) => void): void;
|
|
57
|
+
onRequestHeaders(fcn: (ctx: IContext, callback: (error?: Error) => void) => void): void;
|
|
58
|
+
onResponseHeaders(fcn: (ctx: IContext, callback: (error?: Error) => void) => void): void;
|
|
59
|
+
onWebSocketConnection(fcn: (ctx: IContext, callback: (error?: Error) => void) => void): void;
|
|
60
|
+
onWebSocketSend(fcn: (ctx: IContext, message: any, flags: any, callback: (err: Error | undefined, message: any, flags: any) => void) => void): void;
|
|
61
|
+
onWebSocketMessage(fcn: (ctx: IContext, message: any, flags: any, callback: (err: Error | undefined, message: any, flags: any) => void) => void): void;
|
|
62
|
+
onWebSocketFrame(fcn: (ctx: IContext, type: any, fromServer: boolean, message: any, flags: any, callback: (err: Error | undefined, message: any, flags: any) => void) => void): void;
|
|
63
|
+
onWebSocketError(fcn: (ctx: IContext, err: Error | undefined) => void): void;
|
|
64
|
+
onWebSocketClose(fcn: (ctx: IContext, code: any, message: any, callback: (err: Error | undefined, code: any, message: any) => void) => void): void;
|
|
65
|
+
|
|
66
|
+
// onConnectHandlers:((req,socket,head,callback)=>void)[];
|
|
67
|
+
// onRequestHandlers:((ctx,callback)=>void)[];
|
|
68
|
+
|
|
69
|
+
options: IProxyOptions;
|
|
70
|
+
httpPort: number;
|
|
71
|
+
timeout: number;
|
|
72
|
+
keepAlive: boolean;
|
|
73
|
+
httpAgent: http.Agent;
|
|
74
|
+
httpsAgent: https.Agent;
|
|
75
|
+
forceSNI: boolean;
|
|
76
|
+
httpsPort?: number;
|
|
77
|
+
sslCaDir: string;
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** signatures for various callback functions */
|
|
82
|
+
export interface ICallbacks {
|
|
83
|
+
onError(/**Adds a function to the list of functions to get called if an error occures.
|
|
84
|
+
|
|
85
|
+
Arguments
|
|
86
|
+
|
|
87
|
+
fn(ctx, err, errorKind) - The function to be called on an error.*/callback: (context: IContext, err?: Error, errorKind?: string) => void): void;
|
|
88
|
+
|
|
89
|
+
/** Adds a function to get called at the beginning of a request.
|
|
90
|
+
|
|
91
|
+
Arguments
|
|
92
|
+
|
|
93
|
+
fn(ctx, callback) - The function that gets called on each request.
|
|
94
|
+
Example
|
|
95
|
+
|
|
96
|
+
proxy.onRequest(function(ctx, callback) {
|
|
97
|
+
console.log('REQUEST:', ctx.clientToProxyRequest.url);
|
|
98
|
+
return callback();
|
|
99
|
+
}); */
|
|
100
|
+
onRequest(fcn: (ctx: IContext, callback: (error?: Error) => void) => void): void;
|
|
101
|
+
|
|
102
|
+
onRequestData(fcn: (ctx: IContext, chunk: Buffer, callback: (error?: Error, chunk?: Buffer) => void) => void): void;
|
|
103
|
+
|
|
104
|
+
onRequestEnd(fcn: (ctx: IContext, callback: (error?: Error) => void) => void): void;
|
|
105
|
+
/** Adds a function to get called at the beginning of the response.
|
|
106
|
+
|
|
107
|
+
Arguments
|
|
108
|
+
|
|
109
|
+
fn(ctx, callback) - The function that gets called on each response.
|
|
110
|
+
Example
|
|
111
|
+
|
|
112
|
+
proxy.onResponse(function(ctx, callback) {
|
|
113
|
+
console.log('BEGIN RESPONSE');
|
|
114
|
+
return callback();
|
|
115
|
+
}); */
|
|
116
|
+
onResponse(fcn: (ctx: IContext, callback: (error?: Error) => void) => void): void;
|
|
117
|
+
|
|
118
|
+
onResponseData(fcn: (ctx: IContext, chunk: Buffer, callback: (error?: Error, chunk?: Buffer) => void) => void): void;
|
|
119
|
+
|
|
120
|
+
onResponseEnd(fcn: (ctx: IContext, callback: (error?: Error) => void) => void): void;
|
|
121
|
+
|
|
122
|
+
/** Adds a module into the proxy. Modules encapsulate multiple life cycle processing functions into one object.
|
|
123
|
+
|
|
124
|
+
Arguments
|
|
125
|
+
|
|
126
|
+
module - The module to add. Modules contain a hash of functions to add.
|
|
127
|
+
Example
|
|
128
|
+
|
|
129
|
+
proxy.use({
|
|
130
|
+
onError: function(ctx, err) { },
|
|
131
|
+
onCertificateRequired: function(hostname, callback) { return callback(); },
|
|
132
|
+
onCertificateMissing: function(ctx, files, callback) { return callback(); },
|
|
133
|
+
onRequest: function(ctx, callback) { return callback(); },
|
|
134
|
+
onRequestData: function(ctx, chunk, callback) { return callback(null, chunk); },
|
|
135
|
+
onResponse: function(ctx, callback) { return callback(); },
|
|
136
|
+
onResponseData: function(ctx, chunk, callback) { return callback(null, chunk); },
|
|
137
|
+
onWebSocketConnection: function(ctx, callback) { return callback(); },
|
|
138
|
+
onWebSocketSend: function(ctx, message, flags, callback) { return callback(null, message, flags); },
|
|
139
|
+
onWebSocketMessage: function(ctx, message, flags, callback) { return callback(null, message, flags); },
|
|
140
|
+
onWebSocketError: function(ctx, err) { },
|
|
141
|
+
onWebSocketClose: function(ctx, code, message, callback) { },
|
|
142
|
+
});
|
|
143
|
+
node-http-mitm-proxy provide some ready to use modules:
|
|
144
|
+
|
|
145
|
+
Proxy.gunzip Gunzip response filter (uncompress gzipped content before onResponseData and compress back after)
|
|
146
|
+
Proxy.wildcard Generates wilcard certificates by default (so less certificates are generated) */
|
|
147
|
+
use(mod: any): void;
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
export type IContext = ICallbacks & {
|
|
155
|
+
isSSL: boolean;
|
|
156
|
+
|
|
157
|
+
/** may be set to true/false when dealing with websockets. */
|
|
158
|
+
closedByServer?: boolean;
|
|
159
|
+
|
|
160
|
+
clientToProxyRequest: http.IncomingMessage;
|
|
161
|
+
proxyToClientResponse: http.ServerResponse;
|
|
162
|
+
proxyToServerRequest: http.ClientRequest;
|
|
163
|
+
serverToProxyResponse: http.IncomingMessage;
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
/** instance of WebSocket object from https://github.com/websockets/ws */
|
|
167
|
+
clientToProxyWebSocket: any;
|
|
168
|
+
/** instance of WebSocket object from https://github.com/websockets/ws */
|
|
169
|
+
proxyToServerWebSocket: any;
|
|
170
|
+
|
|
171
|
+
/** user defined tags, initially constructed in the proxy-internals.tx proxy.onRequest() callback, you can add what you like here. */
|
|
172
|
+
tags: {
|
|
173
|
+
id: number;
|
|
174
|
+
uri:string;
|
|
175
|
+
/** ln 743 of proxy.js, hack to retry */
|
|
176
|
+
failedUpstreamCalls:number;
|
|
177
|
+
/** ln 743 of proxy.js, hack to retry */
|
|
178
|
+
retryProxyRequest:boolean;
|
|
179
|
+
[key: string]: any;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**Adds a stream into the request body stream.
|
|
183
|
+
|
|
184
|
+
Arguments
|
|
185
|
+
|
|
186
|
+
stream - The read/write stream to add in the request body stream.
|
|
187
|
+
Example
|
|
188
|
+
|
|
189
|
+
ctx.addRequestFilter(zlib.createGunzip()); */
|
|
190
|
+
addRequestFilter(stream: any): void;
|
|
191
|
+
/** Adds a stream into the response body stream.
|
|
192
|
+
|
|
193
|
+
Arguments
|
|
194
|
+
|
|
195
|
+
stream - The read/write stream to add in the response body stream.
|
|
196
|
+
Example
|
|
197
|
+
|
|
198
|
+
ctx.addResponseFilter(zlib.createGunzip()); */
|
|
199
|
+
addResponseFilter(stream: any): void;
|
|
200
|
+
|
|
201
|
+
/** filters added by .addRequestFilter() */
|
|
202
|
+
requestFilters: any[];
|
|
203
|
+
|
|
204
|
+
/** filters added by .addResponseFilter() */
|
|
205
|
+
responseFilters: any[];
|
|
206
|
+
|
|
207
|
+
/** undocumented, allows adjusting the request in callbacks (such as .onRequest()) before sending upstream (to proxy or target host)..
|
|
208
|
+
* FYI these values seem pre-populated with defaults based on the request, you can modify them to change behavior. */
|
|
209
|
+
proxyToServerRequestOptions: {
|
|
210
|
+
/** ex: "GET" */
|
|
211
|
+
method: string;
|
|
212
|
+
/** ex: "/success.txt" */
|
|
213
|
+
path: string;
|
|
214
|
+
|
|
215
|
+
/** example: "detectportal.firefox.com" */
|
|
216
|
+
host: string;
|
|
217
|
+
port: null;
|
|
218
|
+
headers: { [key: string]: string };
|
|
219
|
+
agent: http.Agent;
|
|
220
|
+
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
onResponseDataHandlers:Function[];
|
|
224
|
+
onResponseEndHandlers:Function[];
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare const HttpMitmProxy: HttpMitmProxy.IProxyStatic
|
|
232
|
+
export = HttpMitmProxy;
|
|
233
|
+
export as namespace HttpMitmProxy;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var FS = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var Forge = require('node-forge');
|
|
6
|
+
var pki = Forge.pki;
|
|
7
|
+
var mkdirp = require('mkdirp');
|
|
8
|
+
var async = require('async');
|
|
9
|
+
|
|
10
|
+
var CAattrs = [{
|
|
11
|
+
name: 'commonName',
|
|
12
|
+
value: 'NodeMITMProxyCA'
|
|
13
|
+
}, {
|
|
14
|
+
name: 'countryName',
|
|
15
|
+
value: 'Internet'
|
|
16
|
+
}, {
|
|
17
|
+
shortName: 'ST',
|
|
18
|
+
value: 'Internet'
|
|
19
|
+
}, {
|
|
20
|
+
name: 'localityName',
|
|
21
|
+
value: 'Internet'
|
|
22
|
+
}, {
|
|
23
|
+
name: 'organizationName',
|
|
24
|
+
value: 'Node MITM Proxy CA'
|
|
25
|
+
}, {
|
|
26
|
+
shortName: 'OU',
|
|
27
|
+
value: 'CA'
|
|
28
|
+
}];
|
|
29
|
+
|
|
30
|
+
var CAextensions = [{
|
|
31
|
+
name: 'basicConstraints',
|
|
32
|
+
cA: true
|
|
33
|
+
}, {
|
|
34
|
+
name: 'keyUsage',
|
|
35
|
+
keyCertSign: true,
|
|
36
|
+
digitalSignature: true,
|
|
37
|
+
nonRepudiation: true,
|
|
38
|
+
keyEncipherment: true,
|
|
39
|
+
dataEncipherment: true
|
|
40
|
+
}, {
|
|
41
|
+
name: 'extKeyUsage',
|
|
42
|
+
serverAuth: true,
|
|
43
|
+
clientAuth: true,
|
|
44
|
+
codeSigning: true,
|
|
45
|
+
emailProtection: true,
|
|
46
|
+
timeStamping: true
|
|
47
|
+
}, {
|
|
48
|
+
name: 'nsCertType',
|
|
49
|
+
client: true,
|
|
50
|
+
server: true,
|
|
51
|
+
email: true,
|
|
52
|
+
objsign: true,
|
|
53
|
+
sslCA: true,
|
|
54
|
+
emailCA: true,
|
|
55
|
+
objCA: true
|
|
56
|
+
}, {
|
|
57
|
+
name: 'subjectKeyIdentifier'
|
|
58
|
+
}];
|
|
59
|
+
|
|
60
|
+
var ServerAttrs = [{
|
|
61
|
+
name: 'countryName',
|
|
62
|
+
value: 'Internet'
|
|
63
|
+
}, {
|
|
64
|
+
shortName: 'ST',
|
|
65
|
+
value: 'Internet'
|
|
66
|
+
}, {
|
|
67
|
+
name: 'localityName',
|
|
68
|
+
value: 'Internet'
|
|
69
|
+
}, {
|
|
70
|
+
name: 'organizationName',
|
|
71
|
+
value: 'Node MITM Proxy CA'
|
|
72
|
+
}, {
|
|
73
|
+
shortName: 'OU',
|
|
74
|
+
value: 'Node MITM Proxy Server Certificate'
|
|
75
|
+
}];
|
|
76
|
+
|
|
77
|
+
var ServerExtensions = [{
|
|
78
|
+
name: 'basicConstraints',
|
|
79
|
+
cA: false
|
|
80
|
+
}, {
|
|
81
|
+
name: 'keyUsage',
|
|
82
|
+
keyCertSign: false,
|
|
83
|
+
digitalSignature: true,
|
|
84
|
+
nonRepudiation: false,
|
|
85
|
+
keyEncipherment: true,
|
|
86
|
+
dataEncipherment: true
|
|
87
|
+
}, {
|
|
88
|
+
name: 'extKeyUsage',
|
|
89
|
+
serverAuth: true,
|
|
90
|
+
clientAuth: true,
|
|
91
|
+
codeSigning: false,
|
|
92
|
+
emailProtection: false,
|
|
93
|
+
timeStamping: false
|
|
94
|
+
}, {
|
|
95
|
+
name: 'nsCertType',
|
|
96
|
+
client: true,
|
|
97
|
+
server: true,
|
|
98
|
+
email: false,
|
|
99
|
+
objsign: false,
|
|
100
|
+
sslCA: false,
|
|
101
|
+
emailCA: false,
|
|
102
|
+
objCA: false
|
|
103
|
+
}, {
|
|
104
|
+
name: 'subjectKeyIdentifier'
|
|
105
|
+
}];
|
|
106
|
+
|
|
107
|
+
var CA = function () {
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
CA.create = function (caFolder, callback) {
|
|
111
|
+
var ca = new CA();
|
|
112
|
+
ca.baseCAFolder = caFolder;
|
|
113
|
+
ca.certsFolder = path.join(ca.baseCAFolder, 'certs');
|
|
114
|
+
ca.keysFolder = path.join(ca.baseCAFolder, 'keys');
|
|
115
|
+
async.series([
|
|
116
|
+
mkdirp.bind(null, ca.baseCAFolder),
|
|
117
|
+
mkdirp.bind(null, ca.certsFolder),
|
|
118
|
+
mkdirp.bind(null, ca.keysFolder),
|
|
119
|
+
function (callback) {
|
|
120
|
+
FS.exists(path.join(ca.certsFolder, 'ca.pem'), function (exists) {
|
|
121
|
+
if (exists) {
|
|
122
|
+
ca.loadCA(callback);
|
|
123
|
+
} else {
|
|
124
|
+
ca.generateCA(callback);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
], function (err) {
|
|
129
|
+
if (err) {
|
|
130
|
+
return callback(err);
|
|
131
|
+
}
|
|
132
|
+
return callback(null, ca);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
CA.prototype.randomSerialNumber = function () {
|
|
137
|
+
// generate random 16 bytes hex string
|
|
138
|
+
var sn = '';
|
|
139
|
+
for (var i=0; i<4; i++) {
|
|
140
|
+
sn += ('00000000' + Math.floor(Math.random()*Math.pow(256, 4)).toString(16)).slice(-8);
|
|
141
|
+
}
|
|
142
|
+
return sn;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
CA.prototype.generateCA = function (callback) {
|
|
146
|
+
var self = this;
|
|
147
|
+
pki.rsa.generateKeyPair({bits: 2048}, function(err, keys) {
|
|
148
|
+
if (err) {
|
|
149
|
+
return callback(err);
|
|
150
|
+
}
|
|
151
|
+
var cert = pki.createCertificate();
|
|
152
|
+
cert.publicKey = keys.publicKey;
|
|
153
|
+
cert.serialNumber = self.randomSerialNumber();
|
|
154
|
+
cert.validity.notBefore = new Date();
|
|
155
|
+
cert.validity.notBefore.setDate(cert.validity.notBefore.getDate() - 1);
|
|
156
|
+
cert.validity.notAfter = new Date();
|
|
157
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 2);
|
|
158
|
+
cert.setSubject(CAattrs);
|
|
159
|
+
cert.setIssuer(CAattrs);
|
|
160
|
+
cert.setExtensions(CAextensions);
|
|
161
|
+
cert.sign(keys.privateKey, Forge.md.sha256.create());
|
|
162
|
+
self.CAcert = cert;
|
|
163
|
+
self.CAkeys = keys;
|
|
164
|
+
async.parallel([
|
|
165
|
+
FS.writeFile.bind(null, path.join(self.certsFolder, 'ca.pem'), pki.certificateToPem(cert)),
|
|
166
|
+
FS.writeFile.bind(null, path.join(self.keysFolder, 'ca.private.key'), pki.privateKeyToPem(keys.privateKey)),
|
|
167
|
+
FS.writeFile.bind(null, path.join(self.keysFolder, 'ca.public.key'), pki.publicKeyToPem(keys.publicKey))
|
|
168
|
+
], callback);
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
CA.prototype.loadCA = function (callback) {
|
|
173
|
+
var self = this;
|
|
174
|
+
async.auto({
|
|
175
|
+
certPEM: function (callback) {
|
|
176
|
+
FS.readFile(path.join(self.certsFolder, 'ca.pem'), 'utf-8', callback);
|
|
177
|
+
},
|
|
178
|
+
keyPrivatePEM: function (callback) {
|
|
179
|
+
FS.readFile(path.join(self.keysFolder, 'ca.private.key'), 'utf-8', callback);
|
|
180
|
+
},
|
|
181
|
+
keyPublicPEM: function (callback) {
|
|
182
|
+
FS.readFile(path.join(self.keysFolder, 'ca.public.key'), 'utf-8', callback);
|
|
183
|
+
}
|
|
184
|
+
}, function (err, results) {
|
|
185
|
+
if (err) {
|
|
186
|
+
return callback(err);
|
|
187
|
+
}
|
|
188
|
+
self.CAcert = pki.certificateFromPem(results.certPEM);
|
|
189
|
+
self.CAkeys = {
|
|
190
|
+
privateKey: pki.privateKeyFromPem(results.keyPrivatePEM),
|
|
191
|
+
publicKey: pki.publicKeyFromPem(results.keyPublicPEM)
|
|
192
|
+
};
|
|
193
|
+
return callback();
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
CA.prototype.generateServerCertificateKeys = function (hosts, cb) {
|
|
198
|
+
var self = this;
|
|
199
|
+
if (typeof(hosts) === "string") hosts = [hosts];
|
|
200
|
+
var mainHost = hosts[0];
|
|
201
|
+
var keysServer = pki.rsa.generateKeyPair(2048);
|
|
202
|
+
var certServer = pki.createCertificate();
|
|
203
|
+
certServer.publicKey = keysServer.publicKey;
|
|
204
|
+
certServer.serialNumber = this.randomSerialNumber();
|
|
205
|
+
certServer.validity.notBefore = new Date();
|
|
206
|
+
certServer.validity.notBefore.setDate(certServer.validity.notBefore.getDate() - 1);
|
|
207
|
+
certServer.validity.notAfter = new Date();
|
|
208
|
+
certServer.validity.notAfter.setFullYear(certServer.validity.notBefore.getFullYear() + 2);
|
|
209
|
+
var attrsServer = ServerAttrs.slice(0);
|
|
210
|
+
attrsServer.unshift({
|
|
211
|
+
name: 'commonName',
|
|
212
|
+
value: mainHost
|
|
213
|
+
})
|
|
214
|
+
certServer.setSubject(attrsServer);
|
|
215
|
+
certServer.setIssuer(this.CAcert.issuer.attributes);
|
|
216
|
+
certServer.setExtensions(ServerExtensions.concat([{
|
|
217
|
+
name: 'subjectAltName',
|
|
218
|
+
altNames: hosts.map(function(host) {
|
|
219
|
+
if (host.match(/^[\d\.]+$/)) {
|
|
220
|
+
return {type: 7, ip: host};
|
|
221
|
+
}
|
|
222
|
+
return {type: 2, value: host};
|
|
223
|
+
})
|
|
224
|
+
}]));
|
|
225
|
+
certServer.sign(this.CAkeys.privateKey, Forge.md.sha256.create());
|
|
226
|
+
var certPem = pki.certificateToPem(certServer);
|
|
227
|
+
var keyPrivatePem = pki.privateKeyToPem(keysServer.privateKey)
|
|
228
|
+
var keyPublicPem = pki.publicKeyToPem(keysServer.publicKey)
|
|
229
|
+
FS.writeFile(this.certsFolder + '/' + mainHost.replace(/\*/g, '_') + '.pem', certPem, function(error) {
|
|
230
|
+
if (error) console.error("Failed to save certificate to disk in "+self.certsFolder, error);
|
|
231
|
+
});
|
|
232
|
+
FS.writeFile(this.keysFolder + '/' + mainHost.replace(/\*/g, '_') + '.key', keyPrivatePem, function(error) {
|
|
233
|
+
if (error) console.error("Failed to save private key to disk in "+self.keysFolder, error);
|
|
234
|
+
});
|
|
235
|
+
FS.writeFile(this.keysFolder + '/' + mainHost.replace(/\*/g, '_') + '.public.key', keyPublicPem, function(error) {
|
|
236
|
+
if (error) console.error("Failed to save public key to disk in "+self.keysFolder, error);
|
|
237
|
+
});
|
|
238
|
+
// returns synchronously even before files get written to disk
|
|
239
|
+
cb(certPem, keyPrivatePem);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
CA.prototype.getCACertPath = function () {
|
|
243
|
+
return this.certsFolder + '/ca.pem';
|
|
244
|
+
};
|
|
245
|
+
module.exports = CA;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zlib = require('zlib');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
onResponse: function(ctx, callback) {
|
|
7
|
+
if (ctx.serverToProxyResponse.headers['content-encoding']
|
|
8
|
+
&& ctx.serverToProxyResponse.headers['content-encoding'].toLowerCase() == 'gzip') {
|
|
9
|
+
delete ctx.serverToProxyResponse.headers['content-encoding'];
|
|
10
|
+
ctx.addResponseFilter(zlib.createGunzip());
|
|
11
|
+
}
|
|
12
|
+
return callback();
|
|
13
|
+
},
|
|
14
|
+
onRequest: function(ctx, callback) {
|
|
15
|
+
ctx.proxyToServerRequestOptions.headers['accept-encoding'] = 'gzip';
|
|
16
|
+
return callback();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|