7
7
import re
8
8
import fnmatch
9
9
import shlex
10
- import subprocess
11
10
12
11
from utils .listapp import *
13
12
from utils .checkversion import *
@@ -46,15 +45,32 @@ def start_frida_server(param_1):
46
45
47
46
def stop_frida_server (param ):
48
47
fs = "/data/local/tmp/frida-server*"
49
- isProc = os .popen ('adb shell ps |' + param ).read ()
50
- if (isProc ):
51
- logger .info ("[*] Found Process Frida Server:" + isProc )
48
+
49
+ # Check if the Frida server process is running
50
+ isProc = subprocess .getoutput (f'adb shell ps | { param } ' )
51
+
52
+ if isProc :
53
+ logger .info ("[*] Found Process Frida Server: " + isProc )
52
54
logger .info ("[*] Stop Frida Server..." )
53
- os .system ('adb shell ' + 'su -c ' + 'pkill -f ' + fs )
55
+
56
+ # Try to stop the Frida server with su privilege
57
+ result = subprocess .run (f'adb shell su -c "pkill -f { fs } "' , shell = True )
58
+
59
+ # Check if the su command was successful
60
+ if result .returncode != 0 :
61
+ logger .error ("[!] Failed to stop Frida Server with su -c" )
62
+ # Retry without su
63
+ logger .info ("[*] Try to stop Frida Server withou su..." )
64
+ result = subprocess .run (f'adb shell pkill -f { fs } ' , shell = True )
65
+
66
+ if result .returncode != 0 :
67
+ logger .error ("[!] Failed to stop Frida Server" )
68
+ return
69
+
54
70
time .sleep (2 )
55
71
logger .info ("[*] Stop Frida Server Success!!" )
56
72
else :
57
- logger .warning ("[!] Frida Server Not Start " )
73
+ logger .warning ("[!] Frida Server Not Started " )
58
74
59
75
def check_frida_server_run (param ):
60
76
isProc = os .popen ('adb shell ps |' + param ).read ()
@@ -127,6 +143,7 @@ def main():
127
143
action = "store_true" , help = "List All Scripts" , dest = "listscripts" )
128
144
info .add_option ("--logcat" , action = "store_true" , help = "Show system log of device" , dest = "logcat" )
129
145
info .add_option ("--shell" , action = "store_true" , help = "Get the shell of connect device" , dest = "shell" )
146
+ info .add_option ("--proxy" , action = "store_true" , help = "Config global proxy ::3128 and reverse tcp 3128:8080" , dest = "proxy" )
130
147
131
148
parser .add_option_group (info )
132
149
parser .add_option_group (quick )
@@ -158,9 +175,9 @@ def main():
158
175
if re .search (description_pattern , line ):
159
176
description = re .sub (r'\n' , '' , line [16 :])
160
177
if re .search (mode_pattern , line ):
161
- mode = re .sub ('\s+' , '' , line [9 :])
178
+ mode = re .sub (r '\s+' , '' , line [9 :])
162
179
if re .search (version_pattern , line ):
163
- version = re .sub ('\s+' , '' , line [12 :])
180
+ version = re .sub (r '\s+' , '' , line [12 :])
164
181
print ('|%d|%s|%s|%s|%s|' % (i , mode , file_name , description , version ))
165
182
else :
166
183
logger .error ('[?] Path frida-script not exists!' )
@@ -203,7 +220,7 @@ def main():
203
220
if (findingScript == False ):
204
221
logger .error ('[x_x] No matching suggestions!' )
205
222
sys .exit (0 )
206
- logger .info ('[*] iOSHook suggestion use ' + findingScript )
223
+ logger .info ('[*] androidhook suggestion use ' + findingScript )
207
224
answer = input ('[?] Do you want continue? (y/n): ' ) or "y"
208
225
if answer == "y" :
209
226
options .script = APP_FRIDA_SCRIPTS + findingScript
@@ -232,7 +249,7 @@ def main():
232
249
if (findingScript == False ):
233
250
logger .error ('[x_x] No matching suggestions!' )
234
251
sys .exit (0 )
235
- logger .info ('[*] iOSHook suggestion use ' + findingScript )
252
+ logger .info ('[*] androidhook suggestion use ' + findingScript )
236
253
answer = input ('[?] Do you want continue? (y/n): ' ) or "y"
237
254
if answer == "y" :
238
255
options .script = APP_FRIDA_SCRIPTS + findingScript
@@ -281,10 +298,12 @@ def main():
281
298
logger .info ('[*] Spawning: ' + options .package )
282
299
logger .info ('[*] Script: ' + method )
283
300
time .sleep (2 )
284
- process = frida .get_usb_device ().attach (options .package )
285
- method = open (method , 'r' )
286
- script = process .create_script (method .read ())
301
+ pid = frida .get_usb_device ().spawn (options .package )
302
+ session = frida .get_usb_device ().attach (pid )
303
+ hook = open (method , 'r' )
304
+ script = session .create_script (hook .read ())
287
305
script .load ()
306
+ frida .get_usb_device ().resume (pid )
288
307
sys .stdin .read ()
289
308
else :
290
309
logger .error ('[x_x] Script for method not found!' )
@@ -296,7 +315,6 @@ def main():
296
315
logger .info ('[*] Intercept NetWork Request: ' )
297
316
logger .info ('[*] Attaching: ' + options .name )
298
317
logger .info ('[*] Script: ' + method )
299
- time .sleep (2 )
300
318
process = frida .get_usb_device ().attach (options .name )
301
319
method = open (method , 'r' )
302
320
script = process .create_script (method .read ())
@@ -308,13 +326,18 @@ def main():
308
326
#Intercept Crypto Operations
309
327
elif options .package and options .method == "i-crypto" :
310
328
method = APP_METHODS ['Intercept Crypto Operations' ]
311
- check_frida_server_run ()
312
329
if os .path .isfile (method ):
313
330
logger .info ('[*] Intercept Crypto Operations: ' )
314
331
logger .info ('[*] Spawning: ' + options .package )
315
332
logger .info ('[*] Script: ' + method )
316
- os .system ('frida -U -f ' + options .package + ' -l ' + method + ' --no-pause' )
317
- #sys.stdin.read()
333
+ time .sleep (2 )
334
+ pid = frida .get_usb_device ().spawn (options .package )
335
+ session = frida .get_usb_device ().attach (pid )
336
+ hook = open (method , 'r' )
337
+ script = session .create_script (hook .read ())
338
+ script .load ()
339
+ frida .get_usb_device ().resume (pid )
340
+ sys .stdin .read ()
318
341
else :
319
342
logger .error ('[x_x] Script for method not found!' )
320
343
@@ -323,7 +346,7 @@ def main():
323
346
logger .info ('[*] Checking for updates...' )
324
347
is_newest = check_version (speak = True )
325
348
# if not is_newest:
326
- # logger.info('[*] There is an update available for iOS hook ')
349
+ # logger.info('[*] There is an update available for androidhook ')
327
350
328
351
#update newversion
329
352
elif options .update :
@@ -336,23 +359,37 @@ def main():
336
359
elif options .package and options .dumpmemory :
337
360
dump_memory (options .dumpmemory , options .package )
338
361
339
- #ios system log
362
+ #android system log
340
363
elif options .logcat :
341
364
cmd = shlex .split ('adb logcat' )
342
365
subprocess .call (cmd )
343
366
sys .exit (0 )
344
367
345
- #ios get the shell
368
+ #android get the shell
346
369
elif options .shell :
347
370
cmd = shlex .split ('adb shell' )
348
371
subprocess .call (cmd )
349
372
sys .exit (0 )
350
373
351
- #ioshook cli
374
+ #androidhook cli
352
375
elif options .cli :
353
376
logger .info ("Welcome to AndroidHook CLI! Type ? to list commands" )
354
377
AndroidHook_CLI ().cmdloop ()
355
378
379
+ #androidhook proxy
380
+ elif options .proxy :
381
+ cmd1 = shlex .split ('adb shell settings put global http_proxy 127.0.0.1:3128' )
382
+ cmd2 = shlex .split ('adb reverse tcp:3128 tcp:8080' )
383
+
384
+ logger .info ("[*] Config device global proxy to ::3128" )
385
+ subprocess .call (cmd1 )
386
+
387
+ logger .info ("[*] Config reverse tcp from device to machine 3128:8080" )
388
+ subprocess .call (cmd2 )
389
+
390
+ logger .info ("[*] Config success - Using proxy 127.0.0.1:8080" )
391
+ sys .exit (0 )
392
+
356
393
else :
357
394
logger .warning ("[!] Specify the options. use (-h) for more help!" )
358
395
# sys.exit(0)
0 commit comments