-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_origin.js
1290 lines (1166 loc) · 57 KB
/
script_origin.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
// 对象输出模式: true为仅输出JSON.stringify(obj, null, 4); false为递归至多三层输出参数值;
var simpleOnly = false;
// 递归输出对象的最大深度
var maxDepth = 3;
// 绕过TracerPid检测
var ByPassTracerPid = function () {
var fgetsPtr = Module.findExportByName('libc.so', 'fgets');
var fgets = new NativeFunction(fgetsPtr, 'pointer', ['pointer', 'int', 'pointer']);
Interceptor.replace(fgetsPtr, new NativeCallback(function (buffer, size, fp) {
var retval = fgets(buffer, size, fp);
var bufstr = Memory.readUtf8String(buffer);
if (bufstr.indexOf('TracerPid:') > -1) {
Memory.writeUtf8String(buffer, 'TracerPid:\t0');
// console.log('tracerpid replaced: ' + Memory.readUtf8String(buffer));
}
return retval;
}, 'pointer', ['pointer', 'int', 'pointer']));
};
Java.perform(function () {
// console.log("---");
// console.log("Unpinning Android app...");
/// -- Generic hook to protect against SSLPeerUnverifiedException -- ///
// In some cases, with unusual cert pinning approaches, or heavy obfuscation, we can't
// match the real method & package names. This is a problem! Fortunately, we can still
// always match built-in types, so here we spot all failures that use the built-in cert
// error type (notably this includes OkHttp), and after the first failure, we dynamically
// generate & inject a patch to completely disable the method that threw the error.
try {
const UnverifiedCertError = Java.use('javax.net.ssl.SSLPeerUnverifiedException');
UnverifiedCertError.$init.implementation = function (str) {
// console.log(' --> Unexpected SSL verification failure, adding dynamic patch...');
try {
const stackTrace = Java.use('java.lang.Thread').currentThread().getStackTrace();
const exceptionStackIndex = stackTrace.findIndex(stack =>
stack.getClassName() === "javax.net.ssl.SSLPeerUnverifiedException"
);
const callingFunctionStack = stackTrace[exceptionStackIndex + 1];
const className = callingFunctionStack.getClassName();
const methodName = callingFunctionStack.getMethodName();
// console.log(` Thrown by ${className}->${methodName}`);
const callingClass = Java.use(className);
const callingMethod = callingClass[methodName];
if (callingMethod.implementation) return; // Already patched by Frida - skip it
// console.log(' Attempting to patch automatically...');
const returnTypeName = callingMethod.returnType.type;
callingMethod.implementation = function () {
// console.log(` --> Bypassing ${className}->${methodName} (automatic exception patch)`);
// This is not a perfect fix! Most unknown cases like this are really just
// checkCert(cert) methods though, so doing nothing is perfect, and if we
// do need an actual return value then this is probably the best we can do,
// and at least we're logging the method name so you can patch it manually:
if (returnTypeName === 'void') {
return;
} else {
return null;
}
};
// console.log(` [+] ${className}->${methodName} (automatic exception patch)`);
} catch (e) {
// console.log(' [ ] Failed to automatically patch failure');
}
return this.$init(str);
};
// console.log('[+] SSLPeerUnverifiedException auto-patcher');
} catch (err) {
// console.log('[ ] SSLPeerUnverifiedException auto-patcher');
}
/// -- Specific targeted hooks: -- ///
// HttpsURLConnection
try {
const HttpsURLConnection = Java.use("javax.net.ssl.HttpsURLConnection");
HttpsURLConnection.setDefaultHostnameVerifier.implementation = function (hostnameVerifier) {
// console.log(' --> Bypassing HttpsURLConnection (setDefaultHostnameVerifier)');
return; // Do nothing, i.e. don't change the hostname verifier
};
// console.log('[+] HttpsURLConnection (setDefaultHostnameVerifier)');
} catch (err) {
// console.log('[ ] HttpsURLConnection (setDefaultHostnameVerifier)');
}
try {
const HttpsURLConnection = Java.use("javax.net.ssl.HttpsURLConnection");
HttpsURLConnection.setSSLSocketFactory.implementation = function (SSLSocketFactory) {
// console.log(' --> Bypassing HttpsURLConnection (setSSLSocketFactory)');
return; // Do nothing, i.e. don't change the SSL socket factory
};
// console.log('[+] HttpsURLConnection (setSSLSocketFactory)');
} catch (err) {
// console.log('[ ] HttpsURLConnection (setSSLSocketFactory)');
}
try {
const HttpsURLConnection = Java.use("javax.net.ssl.HttpsURLConnection");
HttpsURLConnection.setHostnameVerifier.implementation = function (hostnameVerifier) {
// console.log(' --> Bypassing HttpsURLConnection (setHostnameVerifier)');
return; // Do nothing, i.e. don't change the hostname verifier
};
// console.log('[+] HttpsURLConnection (setHostnameVerifier)');
} catch (err) {
// console.log('[ ] HttpsURLConnection (setHostnameVerifier)');
}
// SSLContext
try {
const X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
const SSLContext = Java.use('javax.net.ssl.SSLContext');
const TrustManager = Java.registerClass({
// Implement a custom TrustManager
name: 'dev.asd.test.TrustManager',
implements: [X509TrustManager],
methods: {
checkClientTrusted: function (chain, authType) { },
checkServerTrusted: function (chain, authType) { },
getAcceptedIssuers: function () { return []; }
}
});
// Prepare the TrustManager array to pass to SSLContext.init()
const TrustManagers = [TrustManager.$new()];
// Get a handle on the init() on the SSLContext class
const SSLContext_init = SSLContext.init.overload(
'[Ljavax.net.ssl.KeyManager;', '[Ljavax.net.ssl.TrustManager;', 'java.security.SecureRandom'
);
// Override the init method, specifying the custom TrustManager
SSLContext_init.implementation = function (keyManager, trustManager, secureRandom) {
// console.log(' --> Bypassing Trustmanager (Android < 7) request');
SSLContext_init.call(this, keyManager, TrustManagers, secureRandom);
};
// console.log('[+] SSLContext');
} catch (err) {
// console.log('[ ] SSLContext');
}
// TrustManagerImpl (Android > 7)
try {
const array_list = Java.use("java.util.ArrayList");
const TrustManagerImpl = Java.use('com.android.org.conscrypt.TrustManagerImpl');
// This step is notably what defeats the most common case: network security config
TrustManagerImpl.checkTrustedRecursive.implementation = function(a1, a2, a3, a4, a5, a6) {
// console.log(' --> Bypassing TrustManagerImpl checkTrusted ');
return array_list.$new();
}
TrustManagerImpl.verifyChain.implementation = function (untrustedChain, trustAnchorChain, host, clientAuth, ocspData, tlsSctData) {
// console.log(' --> Bypassing TrustManagerImpl verifyChain: ' + host);
return untrustedChain;
};
// console.log('[+] TrustManagerImpl');
} catch (err) {
// console.log('[ ] TrustManagerImpl');
}
// OkHTTPv3 (quadruple bypass)
try {
// Bypass OkHTTPv3 {1}
const okhttp3_Activity_1 = Java.use('okhttp3.CertificatePinner');
okhttp3_Activity_1.check.overload('java.lang.String', 'java.util.List').implementation = function (a, b) {
// console.log(' --> Bypassing OkHTTPv3 (list): ' + a);
return;
};
// console.log('[+] OkHTTPv3 (list)');
} catch (err) {
// console.log('[ ] OkHTTPv3 (list)');
}
try {
// Bypass OkHTTPv3 {2}
// This method of CertificatePinner.check could be found in some old Android app
const okhttp3_Activity_2 = Java.use('okhttp3.CertificatePinner');
okhttp3_Activity_2.check.overload('java.lang.String', 'java.security.cert.Certificate').implementation = function (a, b) {
// console.log(' --> Bypassing OkHTTPv3 (cert): ' + a);
return;
};
// console.log('[+] OkHTTPv3 (cert)');
} catch (err) {
// console.log('[ ] OkHTTPv3 (cert)');
}
try {
// Bypass OkHTTPv3 {3}
const okhttp3_Activity_3 = Java.use('okhttp3.CertificatePinner');
okhttp3_Activity_3.check.overload('java.lang.String', '[Ljava.security.cert.Certificate;').implementation = function (a, b) {
// console.log(' --> Bypassing OkHTTPv3 (cert array): ' + a);
return;
};
// console.log('[+] OkHTTPv3 (cert array)');
} catch (err) {
// console.log('[ ] OkHTTPv3 (cert array)');
}
try {
// Bypass OkHTTPv3 {4}
const okhttp3_Activity_4 = Java.use('okhttp3.CertificatePinner');
okhttp3_Activity_4['check$okhttp'].implementation = function (a, b) {
// console.log(' --> Bypassing OkHTTPv3 ($okhttp): ' + a);
return;
};
// console.log('[+] OkHTTPv3 ($okhttp)');
} catch (err) {
// console.log('[ ] OkHTTPv3 ($okhttp)');
}
// Trustkit (triple bypass)
try {
// Bypass Trustkit {1}
const trustkit_Activity_1 = Java.use('com.datatheorem.android.trustkit.pinning.OkHostnameVerifier');
trustkit_Activity_1.verify.overload('java.lang.String', 'javax.net.ssl.SSLSession').implementation = function (a, b) {
// console.log(' --> Bypassing Trustkit OkHostnameVerifier(SSLSession): ' + a);
return true;
};
// console.log('[+] Trustkit OkHostnameVerifier(SSLSession)');
} catch (err) {
// console.log('[ ] Trustkit OkHostnameVerifier(SSLSession)');
}
try {
// Bypass Trustkit {2}
const trustkit_Activity_2 = Java.use('com.datatheorem.android.trustkit.pinning.OkHostnameVerifier');
trustkit_Activity_2.verify.overload('java.lang.String', 'java.security.cert.X509Certificate').implementation = function (a, b) {
// console.log(' --> Bypassing Trustkit OkHostnameVerifier(cert): ' + a);
return true;
};
// console.log('[+] Trustkit OkHostnameVerifier(cert)');
} catch (err) {
// console.log('[ ] Trustkit OkHostnameVerifier(cert)');
}
try {
// Bypass Trustkit {3}
const trustkit_PinningTrustManager = Java.use('com.datatheorem.android.trustkit.pinning.PinningTrustManager');
trustkit_PinningTrustManager.checkServerTrusted.implementation = function () {
// console.log(' --> Bypassing Trustkit PinningTrustManager');
};
// console.log('[+] Trustkit PinningTrustManager');
} catch (err) {
// console.log('[ ] Trustkit PinningTrustManager');
}
// Appcelerator Titanium
try {
const appcelerator_PinningTrustManager = Java.use('appcelerator.https.PinningTrustManager');
appcelerator_PinningTrustManager.checkServerTrusted.implementation = function () {
// console.log(' --> Bypassing Appcelerator PinningTrustManager');
};
// console.log('[+] Appcelerator PinningTrustManager');
} catch (err) {
// console.log('[ ] Appcelerator PinningTrustManager');
}
// OpenSSLSocketImpl Conscrypt
try {
const OpenSSLSocketImpl = Java.use('com.android.org.conscrypt.OpenSSLSocketImpl');
OpenSSLSocketImpl.verifyCertificateChain.implementation = function (certRefs, JavaObject, authMethod) {
// console.log(' --> Bypassing OpenSSLSocketImpl Conscrypt');
};
// console.log('[+] OpenSSLSocketImpl Conscrypt');
} catch (err) {
// console.log('[ ] OpenSSLSocketImpl Conscrypt');
}
// OpenSSLEngineSocketImpl Conscrypt
try {
const OpenSSLEngineSocketImpl_Activity = Java.use('com.android.org.conscrypt.OpenSSLEngineSocketImpl');
OpenSSLEngineSocketImpl_Activity.verifyCertificateChain.overload('[Ljava.lang.Long;', 'java.lang.String').implementation = function (a, b) {
// console.log(' --> Bypassing OpenSSLEngineSocketImpl Conscrypt: ' + b);
};
// console.log('[+] OpenSSLEngineSocketImpl Conscrypt');
} catch (err) {
// console.log('[ ] OpenSSLEngineSocketImpl Conscrypt');
}
// OpenSSLSocketImpl Apache Harmony
try {
const OpenSSLSocketImpl_Harmony = Java.use('org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl');
OpenSSLSocketImpl_Harmony.verifyCertificateChain.implementation = function (asn1DerEncodedCertificateChain, authMethod) {
// console.log(' --> Bypassing OpenSSLSocketImpl Apache Harmony');
};
// console.log('[+] OpenSSLSocketImpl Apache Harmony');
} catch (err) {
// console.log('[ ] OpenSSLSocketImpl Apache Harmony');
}
// PhoneGap sslCertificateChecker (https://github.com/EddyVerbruggen/SSLCertificateChecker-PhoneGap-Plugin)
try {
const phonegap_Activity = Java.use('nl.xservices.plugins.sslCertificateChecker');
phonegap_Activity.execute.overload('java.lang.String', 'org.json.JSONArray', 'org.apache.cordova.CallbackContext').implementation = function (a, b, c) {
// console.log(' --> Bypassing PhoneGap sslCertificateChecker: ' + a);
return true;
};
// console.log('[+] PhoneGap sslCertificateChecker');
} catch (err) {
// console.log('[ ] PhoneGap sslCertificateChecker');
}
// IBM MobileFirst pinTrustedCertificatePublicKey (double bypass)
try {
// Bypass IBM MobileFirst {1}
const WLClient_Activity_1 = Java.use('com.worklight.wlclient.api.WLClient');
WLClient_Activity_1.getInstance().pinTrustedCertificatePublicKey.overload('java.lang.String').implementation = function (cert) {
// console.log(' --> Bypassing IBM MobileFirst pinTrustedCertificatePublicKey (string): ' + cert);
return;
};
// console.log('[+] IBM MobileFirst pinTrustedCertificatePublicKey (string)');
} catch (err) {
// console.log('[ ] IBM MobileFirst pinTrustedCertificatePublicKey (string)');
}
try {
// Bypass IBM MobileFirst {2}
const WLClient_Activity_2 = Java.use('com.worklight.wlclient.api.WLClient');
WLClient_Activity_2.getInstance().pinTrustedCertificatePublicKey.overload('[Ljava.lang.String;').implementation = function (cert) {
// console.log(' --> Bypassing IBM MobileFirst pinTrustedCertificatePublicKey (string array): ' + cert);
return;
};
// console.log('[+] IBM MobileFirst pinTrustedCertificatePublicKey (string array)');
} catch (err) {
// console.log('[ ] IBM MobileFirst pinTrustedCertificatePublicKey (string array)');
}
// IBM WorkLight (ancestor of MobileFirst) HostNameVerifierWithCertificatePinning (quadruple bypass)
try {
// Bypass IBM WorkLight {1}
const worklight_Activity_1 = Java.use('com.worklight.wlclient.certificatepinning.HostNameVerifierWithCertificatePinning');
worklight_Activity_1.verify.overload('java.lang.String', 'javax.net.ssl.SSLSocket').implementation = function (a, b) {
// console.log(' --> Bypassing IBM WorkLight HostNameVerifierWithCertificatePinning (SSLSocket): ' + a);
return;
};
// console.log('[+] IBM WorkLight HostNameVerifierWithCertificatePinning (SSLSocket)');
} catch (err) {
// console.log('[ ] IBM WorkLight HostNameVerifierWithCertificatePinning (SSLSocket)');
}
try {
// Bypass IBM WorkLight {2}
const worklight_Activity_2 = Java.use('com.worklight.wlclient.certificatepinning.HostNameVerifierWithCertificatePinning');
worklight_Activity_2.verify.overload('java.lang.String', 'java.security.cert.X509Certificate').implementation = function (a, b) {
// console.log(' --> Bypassing IBM WorkLight HostNameVerifierWithCertificatePinning (cert): ' + a);
return;
};
// console.log('[+] IBM WorkLight HostNameVerifierWithCertificatePinning (cert)');
} catch (err) {
// console.log('[ ] IBM WorkLight HostNameVerifierWithCertificatePinning (cert)');
}
try {
// Bypass IBM WorkLight {3}
const worklight_Activity_3 = Java.use('com.worklight.wlclient.certificatepinning.HostNameVerifierWithCertificatePinning');
worklight_Activity_3.verify.overload('java.lang.String', '[Ljava.lang.String;', '[Ljava.lang.String;').implementation = function (a, b) {
// console.log(' --> Bypassing IBM WorkLight HostNameVerifierWithCertificatePinning (string string): ' + a);
return;
};
// console.log('[+] IBM WorkLight HostNameVerifierWithCertificatePinning (string string)');
} catch (err) {
// console.log('[ ] IBM WorkLight HostNameVerifierWithCertificatePinning (string string)');
}
try {
// Bypass IBM WorkLight {4}
const worklight_Activity_4 = Java.use('com.worklight.wlclient.certificatepinning.HostNameVerifierWithCertificatePinning');
worklight_Activity_4.verify.overload('java.lang.String', 'javax.net.ssl.SSLSession').implementation = function (a, b) {
// console.log(' --> Bypassing IBM WorkLight HostNameVerifierWithCertificatePinning (SSLSession): ' + a);
return true;
};
// console.log('[+] IBM WorkLight HostNameVerifierWithCertificatePinning (SSLSession)');
} catch (err) {
// console.log('[ ] IBM WorkLight HostNameVerifierWithCertificatePinning (SSLSession)');
}
// Conscrypt CertPinManager
try {
const conscrypt_CertPinManager_Activity = Java.use('com.android.org.conscrypt.CertPinManager');
conscrypt_CertPinManager_Activity.isChainValid.overload('java.lang.String', 'java.util.List').implementation = function (a, b) {
// console.log(' --> Bypassing Conscrypt CertPinManager: ' + a);
return true;
};
// console.log('[+] Conscrypt CertPinManager');
} catch (err) {
// console.log('[ ] Conscrypt CertPinManager');
}
// CWAC-Netsecurity (unofficial back-port pinner for Android<4.2) CertPinManager
try {
const cwac_CertPinManager_Activity = Java.use('com.commonsware.cwac.netsecurity.conscrypt.CertPinManager');
cwac_CertPinManager_Activity.isChainValid.overload('java.lang.String', 'java.util.List').implementation = function (a, b) {
// console.log(' --> Bypassing CWAC-Netsecurity CertPinManager: ' + a);
return true;
};
// console.log('[+] CWAC-Netsecurity CertPinManager');
} catch (err) {
// console.log('[ ] CWAC-Netsecurity CertPinManager');
}
// Worklight Androidgap WLCertificatePinningPlugin
try {
const androidgap_WLCertificatePinningPlugin_Activity = Java.use('com.worklight.androidgap.plugin.WLCertificatePinningPlugin');
androidgap_WLCertificatePinningPlugin_Activity.execute.overload('java.lang.String', 'org.json.JSONArray', 'org.apache.cordova.CallbackContext').implementation = function (a, b, c) {
// console.log(' --> Bypassing Worklight Androidgap WLCertificatePinningPlugin: ' + a);
return true;
};
// console.log('[+] Worklight Androidgap WLCertificatePinningPlugin');
} catch (err) {
// console.log('[ ] Worklight Androidgap WLCertificatePinningPlugin');
}
// Netty FingerprintTrustManagerFactory
try {
const netty_FingerprintTrustManagerFactory = Java.use('io.netty.handler.ssl.util.FingerprintTrustManagerFactory');
netty_FingerprintTrustManagerFactory.checkTrusted.implementation = function (type, chain) {
// console.log(' --> Bypassing Netty FingerprintTrustManagerFactory');
};
// console.log('[+] Netty FingerprintTrustManagerFactory');
} catch (err) {
// console.log('[ ] Netty FingerprintTrustManagerFactory');
}
// Squareup CertificatePinner [OkHTTP<v3] (double bypass)
try {
// Bypass Squareup CertificatePinner {1}
const Squareup_CertificatePinner_Activity_1 = Java.use('com.squareup.okhttp.CertificatePinner');
Squareup_CertificatePinner_Activity_1.check.overload('java.lang.String', 'java.security.cert.Certificate').implementation = function (a, b) {
// console.log(' --> Bypassing Squareup CertificatePinner (cert): ' + a);
return;
};
// console.log('[+] Squareup CertificatePinner (cert)');
} catch (err) {
// console.log('[ ] Squareup CertificatePinner (cert)');
}
try {
// Bypass Squareup CertificatePinner {2}
const Squareup_CertificatePinner_Activity_2 = Java.use('com.squareup.okhttp.CertificatePinner');
Squareup_CertificatePinner_Activity_2.check.overload('java.lang.String', 'java.util.List').implementation = function (a, b) {
// console.log(' --> Bypassing Squareup CertificatePinner (list): ' + a);
return;
};
// console.log('[+] Squareup CertificatePinner (list)');
} catch (err) {
// console.log('[ ] Squareup CertificatePinner (list)');
}
// Squareup OkHostnameVerifier [OkHTTP v3] (double bypass)
try {
// Bypass Squareup OkHostnameVerifier {1}
const Squareup_OkHostnameVerifier_Activity_1 = Java.use('com.squareup.okhttp.internal.tls.OkHostnameVerifier');
Squareup_OkHostnameVerifier_Activity_1.verify.overload('java.lang.String', 'java.security.cert.X509Certificate').implementation = function (a, b) {
// console.log(' --> Bypassing Squareup OkHostnameVerifier (cert): ' + a);
return true;
};
// console.log('[+] Squareup OkHostnameVerifier (cert)');
} catch (err) {
// console.log('[ ] Squareup OkHostnameVerifier (cert)');
}
try {
// Bypass Squareup OkHostnameVerifier {2}
const Squareup_OkHostnameVerifier_Activity_2 = Java.use('com.squareup.okhttp.internal.tls.OkHostnameVerifier');
Squareup_OkHostnameVerifier_Activity_2.verify.overload('java.lang.String', 'javax.net.ssl.SSLSession').implementation = function (a, b) {
// console.log(' --> Bypassing Squareup OkHostnameVerifier (SSLSession): ' + a);
return true;
};
// console.log('[+] Squareup OkHostnameVerifier (SSLSession)');
} catch (err) {
// console.log('[ ] Squareup OkHostnameVerifier (SSLSession)');
}
// Android WebViewClient (double bypass)
try {
// Bypass WebViewClient {1} (deprecated from Android 6)
const AndroidWebViewClient_Activity_1 = Java.use('android.webkit.WebViewClient');
AndroidWebViewClient_Activity_1.onReceivedSslError.overload('android.webkit.WebView', 'android.webkit.SslErrorHandler', 'android.net.http.SslError').implementation = function (obj1, obj2, obj3) {
// console.log(' --> Bypassing Android WebViewClient (SslErrorHandler)');
};
// console.log('[+] Android WebViewClient (SslErrorHandler)');
} catch (err) {
// console.log('[ ] Android WebViewClient (SslErrorHandler)');
}
try {
// Bypass WebViewClient {2}
const AndroidWebViewClient_Activity_2 = Java.use('android.webkit.WebViewClient');
AndroidWebViewClient_Activity_2.onReceivedSslError.overload('android.webkit.WebView', 'android.webkit.WebResourceRequest', 'android.webkit.WebResourceError').implementation = function (obj1, obj2, obj3) {
// console.log(' --> Bypassing Android WebViewClient (WebResourceError)');
};
// console.log('[+] Android WebViewClient (WebResourceError)');
} catch (err) {
// console.log('[ ] Android WebViewClient (WebResourceError)');
}
// Apache Cordova WebViewClient
try {
const CordovaWebViewClient_Activity = Java.use('org.apache.cordova.CordovaWebViewClient');
CordovaWebViewClient_Activity.onReceivedSslError.overload('android.webkit.WebView', 'android.webkit.SslErrorHandler', 'android.net.http.SslError').implementation = function (obj1, obj2, obj3) {
// console.log(' --> Bypassing Apache Cordova WebViewClient');
obj3.proceed();
};
} catch (err) {
// console.log('[ ] Apache Cordova WebViewClient');
}
// Boye AbstractVerifier
try {
const boye_AbstractVerifier = Java.use('ch.boye.httpclientandroidlib.conn.ssl.AbstractVerifier');
boye_AbstractVerifier.verify.implementation = function (host, ssl) {
// console.log(' --> Bypassing Boye AbstractVerifier: ' + host);
};
} catch (err) {
// console.log('[ ] Boye AbstractVerifier');
}
// Appmattus
try {
const appmatus_Activity = Java.use('com.appmattus.certificatetransparency.internal.verifier.CertificateTransparencyInterceptor');
appmatus_Activity['intercept'].implementation = function (a) {
// console.log(' --> Bypassing Appmattus (Transparency)');
return a.proceed(a.request());
};
// console.log('[+] Appmattus (CertificateTransparencyInterceptor)');
} catch (err) {
// console.log('[ ] Appmattus (CertificateTransparencyInterceptor)');
}
try {
const CertificateTransparencyTrustManager = Java.use(
'com.appmattus.certificatetransparency.internal.verifier.CertificateTransparencyTrustManager'
);
CertificateTransparencyTrustManager['checkServerTrusted'].overload(
'[Ljava.security.cert.X509Certificate;',
'java.lang.String'
).implementation = function (x509CertificateArr, str) {
// console.log(' --> Bypassing Appmattus (CertificateTransparencyTrustManager)');
};
CertificateTransparencyTrustManager['checkServerTrusted'].overload(
'[Ljava.security.cert.X509Certificate;',
'java.lang.String',
'java.lang.String'
).implementation = function (x509CertificateArr, str, str2) {
// console.log(' --> Bypassing Appmattus (CertificateTransparencyTrustManager)');
return Java.use('java.util.ArrayList').$new();
};
// console.log('[+] Appmattus (CertificateTransparencyTrustManager)');
} catch (err) {
// console.log('[ ] Appmattus (CertificateTransparencyTrustManager)');
}
// console.log("Unpinning setup completed");
// console.log("---");
});
// 获取调用链
function getStackTrace() {
var Exception = Java.use('java.lang.Exception');
var ins = Exception.$new('Exception');
var straces = ins.getStackTrace();
if (undefined == straces || null == straces) {
return;
}
var result = '';
for (var i = 0; i < straces.length; i++) {
var str = ' ' + straces[i].toString();
result += str + '\r\n';
}
Exception.$dispose();
return result;
}
function get_format_time() {
var myDate = new Date();
return myDate.getFullYear() + '-' + myDate.getMonth() + '-' + myDate.getDate() + ' ' + myDate.getHours() + ':' + myDate.getMinutes() + ':' + myDate.getSeconds();
}
//告警发送
function alertSend(action, messages, arg, returnValue) {
var _time = get_format_time();
if (returnValue == undefined) returnValue = '无返回值';
send({
'type': 'notice',
'time': _time,
'action': action,
'messages': messages,
'arg': arg,
'returnValue': returnValue,
'stacks': getStackTrace()
});
}
// 增强健壮性,避免有的设备无法使用 Array.isArray 方法
if (!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
// 递归获取对象的所有字段
function getAllFields(obj, depth) {
var result = {};
if (simpleOnly) return JSON.stringify(obj, null, 4);
if (depth === maxDepth) {
try {
return JSON.stringify(obj.toString(), null, 4);
} catch (e) {
return JSON.stringify(obj, null, 4);
}
}
try {
var objClass = obj.getClass();
// 处理基本类型
{
switch (obj.getClass().getName()) {
case "java.lang.String":
return obj.toString();
case "java.lang.Integer":
return obj.intValue();
case "java.lang.Boolean":
return obj.booleanValue();
case "java.lang.Long":
return obj.longValue();
case "java.lang.Double":
return obj.doubleValue();
case "java.lang.Float":
return obj.floatValue();
case "java.lang.Short":
return obj.shortValue();
case "java.lang.Byte":
return obj.byteValue();
case "java.lang.Character":
return obj.charValue();
case "java.lang.Void":
return "void";
case "java.lang.Object":
return JSON.stringify(obj, null, 4);
case "java.lang.Class":
return obj.getName();
case "java.lang.Throwable":
case "java.lang.Enum":
return obj.toString();
default:
break;
}
// 处理 startsWith 的情况
const className = obj.getClass().getName();
if (className.startsWith("android.") ||
className.startsWith("java.") ||
className.startsWith("javax.") ||
className.startsWith("androidx.") ||
className.startsWith("kotlin.") ||
className.startsWith("kotlinx.") ||
className.startsWith("sun.") ||
className.startsWith("org.apache.") ||
className.startsWith("org.eclipse.") ||
className.startsWith("jdk.")) {
return JSON.stringify(obj.toString(), null, 4);
}
}
var fields = objClass.getDeclaredFields();
fields.forEach(function(field) {
try {
field.setAccessible(true);
var value = field.get(obj);
result[field.getName()] = getAllFields(value, depth+1);
console.log(value);
// result[field.getName()] = JSON.stringify(value, null, 4);
} catch (e) {
result[field.getName()] = "Cannot access";
}
});
} catch (e) {
result = JSON.stringify(obj, null, 4);
}
return JSON.stringify(result, null, 4);
}
// hook方法
function hookMethod(targetClass, targetMethod, targetArgs, action, messages) {
try {
var _Class = Java.use(targetClass);
} catch (e) {
return false;
}
if (targetMethod == '$init') {
var overloadCount = _Class.$init.overloads.length;
for (var i = 0; i < overloadCount; i++) {
_Class.$init.overloads[i].implementation = function () {
var temp = this.$init.apply(this, arguments);
// 是否含有需要过滤的参数
var argumentValues = Object.values(arguments);
if (Array.isArray(targetArgs) && targetArgs.length > 0 && !targetArgs.every(item => argumentValues.includes(item))) {
return null;
}
var arg = '';
for (var j = 0; j < arguments.length; j++) {
arg += '参数' + j + ':' + JSON.stringify(arguments[j], null, 4) + '\r\n';
}
if (arg.length == 0) arg = '无参数';
else arg = arg.slice(0, arg.length - 1);
var rv = JSON.stringify(temp, null, 4);
alertSend(action, messages, arg, rv);
return temp;
}
}
} else {
try {
var overloadCount = _Class[targetMethod].overloads.length;
} catch (e) {
console.log(e)
console.log('[*] hook(' + targetMethod + ')方法失败,请检查该方法是否存在!!!');
return false;
}
for (var i = 0; i < overloadCount; i++) {
_Class[targetMethod].overloads[i].implementation = function () {
var temp = this[targetMethod].apply(this, arguments);
// 是否含有需要过滤的参数
var argumentValues = Object.values(arguments);
if (Array.isArray(targetArgs) && targetArgs.length > 0 && !targetArgs.every(item => argumentValues.includes(item))) {
return null;
}
var arg = '';
for (var j = 0; j < arguments.length; j++) {
// arg += '参数' + j + ':' + JSON.stringify(arguments[j], null, 4) + '\r\n';
if (arg !== null && arg !== undefined) {
// 如果参数是对象,递归打印对象的所有字段
arg += '参数' + j + ':' + getAllFields(arguments[j], 0) + '\r\n';
} else {
arg += '参数' + j + ':' + JSON.stringify(arguments[j], null, 4) + '\r\n';
}
}
if (arg.length == 0) arg = '无参数';
else arg = arg.slice(0, arg.length - 1);
// var rv = JSON.stringify(temp, null, 4);
if (temp !== null && temp !== undefined) {
// 如果返回值是对象,递归打印对象的所有字段
var rv = getAllFields(temp, 0);
} else {
var rv = JSON.stringify(temp, null, 4);
}
alertSend(action, messages, arg, rv);
return temp;
}
}
}
return true;
}
// hook方法(去掉不存在方法)
function hook(targetClass, methodData) {
try {
var _Class = Java.use(targetClass);
} catch (e) {
return false;
}
var methods = _Class.class.getDeclaredMethods();
_Class.$dispose;
// 排查掉不存在的方法,用于各个android版本不存在方法报错问题。
methodData.forEach(function (methodData) {
for (var i in methods) {
if (methods[i].toString().indexOf('.' + methodData['methodName'] + '(') != -1 || methodData['methodName'] == '$init') {
hookMethod(targetClass, methodData['methodName'], methodData['args'], methodData['action'], methodData['messages']);
break;
}
}
});
}
// hook获取其他app信息api,排除app自身
function hookApplicationPackageManagerExceptSelf(targetMethod, action) {
var _ApplicationPackageManager = Java.use('android.app.ApplicationPackageManager');
try {
try {
var overloadCount = _ApplicationPackageManager[targetMethod].overloads.length;
} catch (e) {
return false;
}
for (var i = 0; i < overloadCount; i++) {
_ApplicationPackageManager[targetMethod].overloads[i].implementation = function () {
var temp = this[targetMethod].apply(this, arguments);
var arg = '';
for (var j = 0; j < arguments.length; j++) {
if (j === 0) {
var string_to_recv;
send({'type': 'app_name', 'data': arguments[j]});
recv(function (received_json_object) {
string_to_recv = received_json_object.my_data;
}).wait();
}
arg += '参数' + j + ':' + JSON.stringify(arguments[j], null, 4) + '\r\n';
}
if (arg.length == 0) arg = '无参数';
else arg = arg.slice(0, arg.length - 1);
if (string_to_recv) {
var rv = JSON.stringify(temp, null, 4);
alertSend(action, targetMethod + '获取的数据为:' + temp, arg, rv);
}
return temp;
}
}
} catch (e) {
console.log(e);
return
}
}
// 申请权限
function checkRequestPermission() {
var action = '申请权限';
//老项目
hook('android.support.v4.app.ActivityCompat', [
{'methodName': 'requestPermissions', 'action': action, 'messages': '申请具体权限看"参数1"'}
]);
hook('androidx.core.app.ActivityCompat', [
{'methodName': 'requestPermissions', 'action': action, 'messages': '申请具体权限看"参数1"'}
]);
}
// 获取电话相关信息
function getPhoneState() {
var action = '获取电话相关信息';
hook('android.telephony.TelephonyManager', [
// Android 8.0
{'methodName': 'getDeviceId', 'action': action, 'messages': '获取IMEI'},
// Android 8.1、9 android 10获取不到
{'methodName': 'getImei', 'action': action, 'messages': '获取IMEI'},
{'methodName': 'getMeid', 'action': action, 'messages': '获取MEID'},
{'methodName': 'getLine1Number', 'action': action, 'messages': '获取电话号码标识符'},
{'methodName': 'getSimSerialNumber', 'action': action, 'messages': '获取IMSI/iccid'},
{'methodName': 'getSubscriberId', 'action': action, 'messages': '获取IMSI'},
{'methodName': 'getSimOperator', 'action': action, 'messages': '获取MCC/MNC'},
{'methodName': 'getNetworkOperator', 'action': action, 'messages': '获取MCC/MNC'},
{'methodName': 'getSimCountryIso', 'action': action, 'messages': '获取SIM卡国家代码'},
{'methodName': 'getCellLocation', 'action': action, 'messages': '获取电话当前位置信息'},
{'methodName': 'getAllCellInfo', 'action': action, 'messages': '获取电话当前位置信息'},
{'methodName': 'requestCellInfoUpdate', 'action': action, 'messages': '获取基站信息'},
// {'methodName': 'getServiceState', 'action': action, 'messages': '获取sim卡是否可用'},
]);
// 电信卡cid lac
hook('android.telephony.cdma.CdmaCellLocation', [
{'methodName': 'getBaseStationId', 'action': action, 'messages': '获取基站cid信息'},
{'methodName': 'getNetworkId', 'action': action, 'messages': '获取基站lac信息'}
]);
// 移动联通卡 cid/lac
hook('android.telephony.gsm.GsmCellLocation', [
{'methodName': 'getCid', 'action': action, 'messages': '获取基站cid信息'},
{'methodName': 'getLac', 'action': action, 'messages': '获取基站lac信息'}
]);
// 短信
// hook('android.telephony.SmsManager', [
// {'methodName': 'sendTextMessageInternal', 'action': action, 'messages': '获取短信信息-发送短信'},
// {'methodName': 'getDefault', 'action': action, 'messages': '获取短信信息-发送短信'},
// {'methodName': 'sendTextMessageWithSelfPermissions', 'action': action, 'messages': '获取短信信息-发送短信'},
// {'methodName': 'sendMultipartTextMessageInternal', 'action': action, 'messages': '获取短信信息-发送短信'},
// {'methodName': 'sendDataMessage', 'action': action, 'messages': '获取短信信息-发送短信'},
// {'methodName': 'sendDataMessageWithSelfPermissions', 'action': action, 'messages': '获取短信信息-发送短信'},
// ]);
}
// 系统信息(AndroidId/标识/content敏感信息)
function getSystemData() {
var action = '获取系统信息';
hook('android.provider.Settings$Secure', [
{'methodName': 'getString', 'args': ['android_id'], 'action': action, 'messages': '获取安卓ID'}
]);
hook('android.provider.Settings$System', [
{'methodName': 'getString', 'args': ['android_id'], 'action': action, 'messages': '获取安卓ID'}
]);
hook('android.os.Build', [
{'methodName': 'getSerial', 'action': action, 'messages': '获取设备序列号'},
]);
hook('android.app.admin.DevicePolicyManager', [
{'methodName': 'getWifiMacAddress', 'action': action, 'messages': '获取mac地址'},
]);
// hook('android.content.ClipboardManager', [
// {'methodName': 'getPrimaryClip', 'action': action, 'messages': '读取剪切板信息'},
// {'methodName': 'setPrimaryClip', 'action': action, 'messages': '写入剪切板信息'},
// ]);
hook('android.telephony.UiccCardInfo', [
{'methodName': 'getIccId', 'action': action, 'messages': '读取手机IccId信息'},
]);
//小米
hook('com.android.id.impl.IdProviderImpl', [
{'methodName': 'getUDID', 'action': action, 'messages': '读取小米手机UDID'},
{'methodName': 'getOAID', 'action': action, 'messages': '读取小米手机OAID'},
{'methodName': 'getVAID', 'action': action, 'messages': '读取小米手机VAID'},
{'methodName': 'getAAID', 'action': action, 'messages': '读取小米手机AAID'},
]);
//三星
hook('com.samsung.android.deviceidservice.IDeviceIdService$Stub$Proxy', [
{'methodName': 'getOAID', 'action': action, 'messages': '读取三星手机OAID'},
{'methodName': 'getVAID', 'action': action, 'messages': '读取三星手机VAID'},
{'methodName': 'getAAID', 'action': action, 'messages': '读取三星手机AAID'},
]);
hook('repeackage.com.samsung.android.deviceidservice.IDeviceIdService$Stub$Proxy', [
{'methodName': 'getOAID', 'action': action, 'messages': '读取三星手机OAID'},
{'methodName': 'getVAID', 'action': action, 'messages': '读取三星手机VAID'},
{'methodName': 'getAAID', 'action': action, 'messages': '读取三星手机AAID'},
]);
//获取content敏感信息
// try {
// // 通讯录内容
// var ContactsContract = Java.use('android.provider.ContactsContract');
// var contact_authority = ContactsContract.class.getDeclaredField('AUTHORITY').get('java.lang.Object');
// } catch (e) {
// console.log(e)
// }
// try {
// // 日历内容
// var CalendarContract = Java.use('android.provider.CalendarContract');
// var calendar_authority = CalendarContract.class.getDeclaredField('AUTHORITY').get('java.lang.Object');
// } catch (e) {
// console.log(e)
// }
// try {
// // 浏览器内容
// var BrowserContract = Java.use('android.provider.BrowserContract');
// var browser_authority = BrowserContract.class.getDeclaredField('AUTHORITY').get('java.lang.Object');
// } catch (e) {
// console.log(e)
// }
// try {
// // 相册内容
// var MediaStore = Java.use('android.provider.MediaStore');
// var media_authority = MediaStore.class.getDeclaredField('AUTHORITY').get('java.lang.Object');
// } catch (e) {
// console.log(e)
// }
// try {
// var ContentResolver = Java.use('android.content.ContentResolver');
// var queryLength = ContentResolver.query.overloads.length;
// for (var i = 0; i < queryLength; i++) {
// ContentResolver.query.overloads[i].implementation = function () {
// var temp = this.query.apply(this, arguments);
// if (arguments[0].toString().indexOf(contact_authority) != -1) {
// var rv = JSON.stringify(temp, null, 4);
// alertSend(action, '获取手机通信录内容', '', rv);
// } else if (arguments[0].toString().indexOf(calendar_authority) != -1) {
// var rv = JSON.stringify(temp, null, 4);
// alertSend(action, '获取日历内容', '', rv);
// } else if (arguments[0].toString().indexOf(browser_authority) != -1) {
// var rv = JSON.stringify(temp, null, 4);
// alertSend(action, '获取浏览器内容', '', rv);
// } else if (arguments[0].toString().indexOf(media_authority) != -1) {
// var rv = JSON.stringify(temp, null, 4);
// alertSend(action, '获取相册内容', '', rv);
// }
// return temp;
// }
// }
// } catch (e) {
// console.log(e);
// return
// }
}
//获取其他app信息
function getPackageManager() {
var action = '获取其他app信息';
hook('android.content.pm.PackageManager', [
{'methodName': 'getInstalledPackages', 'action': action, 'messages': 'APP获取了其他app信息'},
{'methodName': 'getInstalledApplications', 'action': action, 'messages': 'APP获取了其他app信息'}
]);
hook('android.app.ApplicationPackageManager', [
{'methodName': 'getInstalledPackages', 'action': action, 'messages': 'APP获取了其他app信息'},
{'methodName': 'getInstalledApplications', 'action': action, 'messages': 'APP获取了其他app信息'},
{'methodName': 'queryIntentActivities', 'action': action, 'messages': 'APP获取了其他app信息'},
]);
hook('android.app.ActivityManager', [
{'methodName': 'getRunningAppProcesses', 'action': action, 'messages': '获取了正在运行的App'},