forked from devoteam-cybertrust/droidstatx
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSmaliChecks.py
More file actions
579 lines (505 loc) · 29.4 KB
/
SmaliChecks.py
File metadata and controls
579 lines (505 loc) · 29.4 KB
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
import os
import re
from Configuration import Configuration
from subprocess import PIPE, Popen
from sys import platform
class NotFound(Exception):
"""Object not found in source code"""
class SmaliChecks:
smaliPaths = []
vulnerableTrustManagers = []
vulnerableWebViewSSLErrorBypass = []
vulnerableSetHostnameVerifiers = []
vulnerableHostnameVerifiers = []
vulnerableSocketsLocations = []
vulnerableContentProvidersSQLiLocations = []
vulnerableContentProvidersPathTraversalLocations = []
dynamicRegisteredBroadcastReceiversLocations = []
encryptionFunctionsLocation = []
decryptionFunctionsLocation = []
undeterminedCryptographicFunctionsLocation = []
keystoreLocations = []
webViewLoadUrlUsageLocation = []
webViewAddJavascriptInterfaceUsageLocation = []
okHttpCertificatePinningLocation = []
customCertifificatePinningLocation = []
AESwithECBLocations = []
DESLocations = []
javascriptEnabledWebviews = []
fileAccessEnabledWebviews = []
universalAccessFromFileURLEnabledWebviewsLocations = []
customChecksLocations = {}
configuration = Configuration()
def __init__(self, paths):
for path in paths:
self.smaliPaths.append(path)
self.checkWebviewSSLErrorBypass()
self.findWebviewJavascriptInterfaceUsage()
self.findWeakCryptographicUsage()
self.checkVulnerableTrustManagers()
self.checkInsecureHostnameVerifier()
self.checkVulnerableSockets()
self.findEncryptionFunctions()
self.checkVulnerableHostnameVerifiers()
self.findWebViewLoadUrlUsage()
self.findPropertyEnabledWebViews()
self.checkOKHttpCertificatePinning()
self.checkCustomPinningImplementation()
self.findKeystoreUsage()
self.findDynamicRegisteredBroadcastReceivers()
# self.findPathTraversalContentProvider()
self.findCustomChecks()
def getAnalysis(self):
attrs = [
"vulnerableTrustManagers",
"vulnerableWebViewSSLErrorBypass",
"vulnerableHostnameVerifiers",
"encryptionFunctionsLocation",
"decryptionFunctionsLocation",
"undeterminedCryptographicFunctionsLocation",
"vulnerableSetHostnameVerifiers",
"vulnerableSocketsLocations",
"webViewLoadUrlUsageLocation",
"webViewAddJavascriptInterfaceUsageLocation",
"AESwithECBLocations",
"DESLocations",
"javascriptEnabledWebviews",
"fileAccessEnabledWebviews",
"universalAccessFromFileURLEnabledWebviewsLocations",
"okHttpCertificatePinningLocation",
"customCertifificatePinningLocation",
"keystoreLocations",
"dynamicRegisteredBroadcastReceiversLocations",
"vulnerableContentProvidersSQLiLocations",
"vulnerableContentProvidersPathTraversalLocations",
"customChecksLocations"
]
data = {}
output_path = os.path.realpath(self.smaliPaths[0] + "/../")
for attr in attrs:
value = getattr(self, attr)
value = list(map(lambda x: os.path.relpath(x, output_path), value))
data[attr] = value
return data
def getSmaliPaths(self):
return self.smaliPaths
def getOSGnuGrepCommand(self):
if platform == "darwin":
return "ggrep"
else:
return "grep"
def checkForExistenceInFolder(self, objectRegEx, folderPath):
command = [self.getOSGnuGrepCommand(), "-s", "-r", "-l", "-P", objectRegEx, " --exclude-dir=" + self.configuration.getFolderExclusions()]
for path in folderPath:
command.append(path)
grep = Popen(command, stdout=PIPE, universal_newlines=True)
filePaths = grep.communicate()[0].strip().split('\n')
if len(filePaths) > 0:
return filePaths
else:
raise NotFound
def existsInFile(self, objectRegEx, filePath):
grep = Popen([self.getOSGnuGrepCommand(), "-l", "-P", objectRegEx, filePath], stdout=PIPE, universal_newlines=True)
filePaths = grep.communicate()[0].strip().split('\n')
if len(filePaths) > 0:
return filePaths
else:
return False
# Note: returns [''] if method not found
def getMethodCompleteInstructions(self, methodRegEx, filePath):
sed = Popen(["sed", "-n", methodRegEx, filePath], stdout=PIPE, universal_newlines=True)
methodContent = sed.communicate()[0]
return methodContent.strip().replace(' ', '').split('\n')
def getFileContent(self, filePath):
sed = Popen(["sed", "1p", filePath], stdout=PIPE, universal_newlines=True)
fileContent = sed.communicate()[0]
return fileContent.strip().replace(' ', '').split('\n')
def getMethodInstructions(self, methodRegEx, filePath):
sed = Popen(["sed", "-n", methodRegEx, filePath], stdout=PIPE, universal_newlines=True)
methodContent = sed.communicate()[0]
try:
match = re.search(r".locals \d{1,}([\S\s]*?).end method", methodContent)
instructions = str(match.group(1)).strip().replace(' ', '').split('\n')
return instructions
except:
return ""
def isMethodEmpty(self, instructions):
for i in range(len(instructions) - 1, 0, -1):
if instructions[i] == '.end method':
continue
else:
if instructions[i] == "return-void":
return True
else:
return False
def hasOperationProceed(self, instructions):
for i in range(len(instructions) - 1, 0, -1):
if 'Landroid/webkit/SslErrorHandler;->proceed()V' in instructions[i]:
return True
else:
continue
return False
def doesMethodReturnNull(self, instructions):
for i in range(len(instructions) - 1, 0, -1):
if instructions[i] == "return-object v0":
if i - 2 >= 0 and instructions[i - 2] == "const/4 v0, 0x0":
return True
elif i - 2 >= 0 and instructions[i - 2] == "new-array v0, v0, [Ljava/security/cert/X509Certificate;":
if i - 4 >= 0 and instructions[i - 4] == "const/4 v0, 0x0":
return True
else:
return False
else:
return False
else:
continue
return False
def doesMethodReturnTrue(self, instructions):
maxLen = len(instructions) - 1
for i in range(maxLen, 0, -1):
if instructions[i] == "return v0":
if i - 2 >= 0 and instructions[i - 2] == "const/4 v0, 0x1":
return True
else:
return False
else:
continue
return False
# Returns the register that has the target value assigned
def searchRegisterByAssignedValue(self, instructions, value):
register = ""
for instruction in instructions:
if "const/" in instruction and value in instruction:
registerEnd = instruction.find(",")
registerBegin = instruction.find(" ", 0, registerEnd) + 1
register = instruction[registerBegin:registerEnd]
break
return register
# Returns the assigned value to the targer register.
def getAssignedValueByRegister(self, instructions, register):
register = ""
for instruction in instructions:
if "const/" in instruction and register in instruction:
registerEnd = instruction.find(",")
registerBegin = instruction.find(" ", 0, registerEnd) + 1
register = instruction[registerBegin:registerEnd]
break
return register
def doesActivityExtendsPreferenceActivity(self, activity):
activity = activity.replace(".", "/")
activityLocation = self.checkForExistenceInFolder(".class public([a-zA-Z\s]*)L" + activity + ";", self.getSmaliPaths())
if activityLocation[0] != "":
preferenceExtends = self.existsInFile(".super Landroid\/preference\/PreferenceActivity;", activityLocation[0])
if preferenceExtends[0] != '':
return True
else:
return False
def doesPreferenceActivityHasValidFragmentCheck(self, activity):
activity = activity.replace(".", "/")
activityLocation = self.checkForExistenceInFolder(".class public([a-zA-Z\s]*)L" + activity + ";", self.getSmaliPaths())
if activityLocation[0] != "":
isValidFragmentFunction = self.getMethodCompleteInstructions('/.method protected isValidFragment(Ljava\/lang\/String;)Z/,/^.end method/p', activityLocation[0])
if isValidFragmentFunction[0] != '':
return True
else:
return False
def doesActivityHasFlagSecure(self, activity):
activity = activity.replace(".", "/")
end = activity.rfind('/') + 1
customPath = []
x = len(self.getSmaliPaths())
for a in range(0, x):
customPath.append(self.getSmaliPaths()[a] + activity[:end])
activityLocation = self.checkForExistenceInFolder(".class public([a-zA-Z\s]*)L" + activity + ";", customPath)
if activityLocation[0] != "":
methodInstructions = self.getMethodCompleteInstructions('/.method \([a-zA-Z]* \)onCreate(Landroid\/os\/Bundle;)V/,/^.end method/p', activityLocation[0])
register = self.searchRegisterByAssignedValue(methodInstructions, "0x2000")
if register.strip() == "":
return False
else:
flag = self.existsInFile("invoke-virtual.*" + register + ".*Landroid\/view\/Window;->setFlags\(II\)V", activityLocation[0])
if flag[0] != '':
return True
else:
return False
def findRegisterAssignedValueFromIndexBackwards(self, instructionsList, register, index):
for pointer in range(index, 0, -1):
if register in instructionsList[pointer] and ("const" in instructionsList[pointer] or "sget-object" in instructionsList[pointer]):
valueBegin = instructionsList[pointer].find(",")
value = instructionsList[pointer][valueBegin + 2:]
return value
def findRegistersPassedToFunction(self, functionInstruction):
match = re.search(r"{(.*)}", functionInstruction)
try:
if "range" in functionInstruction:
registers = str(match.group(1)).strip().replace(' ', '').split("..")
else:
registers = str(match.group(1)).strip().replace(' ', '').split(",")
except:
match = re.search(r"\D\d", functionInstruction)
try:
registers = str(match.group(0))
except:
return ""
return registers
def findInstructionIndex(self, instructionsList, instructionToSearch):
indexList = []
regex = re.compile(instructionToSearch)
for index, instruction in enumerate(instructionsList):
if re.search(regex, instruction):
indexList.append(index)
return indexList
def findDynamicRegisteredBroadcastReceivers(self):
dynamicRegisteredBroadcastReceiversLocations = self.checkForExistenceInFolder(
";->registerReceiver\(Landroid\/content\/BroadcastReceiver;Landroid\/content\/IntentFilter;\)",
self.getSmaliPaths())
for location in dynamicRegisteredBroadcastReceiversLocations:
if location:
self.dynamicRegisteredBroadcastReceiversLocations.append(location)
def findEncryptionFunctions(self):
encryptionFunctionsLocations = self.checkForExistenceInFolder("invoke-virtual {(.*)}, Ljavax\/crypto\/Cipher;->init\(ILjava\/security\/Key", self.getSmaliPaths())
if encryptionFunctionsLocations[0] != "":
for location in encryptionFunctionsLocations:
if "org/bouncycastle" in location:
continue
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, "Ljavax/crypto/Cipher;->init\(ILjava/security/Key")
if len(indexList) != 0:
for index in indexList:
registers = self.findRegistersPassedToFunction(instructions[index])
if self.findRegisterAssignedValueFromIndexBackwards(instructions, registers[1], index) == "0x1":
self.encryptionFunctionsLocation.append(location)
elif self.findRegisterAssignedValueFromIndexBackwards(instructions, registers[1], index) == "0x2":
self.decryptionFunctionsLocation.append(location)
else:
if location not in self.undeterminedCryptographicFunctionsLocation:
self.undeterminedCryptographicFunctionsLocation.append(location)
def findKeystoreUsage(self):
keystoreUsageLocations = self.checkForExistenceInFolder("invoke-virtual {(.*)}, Ljava\/security\/KeyStore;->getEntry\(Ljava\/lang\/String;Ljava\/security\/KeyStore\$ProtectionParameter;\)Ljava\/security\/KeyStore\$Entry", self.getSmaliPaths())
if keystoreUsageLocations[0] != "":
for location in keystoreUsageLocations:
self.keystoreLocations.append(location)
def findWebViewLoadUrlUsage(self):
webViewUsageLocations = self.checkForExistenceInFolder("Landroid\/webkit\/WebView;->loadUrl\(Ljava\/lang\/String;\)V", self.getSmaliPaths())
if webViewUsageLocations[0] != "":
for location in webViewUsageLocations:
self.webViewLoadUrlUsageLocation.append(location)
# *** Improper Platform Usage ***
# XXX: Unused
def findPathTraversalContentProvider(self):
contentProvidersLocations = self.checkForExistenceInFolder(".super Landroid\/content\/ContentProvider;", self.getSmaliPaths())
if contentProvidersLocations[0] != '':
for location in contentProvidersLocations:
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, "")
if len(indexList) > 0:
indexList = self.findInstructionIndex(instructions, "")
def determineContentProviderPathTraversal(self, provider):
provider = provider.replace("$", "\$").replace(".", "\/")
location = self.checkForExistenceInFolder(".class (.*) L" + provider, self.getSmaliPaths())
if not location:
return
instructions = self.getMethodCompleteInstructions('/.method public openFile(Landroid\/net\/Uri;Ljava\/lang\/String;)Landroid\/os\/ParcelFileDescriptor;/,/^.end method/p', location[0])
if not instructions or instructions[0] == "":
return
indexList = self.findInstructionIndex(instructions, "Ljava\/io\/File;->getCanonicalPath\(\)")
# If a file is being loaded with getCanonicalPath(), then it is probably safe
if not indexList:
self.vulnerableContentProvidersPathTraversalLocations.append(location[0])
def determineContentProviderSQLi(self, provider):
provider = provider.replace("$", "\$").replace(".", "\/")
location = self.checkForExistenceInFolder(".class (.*) L" + provider, self.getSmaliPaths())
if not location:
return
instructions = self.getMethodCompleteInstructions('/.method public query(Landroid\/net\/Uri;\[Ljava\/lang\/String;Ljava\/lang\/String;\[Ljava\/lang\/String;Ljava\/lang\/String;)Landroid\/database\/Cursor;/,/^.end method/p', location[0])
indexList = self.findInstructionIndex(instructions, "invoke-virtual(.*) {(.*)}, Landroid\/database\/sqlite\/SQLiteDatabase;->query")
indexList.extend(self.findInstructionIndex(instructions, "invoke-virtual(.*) {(.*)}, Landroid\/database\/sqlite\/SQLiteQueryBuilder;->query\(Landroid/database/sqlite/SQLiteDatabase;"))
if len(indexList) > 0:
indexList = self.findInstructionIndex(instructions, "\?")
if len(indexList) == 0:
self.vulnerableContentProvidersSQLiLocations.append(location[0])
def findWeakCryptographicUsage(self):
getInstanceLocations = self.checkForExistenceInFolder("Ljavax\/crypto\/Cipher;->getInstance\(Ljava\/lang\/String;\)Ljavax\/crypto\/Cipher;", self.getSmaliPaths())
if getInstanceLocations[0] != '':
for location in getInstanceLocations:
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, "Ljavax/crypto/Cipher;->getInstance\(Ljava/lang/String;\)Ljavax/crypto/Cipher;")
for index in indexList:
register = self.findRegistersPassedToFunction(instructions[index])
transformationValue = self.findRegisterAssignedValueFromIndexBackwards(instructions, register[0], index)
if transformationValue is not None:
if transformationValue == "\"AES\"" or "AES/ECB/" in transformationValue:
self.AESwithECBLocations.append(location)
elif "DES" in transformationValue:
self.DESLocations.append(location)
def findPropertyEnabledWebViews(self):
webviewUsageLocations = self.checkForExistenceInFolder(";->getSettings\(\)Landroid\/webkit\/WebSettings;", self.getSmaliPaths())
if webviewUsageLocations[0] != '':
for location in webviewUsageLocations:
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, "Landroid/webkit/WebSettings;->setJavaScriptEnabled\(Z\)V")
if len(indexList) > 0:
for index in indexList:
register = self.findRegistersPassedToFunction(instructions[index])
value = self.findRegisterAssignedValueFromIndexBackwards(instructions, register[1], index)
if value == "0x1":
self.javascriptEnabledWebviews.append(location)
indexList = self.findInstructionIndex(instructions, "Landroid/webkit/WebSettings;->setAllowFileAccess\(Z\)V")
if len(indexList) > 0:
for index in indexList:
register = self.findRegistersPassedToFunction(instructions[index])
value = self.findRegisterAssignedValueFromIndexBackwards(instructions, register[1], index)
if value == "0x1":
self.fileAccessEnabledWebviews.append(location)
else:
self.fileAccessEnabledWebviews.append(location)
indexList = self.findInstructionIndex(instructions, "Landroid/webkit/WebSettings;->setAllowUniversalAccessFromFileURLs\(Z\)V")
if len(indexList) > 0:
for index in indexList:
register = self.findRegistersPassedToFunction(instructions[index])
value = self.findRegisterAssignedValueFromIndexBackwards(instructions, register[1], index)
if value == "0x1":
self.universalAccessFromFileURLEnabledWebviewsLocations.append(location)
def findWebviewJavascriptInterfaceUsage(self):
javascriptInterfaceLocations = self.checkForExistenceInFolder(";->addJavascriptInterface\(Ljava\/lang\/Object;Ljava\/lang\/String;\)V", self.getSmaliPaths())
if javascriptInterfaceLocations[0] != '':
for location in javascriptInterfaceLocations:
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, ";->addJavascriptInterface\(Ljava/lang/Object;Ljava/lang/String;\)V")
if len(indexList) != 0:
for index in indexList:
registers = self.findRegistersPassedToFunction(instructions[index])
self.webViewAddJavascriptInterfaceUsageLocation.append(location)
# *** Insecure Communication Checks ***
# Check for the implementation of custom HostnameVerifiers
def checkInsecureHostnameVerifier(self):
insecureHostNameVerifierLocations = self.checkForExistenceInFolder(".implements Ljavax\/net\/ssl\/HostnameVerifier;", self.getSmaliPaths())
if insecureHostNameVerifierLocations[0] != '':
for location in insecureHostNameVerifierLocations:
methodInstructions = self.getMethodCompleteInstructions('/.method .* verify(Ljava\/lang\/String;Ljavax\/net\/ssl\/SSLSession;)Z/,/^.end method/p', location)
if methodInstructions != "":
if self.doesMethodReturnTrue(methodInstructions) is True:
self.vulnerableHostnameVerifiers.append(location)
# Check for the presence of the custom function that allows to bypass SSL errors in WebViews
def checkWebviewSSLErrorBypass(self):
webviewErrorBypassLocations = self.checkForExistenceInFolder("Landroid\/webkit\/SslErrorHandler;->proceed\(\)V", self.getSmaliPaths())
if webviewErrorBypassLocations[0] != '':
for location in webviewErrorBypassLocations:
self.vulnerableWebViewSSLErrorBypass.append(location)
# Check for the presence of custom TrustManagers that are vulnerable.
def checkVulnerableTrustManagers(self):
vulnerableTrustManagers = []
try:
checkClientTrustedLocations = self.checkForExistenceInFolder(".method public checkClientTrusted\(\[Ljava\/security\/cert\/X509Certificate;Ljava\/lang\/String;\)V", self.getSmaliPaths())
if checkClientTrustedLocations[0] != '':
for location in checkClientTrustedLocations:
methodInstructions = self.getMethodCompleteInstructions('/method public checkClientTrusted\(\)/,/^.end method/p', location)
if methodInstructions != "":
if self.isMethodEmpty(methodInstructions) is True:
getAcceptedIssuersLocations = self.existsInFile(".method public getAcceptedIssuers\(\)\[Ljava\/security\/cert\/X509Certificate;", location)
if methodInstructions != "":
methodInstructions = self.getMethodCompleteInstructions('/method public getAcceptedIssuers()\[Ljava\/security\/cert\/X509Certificate;/,/^.end method/p', getAcceptedIssuersLocations[0])
if self.doesMethodReturnNull(methodInstructions) is True:
checkServerTrustedLocations = self.existsInFile(".method public checkServerTrusted\(\[Ljava\/security\/cert\/X509Certificate;Ljava\/lang\/String;\)V", location)
if methodInstructions != "":
methodInstructions = self.getMethodCompleteInstructions('/method public checkServerTrusted\(\)/,/^.end method/p', checkServerTrustedLocations[0])
if self.isMethodEmpty(methodInstructions) is True:
vulnerableTrustManagers.append(location)
self.vulnerableTrustManagers.append(location)
return vulnerableTrustManagers
except NotFound:
pass
# Check for the presence of setHostnameVerifier with ALLOW_ALL_HOSTNAME_VERIFIER
def checkVulnerableHostnameVerifiers(self):
setHostnameVerifierLocations = self.checkForExistenceInFolder("invoke-virtual {(.*)}, Lorg\/apache\/http\/conn\/ssl\/SSLSocketFactory;->setHostnameVerifier\(Lorg\/apache\/http\/conn\/ssl\/X509HostnameVerifier;\)V", self.getSmaliPaths())
if setHostnameVerifierLocations[0] != "":
for location in setHostnameVerifierLocations:
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, "Lorg/apache/http/conn/ssl/SSLSocketFactory;->setHostnameVerifier")
if len(indexList) != 0:
for index in indexList:
registers = self.findRegistersPassedToFunction(instructions[index])
if self.findRegisterAssignedValueFromIndexBackwards(instructions, registers[1], index) == "Lorg/apache/http/conn/ssl/SSLSocketFactory;->ALLOW_ALL_HOSTNAME_VERIFIER:Lorg/apache/http/conn/ssl/X509HostnameVerifier;":
self.vulnerableSetHostnameVerifiers.append(location)
# Check for SocketFactory without Hostname Verify
def checkVulnerableSockets(self):
vulnerableSocketsLocations = self.checkForExistenceInFolder("Ljavax\/net\/SocketFactory;->createSocket\(Ljava\/lang\/String;I\)Ljava\/net\/Socket;", self.getSmaliPaths())
if vulnerableSocketsLocations[0] != "":
for location in vulnerableSocketsLocations:
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, "Ljavax/net/ssl/HostnameVerifier;->verify\(Ljava/lang/String;Ljavax/net/ssl/SSLSession;\)Z")
if len(indexList) == 0:
self.vulnerableSocketsLocations.append(location)
# Check for the implementation of OKHttp Certificate Pinning
def checkOKHttpCertificatePinning(self):
okHttpCertificatePinningLocations = self.checkForExistenceInFolder("add\(Ljava\/lang\/String;\[Ljava\/lang\/String;\)Lokhttp3\/CertificatePinner\$Builder", self.getSmaliPaths())
if okHttpCertificatePinningLocations[0] != '':
for location in okHttpCertificatePinningLocations:
# Bypass library files
if "/okhttp" in location:
continue
instructions = self.getFileContent(location)
indexList = self.findInstructionIndex(instructions, "certificatePinner\(Lokhttp3/CertificatePinner;\)Lokhttp3/OkHttpClient$Builder;")
if len(indexList) == 0:
self.okHttpCertificatePinningLocation.append(location)
# Check for custom Certificate Pinning Implementation
def checkCustomPinningImplementation(self):
customCertificatePinningLocations = self.checkForExistenceInFolder("invoke-virtual {(.*)}, Ljavax\/net\/ssl\/TrustManagerFactory;->init\(Ljava\/security\/KeyStore;\)V", self.getSmaliPaths())
if customCertificatePinningLocations[0] != '':
for location in customCertificatePinningLocations:
if "/okhttp" in location or "io/fabric" in location:
continue
self.customCertifificatePinningLocation.append(location)
# *** CUSTOM CHECKS ***
def findCustomChecks(self):
for check in self.configuration.getCustomChecks():
self.customChecksLocations[check[0]] = []
customCheckLocationsFound = self.checkForExistenceInFolder(check[1], self.getSmaliPaths())
if customCheckLocationsFound[0] != '':
for location in customCheckLocationsFound:
self.customChecksLocations[check[0]].append(location)
# *** GETTERS ***
def getVulnerableTrustManagers(self):
return self.vulnerableTrustManagers
def getVulnerableWebViewSSLErrorBypass(self):
return self.vulnerableWebViewSSLErrorBypass
def getVulnerableHostnameVerifiers(self):
return self.vulnerableHostnameVerifiers
def getEncryptionFunctionsLocations(self):
return self.encryptionFunctionsLocation
def getDecryptionFunctionsLocations(self):
return self.decryptionFunctionsLocation
def getUndeterminedCryptographicFunctionsLocations(self):
return self.undeterminedCryptographicFunctionsLocation
def getVulnerableSetHostnameVerifier(self):
return self.vulnerableSetHostnameVerifiers
def getVulnerableSockets(self):
return self.vulnerableSocketsLocations
def getWebViewsLoadUrlUsageLocations(self):
return self.webViewLoadUrlUsageLocation
def getCustomChecksLocations(self):
return self.customChecksLocations
def getWebviewAddJavascriptInterfaceLocations(self):
return self.webViewAddJavascriptInterfaceUsageLocation
def getAESwithECBLocations(self):
return self.AESwithECBLocations
def getDESLocations(self):
return self.DESLocations
def getJavascriptEnabledWebViews(self):
return self.javascriptEnabledWebviews
def getFileAccessEnabledWebViews(self):
return self.fileAccessEnabledWebviews
def getUniversalAccessFromFileURLEnabledWebviewsLocations(self):
return self.universalAccessFromFileURLEnabledWebviewsLocations
def getOkHTTPCertificatePinningLocations(self):
return self.okHttpCertificatePinningLocation
def getCustomCertificatePinningLocations(self):
return self.customCertifificatePinningLocation
def getKeystoreLocations(self):
return self.keystoreLocations
def getDynamicRegisteredBroadcastReceiversLocations(self):
return self.dynamicRegisteredBroadcastReceiversLocations
def getVulnerableContentProvidersSQLiLocations(self):
return self.vulnerableContentProvidersSQLiLocations
def getVulnerableContentProvidersPathTraversalLocations(self):
return self.vulnerableContentProvidersPathTraversalLocations