80 lines
3.2 KiB
Python
80 lines
3.2 KiB
Python
import json
|
|
from mitmproxy import http
|
|
from mitmproxy.tools.main import mitmdump
|
|
import sys
|
|
from colorama import init, Fore, Style
|
|
|
|
# 初始化 colorama
|
|
init(autoreset=True)
|
|
|
|
class RequestAnalyzer:
|
|
"""分析 DuoPlus 注册相关的网络请求"""
|
|
|
|
def __init__(self):
|
|
self.target_domain = "my.duoplus.cn"
|
|
self.captured_requests = []
|
|
|
|
def request(self, flow: http.HTTPFlow) -> None:
|
|
"""处理请求"""
|
|
if self.target_domain in flow.request.pretty_host:
|
|
request_info = {
|
|
"method": flow.request.method,
|
|
"url": flow.request.pretty_url,
|
|
"headers": dict(flow.request.headers),
|
|
"body": None
|
|
}
|
|
|
|
# 尝试解析请求体
|
|
if flow.request.content:
|
|
try:
|
|
request_info["body"] = json.loads(flow.request.content.decode('utf-8'))
|
|
except:
|
|
request_info["body"] = flow.request.content.decode('utf-8', errors='ignore')
|
|
|
|
# 打印关键请求
|
|
if any(keyword in flow.request.pretty_url for keyword in ['auth', 'register', 'captcha', 'verify']):
|
|
print(f"\n{Fore.CYAN}[REQUEST] {flow.request.method} {flow.request.pretty_url}")
|
|
print(f"{Fore.YELLOW}Headers: {json.dumps(dict(flow.request.headers), indent=2, ensure_ascii=False)}")
|
|
if request_info["body"]:
|
|
print(f"{Fore.GREEN}Body: {json.dumps(request_info['body'], indent=2, ensure_ascii=False)}")
|
|
|
|
def response(self, flow: http.HTTPFlow) -> None:
|
|
"""处理响应"""
|
|
if self.target_domain in flow.request.pretty_host:
|
|
# 打印关键响应
|
|
if any(keyword in flow.request.pretty_url for keyword in ['auth', 'register', 'captcha', 'verify']):
|
|
print(f"\n{Fore.MAGENTA}[RESPONSE] {flow.response.status_code} for {flow.request.pretty_url}")
|
|
|
|
# 尝试解析响应体
|
|
if flow.response.content:
|
|
try:
|
|
response_body = json.loads(flow.response.content.decode('utf-8'))
|
|
print(f"{Fore.GREEN}Response: {json.dumps(response_body, indent=2, ensure_ascii=False)}")
|
|
except:
|
|
print(f"{Fore.RED}Response (raw): {flow.response.content.decode('utf-8', errors='ignore')[:200]}...")
|
|
|
|
# 创建分析器实例
|
|
analyzer = RequestAnalyzer()
|
|
|
|
def request(flow: http.HTTPFlow) -> None:
|
|
analyzer.request(flow)
|
|
|
|
def response(flow: http.HTTPFlow) -> None:
|
|
analyzer.response(flow)
|
|
|
|
if __name__ == "__main__":
|
|
print(f"""
|
|
{Fore.CYAN}=== DuoPlus 网络请求分析工具 ===
|
|
|
|
{Fore.YELLOW}使用方法:
|
|
1. 安装 mitmproxy: pip install mitmproxy
|
|
2. 运行代理: mitmdump -s analyze_requests.py -p 8080
|
|
3. 配置浏览器使用 127.0.0.1:8080 作为HTTP代理
|
|
4. 访问 https://my.duoplus.cn/sign-up 并执行注册操作
|
|
5. 查看控制台输出的请求和响应信息
|
|
|
|
{Fore.GREEN}提示:
|
|
- 关注包含 'auth', 'register', 'captcha', 'verify' 的请求
|
|
- 记录验证码相关的 app_id 和其他参数
|
|
- 保存完整的请求头和请求体格式
|
|
""") |