SCHALE.GameServer/Mitmproxy_Readme_ZH.md

128 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
# 🌐 **Mitmproxy 方案使用教程**
*(By 北野樱奈)*
---
## 🛠️ **前置要求**
1. 下载并安装 [**Mitmproxy**](https://mitmproxy.org/)。
2. 熟悉 **WireGuard** 和 **Python 脚本**的基本操作。
3. 准备以下设备:
- 一台运行 **Mitmproxy** 的主机。
- 一台客户端设备(如 Android 模拟器或手机)。
---
## 📥 **第一步:安装 Mitmproxy**
### 📂 安装步骤
#### Linux / MacOS
```bash
# Ubuntu/Debian
sudo apt update
sudo apt install mitmproxy
# macOS
brew install mitmproxy
```
#### Windows
从 [**mitmproxy.org**](https://mitmproxy.org/) 下载 `.exe` 安装程序并按说明完成安装。
### ✅ 验证安装
运行以下命令确保安装成功:
```bash
mitmproxy --version
```
---
## 🔑 **第二步:安装 CA 证书**
### 📜 操作步骤
1. 启动 `mitmproxy` 并生成证书:
```bash
mitmdump
```
2. 找到生成的证书文件:
- 证书位于:
`C:\Users\<用户名>\.mitmproxy\mitmproxy-ca-cert.crt`Windows
`~/.mitmproxy/`Linux / MacOS
3.`mitmproxy-ca-cert.crt` 重命名为 `c8750f0d.0`
4. 使用以下命令将证书移动到系统 CA 目录并设置权限:
```bash
adb root
adb remount
adb shell mv /sdcard/c8750f0d.0 /system/etc/security/cacerts/
adb shell chmod 644 /system/etc/security/cacerts/c8750f0d.0
adb reboot
```
---
## 🔧 **第三步:配置重定向脚本**
从仓库下载 `redirect_server.py` 并修改其中的 `SERVER_HOST`
```python
import gzip
import json
from mitmproxy import http
SERVER_HOST = '修改这里' # 替换为你的服务器 IP
SERVER_PORT = 80
REWRITE_HOST_LIST = [
'ba-jp-sdk.bluearchive.jp',
'prod-gateway.bluearchiveyostar.com',
'prod-game.bluearchiveyostar.com',
]
```
---
## 🚀 **第四步:启动 Mitmproxy**
使用以下命令加载重定向脚本并启动代理:
```bash
mitmweb -m wireguard --no-http2 -s redirect_server.py --set termlog_verbosity=warn --ignore <你的IP地址>
```
### 📝 参数说明:
- `-m wireguard`: 使用 WireGuard 作为网络层协议。
- `--no-http2`: 禁用 HTTP/2 提高兼容性。
- `-s redirect_server.py`: 加载重定向脚本。
- `--set termlog_verbosity=warn`: 仅显示警告级别日志。
访问 `http://localhost:8081` 查看 Mitmproxy 界面。
---
## 🔄 **第五步:安装 WireGuard**
### 📥 安装步骤
- **Android**: 从 [**Google Play**](https://play.google.com/store/apps/details?id=com.wireguard.android) 下载。
- **其他平台**: 参考 [**WireGuard 官方安装指南**](https://www.wireguard.com/install/)。
### ⚙️ 配置步骤
1. 打开 WireGuard 客户端并扫描 Mitmproxy 提供的二维码。
2. 完成后启用该配置,将所有流量路由到 `Mitmproxy`
---
## 🛠️ **故障排查**
### ❌ 错误Client TLS handshake failed
- 检查电脑与客户端是否安装了相同的 CA 证书。
- 确保 CA 证书安装为系统证书。
### ❌ 安卓端证书消失
- 使用 MT 管理器授予 SU 权限。
- 手动前往 `/system/etc/security/cacerts/`,重新设置权限为 `644`
---
🎉 **完成!**