-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add iOS Patching technique (MASTG-TECH-0140) #3654
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
Draft
Copilot
wants to merge
3
commits into
master
Choose a base branch
from
copilot/patch-app-for-debugging
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- | ||
| title: Patching | ||
| platform: ios | ||
| --- | ||
|
|
||
| Making small changes to an iOS app can help overcome common obstacles during security testing and reverse engineering. On iOS, two issues in particular happen regularly: | ||
|
|
||
| 1. You can't intercept HTTPS traffic with a proxy because the app implements SSL pinning. | ||
| 2. You can't attach a debugger to the app because it lacks the `get-task-allow` entitlement. | ||
|
|
||
| In most cases, both issues can be fixed by patching the app and then re-signing and repackaging it. Apps that implement additional integrity checks beyond default iOS code-signing are an exception. In those cases, you have to patch the additional checks as well. | ||
|
|
||
| The first step is to obtain and extract the IPA file as described in @MASTG-TECH-0054. | ||
|
|
||
| !!! note | ||
| If the app binary is encrypted (apps from the App Store), you must first decrypt it before patching. See the decryption section in @MASTG-TECH-0054 for details. | ||
|
|
||
| ## Patching Example: Making an App Debuggable | ||
|
|
||
| By default, apps available on the Apple App Store are not debuggable. To debug an iOS application, it must have the `get-task-allow` entitlement enabled. This entitlement allows other processes (like a debugger) to attach to the app. Xcode doesn't add the `get-task-allow` entitlement in a distribution provisioning profile; it is only included in development provisioning profiles. | ||
|
|
||
| When reverse engineering apps, you'll often only have access to the release build. Release builds aren't meant to be debugged. Although this is a security feature, being able to attach a debugger and inspect the runtime state of a program makes understanding the program significantly easier. | ||
|
|
||
| To enable debugging on a release build, you need to re-sign the app with a development provisioning profile that includes the `get-task-allow` entitlement. | ||
|
|
||
| ### Steps | ||
|
|
||
| 1. **Obtain a development provisioning profile**: Follow the steps in @MASTG-TECH-0079 to obtain a valid development provisioning profile. The profile will automatically include the `get-task-allow` entitlement set to `true`. | ||
|
|
||
| 2. **Extract the IPA**: Unzip the IPA file to access its contents: | ||
|
|
||
| ```bash | ||
| unzip target_app.ipa -d extracted_app | ||
| ``` | ||
|
|
||
| 3. **Verify the entitlements**: You can inspect the current entitlements of the app binary using @MASTG-TOOL-0114: | ||
|
|
||
| ```bash | ||
| codesign -d --entitlements - "extracted_app/Payload/TargetApp.app" | ||
| ``` | ||
|
|
||
| For release builds from the App Store, you will typically see that `get-task-allow` is either missing or set to `false`. | ||
|
|
||
| 4. **Re-sign the app**: Use your development provisioning profile to re-sign the app. The provisioning profile contains the `get-task-allow` entitlement. Follow the signing instructions in @MASTG-TECH-0092 to complete this step. | ||
|
|
||
| The re-signing process will apply the entitlements from your development provisioning profile to the app, including `get-task-allow` set to `true`. | ||
|
|
||
| 5. **Repackage the IPA**: After re-signing, repackage the modified app: | ||
|
|
||
| ```bash | ||
| cd extracted_app | ||
| zip -r ../patched_app.ipa Payload | ||
| ``` | ||
|
|
||
| 6. **Install and launch in debug mode**: Install the patched app on your device as described in @MASTG-TECH-0056, then launch it in debug mode following @MASTG-TECH-0055. | ||
|
|
||
| 7. **Attach a debugger**: You can now attach @MASTG-TOOL-0057 or other debuggers to the app as described in @MASTG-TECH-0084. | ||
|
|
||
| ### Verification | ||
|
|
||
| To verify that the `get-task-allow` entitlement is now present, check the entitlements of the re-signed app: | ||
|
|
||
| ```bash | ||
| codesign -d --entitlements - "extracted_app/Payload/TargetApp.app" | ||
| ``` | ||
|
|
||
| You should see: | ||
|
|
||
| ```xml | ||
| <key>get-task-allow</key> | ||
| <true/> | ||
| ``` | ||
|
|
||
| ## Patching Binary Code | ||
|
|
||
| In some cases, you may need to patch the app's binary code directly, for example, to bypass certificate pinning checks or disable jailbreak detection. Tools like @MASTG-TOOL-0031 and @MASTG-TOOL-0033 can help you analyze and understand the binary, while tools like @MASTG-TOOL-0059 can modify the binary by adding or changing load commands. | ||
|
|
||
| For more advanced binary patching, consider using disassemblers for static analysis or writing custom Frida scripts to hook and modify behavior at runtime instead of patching the binary directly. | ||
|
|
||
| ## Patching React Native Apps | ||
|
|
||
| If the app uses React Native, see @MASTG-TECH-0098 for specific guidance on patching React Native applications. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
MASTG-TECHID DetectedThis file has the ID
MASTG-TECH-0140which already exists intechniques/android/MASTG-TECH-0140.md.IMPORTANT: Please use the next available ID:
MASTG-TECH-0144