百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

mars

> 编程语言
开源

HTTP(S) 代理, 用于抓包调试

183 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

HTTP(S) 代理, 用于抓包调试

Mars - HTTP(S)代理, 用于抓包调试

功能特性

  • 作为普通HTTP(S)代理服务器使用
  • 抓包调试, web页面查看流量
  • 流量持久化到leveldb中, 可用于后期分析
  • 拦截请求自定义逻辑

截图

目录

  • 下载
  • 安装
    • 二进制安装
    • 源码安装
  • 配置文件
  • 命令
  • 结合其他程序使用
    • Nginx
    • frp
  • 开发
    • 服务端
    • 前端
      • 基于已有代码开发
      • 自定义实现

下载

releases

安装

二进制安装

  1. 解压压缩包
  2. 启动: ./mars server
  3. 访问代理: http://localhost:8888
  4. 查看流量web页: http://localhost:9999, 客户端可扫描二维码下载根证书

docker

bash
docker run --name mars -p 8888:8888 -p 9999:9999 -d ouqg/mars:1.0.0

配置: /app/conf/app.toml

源码安装

Go版本1.11+ 启用go module

bash
export GO111MODULE=on

启动: make run

配置文件

配置支持通过环境变量覆盖, 如MARS_APP_PROXYPORT=8080

toml
[app]
host = "0.0.0.0"
# 代理监听端口
proxyPort = 8888
# 查看流量web页监听端口
inspectorPort = 9999

[mitmProxy]
# 是否开启中间人代理,不开启则盲转发
enabled = true
# 是否解密HTTPS, 客户端系统需安装根证书
decryptHTTPS = false
# 证书缓存大小
certCacheSize = 1000
# 数据缓存大小
leveldbCacheSize = 1000

命令

查看版本

bash
$ ./mars version

   Version: v1.0.0
Go Version: go1.11
Git Commit: 2151a6d
     Built: 2018-11-18 20:04:17
   OS/ARCH: darwin/amd64

命令行参数

bash
$ ./mars server -h
run proxy server

Usage:
  mars server [flags]

Flags:
  -c, --configFile string   config file path (default "conf/app.toml")
  -e, --env string          dev | prod (default "prod")
  -h, --help                help for server

结合其他程序使用

经过mars的流量可在web页查看

Nginx

请求包含特定header, 则转发给mars, 由mars访问实际的后端

原配置

nginx
proxy_pass http://172.16.10.103:8080;

使用mars后的配置

nginx
 set $targetHost $host;

 if ($http_x_mars_debug = "1") {
   set $targetHost "172.16.10.103:8080";
 }

 proxy_set_header X-Mars-Host $host;
 proxy_set_header Host $targetHost;
 if ($http_x_mars_debug = "1") {
   proxy_pass http://127.0.0.1:8888;
   break;
 }

frp

原配置

ini
[web]
type = http
local_ip = 127.0.0.1
local_port = 80
subdomain = test

使用mars后的配置

ini
[web]
type = http
local_ip = 127.0.0.1
local_port = 8888
subdomain = test
host_header_rewrite = 127.0.0.1:80

开发

服务端

拦截请求

实现Interceptor接口, 参考interceptor/example.go

go
// Interceptor 拦截器
type Interceptor interface {
	// Connect 收到客户端连接, 自定义response返回
	Connect(ctx *goproxy.Context, rw http.ResponseWriter)
	// BeforeRequest 请求发送前, 修改request
	BeforeRequest(ctx *goproxy.Context)
	// BeforeResponse 响应发送前, 修改response
	BeforeResponse(ctx *goproxy.Context, resp *http.Response, err error)
}

自定义存储

默认存储为leveldb

实现Storage接口

go
// Storage 存取transaction接口
type Storage interface {
	Get(txId string) (*Transaction, error)
	Put(*Transaction) error
}

自定义输出

内置输出到console、websocket 实现Output接口

go
// Output 输出transaction接口
type Output interface {
	Write(*Transaction) error
}

make

  • make 编译
  • make run 编译并运行
  • make package 生成当前平台的压缩包
  • make package-all 生成Windows、Linux、Mac的压缩包

前端

基于已有代码开发

Vue + Element UI

  1. 安装Go1.11+, Node.js, Yarn
  2. 安装前端依赖 make install-vue
  3. 启动mars: make run
  4. 启动node server: make run-vue
  5. App.vue中替换websocket连接地址为http://localhost:9999
  6. 打包: make build-vue
  7. 安装静态文件嵌入工具go get github.com/rakyll/statik
  8. 静态文件嵌入make statik

自定义实现

基于websocket, 消息序列化协议: json 消息格式, 请求响应相同

json
{
  "type": 3000,
  "payload": {}
}

type取值范围

  • 1000 - 1999 客户端请求
  • 2000 - 2999 服务端响应
  • 3000+ 服务端主动推送

websocket连接

javascript
var ws = new WebSocket('http://localhost:9999/ws')

发送心跳

心跳超时为30秒,连续两次超时将断开连接

请求

json
{
  "type": 1000,
  "payload": {}
}

响应

json
{
  "type": 2000,
  "payload": {}
}

服务端主动推送

只包含transaction基本信息

json
{
  "type": 3000,
  "payload": {
    "id": "b56cb03d-855c-48a2-81e8-bbf71f285ecf",
    "method": "GET",
    "host": "api.zhihu.com",
    "path": "/user-permission",
    "duration": 235519397,
    "response_status_code": 200,
    "response_err": "",
    "response_content_type": "application/json",
    "response_len": 135
  }
}

获取transaction详情

请求

json
{
  "type": 1002,
  "payload": {
    "id": "b56cb03d-855c-48a2-81e8-bbf71f285ecf"
  }
}

响应

…

请求重放

请求

json
{
  "type": 1001,
  "payload": {
    "id": "b56cb03d-855c-48a2-81e8-bbf71f285ecf"
  }
}

响应

json
{
  "type": 2001,
  "payload": {
    "err": ""
  }
}

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gogohttpproxymitmproxy

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言