node-mitmproxy is a man-in-the-middle (MITM) proxy based on nodejs that supports http / https, which is convenient for penetration testing and development debugging.
This version translated from the original Chinese.
- Supports https
- Supports configuration startup and also supports the introduction of modules into the code.
npm install node-mitmproxy -g
sudo npm install node-mitmproxy -g
simpleConfig.js
module.exports = {
sslConnectInterceptor: (req, cltSocket, head) => true,
requestInterceptor: (rOptions, req, res, ssl, next) => {
console.log(`Is visiting:${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}`);
console.log('cookie:', rOptions.headers.cookie);
res.end('hello node-mitmproxy!');
next();
}
};
[Detailed configuration instructions](https://github.com/wuchangming/node-mitmproxy#4Detailed configuration instructions) More examples
node-mitmproxy -c simpleConfig.js
Default path to generate CA root certificate: %username%/node-mitmproxy
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/node-mitmproxy/node-mitmproxy.ca.crt
Note: Certificate needs to be installed under ** Trusted Root Certificate Directory ** reference issues#3
start %HOMEPATH%/node-mitmproxy/node-mitmproxy.ca.crt
var mitmproxy = require('node-mitmproxy');
mitmproxy.createProxy({
sslConnectInterceptor: (req, cltSocket, head) => true,
requestInterceptor: (rOptions, req, res, ssl, next) => {
console.log(`Is visiting:${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}`);
console.log('cookie:', rOptions.headers.cookie);
res.end('Hello node-mitmproxy!');
next();
},
responseInterceptor: (req, res, proxyReq, proxyRes, ssl, next) => {
next();
}
});
Start port (default: 6789)
port: 6789
Determine whether the connnect request requires a proxy. Pass in the parameter reference http connnect
sslConnectInterceptor: (clientReq, clientSocket, head) => true,
Intercepting client requests / responses
Parameter Description:
- requestOptions: client request parameters
- clientReq: client request, refer to http.IncomingMessage
- clientRes: client response, refer to http.ServerResponse
- ssl: whether the request is https
- next: callback function, call this method after executing the interception logic
requestInterceptor: (requestOptions, clientReq, clientRes, ssl, next) => {
next();
}
Intercept server requests / responses Parameter Description:
- clientReq: client request, refer to http.IncomingMessage
- clientRes: client response, refer to http.ServerResponse
- proxyRes: server request, refer to http.IncomingMessage
- proxyRes: server response, refer to http.ServerResponse
- ssl: whether the request is https
- next: callback function, call this method after executing the interception logic
responseInterceptor: (clientReq, clientRes, proxyRes, proxyRes, ssl, next) => {
next();
}
CA root certificate path (ps: no special case, no configuration required) Default: %HOMEPATH%/node-mitmproxy/node-mitmproxy.ca.crt
caCertPath: 'xxxx/xxxx.crt'
CA root certificate key path (ps: no special case, no configuration required) Default: %HOMEPATH%/node-mitmproxy/node-mitmproxy.ca.key.pem
caKeyPath: 'xxxx/xxxx.pem'