Skip to content

Commit

Permalink
MASWE-0103 demo (by @talsec)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Žigrai authored and Martin Žigrai committed Nov 22, 2024
1 parent 6321397 commit 701f402
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
31 changes: 31 additions & 0 deletions demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Demonstration of RASP Presence in a Mobile Application
platform: android
code:  [kotlin]
id: MASTG-DEMO-0021
test: MASTG-TEST-0228
---

### Sample

The following code snippet demonstrates the implementation of the freeRASP security library SDK. freeRASP periodically scans the device for threats, monitors its state, and gathers data to generate detailed threat reports. Threats are detected and communicated to the app via listeners. In this example, the root detection scenario is simulated.

{{ MastgTest.kt }}

### Steps

Check failure on line 15 in demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md

View workflow job for this annotation

GitHub Actions / markdown-lint-check

Headings should be surrounded by blank lines

demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md:15 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Steps"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md022.md
Start the device, in this case, the Android emulator:
```bash

Check failure on line 17 in demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md

View workflow job for this annotation

GitHub Actions / markdown-lint-check

Fenced code blocks should be surrounded by blank lines

demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md:17 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```bash"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md031.md
emulator -avd Pixel_3a_API_33_arm64-v8a -writable-system
```

**Note:** The snippet implements a simulated test for the freeRASP security library's root detection feature. The MastgTest class, which implements the ThreatDetected interface, includes various threat detection methods such as root detection, debugger detection, and emulator detection. The test specifically focuses on mocking the root detection functionality by invoking the onRootDetected() method, which logs the detection event and simulates app termination using the closeApp() method.

Launch the app from Android Studio and check the log. The snippet will log the “freeRASP Threat: onRootDetected”.


Check failure on line 25 in demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md

View workflow job for this annotation

GitHub Actions / markdown-lint-check

Multiple consecutive blank lines

demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md:25 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md012.md
### Observation

Check failure on line 26 in demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md

View workflow job for this annotation

GitHub Actions / markdown-lint-check

Headings should be surrounded by blank lines

demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md:26 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Observation"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md022.md
The RASP policy is only configured for root detection, other threats are not evaluated. The threat was detected immediately after app start. Sample includes commented-out code to forcefully terminate the app.


Check failure on line 29 in demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md

View workflow job for this annotation

GitHub Actions / markdown-lint-check

Multiple consecutive blank lines

demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md:29 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md012.md
### Evaluation

Check failure on line 30 in demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md

View workflow job for this annotation

GitHub Actions / markdown-lint-check

Headings should be surrounded by blank lines

demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MASTG-DEMO-0021.md:30 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Evaluation"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md022.md
The app didn’t utilise all the available security checks. It would be possible to bypass freeRASP API with Frida script or disable the termination method.
91 changes: 91 additions & 0 deletions demos/android/MASVS-RESILIENCE/MASTG-DEMO-0021/MastgTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.owasp.mastestapp


import android.content.Context
import android.util.Log


// mock: freeRASP ThreatDetected interface
interface ThreatDetected {
fun onRootDetected()
fun onDebuggerDetected()
fun onEmulatorDetected()
fun onTamperDetected()
fun onUntrustedInstallationSourceDetected()
fun onHookDetected()
fun onDeviceBindingDetected()
fun onObfuscationIssuesDetected()
}


// MastgTest class implementing ThreatDetected
class MastgTest(private val context: Context) : ThreatDetected {


companion object {
const val FREERASP_THREAT_TAG = "freeRASP Threat: "
}


fun mastgTest(): String {
return simulateThreatDetection()
}


// Simulate a test by calling onRootDetected
fun simulateThreatDetection() : String {
onRootDetected() // mock root was detected by freeRASP


return "freeRASP Threat: onRootDetected"
}


fun closeApp() {
// finishAffinity() // Closes all screens of the app
// System.exit(0) // Completely exits the app process
}




override fun onRootDetected() {
Log.d(FREERASP_THREAT_TAG, "onRootDetected")
closeApp() // Standard method to forcefully terminate the app
}


override fun onDebuggerDetected() {
Log.d(FREERASP_THREAT_TAG, "onDebuggerDetected")
}


override fun onEmulatorDetected() {
Log.d(FREERASP_THREAT_TAG, "onEmulatorDetected")
}


override fun onTamperDetected() {
Log.d(FREERASP_THREAT_TAG, "onTamperDetected")
}


override fun onUntrustedInstallationSourceDetected() {
Log.d(FREERASP_THREAT_TAG, "onUntrustedInstallationSourceDetected")
}


override fun onHookDetected() {
Log.d(FREERASP_THREAT_TAG, "onHookDetected")
}


override fun onDeviceBindingDetected() {
Log.d(FREERASP_THREAT_TAG, "onDeviceBindingDetected")
}


override fun onObfuscationIssuesDetected() {
Log.d(FREERASP_THREAT_TAG, "onObfuscationIssuesDetected")
}
}

0 comments on commit 701f402

Please sign in to comment.