-
Notifications
You must be signed in to change notification settings - Fork 3
/
mitm.py
39 lines (32 loc) · 1.39 KB
/
mitm.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
36
37
38
39
"""MITM script for Worst Game."""
# pyright: reportMissingImports=false
# vs code pls shut up.
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 nextlayer.context.client.tls and sni and (sni.endswith("yuanshen.com") or sni.endswith("mihoyo.com") or sni.endswith("hoyoverse.com") or sni.endswith("starrails.com")):
ctx.log('sni:' + sni)
nextlayer.context.server.address = ("127.0.0.1", 443)
def request(flow: http.HTTPFlow) -> None:
# flow.request.scheme = "http"
return
# pretty_host takes the "Host" header of the request into account
# if flow.request.pretty_url.startswith('http://log-upload-os.mihoyo.com'):
# flow.response = http.Response.make(
# 404, # (optional) status code
# b"404 not found", # (optional) content
# {"Content-Type": "text/html"} # (optional) headers
# )
# return