import
argparse
import
urllib
from
urllib.parse
import
quote, unquote
from
threading
import
Thread
from
http.server
import
HTTPServer, BaseHTTPRequestHandler
import
sys
import
requests
import
frida
import
re
class
RequestHandler(BaseHTTPRequestHandler):
def
do_REQUEST(
self
):
content_length
=
int
(
self
.headers.get(
'content-length'
,
0
))
self
.send_response(
200
)
self
.send_header(
'Content_Length'
,
str
(content_length))
self
.send_header(
'X-Mirror-Server'
,
'True'
)
self
.send_header(
'TMF_apiName'
,
self
.headers.get(
'TMF_apiName'
))
self
.end_headers()
self
.wfile.write(
self
.rfile.read(content_length))
def
do_RESPONSE(
self
):
content_length
=
int
(
self
.headers.get(
'content-length'
,
0
))
self
.send_response(
200
)
self
.send_header(
'Content_Length'
,
str
(content_length))
self
.send_header(
'X-Mirror-Server'
,
'True'
)
self
.end_headers()
self
.wfile.write(
self
.rfile.read(content_length))
def
echo_server_thread():
print
(
'start echo server at port {}'
.
format
(
28080
))
server
=
HTTPServer(('',
28080
), RequestHandler)
server.serve_forever()
t
=
Thread(target
=
echo_server_thread)
t.daemon
=
True
t.start()
proxies
=
{
'http'
:
'http://127.0.0.1:8080'
}
def
on_message(message, data):
if
message[
'type'
]
=
=
'send'
:
payload
=
message[
'payload'
]
TAG
=
payload[
'TAG'
]
if
TAG
=
=
'Request'
:
RequestBody
=
unquote(payload[
"RequestBody"
])
requestHeaders
=
{
'X-Turbo_Intruder'
:
's'
}
requestURL
=
"http://127.0.0.1:28080/Request/"
request
=
requests.request(
"REQUEST"
, requestURL, proxies
=
proxies, headers
=
requestHeaders, data
=
RequestBody.encode(
"utf-8"
))
request.encoding
=
'utf-8'
script.post({
"modify_requestBody"
: request.text})
elif
TAG
=
=
'Response'
:
ResponseBody
=
payload[
"ResponseBody"
]
responseURL
=
"http://127.0.0.1:28080/Response"
response
=
requests.request(
"RESPONSE"
, responseURL, proxies
=
proxies, data
=
ResponseBody.encode(
'utf-8'
))
script.post({
"modify_responseBody"
: response.text})
else
:
print
(
"error"
, message)
process
=
frida.get_device_manager().add_remote_device(
'127.0.0.1:26666'
).attach(
'中文包名'
)
with
open
(
"dodonew.js"
,
"r"
, encoding
=
'utf-8'
) as f:
js_code
=
f.read()
script
=
process.create_script(js_code)
script.on(
'message'
, on_message)
script.load()
sys.stdin.read()