-
Notifications
You must be signed in to change notification settings - Fork 6
/
pretendo_addon.py
59 lines (49 loc) · 2.02 KB
/
pretendo_addon.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from mitmproxy import http, ctx
class PretendoAddon:
def load(self, loader) -> None:
loader.add_option(
name="pretendo_redirect",
typespec=bool,
default=True,
help="Redirect all requests from Nintendo to Pretendo",
)
loader.add_option(
name="pretendo_host",
typespec=str,
default="",
help="Host to send Pretendo requests to (keeps the original host in the Host header)",
)
loader.add_option(
name="pretendo_host_port",
typespec=int,
default=80,
help="Port to send Pretendo requests to (only applies if pretendo_host is set)",
)
loader.add_option(
name="pretendo_http",
typespec=bool,
default=False,
help="Sets Pretendo requests to HTTP (only applies if pretendo_host is set)",
)
def request(self, flow: http.HTTPFlow) -> None:
if ctx.options.pretendo_redirect:
if "nintendo.net" in flow.request.pretty_host:
flow.request.host = flow.request.pretty_host.replace(
"nintendo.net", "pretendo.cc"
)
elif "nintendowifi.net" in flow.request.pretty_host:
flow.request.host = flow.request.pretty_host.replace(
"nintendowifi.net", "pretendo.cc"
)
if ctx.options.pretendo_host and (
"pretendo.cc" in flow.request.pretty_host
or "pretendo.network" in flow.request.pretty_host
or "pretendo-cdn.b-cdn.net" in flow.request.pretty_host
):
original_host = flow.request.host_header
flow.request.host = ctx.options.pretendo_host
flow.request.port = ctx.options.pretendo_host_port
flow.request.host_header = original_host
if ctx.options.pretendo_http:
flow.request.scheme = "http"
addons = [PretendoAddon()]