Skip to content

Commit 0dfd265

Browse files
authored
Update 2025-10-07-iOS-All-The-Things-Part-IV.md
1 parent 35ed5b3 commit 0dfd265

File tree

1 file changed

+318
-2
lines changed

1 file changed

+318
-2
lines changed

_posts/2025-10-07-iOS-All-The-Things-Part-IV.md

Lines changed: 318 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
date: 2025-10-08 00:02:15
2+
date: 2025-10-09 06:58:15
33
layout: post
44
title: iOS All The Things - Part IV
55

@@ -23,7 +23,7 @@ tags:
2323
2. [iOS Code Security](#ios-code-security)
2424
3. [Third Party Libraries](#third-party-libraries)
2525
4. [Inter-Process Communication (IPC)](#inter-process-communication-ipc)
26-
5. [iOS App Attack Surface](#ios-app-attack-surface)
26+
5. [Web Views Javascript to Native Bridge](#web-views-javascript-to-native-bridge)
2727
6. [Conclusion](#conclusion)
2828

2929
## Intro
@@ -273,6 +273,7 @@ b. Dylib Risks
273273
We can use frida script to monitor dylib loading:
274274

275275
```javascript
276+
# Real-time interception of library loading
276277
Interceptor.attach(Module.findExportByName(null, "dlopen"), {
277278
onEnter: function(args) {
278279
var path = args[0].readCString();
@@ -284,8 +285,323 @@ b. Dylib Risks
284285
}
285286
});
286287
```
288+
289+
c. Library Permissions Analysis
290+
291+
* Libraries often request more permissions than needed
292+
* Can lead to data leakage or privilege escalation
293+
294+
Checking Library Permissions:
295+
296+
```bash
297+
# run command on ios jailbroken device
298+
# Extract entitlements from the app
299+
ldid -e "Binary-App" > app_entitlements.plist
300+
301+
# Check embedded framework entitlements
302+
ldid -e App/Frameworks/Analytics.framework > analytics_entitlements.plist
303+
```
304+
305+
Common Over-Privileged Libraries:
306+
307+
```xml
308+
<!-- Example of excessive entitlements in library -->
309+
<key>com.apple.developer.associated-domains</key>
310+
<array>
311+
<string>applinks:example.com</string>
312+
<string>applinks:tracking-library.com</string> <!-- Suspicious -->
313+
</array>
314+
<key>com.apple.developer.networking.wifi-info</key> <!-- Often unnecessary -->
315+
<true/>
316+
```
317+
318+
**Testing Methodology:**
319+
320+
* Dependency Vulnerability Assessment:
321+
322+
```bash
323+
# Automated vulnerability scanning
324+
dependency-check --project "App" --scan "Podfile.lock"
325+
326+
# Manual version verification
327+
grep -A 10 "Alamofire" Podfile.lock
328+
grep -A 10 "Firebase" Podfile.lock
329+
```
330+
331+
* Dylib Security Analysis:
287332
333+
```javascript
334+
// Snapshot of currently loaded librarie
335+
Process.enumerateModules({
336+
onMatch: function(module){
337+
if (module.path.includes(".dylib")) {
338+
console.log("Loaded Dylib: " + module.name + " at " + module.path);
339+
}
340+
},
341+
onComplete: function(){}
342+
});
343+
```
344+
345+
* Permission Audit:
346+
347+
```bash
348+
# Compare app vs library entitlements
349+
diff app_entitlements.plist analytics_entitlements.plist
350+
```
351+
352+
**Remediation Recommendations**
353+
354+
* For Developers:
355+
* Regular Dependency Updates.
356+
* Dylib Security:
357+
* Use @loader_path instead of @executable_path.
358+
* Validate dylib code signatures at runtime.
359+
* Restrict dylib loading to app bundle only.
360+
* Permission Minimization:
361+
* Review each library's entitlement requests.
362+
* Remove unnecessary permissions.
363+
* Use app groups selectively.
364+
365+
* For Penetration Testers:
366+
* Always include dependency vulnerability scanning.
367+
* Verify dylib loading paths and signatures.
368+
* Audit library permissions against functionality.
369+
* Test for runtime library manipulation.
370+
371+
> **Important Link:** special for [Dylib](https://book.hacktricks.wiki/en/macos-hardening/macos-security-and-privilege-escalation/macos-dyld-hijacking-and-dyld_insert_libraries.html)
288372
373+
## Inter-Process Communication (IPC)
289374
375+
Inter-Process Communication (IPC) allows iOS applications to exchange data and communicate with other apps, extensions, and system services. While IPC enables powerful functionality, it also creates significant security risks that penetration testers must evaluate.
376+
377+
**Types of IPC Mechanisms in iOS:**
378+
379+
a. URL Schemes:
380+
381+
* Allow apps to communicate via custom URLs.
382+
* Can be exploited for unauthorized data access or actions.
383+
* How They Work:
384+
* Apps register a custom URL scheme (e.g., `myapp://`) in their `Info.plist`:
385+
386+
```xml
387+
<key>CFBundleURLTypes</key>
388+
<array>
389+
<dict>
390+
<key>CFBundleURLSchemes</key>
391+
<array>
392+
<string>myapp</string>
393+
</array>
394+
</dict>
395+
</array>
396+
```
397+
398+
* When a user clicks a link like `myapp://profile/123`, iOS checks if any app has registered `myapp://` and opens it.
399+
400+
b. Universal Links:
401+
402+
* A deeplink in mobile application is like a special link that takes you directly to a specific part of a mobile app instead of a website. This means you can easily switch between apps or go from a website to an app without having to click a lot of buttons. It makes it quicker and easier to find what you’re looking for in the app.
403+
* Can be hijacked if not properly validated.
404+
* How They Work:
405+
* Uses standard HTTPS links (e.g., `https://example.com/profile/123`) instead of custom schemes.
406+
* Server Setup: Host an `apple-app-site-association` (AASA) JSON file at `https://example.com/.well-known/apple-app-site-association`.
407+
408+
```json
409+
{
410+
"applinks": {
411+
"apps": [],
412+
"details": [
413+
{
414+
"appID": "TEAMID.com.example.app",
415+
"paths": ["/profile/*", "/settings"]
416+
}
417+
]
418+
}
419+
}
420+
```
421+
422+
* App Setup: Enable "Associated Domains" in Xcode and add
423+
424+
```text
425+
applinks:example.com
426+
```
427+
428+
**URL Schemes vs Universal Links:**
429+
430+
| Feature | URL Schemes (`myapp://`) | Universal Links (`https://`) |
431+
| ------------------- | ----------------------------| -----------------------------|
432+
| **Security** | No ownership check | Verified via AASA file |
433+
| **User Experience** | Shows "Open in App?" prompt | Opens silently |
434+
| **Fallback** | Fails if app not installed | Opens in Safari |
435+
| **Implementation** | Just `Info.plist` | Needs server config |
436+
| **iOS Support** | All versions | iOS 9+ |
437+
| **Phishing Risk** | High (hijackable) | Low (secure) |
438+
439+
**How to test url schemes and universal links**
440+
441+
* Get all url schemes and universal links.
442+
443+
```bash
444+
# go to file and search on "CFBundleURLTypes" or "LSApplicationQueriesSchemes" to get url schemes
445+
ipsw plist info.plist > info.plist.json
446+
447+
# search on "com.apple.developer.associated-domain" to get universal links
448+
ipsw macho info Binary-App
449+
```
450+
451+
![image](/assets/img/ios-pentesting/Part-IV/url-schemes.png)
452+
453+
![image](/assets/img/ios-pentesting/Part-IV/universal-links.png)
454+
455+
* Another way to get all links.
456+
457+
```bash
458+
strings Binary-App | grep "://"
459+
```
460+
461+
![image](/assets/img/ios-pentesting/Part-IV/links.png)
462+
463+
* Use uiopen on ios jailbroken device to check links.
464+
465+
```bash
466+
# Test Url Schemes Handling
467+
uiopen "myapp://profile/123"
468+
469+
# Check for sensitive data exposure
470+
uiopen "myapp://get-token"
471+
uiopen "myapp://export-database"
472+
```
473+
474+
* We can use Frida instead of uiopen to do same thing:
475+
* To intercept openurl function
476+
477+
```javascript
478+
function openURL(url) {
479+
var UIApplication = ObjC.classes.UIApplication.sharedApplication();
480+
var nsURL = ObjC.classes.NSURL.URLWithString_(url);
481+
return UIApplication.openURL_(nsURL);
482+
}
483+
```
484+
* Request the url schemas
485+
486+
![image](/assets/img/ios-pentesting/Part-IV/openurl.png)
487+
488+
489+
* Can use frida-trace to get the methods and classes that using openurl, run it then go to ssh connection on device and run the url schema using uiopen to trace exactly what is method and class use that url schema.
490+
491+
```bash
492+
frida-trace -U -m '*[* *openURL*]' -p 1234
493+
```
494+
495+
![image](/assets/img/ios-pentesting/Part-IV/trace.png)
496+
497+
c. Keychain Sharing:
498+
499+
* The iOS Keychain is a secure storage system for sensitive information like passwords, credit card details, and cryptographic keys, accessible to apps and the user.
500+
* Allows apps from same developer to share sensitive data.
501+
* Implemented through Keychain Access Groups.
502+
503+
![image](/assets/img/ios-pentesting/Part-IV/keychain.png)
290504
505+
* Keychain Data Protection Classes
506+
507+
![image](/assets/img/ios-pentesting/Part-IV/keychain-classes.png)
508+
509+
* To know the ios app use keychain or not, check keychain api includes the following main operations:
510+
* secitemadd
511+
* secitemupdate
512+
* secitemdelete
513+
* secitemdelete
514+
515+
```bash
516+
strings Binary-app | grep "SecItem"
517+
```
518+
519+
![image](/assets/img/ios-pentesting/Part-IV/ops-keychain.png)
520+
521+
* Keychain data extraction
522+
523+
```bash
524+
// Using Objection to dump keychain
525+
ios keychain dump
526+
527+
// Using Frida for keychain analysis
528+
ObjC.classes.SecItem.copyMatching.implementation = function(query) {
529+
console.log("[+] Keychain query: " + query);
530+
return this.self.copyMatching(query);
531+
};
532+
```
533+
534+
d. XPC Services:
535+
536+
* Lightweight inter-process communication.
537+
* Used for app-to-app and app-to-system service communication.
538+
539+
e. App Extensions:
540+
541+
* Today Widgets, Share Extensions, Action Extensions.
542+
* Run in separate processes but share data with host app.
543+
544+
f. UIActivityViewController:
545+
546+
* Shares data between apps through system-provided activities.
547+
* Can leak sensitive information to unauthorized apps.
548+
549+
g. App Groups:
550+
551+
* Allows multiple apps or extensions to share container storage.
552+
* Uses shared file containers for data exchange.
553+
554+
**Common IPC Vulnerabilities:**
555+
556+
a. URL Scheme Hijacking:
557+
558+
* Unprotected URL schemes allowing any app to trigger actions.
559+
* Lack of input validation in URL parameters.
560+
* Sensitive data exposure through callback URLs.
561+
562+
b. Insecure App Group Sharing:
563+
564+
* World-readable shared containers.
565+
* Lack of encryption in shared files.
566+
* Improper access controls.
567+
568+
c. Keychain Access Issues:
569+
570+
* Overly permissive keychain access groups.
571+
* Weak keychain item protection classes.
572+
* Failure to use appropriate accessibility settings.
573+
574+
d. Extension Vulnerabilities:
575+
576+
* Extensions with excessive permissions.
577+
* Data leakage between host app and extension.
578+
* Inadequate sandboxing.
579+
580+
**Security Best Practices**
581+
582+
a. URL Scheme Protection:
583+
584+
* Validate incoming URL parameters.
585+
* Implement custom URL scheme authentication.
586+
* Restrict sensitive actions to authenticated users.
587+
588+
b. App Group Security:
589+
590+
* Encrypt sensitive data in shared containers.
591+
* Implement proper file permissions.
592+
* Use separate app groups for different sensitivity levels.
593+
594+
c. Keychain Hardening:
595+
596+
* Use appropriate protection classes (kSecAttrAccessibleWhenUnlocked).
597+
* Implement proper access control settings.
598+
* Regularly audit keychain usage.
599+
600+
d. Extension Security:
601+
602+
* Minimize extension permissions.
603+
* Implement data sanitization.
604+
* Use separate app groups for sensitive data.
605+
606+
## Web Views Javascript to Native Bridge
291607

0 commit comments

Comments
 (0)