-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
230 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,15 @@ FROM mitmproxy/mitmproxy | |
LABEL MAINTAINER [email protected] | ||
LABEL VERSION 1.0.0 | ||
|
||
RUN apt-get update && apt-get install -y curl && \ | ||
RUN apt-get update && apt-get install -y curl nginx && \ | ||
pip install requests | ||
|
||
COPY mitmproxy.py /mitmproxy.py | ||
|
||
EXPOSE 8080 8081 | ||
COPY nginx.conf /etc/nginx/nginx.conf | ||
|
||
ENTRYPOINT ["mitmweb", "--web-host", "0.0.0.0", "--web-port", "8081", "--listen-port", "8080", "-s", "/mitmproxy.py"] | ||
COPY --chmod=755 entrypoint.sh / | ||
|
||
EXPOSE 80 8080 8081 | ||
|
||
ENTRYPOINT [ "/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# 设置环境变量 | ||
export MITMPROXY_USER=${MITMPROXY_USER:-""} | ||
export MITMPROXY_PASS=${MITMPROXY_PASS:-""} | ||
|
||
# 构建 mitmweb 命令 | ||
MITMWEB_CMD="mitmweb --web-host 0.0.0.0 --web-port 8081 --listen-port 8080 -s /mitmproxy.py $@" | ||
|
||
# 如果设置了用户名和密码,添加代理认证 | ||
if [ -n "$MITMPROXY_USER" ] && [ -n "$MITMPROXY_PASS" ]; then | ||
MITMWEB_CMD="$MITMWEB_CMD --proxyauth $MITMPROXY_USER:$MITMPROXY_PASS" | ||
fi | ||
|
||
nginx -g 'daemon off;' & | ||
|
||
# 执行 mitmweb 命令 | ||
exec $MITMWEB_CMD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 80; | ||
server_name localhost; | ||
|
||
location / { | ||
proxy_pass http://localhost:8081; | ||
proxy_set_header Host localhost:8081; | ||
proxy_set_header Origin http://localhost:8081; | ||
|
||
expires off; | ||
proxy_http_version 1.1; | ||
proxy_redirect http://$http_host:8081 http://$http_host; | ||
proxy_buffering off; | ||
|
||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Cookie $http_cookie; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,100 @@ | ||
def request(flow): | ||
flow.request.headers["Custom-Header"] = "Custom-Value" | ||
def handle_event(flow, event_type): | ||
print(f"Event: {event_type}") | ||
|
||
if event_type == 'request': | ||
# 处理请求 | ||
# 可以修改请求头、URL、方法等 | ||
flow.request.headers["X-Custom-Request-Header"] = "CustomRequestValue" | ||
print(f"Request URL: {flow.request.url}") | ||
|
||
elif event_type == 'response': | ||
# 处理响应 | ||
# 可以修改响应头、内容、状态码等 | ||
flow.response.headers["X-Custom-Response-Header"] = "CustomResponseValue" | ||
print(f"Response status code: {flow.response.status_code}") | ||
|
||
elif event_type == 'client_connected': | ||
# 客户端连接时触发 | ||
print(f"Client connected: {flow}") | ||
|
||
elif event_type == 'client_disconnected': | ||
# 客户端断开连接时触发 | ||
print(f"Client disconnected: {flow}") | ||
|
||
elif event_type == 'server_connect': | ||
# 服务器连接开始时触发 | ||
print(f"Server connecting: {flow}") | ||
|
||
elif event_type == 'server_connected': | ||
# 服务器连接建立时触发 | ||
print(f"Server connected: {flow}") | ||
|
||
elif event_type == 'server_disconnected': | ||
# 服务器断开连接时触发 | ||
print(f"Server disconnected: {flow}") | ||
|
||
elif event_type == 'tcp_start': | ||
# TCP连接开始时触发 | ||
print(f"TCP connection started: {flow}") | ||
|
||
elif event_type == 'tcp_message': | ||
# 收到TCP消息时触发 | ||
print(f"TCP message: {flow}") | ||
|
||
elif event_type == 'tcp_error': | ||
# TCP连接出错时触发 | ||
print(f"TCP error: {flow}") | ||
|
||
elif event_type == 'tcp_end': | ||
# TCP连接结束时触发 | ||
print(f"TCP connection ended: {flow}") | ||
|
||
elif event_type == 'http_connect': | ||
# 处理HTTP CONNECT请求 | ||
print(f"HTTP CONNECT: {flow}") | ||
|
||
elif event_type == 'websocket_handshake': | ||
# WebSocket握手完成时触发 | ||
print(f"WebSocket handshake: {flow}") | ||
|
||
elif event_type == 'websocket_start': | ||
# WebSocket连接开始时触发 | ||
print(f"WebSocket started: {flow}") | ||
|
||
elif event_type == 'websocket_message': | ||
# 收到WebSocket消息时触发 | ||
print(f"WebSocket message: {flow.websocket.messages[-1].content}") | ||
|
||
elif event_type == 'websocket_error': | ||
# WebSocket连接出错时触发 | ||
print(f"WebSocket error: {flow}") | ||
|
||
elif event_type == 'websocket_end': | ||
# WebSocket连接结束时触发 | ||
print(f"WebSocket ended: {flow}") | ||
|
||
elif event_type == 'next_layer': | ||
# 用于协议嗅探和动态协议切换 | ||
print(f"Next layer: {flow}") | ||
|
||
elif event_type == 'configure': | ||
# 配置发生变化时触发 | ||
print(f"Configuration changed: {flow}") | ||
|
||
elif event_type == 'done': | ||
# addon关闭时触发 | ||
print("Addon is shutting down") | ||
|
||
elif event_type == 'load': | ||
# addon首次加载时触发 | ||
print(f"Addon loaded: {flow}") | ||
|
||
elif event_type == 'running': | ||
# 代理完全启动并运行时触发 | ||
print("Proxy is running") | ||
|
||
# 可以根据需要添加更多的事件处理逻辑 | ||
# 例如,可以在这里添加日志记录、数据分析或其他自定义操作 | ||
|
||
# 主执行点 | ||
handle_event(flow, event_type) |