npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-mitmproxy-pro

v1.1.1

Published

Node.js MITM Proxy Pro

Downloads

12

Readme

node-mitmproxy-pro

注意: 此项目由node-mitmproxy修改而来
原项目地址:https://github.com/wuchangming/node-mitmproxy
原项目官网:https://www.npmjs.com/package/node-mitmproxy

npm
node-mitmproxy-pro是一个基于nodejs,支持http/https的中间人(MITM)代理,便于渗透测试和开发调试。由于原作者已6年没有更新,我们决定fork并继续维护这个增强版本。

1、特性

1、支持https
2、支持配置的方式启动,也支持以模块的方式引入到代码中 3、轻松重写请求和响应

2、安装

windows
    npm install node-mitmproxy-pro -g
Mac
    sudo npm install node-mitmproxy-pro -g

3、使用

关于配置文件

简单配置:

simpleConfig.js

module.exports = {
    sslConnectInterceptor: (req, cltSocket, head) => true,
    requestInterceptor: (requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {
        console.log(`正在访问:${requestOptions.protocol}//${requestOptions.hostname}:${requestOptions.port}`);
        console.log('cookie:', requestOptions.headers.cookie);
        res.end('hello node-mitmproxy-pro!');
        pipe();
    }
};

效果图:

更多例子

启动方式

node-mitmproxy-pro -c simpleConfig.js

安装node-mitmproxy-pro CA根证书

生成CA根证书的默认路径:%用户名%/node-mitmproxy-pro

PC下安装根证书方式

Mac
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/node-mitmproxy-pro/node-mitmproxy-pro.ca.crt
windows

注: 证书需要安装到 ** 受信任的根证书目录 ** 下

start %HOMEPATH%/node-mitmproxy-pro/node-mitmproxy-pro.ca.crt

以nodejs模块的方式引用到代码中

var mitmproxy = require('node-mitmproxy-pro');

mitmproxy.createProxy({
    sslConnectInterceptor: (req, cltSocket, head) => true,
    requestInterceptor: (requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {
        console.log(`正在访问:${requestOptions.protocol}//${requestOptions.hostname}:${requestOptions.port}`);
        console.log('cookie:', requestOptions.headers.cookie);
        res.end('Hello node-mitmproxy-pro!');
        pipe();
    },
    responseInterceptor: (requestId, res, proxyRes, ssl, pipe) => {
        pipe();
    }
});

4、配置详细说明

port

启动端口(默认:6789)

    port: 6789

sslConnectInterceptor

判断该connnect请求是否需要代理,传入参数参考http connnect

(req, cltSocket, head) => {}

参数说明:

  • req: 客户端请求对象
  • cltSocket: 客户端socket连接
  • head: 客户端请求头

该函数返回一个布尔值,用于判断该connect请求是否需要代理。


requestInterceptor

请求拦截器,用于拦截和处理HTTP/HTTPS请求。

(requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {}

参数说明:

| 参数 | 类型 | 说明 | |------|------|------| | requestId | String | 请求唯一标识符,与对应响应的ID保持一致 | | requestOptions | Object | 请求参数对象(可选,参数信息已包含在req.headers中) | | req | Object | 原始请求对象 | | res | Object | 响应对象,可用于提前结束流程并返回自定义响应体,无需经过实际网络请求 | | proxyReq | Object | 代理请求对象,支持修改请求头和请求体 | | ssl | Boolean | 标识是否为HTTPS请求 | | pipe | Function | 管道函数,将请求对象写入代理请求对象。仅在无需修改请求时调用;如需自定义处理,可监听ondata事件自行实现 |


responseInterceptor

响应拦截器,用于拦截和处理HTTP/HTTPS响应。

(requestId, res, proxyRes, ssl, pipe) => {}

参数说明:

| 参数 | 类型 | 说明 | |------|------|------| | requestId | String | 请求唯一标识符,与对应请求的ID保持一致 | | res | Object | 响应对象,支持修改响应头和响应体 | | proxyRes | Object | 代理响应对象 | | ssl | Boolean | 标识是否为HTTPS请求 | | pipe | Function | 管道函数,将代理响应对象写入响应对象。仅在无需修改响应时调用;如需自定义处理,可监听ondata事件自行实现 |


caCertPath

CA根证书路径(ps: 无特殊情况无需配置) 默认:%HOMEPATH%/node-mitmproxy-pro/node-mitmproxy-pro.ca.crt

caCertPath: 'xxxx/xxxx.crt'

caKeyPath

CA根证书密钥路径(ps: 无特殊情况无需配置) 默认:%HOMEPATH%/node-mitmproxy-pro/node-mitmproxy-pro.ca.key.pem

caKeyPath: 'xxxx/xxxx.pem'

5、更多

关于伪造https证书的逻辑图

6、API使用示例

const mitmproxy = require('node-mitmproxy-pro');

mitmproxy.createProxy({
  sslConnectInterceptor: (req, cltSocket, head) => {
    // 处理SSL连接
    return true;
  },

  requestInterceptor: (requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {
    // 修改请求头
    proxyReq.setHeader('X-Custom-Header', 'CustomValue');

    // 不修改请求时,调用pipe
    pipe();
  },

  responseInterceptor: (requestId, res, proxyRes, ssl, pipe) => {
    // 修改响应头
    res.setHeader('X-Response-Header', 'ResponseValue');

    // 不修改响应时,调用pipe
    pipe();
  }
});

7、范例项目

https://github.com/cyrilguocode/auto366