-
Notifications
You must be signed in to change notification settings - Fork 41
/
frida_script.py
258 lines (217 loc) · 8.79 KB
/
frida_script.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
from flask import Flask, render_template, request, jsonify
from flask_socketio import SocketIO
from colorama import Fore, Back, Style, init
import subprocess
import os
import json
import base64
import hashlib
import threading
import time
import signal
import logging
import re
app = Flask(__name__)
socketio = SocketIO(app)
process = None
SCRIPTS_DIRECTORY = f"{os.getcwd()}/scripts"
if "tmp" not in os.listdir("."):
os.mkdir("tmp")
class OsNotSupportedError(Exception):
pass
def get_device_type():
if os.name == 'nt':
return "Windows"
elif os.name == 'posix':
if os.uname().sysname == 'Darwin':
return "macOS"
else:
return "Linux"
else:
return "Unknown"
# adb status and connect
def run_adb_command(command, timeout=5):
try:
result = subprocess.run(command, capture_output=True, text=True, check=True, timeout=timeout)
return result.stdout
except subprocess.CalledProcessError as e:
return f"Error: ADB command failed. {e}"
def run_ideviceinfo(timeout=5):
try:
result = subprocess.run(["ideviceinfo"], capture_output=True, text=True, check=True, timeout=timeout)
return result.stdout
except subprocess.TimeoutExpired:
return "Error: ideviceinfo command timed out."
def there_is_adb_and_devices():
adb_is_active = False
available_devices = []
message = ""
try:
result = run_adb_command(["adb", "devices"])
connected_devices = result.strip().split('\n')[1:]
device_ids = [line.split('\t')[0] for line in connected_devices if line.strip()]
if device_ids:
for device_id in device_ids:
model = run_adb_command(["adb", "-s", device_id, "shell", "getprop", "ro.product.model"])
serial_number = run_adb_command(["adb", "-s", device_id, "shell", "getprop", "ro.serialno"])
versi_andro = run_adb_command(["adb", "-s", device_id, "shell", "getprop", "ro.build.version.release"])
available_devices.append({"model": model, "serial_number": serial_number, "versi_andro": versi_andro})
adb_is_active = True
message = "Device is available"
except Exception as e:
message = f"Error checking Android device connectivity: {e}"
else:
# for ios use ideviceinfo
try:
ideviceinfo_output = run_ideviceinfo()
if ideviceinfo_output:
adb_is_active = True
deviceId = re.search(r'UniqueDeviceID:\s*([a-zA-Z0-9]+)', ideviceinfo_output)
model = re.search(r'ProductType:\s*([\w\d,]+)', ideviceinfo_output)
if deviceId and model:
available_devices.append({"model": model.group(1).strip(), "UDID": deviceId.group(1).strip()})
message = "iOS device is available"
except Exception as e:
message = f"Error checking iOS device connectivity: {e}"
return {"is_true": adb_is_active, "available_devices": available_devices, "message": message}
def get_package_identifiers():
try:
# if get_device_type() in ["Windows","Linux"]:
# process = subprocess.Popen(['frida-ps', '-Uai'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
# result, _ = process.communicate()
# lines = result.strip().split('\n')[1:]
# else:
result = subprocess.run(['frida-ps', '-Uai'], capture_output=True, text=True)
lines = result.stdout.strip().split('\n')[1:]
identifiers = [line.split()[1] + " - " + line.split()[-1] for line in lines]
return identifiers
except Exception as e:
print(f"Error getting package identifiers: {e}")
return []
def get_bypass_scripts():
list_script = json.load(open("script.json","r"))["scripts"]
IOS = []
ANDROID = []
for item in list_script:
k = [i for i in item.keys()][0]
if item[k]["category"] == "IOS":
IOS.append(item[k])
else:
ANDROID.append(item[k])
return ANDROID, IOS
def get_script_content(script_path):
try:
with open(script_path, 'r') as file:
content = file.read()
return content
except Exception as e:
return str(e), 500
@app.route('/get-script-content')
def get_script_content_route():
script_name = request.args.get('script')
script_path = os.path.join(SCRIPTS_DIRECTORY, script_name)
content = get_script_content(script_path)
return content
@app.route('/')
def index():
device_type = get_device_type()
adb_check = there_is_adb_and_devices()
if adb_check["is_true"]:
try:
identifiers = get_package_identifiers()
bypass_scripts_1, bypass_scripts_2 = get_bypass_scripts()
return render_template('index.html', identifiers=identifiers, bypass_scripts_android=bypass_scripts_1, bypass_scripts_ios=bypass_scripts_2,devices=adb_check,connected_device=adb_check["available_devices"])
except Exception as e:
return render_template('index.html', error=f"Error: {e}")
else:
return render_template('no-usb.html')
@app.route('/run-frida', methods=['POST'])
def run_frida():
global process
try:
package = request.form['package']
if not 'use_custom_script' in request.form.keys():
use_custom_script = False
else:
use_custom_script = int(request.form['use_custom_script']) == 1
selected_script = request.form['selected_script']
script_content = request.form['script_content']
if use_custom_script:
script_name = hashlib.sha256(script_content.encode()).hexdigest() + ".js"
script_path = os.path.join("tmp", script_name)
selected_script = script_name
with open(script_path, 'w') as file:
file.write(script_content)
else:
script_path = os.path.join(SCRIPTS_DIRECTORY, selected_script)
if process and process.poll() is None:
process.terminate()
# memakai threading flask
socketio_thread = threading.Thread(target=run_frida_with_socketio, args=(script_path, package))
socketio_thread.daemon = True
socketio_thread.start()
return jsonify({"result": f'Successfully started Frida on {package} using {selected_script}'}), 200
except KeyboardInterrupt:
return jsonify({"error": "Frida process interrupted by user."}), 500
except Exception as e:
return jsonify({"error": f"Error: {e}"}), 500
def run_frida_with_socketio(script_path, package):
global process
try:
command = ["frida", "-l", script_path, "-U", "-f", package]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
while True:
output = process.stdout.readline()
if output == "" and process.poll() is not None:
break
if output:
socketio.emit("output", {"data": output})
time.sleep(0.010)
socketio.emit("output", {"data": "Frida process finished."})
except KeyboardInterrupt:
socketio.emit("output", {"data": "Frida process interrupted by user."})
except Exception as e:
socketio.emit("output", {"data": f"Error: {e}"})
@socketio.on("connect")
def handle_connect():
pass
@app.route('/stop-frida')
def stop_frida():
global process
# proses dihentikan sebelum dikirim ke response
if process and process.poll() is None:
process.kill()
process.wait()
return 'Frida process stopped', 200
else:
return 'Frida process is not running', 200
if __name__ == '__main__':
try:
print(Fore.GREEN + r"""
‸
_)\.-.
.-.__,___,_.-=-. )\` ͡⇼`\_
.-.__\__,__,__.-=-. `/ \ `\\
{~,-~-,-~.-~,-,;;;;\ | '--;`)/
\-,~_-~_-,~-,(_(_(;\/ ,;/
",-.~_,-~,-~,)_)_)'. ;;(
`~-,_-~,-~(_(_(_(_\ `;\\
, `"~~--,)_)_)_)\_ \\
|\ (_(_/_(_, \ ;
\ '-. _.--' /_/_/_) | | FSR v1.3
'--.\ .' /_/ | |
)) / \ | /.'
// /, | __.'| ||
// || /` ( ||
|| || .' \ \\
|| || .'_ \ \\
\\ // / _ `\ \ \\__
\\'-'/( _ `\,; \ '--:,
`"` `"` `-,,; `"`",,;
""")
print("Please Access http://127.0.0.1:5000\n")
print("Press CTRL+C to stop this program.")
socketio.run(app, debug=False if get_device_type() not in ['Windows','Linux'] else False)
except KeyboardInterrupt:
pass
print("\nThanks For Using This Tools ♡")