Skip to content
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-0082: Testing whether the App is Debuggable (ios) (by @appknox) #3097

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jeel38
Copy link
Collaborator

@jeel38 jeel38 commented Dec 16, 2024

closes #3010


## Steps

1. Run a static analysis using @MASTG-TOOL-0111 to extract entitlements from the binary to check the value of the `get-task-allow` key and is set to `true`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to use the technique instead of specific tools in TESTS

https://mas.owasp.org/MASTG/techniques/ios/MASTG-TECH-0111/

Also, let's do the evaluation (check for true, in this case) later.

Suggested change
1. Run a static analysis using @MASTG-TOOL-0111 to extract entitlements from the binary to check the value of the `get-task-allow` key and is set to `true`.
1. Use @MASTG-TECH-0111 to extract entitlements from the binary and obtain the value of the `get-task-allow` key.

## Steps

1. Run a static analysis using @MASTG-TOOL-0111 to extract entitlements from the binary to check the value of the `get-task-allow` key and is set to `true`.
2. Run a [dynamic analysis](../../../techniques/ios/MASTG-TECH-0084.md) using @MASTG-TOOL-0057.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static analysis step should be enough. However, you still can refer to this TECH. See overview


## Observation

The entitlement get-task-allow is false, and anti-reverse engineering measures prevent debugger attachment attempts.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The entitlement get-task-allow is false, and anti-reverse engineering measures prevent debugger attachment attempts.
The output contains the value of the `get-task-allow` entitlement.


## Evaluation

The test fails as the entitlement get-task-allow is true, allowing debugger attachment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The test fails as the entitlement get-task-allow is true, allowing debugger attachment.
The test fails if the `get-task-allow` entitlement is `true`.


## Overview

The test evaluates whether an iOS application is configured to allow debugging. If an app is debuggable, attackers can leverage debugging tools to reverse-engineer the application, analyse its runtime behaviour, and potentially compromise sensitive data or functionality.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The test evaluates whether an iOS application is configured to allow debugging. If an app is debuggable, attackers can leverage debugging tools to reverse-engineer the application, analyse its runtime behaviour, and potentially compromise sensitive data or functionality.
The test evaluates whether an iOS application is configured to allow debugging. If an app is debuggable, attackers can leverage debugging tools (see @MASTG-TECH-0084) to analyse the runtime behaviour of the app, and potentially compromise sensitive data or functionality.

@cpholguera
Copy link
Collaborator

First round of review done. Please remember to include a demo using https://github.com/cpholguera/MASTestApp-iOS

Thanks a lot @jeel38!

@jeel38
Copy link
Collaborator Author

jeel38 commented Feb 3, 2025

@cpholguera Please Review it

Copy link
Collaborator

@serek8 serek8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution. I added a few comments in code.

One more thingy, your demo covers 2 cases:

  • detects if an app is debuggable
  • detects if an app is currently being debugged

Can you split these two cases into two distinct demos and make sure this subtle difference is clear for the reader?

print("📄 Info.plist Path: \(infoPath)")

if let infoDict = NSDictionary(contentsOfFile: infoPath) {
print("📋 Info.plist Contents: \(infoDict)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we print Info.plist? Does it contain info about a debuggable capability?


if data.count > 0 {
if let content = String(data: data, encoding: .ascii),
content.contains("get-task-allow") {
Copy link
Collaborator

@serek8 serek8 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid this method might cause false positives. For example, if there is a third-party code in the binary that also contains get-task-allow string, this would trigger a false positive. It's also a bit slow to search through the whole binary, no? Can you optimise it?


// Method 4: Process Info
print("\nMethod 4: Checking Process Info")
let isDebugger = isDebuggerAttached()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make such a function for each method? It would clean up the code a bit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this file at all? If I'm not wrong I think we just need the modified entitlements file, so that we can build the app using it, and the reversed version.

Here's the original: https://github.com/cpholguera/MASTestApp-iOS/blob/main/entitlements.plist

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reducing this demo to only one method is also ok

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -0,0 +1 @@
r2 -q -i debuggable.r2 -A MASTestApp > output.asm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r2 -q -i debuggable.r2 -A MASTestApp > output.asm
rabin2 -OC MASTestApp | grep -A1 get-task-allow

Comment on lines +1 to +3
search for get-task-allow
271 0x00011987 0x100011987 401 402 ascii <?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n\t<key>application-identifier</key>\n\t<string>AYRP7NNB54.org.owasp.mastestapp.MASTestApp-iOS</string>\n\t<key>com.apple.developer.team-identifier</key>\n\t<string>AYRP7NNB54</string>\n\t<key>get-task-allow</key>\n\t<true/>\n</dict>\n</plist>\n
273 0x00011baa 0x100011baa 14 15 ascii get-task-allow
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
search for get-task-allow
271 0x00011987 0x100011987 401 402 ascii <?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n\t<key>application-identifier</key>\n\t<string>AYRP7NNB54.org.owasp.mastestapp.MASTestApp-iOS</string>\n\t<key>com.apple.developer.team-identifier</key>\n\t<string>AYRP7NNB54</string>\n\t<key>get-task-allow</key>\n\t<true/>\n</dict>\n</plist>\n
273 0x00011baa 0x100011baa 14 15 ascii get-task-allow
<key>get-task-allow</key>
<true/>


## Steps

1. Use @MASTG-TECH-0111 to extract entitlements from the binary and obtain the value of the `get-task-allow` key.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Use @MASTG-TECH-0111 to extract entitlements from the binary and obtain the value of the `get-task-allow` key.
1. Use @MASTG-TECH-0111 to extract entitlements from the binary
2. Search for the `get-task-allow` key.


The code snippet below shows sample code that verify the application is debuggable.

{{ MastgTest.swift }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this we need the modified entitlements file, so that we can build the app using it, and the reversed version.

Here's the original: https://github.com/cpholguera/MASTestApp-iOS/blob/main/entitlements.plist

Suggested change
{{ MastgTest.swift }}
{{ entitlements.plist # entitlements_reversed.plist }}

Comment on lines +18 to +20
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.

{{ debuggable.r2 }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script.
{{ debuggable.r2 }}
2. Run @MASTG-TOOL-0129 with the `-OC` options to obtain the entitlements file.


### Evaluation

The test passes because debugging detection checks are implemented in the app.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The test passes because debugging detection checks are implemented in the app.
The test fails because the app is debuggable due to the `get-task-allow` entitlement being present.

@@ -0,0 +1,32 @@
---
platform: ios
title: Verify App is Debuggable with r2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: Verify App is Debuggable with r2
title: Debuggable Entitlement Enabled in the entitlements.plist with rabin2

@@ -0,0 +1,23 @@
---
platform: ios
title: Testing Whether the App is Debuggable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: Testing Whether the App is Debuggable
title: Debuggable Entitlement Enabled in the entitlements.plist

title: Testing Whether the App is Debuggable
id: MASTG-TEST-0x82
type: [static, dynamic]
weakness: MASWE-0101
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MASWE-0067: Debuggable Flag Not Disabled

Suggested change
weakness: MASWE-0101
weakness: MASWE-0067

@cpholguera
Copy link
Collaborator

@jeel38 we're almost there, thanks!!

@cpholguera cpholguera changed the title Port MASTG-TEST-0082 (by @appknox) Port MASTG-TEST-0082: Testing whether the App is Debuggable (ios) (by @appknox) Feb 24, 2025
@cpholguera
Copy link
Collaborator

cpholguera commented Feb 28, 2025

@jeel38 any news? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MASTG v1->v2 MASTG-TEST-0082: Testing whether the App is Debuggable (ios)
3 participants