-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port MASTG-TEST-0012 (by @guardsquare) #3113
base: master
Are you sure you want to change the base?
Conversation
|
||
### Evaluation | ||
|
||
The test succeeds because the output files show references to Device-Access-Security APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test succeeds because the output files show references to Device-Access-Security APIs | |
The test passes because the output show references to Device-Access-Security APIs. |
- a recent OS version | ||
- a OS build intended for the end users | ||
|
||
{{ MastgTest.kt }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{{ MastgTest.kt }} | |
{{ MastgTest.kt # MastgTest_reversed.java }} |
The third argument of `objc_msgSend(...)` is `LAPolicyDeviceOwnerAuthentication` because `w2` register at the time of the function invocation is set to `2` with a `mov` instruction at Line 9. `2` is an | ||
[enum](https://developer.apple.com/documentation/localauthentication/lapolicy?language=objc) representation of `LAPolicyDeviceOwnerAuthentication`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice!
The third argument of `objc_msgSend(...)` is `LAPolicyDeviceOwnerAuthentication` because `w2` register at the time of the function invocation is set to `2` with a `mov` instruction at Line 9. `2` is an | |
[enum](https://developer.apple.com/documentation/localauthentication/lapolicy?language=objc) representation of `LAPolicyDeviceOwnerAuthentication`. | |
The third argument of `objc_msgSend(...)` is `LAPolicyDeviceOwnerAuthentication` because `w2` register at the time of the function invocation is set to `2` with a `mov` instruction at Line 9. `2` is an [enum](https://developer.apple.com/documentation/localauthentication/lapolicy?language=objc) representation of `LAPolicyDeviceOwnerAuthentication`. |
|
||
### Evaluation | ||
|
||
The test succeeds because the output files show references to Device-Access-Security API, which indicates that a developer checks whether a passcode is set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test succeeds because the output files show references to Device-Access-Security API, which indicates that a developer checks whether a passcode is set. | |
The test passes because the output show references to Device-Access-Security APIs, which indicates that a developer checks whether a passcode is set. |
--- | ||
platform: ios | ||
title: References to Device-Access-Security Policy APIs | ||
id: MASTG-TEST-0243 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix file name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain in the PR description why this was removed:
You can implement checks on the Android device by querying Settings.Secure for system preferences. Device Administration API offers techniques for creating applications that can enforce password policies and device encryption.
My understanding is that:
- Device Administration API
- is something that apps like Intune would use. Also it's deprecated. Instead, Android for enterprise should be used.
- requires device admin privileges so it's not apt for "regular apps" and we can ignore it for these tests.
- Settings.Secure seems to be unrelated and the right API is isDeviceSecure
|
||
This test checks whether an application is running on a device with secure policies such as | ||
|
||
- device passcode is set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about including...?
biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG)
checks if the device supports strong biometric authentication and if the user has enrolled biometric credentials. The method returns one of the following constants:
- BIOMETRIC_SUCCESS: The device supports biometrics, and the user has enrolled at least one biometric credential.
- BIOMETRIC_ERROR_NO_HARDWARE: The device does not have biometric hardware.
- BIOMETRIC_ERROR_HW_UNAVAILABLE: The biometric hardware is currently unavailable.
- BIOMETRIC_ERROR_NONE_ENROLLED: The user has not enrolled any biometric credentials.
Requires Manifest.permission.USE_BIOMETRIC
package org.owasp.mastestapp | ||
|
||
import android.app.KeyguardManager | ||
import android.content.Context | ||
import android.os.Build | ||
|
||
|
||
class MastgTest (private val context: Context){ | ||
|
||
fun mastgTest(): String { | ||
val isLocked = isDeviceSecure(context) | ||
val androidSdkVersion = getSystemSdkVersion() | ||
val isSystemDebuggable = isSystemDebuggable() | ||
return "Device has a passcode: $isLocked\nandroidSdkVersion:$androidSdkVersion\nisSystemDebuggable:$isSystemDebuggable" | ||
} | ||
|
||
fun isDeviceSecure(context: Context): Boolean { | ||
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager | ||
return keyguardManager.isDeviceSecure | ||
} | ||
|
||
fun getSystemSdkVersion(): Int { | ||
return android.os.Build.VERSION.SDK_INT | ||
} | ||
|
||
fun isSystemDebuggable(): Boolean { | ||
return Build.TYPE == "eng" || Build.TYPE == "userdebug" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package org.owasp.mastestapp | |
import android.app.KeyguardManager | |
import android.content.Context | |
import android.os.Build | |
class MastgTest (private val context: Context){ | |
fun mastgTest(): String { | |
val isLocked = isDeviceSecure(context) | |
val androidSdkVersion = getSystemSdkVersion() | |
val isSystemDebuggable = isSystemDebuggable() | |
return "Device has a passcode: $isLocked\nandroidSdkVersion:$androidSdkVersion\nisSystemDebuggable:$isSystemDebuggable" | |
} | |
fun isDeviceSecure(context: Context): Boolean { | |
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager | |
return keyguardManager.isDeviceSecure | |
} | |
fun getSystemSdkVersion(): Int { | |
return android.os.Build.VERSION.SDK_INT | |
} | |
fun isSystemDebuggable(): Boolean { | |
return Build.TYPE == "eng" || Build.TYPE == "userdebug" | |
} | |
} | |
package org.owasp.mastestapp | |
import android.app.KeyguardManager | |
import android.content.Context | |
import android.hardware.biometrics.BiometricManager | |
import android.os.Build | |
class MastgTest(private val context: Context) { | |
fun mastgTest(): String { | |
val isLocked = isDeviceSecure(context) | |
val biometricStatus = checkStrongBiometricStatus() | |
return "Device has a passcode: $isLocked\n\n" + | |
"Biometric status: $biometricStatus" | |
} | |
fun isDeviceSecure(context: Context): Boolean { | |
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager | |
return keyguardManager.isDeviceSecure | |
} | |
/** | |
* Checks if the device supports strong biometric authentication (e.g., fingerprint, face, iris) | |
* and if the user has enrolled biometric credentials. | |
* | |
* **Note:** This API is available on API level 30 (Android R) and above. | |
* | |
* @return A human-readable string describing the biometric status. | |
*/ | |
fun checkStrongBiometricStatus(): String { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | |
val biometricManager = context.getSystemService(BiometricManager::class.java) | |
val result = biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) | |
return when (result) { | |
BiometricManager.BIOMETRIC_SUCCESS -> | |
"BIOMETRIC_SUCCESS - Strong biometric authentication is available." | |
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE -> | |
"BIOMETRIC_ERROR_NO_HARDWARE - No biometric hardware available." | |
BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE -> | |
"BIOMETRIC_ERROR_HW_UNAVAILABLE - Biometric hardware is currently unavailable." | |
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> | |
"BIOMETRIC_ERROR_NONE_ENROLLED - No biometrics enrolled." | |
else -> | |
"Unknown biometric status: $result" | |
} | |
} else { | |
return "Strong biometric authentication check is not supported on this API level." | |
} | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs <uses-permission android:name="android.permission.USE_BIOMETRIC" />
in the AndroidManifest
e asm.bytes=false | ||
e scr.color=false | ||
e asm.var=false | ||
|
||
aao | ||
e asm.emu=true | ||
|
||
?e Print xrefs to \'canEvaluatePolicy\" | ||
f~str.canEvaluatePolicy:error: | ||
|
||
?e Print xrefs to 0x100008360 | ||
axt 0x100008360 | ||
|
||
?e Print disassembly around \"canEvaluatePolicy\" in the function | ||
pdf @ 0x100004f10 | grep -B 5 "canEvaluatePolicy:error:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works with the latest r2 from git
e asm.bytes=false | |
e scr.color=false | |
e asm.var=false | |
aao | |
e asm.emu=true | |
?e Print xrefs to \'canEvaluatePolicy\" | |
f~str.canEvaluatePolicy:error: | |
?e Print xrefs to 0x100008360 | |
axt 0x100008360 | |
?e Print disassembly around \"canEvaluatePolicy\" in the function | |
pdf @ 0x100004f10 | grep -B 5 "canEvaluatePolicy:error:" | |
e asm.bytes=false | |
e scr.color=false | |
e asm.var=false | |
?e Print xrefs to \'canEvaluatePolicy\" | |
f~canEvaluatePolicy | |
?e | |
?e Print xrefs to 0x100008360 | |
axt @ 0x100008360 | |
?e | |
?e Print xrefs to 0x1000100a0 | |
axt @ 0x1000100a0 | |
?e | |
?e Print disassembly around \"canEvaluatePolicy\" in the function | |
pdf @ 0x100004f10 | grep -C 5 "canEvaluatePolicy:error:" |
@@ -0,0 +1,2 @@ | |||
#!/bin/bash | |||
r2 -q -i isDevicePasscodeSet.r2 -A MASTestApp > output.asm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r2 -q -i isDevicePasscodeSet.r2 -A MASTestApp > output.asm | |
r2 -q -i isDevicePasscodeSet.r2 -e emu.str=true -A MASTestApp > output.asm |
|
||
## Overview | ||
|
||
This test verifies that an application is running on a device with a set passcode. A set passcode ensures that data on the device is encrypted and access to the device is restricted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also include this?
From the weakness draft:
to make sure that biometrics can be used, verify that the
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
or thekSecAttrAccessibleWhenPasscodeSet
protection class is set when theSecAccessControlCreateWithFlags
method is called
To use Optic ID, Face ID, or Touch ID, the user must set up their device so that a passcode or password is required to unlock it.
https://support.apple.com/en-ph/guide/security/sec9479035f1/web
…ice security enforcement
@@ -0,0 +1,35 @@ | |||
--- | |||
platform: ios | |||
title: Uses of Device-Access-Security APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: Uses of Device-Access-Security APIs | |
title: Uses of LAContext.canEvaluatePolicy with r2 |
@@ -0,0 +1,39 @@ | |||
--- | |||
platform: android | |||
title: Uses of Device-Access-Security APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: Uses of Device-Access-Security APIs | |
title: Uses of KeyguardManager.isDeviceSecure with semgrep |
- running on a recent version of Android OS | ||
- running on a secure system build intended for the end users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in Slack, these two can be removed from here after the changes done in MASWE-0008. If anything, they'd belong in MASWE-0077 or other MASWEs related to MASVS-RESILIENCE-1
- running on a recent version of Android OS | |
- running on a secure system build intended for the end users |
@@ -1,29 +1,28 @@ | |||
--- | |||
title: Device Access Security Policy Not Enforced | |||
title: Secured Device Detection Not Implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or "Missing Device Secure Lock Verification Implementation". Any other ideas?
@@ -0,0 +1,25 @@ | |||
--- | |||
platform: ios | |||
title: References to Device-Access-Security Policy APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe?
title: References to Device-Access-Security Policy APIs | |
title: References to Secure Lock Verification APIs |
@@ -0,0 +1,31 @@ | |||
--- | |||
platform: android | |||
title: References to Device-Access-Security Policy APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe?
title: References to Device-Access-Security Policy APIs | |
title: References to Secure Lock Verification APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-device-access-security-sdk-version.yml ./MastgTest_reversed.java --text -o output_version.txt | ||
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-device-access-security-debuggable-system.yml ./MastgTest_reversed.java --text -o output_debuggable_system.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-device-access-security-sdk-version.yml ./MastgTest_reversed.java --text -o output_version.txt | |
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-device-access-security-debuggable-system.yml ./MastgTest_reversed.java --text -o output_debuggable_system.txt |
This PR closes #2937