forked from tcc0lin/arida
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
106 lines (96 loc) · 3.18 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : app.py
@Time : 2020/09/22 18:52:11
@Author : Lateautumn4lin
@Version : 1.0
@Contact : Lateautumn4lin
@License : (C)Copyright 2020
@Desc : None
'''
from pathlib import Path
from pydantic import BaseModel, Field, create_model
from fastapi import APIRouter
from fastapi.openapi.utils import get_openapi
import time
import os
import frida
from starlette.applications import Starlette
from fastapi import FastAPI
from loguru import logger
from utils.generate_function import generate_function
from utils import (
name_transform,
detect_frida_state,
start_frida_server,
get_app_info
)
from config import *
# 配置相关函数的参数类型列表
function_params_hints = {
"encryptData": [0, 0, 0, 0, "", 0, 0, 0, 0, 0, 0]
}
# app相关信息
_frida_js_path1 = Path(__file__).absolute().parent/"apps/yuxueyuan.js"
_frida_js_path = Path(__file__).absolute().parent/"apps/kuaiduizuoye.js"
_package_name = "com.kuaiduizuoye.scan"
_package_name1 = "com.drcuiyutao.babyhealth"
os.environ["EXECJS_RUNTIME"]="Noe"
# frida启动前检测
if not detect_frida_state():
# 启动frida-server,增加延迟防止附加失败
start_frida_server()
time.sleep(3)
for app_info in INJECTION_APPS:
session = frida.get_usb_device().attach(app_info["package_name"])
app_info["absolute_path"] = Path(__file__).absolute().parent / \
f"apps/{app_info['path']}.js"
script = session.create_script(
open(
app_info["absolute_path"],
encoding="utf-8"
).read()
)
script.load()
app_info["script"] = script
def init_app() -> Starlette:
app = FastAPI()
# 每个app创建特有路由
for app_info in INJECTION_APPS:
router = APIRouter()
for api_name, params in get_app_info(parse_path=PRASE_PATH, frida_js_path=app_info["absolute_path"]).items():
params_dict = dict(zip(params, function_params_hints[api_name])) if (
api_name in function_params_hints) else dict.fromkeys(params, "bb")
model_name = f"{api_name}Model"
Model = create_model(model_name, **params_dict)
new_api_name = name_transform(api_name)
func = generate_function(
new_api_name,
app_info["script"],
model_name,
Model
)
router.add_api_route(f"/{new_api_name}", func, methods=["POST"])
app.include_router(
router,
prefix=f"/{app_info['path']}",
tags=[app_info["name"]]
)
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Arida框架",
version="0.0.1",
description="基于FastAPI实现的Frida-RPC工具 https://github.com/lateautumn4lin/arida",
routes=app.routes,
)
openapi_schema["info"]["x-logo"] = {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
}
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
return app
app = init_app()