tls_mitm_server

package module
v0.2.1-alpha.hotfix1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2025 License: LGPL-3.0 Imports: 0 Imported by: 0

README

TLS MITM Server

Go Version License Version

一个基于Go实现的MITM代理服务器,支持自定义TLS指纹和多级代理链。

版本说明

当前版本:v0.2.1-alpha.hotfix1

我们遵循语义化版本规范进行版本管理。

功能特性

  • ✨ 中间人代理服务器,支持拦截和处理HTTP及HTTPS流量
  • 🔑 基于自签名CA证书的TLS会话拦截
  • 🎭 可自定义TLS Client Hello指纹,支持多种预设配置
  • ⛓️ 灵活的代理链配置,支持HTTP和SOCKS5上游代理
  • 📝 结构化日志记录,支持多种输出格式
  • 🚀 异步处理设计,高效的请求处理
  • 🔧 完善的配置选项和命令行参数支持

技术栈

  • Go 1.23+
  • utls - TLS指纹定制
  • goproxy - 代理服务器基础功能
  • zerolog - 高性能日志库

快速开始

安装
# 克隆仓库
git clone https://github.com/aberstone/tls_mitm_server.git

# 进入项目目录
cd tls_mitm_server

# 编译
make
生成CA证书

首次使用需要生成CA证书:

./build/gen-ca

此命令会在当前目录生成:

  • ca.crt - CA证书
  • ca.key - CA私钥
启动代理服务器
./build/mitm --port 8080 --ca-cert ca.crt --ca-key ca.key
配置选项
Usage of ./build/mitm:
  --port int            代理服务器监听端口 (默认 8080)
  --ca-cert string      CA证书路径 (默认 "ca.crt")
  --ca-key string       CA私钥路径 (默认 "ca.key")
  --fingerprint string  TLS指纹类型 (default, chrome, firefox等)
  --upstream string     上游代理URL (可选,支持HTTP和SOCKS5)
  --log-level string   日志级别 (debug, info, warn, error)
  --log-format string  日志格式 (text, json)
  --verbose            显示详细日志

架构设计

核心组件
graph TD
    A[入站请求] --> B{代理服务器}
    B --> C[请求分类]
    C --> D[HTTP请求]
    C --> E[HTTPS请求]
    E --> F[TLS拦截]

    subgraph TLS Transport
    F --> G[TLS指纹模拟]
    G --> H[TLS拨号器]
    H --> I{ProxyConnector}
    I --> J[直连]
    I --> K[上游代理]
    end

    subgraph 上游代理实现
    K --> L[HTTP代理]
    K --> M[SOCKS5代理]
    end

    D --> K
关键特性
  1. 模块化设计

    • 请求处理器接口
    • TLS指纹定制组件
    • 代理连接器抽象
    • 可扩展的上游代理支持
    • 可扩展的日志系统
  2. 高性能实现

    • 异步请求处理
    • 高效的日志记录
    • 合理的资源管理

开发指南

环境要求
  • Go 1.23+
  • Make
  • Git
本地开发
  1. 克隆仓库
git clone https://github.com/aberstone/tls_mitm_server.git
  1. 安装依赖
go mod download
  1. 运行测试
make test
  1. 构建项目
make
代码结构
.
├── cmd/                # 命令行工具
│   ├── mitm/          # 代理服务器
│   └── generate-ca/   # CA证书生成工具
├── internal/          # 内部包
│   ├── cert/         # 证书处理
│   ├── config/       # 配置管理
│   ├── errors/       # 错误处理
│   ├── fingerprint/  # TLS指纹
│   ├── interfaces/   # 接口定义
│   ├── logging/      # 日志系统
│   ├── proxy/        # 代理核心
│   └── transport/    # 传输层
└── build/            # 编译产物

贡献指南

我们欢迎任何形式的贡献!在提交代码前,请确保阅读:

贡献流程
  1. Fork 项目
  2. 创建特性分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'feat: add amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 提交Pull Request
提交规范

我们使用Conventional Commits规范:

  • feat: 新功能
  • fix: 修复
  • docs: 文档更新
  • style: 代码风格修改
  • refactor: 重构
  • test: 测试相关
  • chore: 构建/工具链/辅助工具的变动

许可证

本项目采用 GNU Lesser General Public License v3.0 (LGPL-3.0) 许可证。这意味着:

  • ✔️ 商业用途
  • ✔️ 修改
  • ✔️ 分发
  • ✔️ 私人使用
  • ❗ 必须公开源代码
  • ❗ 需要保留许可证和版权信息
  • ❗ 需要说明修改内容

查看 LICENSE 文件了解详情。

支持与反馈


⭐️ 如果这个项目对你有帮助,欢迎点Star支持!

Documentation

Overview

  • Copyright (C) 2024 aberstone *
  • This library is free software; you can redistribute it and/or
  • modify it under the terms of the GNU Lesser General Public
  • License as published by the Free Software Foundation; either
  • version 3 of the License, or (at your option) any later version. *
  • This library 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
  • Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public
  • License along with this library; if not, write to the Free Software
  • Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Package tls_mitm_server 实现了一个支持自定义 TLS 指纹的 MITM 代理服务器。 该代理服务器可以同时支持 HTTP 和 SOCKS5 协议,并且能够模拟不同浏览器的 TLS 指纹。

项目结构:

cmd/                    - 可执行程序目录
  ├── generate-ca/      - CA证书生成工具
  └── mitm/            - 代理服务器主程序

internal/              - 内部包实现
  ├── cert/           - 证书生成和管理
  ├── proxy/          - 代理服务器核心实现
  └── transport/      - 自定义传输层和TLS指纹实现

主要特性:

  • 支持HTTP和SOCKS5代理协议
  • 支持自定义TLS指纹(可模拟Chrome或Firefox)
  • 支持上游代理链式代理
  • 支持HTTPS解密和重加密
  • 提供证书生成和管理工具

使用示例:

# 生成CA证书
$ ./gen-ca -cert ca.crt -key ca.key

# 启动HTTP代理服务器(Chrome指纹)
$ ./mitm -port 8080 -ca-cert ca.crt -ca-key ca.key -browser chrome -protocol http

# 启动SOCKS5代理服务器(Firefox指纹)
$ ./mitm -port 1080 -ca-cert ca.crt -ca-key ca.key -browser firefox -protocol socks5

# 启动双协议代理服务器(Chrome指纹)
$ ./mitm -port 8888 -ca-cert ca.crt -ca-key ca.key -browser chrome -protocol both

Directories

Path Synopsis
cmd
generate-ca command
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
mitm command
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
internal
cert
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
config
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
errors
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
fingerprint
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
interfaces
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
logging
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
proxy
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
transport
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.
* Copyright (C) 2024 aberstone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL