This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
proxy-for-proxy.py
35 lines (31 loc) · 1.96 KB
/
proxy-for-proxy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from mitmproxy import http
from mitmproxy import ctx
from mitmproxy.proxy import layer, layers
def load(loader):
# ctx.options.web_open_browser = False
# We change the connection strategy to lazy so that next_layer happens before we actually connect upstream.
ctx.options.connection_strategy = "lazy"
ctx.options.upstream_cert = False
ctx.options.ssl_insecure = True
def next_layer(nextlayer: layer.NextLayer):
# ctx.log(
# f"{nextlayer.context=}\n"
# f"{nextlayer.data_client()[:70]=}\n"
# )
sni = nextlayer.context.client.sni
# if sni and (sni.endswith("yuanshen.com") or sni.endswith("mihoyo.com") or sni.endswith("hoyoverse.com") or sni.endswith("starrails.com") or sni.endswith("bhsr.com") or sni.endswith("kurogame.com") or sni.endswith("zenlesszonezero.com") or sni.endswith("api.g3.proletariat.com") or sni.endswith("global01.os.honkaiimpact3.com") or sni.endswith("overseas01-appsflyer-report.honkaiimpact3.com") or sni.endswith("westglobal01.honkaiimpact3.com") or sni.endswith("bh3.com") and not (sni.endswith("bundle.bh3.com") or sni.endswith("qcloud.bh3.com") or sni.endswith("bh3rd-beta.bh3.com"))):
# ctx.log('sni:' + sni)
# nextlayer.context.server.address = ("127.0.0.1", 443)
def request(flow: http.HTTPFlow) -> None:
# flow.request.scheme = "http"
# pretty_host takes the "Host" header of the request into account
if flow.request.pretty_url.startswith('http://global01.west.honkaiimpact3.com') or "query_" in flow.request.pretty_url:
flow.request.host = "127.0.0.1"
flow.request.headers["Host"] = "127.0.0.1"
if flow.request.pretty_url.startswith('http://log-upload-os.mihoyo.com') or flow.request.pretty_url.startswith('http://client-report.bh3.com'):
flow.response = http.Response.make(
404, # (optional) status code
b"404 not found", # (optional) content
{"Content-Type": "text/html"} # (optional) headers
)
return