GrassClipper/proxy/proxy.py

101 lines
2.8 KiB
Python
Raw Normal View History

2022-04-20 02:15:17 +00:00
##
#
# Copyright (C) 2002-2022 MlgmXyysd All Rights Reserved.
#
##
##
#
# Anime game script for mitmproxy
2022-04-20 02:15:17 +00:00
#
# https://github.com/MlgmXyysd/
#
# *Original fiddler script from https://github.lunatic.moe/fiddlerscript
#
# Environment requirement:
# - mitmdump from mitmproxy
#
# @author MlgmXyysd
# @version 1.0
#
##
2022-04-20 02:33:17 +00:00
import string
from mitmproxy import ctx
2022-04-20 02:15:17 +00:00
from mitmproxy import http
class MlgmXyysd_Anime_Game_Proxy:
2022-04-20 02:15:17 +00:00
2022-04-20 02:33:17 +00:00
def load(self, loader):
loader.add_option(
name = "ip",
typespec = str,
2022-04-26 01:59:14 +00:00
default = "127.0.0.1",
2022-04-20 02:33:17 +00:00
help = "IP address to replace",
)
2022-04-24 07:32:17 +00:00
loader.add_option(
name = "port",
typespec = int,
default = 80,
help = "Port to replace",
)
2022-04-24 23:17:23 +00:00
loader.add_option(
name = "use_https",
typespec = bool,
default = True,
help = "Use HTTPS",
)
2022-04-20 02:15:17 +00:00
def request(self, flow: http.HTTPFlow) -> None:
# This can also be replaced with another IP address.
2022-04-20 02:33:17 +00:00
REMOTE_HOST = ctx.options.ip
2022-04-24 07:32:17 +00:00
REMOTE_PORT = ctx.options.port
2022-04-20 02:15:17 +00:00
LIST_DOMAINS = [
"api-os-takumi.mihoyo.com",
"hk4e-api-os-static.mihoyo.com",
"hk4e-sdk-os.mihoyo.com",
"dispatchosglobal.yuanshen.com",
"osusadispatch.yuanshen.com",
"account.mihoyo.com",
"log-upload-os.mihoyo.com",
"dispatchcntest.yuanshen.com",
"devlog-upload.mihoyo.com",
"webstatic.mihoyo.com",
"log-upload.mihoyo.com",
"hk4e-sdk.mihoyo.com",
"api-beta-sdk.mihoyo.com",
"api-beta-sdk-os.mihoyo.com",
"cnbeta01dispatch.yuanshen.com",
"dispatchcnglobal.yuanshen.com",
"cnbeta02dispatch.yuanshen.com",
"sdk-os-static.mihoyo.com",
"webstatic-sea.mihoyo.com",
"webstatic-sea.hoyoverse.com",
"hk4e-sdk-os-static.hoyoverse.com",
"sdk-os-static.hoyoverse.com",
"api-account-os.hoyoverse.com",
"hk4e-sdk-os.hoyoverse.com",
2022-04-23 09:16:00 +00:00
"overseauspider.yuanshen.com",
"gameapi-account.mihoyo.com",
"minor-api.mihoyo.com",
"public-data-api.mihoyo.com",
"uspider.yuanshen.com",
"sdk-static.mihoyo.com",
"abtest-api-data-sg.hoyoverse.com",
"log-upload-os.hoyoverse.com"
2022-04-20 02:15:17 +00:00
]
if flow.request.host in LIST_DOMAINS:
2022-04-24 23:17:23 +00:00
if ctx.options.use_https:
flow.request.scheme = "https"
else:
flow.request.scheme = "http"
2022-04-20 02:15:17 +00:00
flow.request.host = REMOTE_HOST
2022-04-24 07:32:17 +00:00
flow.request.port = REMOTE_PORT
2022-04-20 02:15:17 +00:00
addons = [
MlgmXyysd_Anime_Game_Proxy()
2022-04-20 02:15:17 +00:00
]