-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathapp.py
457 lines (414 loc) · 14 KB
/
app.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
from flask import Flask, render_template, request, jsonify, g, Response, stream_with_context
from flask_socketio import SocketIO, emit
from werkzeug.utils import secure_filename
from threading import Thread
import frida
import json
import os
import time
import argparse
from threading import Event
import gpapi
from getapklist import Getlists
from downloader import Downloader
from assets import Assets
from soFrida import soFrida
from awstester import awsTester
from FridaGUI import FridaGUI
from PresetScript import PresetScript
app = Flask(__name__)
ps = PresetScript()
fg = FridaGUI(ps)
app.secret_key = "secret"
socketio = SocketIO(app, async_mode="threading", engineio_logger=True)
BASE_URI = os.path.dirname(__file__)
getlist = Getlists(socketio)
downloader = Downloader(socketio)
sofrida = soFrida(socketio)
at = awsTester(socketio)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/apk_download")
def apk_download_layout():
return render_template("apk_download.html")
@app.route("/assets")
def assets_layout():
asset = Assets()
asset_infos = asset.get_exist_sdk()
return render_template("assets.html", asset_infos=asset_infos)
@app.route("/keylist")
def keylist_layout():
asset = Assets()
key_infos = asset.get_exist_key()
return render_template("keylist.html", key_infos=key_infos)
#device
@app.route("/devices", methods=["GET"])
def devices():
devices = fg.get_device_list()
return render_template("modal/device.html", devices=devices)
@app.route("/device", methods=["GET"])
def device():
return jsonify(serial=fg.serial)
@app.route("/serial/<serial>", methods=["GET"])
def set_serial(serial):
fg.serial = serial
return jsonify(
serial=fg.serial
)
@socketio.on("connect", namespace="/device")
def installed_connect():
if fg.serial != "":
device = fg.get_current_device()
socketio.emit("device", {"devices":[device]}, namespace="/device")
else:
devices = fg.get_device_list()
socketio.emit("device", {"devices":devices}, namespace="/device")
#installed
@app.route("/installed")
def installed_layout():
return render_template("installed.html")
@app.route("/installed_list/<serial>", methods=["GET"])
def installed_list_layout(serial):
package_list = fg.installed_list(serial)
return render_template("card/installed.html", result=package_list)
@socketio.on("pull", namespace="/installed")
def apk_pull(data):
for package in data['list']:
fg.apk_pull(package)
socketio.emit("pull_res", {"name":package['name']}, namespace="/installed")
#download
@app.route("/downloaded")
def downloaded_layout():
downloaded_list = fg.get_downloaded_list()
return render_template("downloaded.html", result=downloaded_list)
@socketio.on("remove", namespace="/donwloaded")
def apk_remove(data):
for package in data['list']:
fg.apk_remove(package)
socketio.emit("remove_res", {"name":package}, namespace="/donwloaded")
#dex or class
@app.route("/dex/<package_name>")
def dex(package_name):
fg.package_name = package_name
return render_template("dex.html")
@app.route("/memory/<pid>/<package_name>")
def memory(pid, package_name):
fg.pid = pid
fg.package_name = package_name
return render_template("memory.html")
@app.route("/classes_android")
def get_classes_android():
return get_classes_apk(fg.package_name)
@app.route("/classes_android/<package_name>", methods=["GET"])
def get_classes_apk(package_name):
classes = fg.get_dex(package_name)
class_list = []
for c in classes:
class_list.append(c)
return jsonify(
result=class_list
)
@app.route("/classes_ios")
def get_classes_ios():
return get_classes_memory(fg.pid)
@app.route("/classes_ios/<pid>", methods=["GET"])
def get_classes_memory(pid):
classes = fg.get_classes(pid)
return jsonify(
result=classes
)
@app.route("/class_table", methods=["POST"])
def class_table():
class_list = request.get_json(force=True)['list']
return render_template("card/class_table.html", result=class_list)
@app.route("/methods/<class_name>", methods=["GET"])
def methods(class_name):
methods = fg.get_methods(class_name)
if fg.is_ios:
return render_template("card/method_table_ios.html", result=methods)
else:
return render_template("card/method_table.html", result=methods)
@app.route("/code/<class_name>/<index>", methods=["GET"])
def code(class_name, index):
code = fg.intercept_code(class_name, index)
return render_template("card/code.html", code=code)
@app.route("/codes/<class_name>", methods=["POST"])
def codes(class_name):
index_list = request.get_json(force=True)['list']
code = ""
for index in index_list:
code += fg.intercept_code(class_name, index)+"\n"
return render_template("card/code.html", code=code)
@app.route("/load", methods=["POST"])
def load():
fg.loaded = False
data = request.get_json(force=True)
code = data['code']
pid = int(data['pid'])
package_name = data['package_name']
def callback(message, data):
if "payload" in message:
socketio.emit("load_result", message['payload'], namespace="/load")
else:
socketio.emit("load_error", message['stack'], namespace="/load")
socketio.start_background_task(fg.load, pid=pid, js=code, callback=callback)
#fg.load(pid, code, callback)
return jsonify(
result = "success"
)
@app.route("/spawn", methods=["POST"])
def spawn():
fg.loaded = False
data = request.get_json(force=True)
code = data['code']
package_name = data['package_name']
process = fg.spawn()
socketio.emit("process", {"processes":[process]}, namespace="/process")
def callback(message, data):
if "payload" in message:
socketio.emit("load_result", message['payload'], namespace="/load")
else:
socketio.emit("load_error", message['stack'], namespace="/load")
socketio.start_background_task(fg.load_and_resume, pid=process['pid'], js=code, callback=callback)
return jsonify(
result = "success"
)
@socketio.on("script_unload", namespace="/load")
def unload():
fg.loaded = False
@socketio.on("connect", namespace="/process")
def connect_process():
process_list = fg.get_process()
if process_list == None:
socketio.emit("process", {"processes":[]}, namespace="/process")
else:
if len(process_list) == 0:
process = fg.spawn()
fg.resume(process['pid'])
socketio.emit("process", {"processes":[process]}, namespace="/process")
else:
socketio.emit("process", {"processes":process_list}, namespace="/process")
#aws
@app.route("/awstest/<package_name>", methods=['GET'])
def awstest_layout(package_name):
asset = Assets()
ass = asset.get(package_name)
dic_service = []
for s in ass['service'].split(","):
dic_service.append("/static/icons/AWS-"+s+".svg")
return render_template("awstest.html", services=dic_service)
def downfile_check(package_name):
return os.path.exists(os.path.join("./apk/") + package_name + '.apk')
@socketio.on("search", namespace="/apk_download")
def search(data):
downloader.set_locale(data['locale'])
getlist.init_request(data['mode'].lower().strip(), data['text'], data['locale'].split("_")[1])
socketio.start_background_task(target=getlist.get_pkginfo)
@app.route("/google_login_check", methods=['GET'])
def google_login_check():
if downloader.authSubToken == "":
return jsonify(
result="fail"
)
else:
return jsonify(
result="success"
)
@app.route("/google_login", methods=['POST'])
def google_login():
id = request.form['id']
pw = request.form['pw']
if downloader.firstlogin(id, pw):
return jsonify(
result="success"
)
else:
return jsonify(
result="fail"
)
@socketio.on("download", namespace="/apk_download")
def download(message):
package_list = message['list']
for package_name in message['list']:
asset = Assets()
info = getlist.result[package_name]
if not asset.exist(package_name):
asset.add(package_name, info['title'], int(info['popular'].replace(",","")), info['category'])
asset.close()
else:
ass = asset.get(package_name)
if ass['popular'] < int(info['popular'].replace(",","")):
asset.update_asset(package_name, ['title', 'popular', 'category'], [info['title'], int(info['popular'].replace(",","")), info['category'], package_name])
socketio.start_background_task(target=downloader.download_packages, package_list=package_list)
@socketio.on("select_remove", namespace="/assets")
def select_remove(message):
asset = Assets()
for package in message['list']:
try:
os.remove(os.path.join("./apk/") + package + '.apk')
except:
pass
socketio.emit("remove_result", {"result":asset.delete_one(package),"package":package}, namespace="/assets")
@app.route("/analyze/<package_name>", methods=["GET"])
def analyze(package_name):
sofrida.set_pkgid(package_name)
return render_template("analyze.html", package_name=package_name)
@app.route("/import_file", methods=["POST"])
def import_file():
f = request.files['data']
f.save(secure_filename(f.filename))
downloader.set_locale(request.form['locale'])
file_data = open(f.filename, "r").read().strip()
pkg_list = file_data.split("\n")
return jsonify(
list=pkg_list
)
@socketio.on("import_file_result", namespace="/apk_download")
def import_file_result(msg):
get_list = {}
i = 1
for pkg_id in msg['pkg_list']:
getlist.init_request("pkgid", pkg_id, downloader.locale.split("_")[1])
getlist.get_pkginfo_for_socket_io()
while getlist.finished == False:
pass
get_list[pkg_id] = getlist.result[pkg_id]
socketio.emit("log", {"type": "log","data":"("+str(i)+"/"+str(len(msg['pkg_list']))+")" +pkg_id+ " pkgid info loaded."}, namespace="/apk_download")
i+=1
getlist.result = get_list
socketio.emit("exit", {}, namespace="/apk_download")
@socketio.on('soFrida_start', namespace="/analyze")
def soFrida_start(message):
socketio.start_background_task(target=sofrida.soFrida_start, serial=fg.serial)
@socketio.on('soFrida_stop', namespace="/analyze")
def soFrida_stop(message):
sofrida.isStop = True
if "keys" in message:
asset = Assets()
asset.update_keys(message['package_name'], message['keys'])
asset.update_status(message['package_name'], "analyzed")
@socketio.on("awstest_start" ,namespace="/awstest")
def awstest_start(message):
package_name = message['package_name']
asset = Assets()
keys = asset.get(package_name)
socketio.start_background_task(target=awstest, package_name=package_name, keys=keys)
@socketio.on("manual_log_cmd", namespace="/awstest")
def manual_log_cmd(data):
global at
for line in at.manual_check(data["data"]):
if line != "":
socketio.emit("manual_log", {"data":line}, namespace="/awstest")
@app.route("/counties")
def countries():
return jsonify(
list=json.loads(open(BASE_URI+"/static/locale.json","r", encoding="utf-8").read())
)
def awstest(package_name, keys):
at.set_keys(package_name, keys['access_key_id'], keys['secret_key_id'], keys['session_token'], keys['region'])
auto_check = False
isvuln = False
for service in keys['service'].split(","):
if service == "s3":
auto_check = True
isvuln = isvuln or at.s3_check(keys['bucket'], "ls")
elif service == "kinesis":
auto_check = True
isvuln = isvuln or at.kinesis_check("list_streams")
elif service == "firehose":
auto_check = True
isvuln = isvuln or at.firehose_check("list_delivery_streams")
asset = Assets()
asset.update_one(package_name, "vulnerable", 1 if isvuln else 0)
if not auto_check:
socketio.emit("log", {"service":"auto_check", "type":"no", "msg":"[!] This app is not using \"s3\", \"kinesis\", \"firehose\"."}, namespace="/awstest")
socketio.emit("manual_log", {"data":"[!] AWS Configuration Start!!"}, namespace="/awstest")
at.configure()
socketio.emit("manual_log", {"data":"[!] AWS Configuration Complete!"}, namespace="/awstest")
#ios_process
@app.route("/ios_process")
def ios_process_layout():
return render_template("ios_process.html")
@app.route("/ios_process_list/<serial>", methods=["GET"])
def ios_process_list_layout(serial):
process_list = fg.get_ios_process_list(serial)
return render_template("card/ios_process.html", result=process_list)
#scripts
@app.route("/saved")
def saved():
return render_template("modal/saved_table.html", result=ps.saved_list())
@app.route("/save", methods=["POST"])
def save():
data = request.get_json(force=True)
code = data['code']
name = data['name']
over = data['overwrite']
if over:
if ps.save(code, name, over):
return jsonify(
result="success"
)
else:
if ps.check_name(name):
if ps.save(code, name, over):
return jsonify(
result="success"
)
return jsonify(
result="fail",
msg=ps.msg
)
@app.route("/content_search", methods=["POST"])
def content_search():
data = request.get_json(force=True)
text = data['text']
return render_template("modal/saved_table.html", result=ps.search(text))
@app.route("/set_script", methods=["POST"])
def set_script():
data = request.get_json(force=True)
name = data['name']
doset = data['doset']
if ps.set_script(name, doset):
return jsonify(
result="success"
)
else:
return jsonify(
result="fail"
)
@app.route("/delete_script", methods=["POST"])
def delete_script():
data = request.get_json(force=True)
name = data['name']
if ps.delete_script(name):
return jsonify(
result="success"
)
else:
return jsonify(
result="fail"
)
@app.route("/view_script", methods=["POST"])
def view_script():
data = request.get_json(force=True)
name = data['name']
code = ps.view_script(name)
if code != None:
return jsonify(
result="success",
code=code
)
else:
return jsonify(
result="fail"
)
if __name__ == '__main__':
ap = argparse.ArgumentParser(description='SoFridaGUI')
ap.add_argument('-p', '--proxy', dest='proxy', required=False, help='http://xxx.xxx.xxx.xxx:YYYY')
args = ap.parse_args()
if args.proxy is not None:
proxy = {"http":args.proxy, "https":args.proxy}
downloader.set_proxy(proxy)
getlist.set_proxy(proxy)
socketio.run(app, host='127.0.0.1', port=8888, debug=True, log_output=True)