forked from m0bilesecurity/RMS-Runtime-Mobile-Security
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·1620 lines (1412 loc) · 45 KB
/
app.js
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
const http = require('http');
const express = require("express")
const nunjucks = require('nunjucks')
const bodyParser = require('body-parser');
const frida = require('frida');
const load = require('frida-load');
const fs = require('fs');
const socket_io = require('socket.io');
const datetime = require('node-datetime');
const BETA = false
const FRIDA_DEVICE_OPTIONS=["USB","Remote","ID"]
const FRIDA_DEVICE_ARGS_OPTIONS={'host': 'IP:PORT','id': 'Device’s serial number'}
//PATH files
const FRIDA_AGENT_PATH = __dirname+"/agent/compiled_RMS_core.js"
const CONFIG_FILE_PATH = __dirname+"/config/config.json"
const API_MONITOR_FILE_PATH = __dirname+"/config/api_monitor.json"
const CUSTOM_SCRIPTS_PATH = __dirname+"/custom_scripts/"
const CONSOLE_LOGS_PATH = __dirname+"/console_logs"
const STATIC_PATH = __dirname+"/views/static/"
const TEMPLATE_PATH =__dirname+"/views/templates"
//Global variables
var api = null //contains agent export
var loaded_classes = []
var system_classes = []
var loaded_methods = {}
var target_package = ""
var system_package = ""
var no_system_package=false
var app_list = [] //apps installed on the device
var mobile_OS="N/A"
var app_env_info = {} //app env info
//Global variables - diff analysis
var current_loaded_classes = []
var new_loaded_classes = []
//Global variables - console output
var calls_console_output = ""
var hooks_console_output = ""
var heap_console_output = ""
var global_console_output = ""
var api_monitor_console_output = ""
var static_analysis_console_output = ""
//Global variables - call stack
var call_count = 0
var call_count_stack={}
var methods_hooked_and_executed = []
//app instance
const app = express();
// server instance
const server = http.createServer(app);
// socket listen
const io=socket_io(server);
//bind socket_io to app
app.set('socket_io', io);
//express post config
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//express static path
app.use(express.static(STATIC_PATH))
//nunjucks config
nunjucks.configure(TEMPLATE_PATH, {
autoescape: true,
express: app
});
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Server startup
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
server.listen(5000, () => {
console.log("")
console.log("_________________________________________________________")
console.log("RMS - Runtime Mobile Security")
console.log("Version: 1.5 - NodeJS release")
console.log("by @mobilesecurity_")
console.log("Twitter Profile: https://twitter.com/mobilesecurity_")
console.log("_________________________________________________________")
console.log("")
console.log("Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)");
});
io.on('connection', (socket) => {
console.log('Socket connected');
socket.on('disconnect', () => {
console.log('Socket disconnected');
});
});
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Templates
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
//{{stacktrace}} placeholder is managed nodejs side
template_massive_hook_Android = `
Java.perform(function () {
var classname = "{className}";
var classmethod = "{classMethod}";
var methodsignature = "{methodSignature}";
var hookclass = Java.use(classname);
hookclass.{classMethod}.{overload}implementation = function ({args}) {
send("[Call_Stack]\\nClass: " +classname+"\\nMethod: "+methodsignature+"\\n");
var ret = this.{classMethod}({args});
var s="";
s=s+"[Hook_Stack]\\n"
s=s+"Class: "+classname+"\\n"
s=s+"Method: "+methodsignature+"\\n"
s=s+"Called by: "+Java.use('java.lang.Exception').$new().getStackTrace().toString().split(',')[1]+"\\n"
s=s+"Input: "+eval(args)+"\\n"
s=s+"Output: "+ret+"\\n"
{{stacktrace}}
send(s);
return ret;
};
});
`
template_massive_hook_iOS = `
var classname = "{className}";
var classmethod = "{classMethod}";
var methodsignature = "{methodSignature}";
try {
var hook = eval('ObjC.classes.' + classname + '["' + classmethod + '"]');
Interceptor.attach(hook.implementation, {
onEnter: function (args) {
send("[Call_Stack]\\nClass: " + classname + "\\nMethod: " + methodsignature + "\\n");
this.s = ""
this.s = this.s + "[Hook_Stack]\\n"
this.s = this.s + "Class: " + classname + "\\n"
this.s = this.s + "Method: " + methodsignature + "\\n"
if (classmethod.indexOf(":") !== -1) {
var params = classmethod.split(":");
params[0] = params[0].split(" ")[1];
for (var i = 0; i < params.length - 1; i++) {
try {
this.s = this.s + "Input: " + params[i] + ": " + new ObjC.Object(args[2 + i]).toString() + "\\n";
} catch (e) {
this.s = this.s + "Input: " + params[i] + ": " + args[2 + i].toString() + "\\n";
}
}
}
},
onLeave: function (retval) {
this.s = this.s + "Output: " + retval.toString() + "\\n";
{{stacktrace}}
send(this.s);
}
});
} catch (err) {
send("[!] Exception: " + err.message);
send("Not able to hook \\nClass: " + classname + "\\nMethod: " + methodsignature + "\\n");
}
`
template_hook_lab_Android = `
Java.perform(function () {
var classname = "{className}";
var classmethod = "{classMethod}";
var methodsignature = "{methodSignature}";
var hookclass = Java.use(classname);
//{methodSignature}
hookclass.{classMethod}.{overload}implementation = function ({args}) {
send("[Call_Stack]\\nClass: " +classname+"\\nMethod: "+methodsignature+"\\n");
var ret = this.{classMethod}({args});
var s="";
s=s+"[Hook_Stack]\\n"
s=s+"Class: " +classname+"\\n"
s=s+"Method: " +methodsignature+"\\n"
s=s+"Called by: "+Java.use('java.lang.Exception').$new().getStackTrace().toString().split(',')[1]+"\\n"
s=s+"Input: "+eval({args})+"\\n";
s=s+"Output: "+ret+"\\n";
//uncomment the line below to print StackTrace
//s=s+"StackTrace: "+Java.use('android.util.Log').getStackTraceString(Java.use('java.lang.Exception').$new()).replace('java.lang.Exception','') +"\\n";
send(s);
return ret;
};
});
`
template_hook_lab_iOS = `
var classname = "{className}";
var classmethod = "{classMethod}";
var methodsignature = "{methodSignature}";
try {
var hook = eval('ObjC.classes.' + classname + '["' + classmethod + '"]');
//{methodSignature}
Interceptor.attach(hook.implementation, {
onEnter: function (args) {
send("[Call_Stack]\\nClass: " + classname + "\\nMethod: " + methodsignature + "\\n");
this.s = ""
this.s = this.s + "[Hook_Stack]\\n"
this.s = this.s + "Class: " + classname + "\\n"
this.s = this.s + "Method: " + methodsignature + "\\n"
if (classmethod.indexOf(":") !== -1) {
var params = classmethod.split(":");
params[0] = params[0].split(" ")[1];
for (var i = 0; i < params.length - 1; i++) {
try {
this.s = this.s + "Input: " + params[i] + ": " + new ObjC.Object(args[2 + i]).toString() + "\\n";
} catch (e) {
this.s = this.s + "Input: " + params[i] + ": " + args[2 + i].toString() + "\\n";
}
}
}
},
//{methodSignature}
onLeave: function (retval) {
this.s = this.s + "Output: " + retval.toString() + "\\n";
//uncomment the lines below to replace retvalue
//retval.replace(0);
//uncomment the line below to print StackTrace
//this.s = this.s + "StackTrace: \\n" + Thread.backtrace(this.context, Backtracer.ACCURATE).map(DebugSymbol.fromAddress).join('\\n') + "\\n";
send(this.s);
}
});
} catch (err) {
send("[!] Exception: " + err.message);
send("Not able to hook \\nClass: " + classname + "\\nMethod: " + methodsignature + "\\n");
}
`
template_heap_search_Android = `
Java.performNow(function () {
var classname = "{className}"
var classmethod = "{classMethod}";
var methodsignature = "{methodSignature}";
Java.choose(classname, {
onMatch: function (instance) {
try
{
var returnValue;
//{methodSignature}
returnValue = instance.{classMethod}({args}); //<-- replace v[i] with the value that you want to pass
//Output
var s = "";
s=s+"[Heap_Search]\\n"
s=s + "[*] Heap Search - START\\n"
s=s + "Instance Found: " + instance.toString() + "\\n";
s=s + "Calling method: \\n";
s=s + " Class: " + classname + "\\n"
s=s + " Method: " + methodsignature + "\\n"
s=s + "-->Output: " + returnValue + "\\n";
s = s + "[*] Heap Search - END\\n"
send(s);
}
catch (err)
{
var s = "";
s=s+"[Heap_Search]\\n"
s=s + "[*] Heap Search - START\\n"
s=s + "Instance NOT Found or Exception while calling the method\\n";
s=s + " Class: " + classname + "\\n"
s=s + " Method: " + methodsignature + "\\n"
s=s + "-->Exception: " + err + "\\n"
s=s + "[*] Heap Search - END\\n"
send(s)
}
}
});
});
`
template_heap_search_iOS = `
var classname = "{className}";
var classmethod = "{classMethod}";
var methodsignature = "{methodSignature}";
ObjC.choose(ObjC.classes[classname], {
onMatch: function (instance) {
try
{
var returnValue;
//{methodSignature}
returnValue = instance[classmethod](); //<-- insert args if needed
var s=""
s=s+"[Heap_Search]\\n"
s=s + "[*] Heap Search - START\\n"
s=s+"Instance Found: " + instance.toString() + "\\n";
s=s+"Calling method: \\n";
s=s+" Class: " + classname + "\\n"
s=s+" Method: " + methodsignature + "\\n"
s=s+"-->Output: " + returnValue + "\\n";
s=s+"[*] Heap Search - END\\n"
send(s);
}catch(err)
{
var s = "";
s=s+"[Heap_Search]\\n"
s=s + "[*] Heap Search - START\\n"
s=s + "Instance NOT Found or Exception while calling the method\\n";
s=s + " Class: " + classname + "\\n"
s=s + " Method: " + methodsignature + "\\n"
s=s + "-->Exception: " + err + "\\n"
s=s + "[*] Heap Search - END\\n"
send(s)
}
},
onComplete: function () {
}
});
`
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Device - TAB
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
app.get("/", async function(req, res){
const config = read_json_file(CONFIG_FILE_PATH)
let custom_scripts_Android = []
let custom_scripts_iOS = []
//#exception handling - frida crash
var frida_crash=req.query.frida_crash || "False"
var frida_crash_message=req.query.frida_crash_message
var device=null
app_list=null
//get device
try
{
const device_manager = await frida.getDeviceManager()
switch(config.device_type)
{
case "USB":
device = await frida.getUsbDevice()
break;
case "Remote":
device = await device_manager.getRemoteDevice(config.host)
break;
case "ID":
device= await device_manager.getDevice(config.id)
break;
default:
device = await frida.getUsbDevice()
break;
}
//get app list
app_list = await device.enumerateApplications()
if (app_list.length == 0)
return res.redirect('/config?error=True');
}
catch(err)
{
console.log(err)
return res.redirect('/config?error=True');
}
const device_info="name: "+device.name+" | id: "+device.id+" | mode: "+device.type
//load FRIDA custom scripts list
fs.readdirSync(CUSTOM_SCRIPTS_PATH+"Android").forEach(file => {
if (file.endsWith(".js"))
custom_scripts_Android.push(file)
})
fs.readdirSync(CUSTOM_SCRIPTS_PATH+"iOS").forEach(file => {
if (file.endsWith(".js"))
custom_scripts_iOS.push(file)
})
//sort custom_scripts alphabetically
custom_scripts_Android.sort()
custom_scripts_iOS.sort()
//load API Monitors list
const api_monitor = read_json_file(API_MONITOR_FILE_PATH)
let template = {
device_info: device_info,
app_list: app_list,
api_monitor: api_monitor,
system_package_Android: config.system_package_Android,
system_package_iOS: config.system_package_iOS,
device_mode: config.device_type,
custom_scripts_Android: custom_scripts_Android,
custom_scripts_iOS: custom_scripts_iOS,
frida_crash: frida_crash,
frida_crash_message: frida_crash_message,
no_system_package: no_system_package,
target_package: target_package,
system_package: system_package
}
res.render("device.html", template)
})
app.post("/", async function(req, res){
//output reset
reset_variables_and_output()
//read config file
const config = read_json_file(CONFIG_FILE_PATH)
//obtain device OS
mobile_OS = req.body.mobile_OS
//set the proper system package
if(mobile_OS=="Android")
system_package=config.system_package_Android
else
system_package=config.system_package_iOS
//set the target package
target_package = req.body.package
//Frida Gadget support
if (target_package=="re.frida.Gadget")
target_package="Gadget"
//setup the RMS run
const mode = req.body.mode
const frida_script = req.body.frida_startup_script
const api_selected = req.body.api_selected
//RMS overview - print run options
console.log()
if(target_package)
console.log("Package Name: " + target_package)
if(mode)
console.log("Mode: " + mode)
if(frida_script)
console.log("Frida Startup Script: \n" + frida_script)
else
console.log("Frida Startup Script: None")
if(api_selected)
console.log("APIs Monitors: \n" + api_selected)
else
console.log("APIs Monitors: None")
var device=null
//get device
try
{
const device_manager = await frida.getDeviceManager()
switch(config.device_type)
{
case "USB":
device = await frida.getUsbDevice()
break;
case "Remote":
device = device_manager.add_remote_device(config.host)
break;
case "ID":
device= device_manager.get_device(config.id)
break;
default:
device = await frida.getUsbDevice()
break;
}
}
catch(err)
{
console.log(err)
return res.redirect('/config?error=True');
}
//spawn/attach the app/gadget
let session, script;
try
{
//attaching a persistent process to get enumerateLoadedClasses() result before starting the target app
//default process are com.android.systemui/SpringBoard
session = await device.attach(system_package)
const frida_agent = await load(require.resolve(FRIDA_AGENT_PATH));
script = await session.createScript(frida_agent)
await script.load()
api = await script.exports
system_classes = await api.loadclasses()
//sort list alphabetically
system_classes.sort()
}
catch(err)
{
console.log("Exception: "+err)
if (system_classes.length==0)
no_system_package=true
if (target_package!="Gadget")
console.log(system_package+" is NOT available on your device or a wrong OS has been selected. For a better RE experience, change it via the Config TAB!");
}
session = null
pid=null
try
{
if (mode == "Spawn" && target_package!="Gadget")
{
pid= await device.spawn([target_package])
session = await device.attach(pid)
console.log('[*] Process Spawned')
}
if (mode == "Attach" || target_package=="Gadget")
{
//on iOS device "attach" is performd via package.name instead of identifier
if(mobile_OS=="iOS" && target_package!="Gadget")
{
app_list.forEach(function(p) {
if(p.identifier==target_package)
target_package=p.name
});
}
session = await device.attach(target_package)
console.log('[*] Process Attached')
}
const frida_agent = await load(require.resolve(FRIDA_AGENT_PATH));
script = await session.createScript(frida_agent)
//crash handling
device.processCrashed.connect(onProcessCrashed);
session.detached.connect(onSessionDetached);
//onMessage
script.message.connect(onMessage);
await script.load()
//API export
api = script.exports
if (mode == "Spawn" && target_package!="Gadget")
device.resume(pid)
//loading FRIDA startup script if selected by the user
if (frida_script)
await api.loadcustomfridascript(frida_script)
//loading APIs Monitors if selected by the user
if(api_selected)
{
//load API Monitors list
const api_monitor = read_json_file(API_MONITOR_FILE_PATH)
var api_to_hook=[]
api_monitor.forEach(function(e) {
if(api_selected.includes(e.Category))
api_to_hook.push(e)
});
//load APIs monitors
try
{
await api.apimonitor(api_to_hook)
}
catch(err)
{
console.log("Excpetion: "+err)
}
}
}//end try
catch(err)
{
console.log("Excpetion: "+err)
return res.redirect('/?frida_crash=True&frida_crash_message='+err);
}
//automatically redirect the user to the dump classes and methods tab
let template = {
mobile_OS: mobile_OS,
target_package: target_package,
loaded_classes: loaded_classes,
loaded_methods: loaded_methods,
system_package: system_package,
no_system_package: no_system_package
}
res.render("dump.html",template)
})
/* spawn app android
try{
const pid = await device.spawn(target_package);
session = await device.attach(pid);
//crash reporting
device.processCrashed.connect(onProcessCrashed);
session.detached.connect(onSessionDetached);
const frida_agent = await load(require.resolve(FRIDA_AGENT_PATH));
script = await session.createScript(frida_agent);
script.message.connect(onMessage);
await script.load()
api = await script.exports
console.log('[*] API Test - checkmobileos() =>', await api.checkmobileos());
await device.resume(pid);
}
catch (err) {
console.log(err);
}
*/
function onProcessCrashed(crash) {
console.log('[*] onProcessCrashed() crash:', crash);
console.log(crash.report);
}
function onSessionDetached(reason, crash) {
console.log('[*] onDetached() reason:', reason, 'crash:', crash);
}
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Static Analysis - TAB (iOS only)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
app.get("/static_analysis", async function(req, res){
//obtain static analysis script path
static_analysis_script_path=CUSTOM_SCRIPTS_PATH+ mobile_OS +"/static_analysis.js"
//read the script
static_analysis_script = fs.readFileSync(static_analysis_script_path, 'utf8')
//run it via the loadcustomfridascript api
try
{
await api.loadcustomfridascript(static_analysis_script)
}
catch(err)
{
console.log(err)
}
let template = {
mobile_OS: mobile_OS,
static_analysis_console_output: static_analysis_console_output,
target_package: target_package,
system_package: system_package,
no_system_package: no_system_package
}
res.render("static_analysis.html", template);
})
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dump Classes and Methods - TAB
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
app.get("/dump", async function(req, res){
//# check what the user is triyng to do
const choice = req.query.choice
if (choice == 1){
// --> Dump Loaded Classes (w/o filters)
//clean up the array
loaded_classes = []
loaded_methods = []
//check if the user is trying to filter loaded classes
filter = req.query.filter
//Checking options
regex=0
case_sensitive=0
whole_world=0
if(req.query.regex==1) regex=1
if(req.query.case==1) case_sensitive=1
if(req.query.whole==1) whole_world=1
if (filter)
{
hooked_classes = await api.loadclasseswithfilter(filter,
regex,
case_sensitive,
whole_world)
loaded_classes = hooked_classes
}
else
{
loaded_classes = await api.loadclasses()
//Checking current loaded classes
/*
perform --> loaded classes -
system classes =
______________________
current_loaded_classes
*/
loaded_classes=loaded_classes.filter(function(x)
{
return system_classes.indexOf(x) < 0;
});
}
//sort loaded_classes alphabetically
loaded_classes.sort()
//console.log(loaded_classes)
}
if (choice == 2){
// --> Dump all methods [Loaded Classes]
// NOTE: Load methods for more than 500 classes can crash the app
try
{
loaded_methods = await api.loadmethods(loaded_classes)
//console.log(loaded_methods)
}
catch (err) {
console.log("Excpetion: "+err)
msg="FRIDA crashed while loading methods for one or more classes selected. Try to exclude them from your search!"
console.log(msg)
return res.redirect('/?frida_crash=True&frida_crash_message='+err);
}
}
if (choice == 3)
{
//--> Hook all loaded classes and methods
current_template=""
if (mobile_OS=="Android")
current_template=template_massive_hook_Android
else
current_template=template_massive_hook_iOS
const stacktrace = req.query.stacktrace
if (stacktrace == "yes")
{
if (mobile_OS=="Android")
current_template=current_template.replace("{{stacktrace}}", "s=s+\"StackTrace: \"+Java.use('android.util.Log').getStackTraceString(Java.use('java.lang.Exception').$new()).replace('java.lang.Exception','') +\"\\n\";")
else
current_template=current_template.replace("{{stacktrace}}", "this.s=this.s+\"StackTrace: \\n\"+Thread.backtrace(this.context, Backtracer.ACCURATE).map(DebugSymbol.fromAddress).join('\\n') +\"\\n\";")
}
else
current_template=current_template.replace("{{stacktrace}}", "")
try
{
await api.hookclassesandmethods(loaded_classes,
loaded_methods,
current_template)
}
catch(err)
{
console.log("Excpetion: "+err)
msg="FRIDA crashed while hooking methods for one or more classes selected. Try to exclude them from your search!"
console.log(msg)
return res.redirect('/?frida_crash=True&frida_crash_message='+err);
}
//redirect the user to the console output
return res.redirect('/console_output');
}
let template = {
mobile_OS: mobile_OS,
target_package: target_package,
loaded_classes: loaded_classes,
loaded_methods: loaded_methods,
system_package: system_package,
methods_hooked_and_executed: methods_hooked_and_executed
}
res.render("dump.html",template)
})
app.post("/dump", async function(req, res){
//tohook contains class (index) selected by the user (hooking purposes)
array_to_hook = req.body.tohook
if(!Array.isArray(array_to_hook))
array_to_hook=[array_to_hook]
if (array_to_hook)
{
hooked_classes = []
array_to_hook.forEach(function(index)
{
//hooked classes
hooked_classes.push(loaded_classes[Number(index)])
})
loaded_classes = hooked_classes
}
let template = {
mobile_OS: mobile_OS,
target_package: target_package,
loaded_classes: loaded_classes,
loaded_methods: loaded_methods,
system_package: system_package,
methods_hooked_and_executed: methods_hooked_and_executed
}
res.render("dump.html",template)
})
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Diff Classess - TAB
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
app.get("/diff_classes", async function(req, res){
//# check what the user is triyng to do
const choice = req.query.choice
if (choice == 1)
{
//Checking current loaded classes
/*
perform --> loaded classes -
system classes =
______________________
current_loaded_classes
*/
current_loaded_classes = (await api.loadclasses()).filter(
function(x)
{
return system_classes.indexOf(x) < 0;
});
//sort list alphabetically
current_loaded_classes.sort()
}
if (choice == 2)
{
//Checking NEW loaded classes
/*
perform --> new loaded classes -
old loaded classes -
system classes =
_____________________
new_loaded_classes
*/
new_loaded_classes = (await api.loadclasses()).filter(
function(x)
{
return current_loaded_classes.indexOf(x) < 0;
}
);
new_loaded_classes = new_loaded_classes.filter(
function(x)
{
return system_classes.indexOf(x) < 0;
}
);
//sort list alphabetically
new_loaded_classes.sort()
}
let template = {
mobile_OS: mobile_OS,
current_loaded_classes: current_loaded_classes,
new_loaded_classes: new_loaded_classes,
target_package: target_package,
system_package: system_package
}
res.render("diff_classes.html",template)
})
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hook LAB - TAB
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
function get_hook_lab_template(mobile_OS){
if (mobile_OS=="Android")
return template_hook_lab_Android
else
return template_hook_lab_iOS
}
app.get("/hook_lab", async function(req, res){
//check if methods are loaded or not
if (loaded_methods === undefined || loaded_methods.length == 0)
{
try{
loaded_methods = await api.loadmethods(loaded_classes)
return res.redirect("/hook_lab")
}
catch(err){
console.log("Excpetion: "+err)
const msg="FRIDA crashed while loading methods for one or more classes selected. Try to exclude them from your search!"
console.log(msg)
return res.redirect('/?frida_crash=True&frida_crash_message='+err);
}
}
var hook_template = ""
var selected_class = ""
//class_index contains the index of the loaded class selected by the user
class_index = req.query.class_index
if(class_index)
{
//get methods of the selected class
selected_class = loaded_classes[class_index]
//method_index contains the index of the loaded method selected by the user
method_index = req.query.method_index
//Only class selected - load heap search template for all the methods
if (!method_index)
{
//hook template generation
hook_template = await api.generatehooktemplate(
[selected_class],
loaded_methods,
get_hook_lab_template(mobile_OS)
)
}
//class and method selected - load heap search template for selected method only
else
{
var selected_method={}
//get method of the selected class
selected_method[selected_class] =
[(loaded_methods[selected_class])[method_index]]
//hook template generation
hook_template = await api.generatehooktemplate(
[selected_class],
selected_method,
get_hook_lab_template(mobile_OS)
)
}
}
//print hook template
let template = {
mobile_OS: mobile_OS,
target_package: target_package,
system_package: system_package,
no_system_package: no_system_package,
loaded_classes: loaded_classes,
loaded_methods: loaded_methods,
selected_class: selected_class,
methods_hooked_and_executed: methods_hooked_and_executed,
hook_template_str: hook_template
}
res.render("hook_lab.html",template);
})
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Heap Search - TAB
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
function get_heap_search_template(mobile_OS){
if (mobile_OS=="Android")
return template_heap_search_Android
else
return template_heap_search_iOS
}
app.get("/heap_search", async function(req, res){