mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
79 lines
3.8 KiB
Markdown
79 lines
3.8 KiB
Markdown
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
在 iOS 设备上,应用程序之间的数据共享是通过 [`UIPasteboard`](https://developer.apple.com/documentation/uikit/uipasteboard) 机制实现的,该机制分为两类:
|
||
|
||
- **系统范围的通用粘贴板**:用于与 **任何应用程序** 共享数据,并设计为在设备重启和应用程序卸载之间持久化数据,该功能自 iOS 10 起可用。
|
||
- **自定义/命名粘贴板**:专门用于 **在应用程序内或与共享相同团队 ID 的其他应用程序** 共享数据,并不设计为在创建它们的应用程序进程的生命周期之外持久化,遵循 iOS 10 引入的更改。
|
||
|
||
**安全考虑** 在使用粘贴板时起着重要作用。例如:
|
||
|
||
- 用户没有机制来管理应用程序访问 **粘贴板** 的权限。
|
||
- 为了减轻未经授权的后台监控粘贴板的风险,访问限制为应用程序在前台时(自 iOS 9 起)。
|
||
- 由于隐私问题,不鼓励使用持久命名粘贴板,而是倾向于使用共享容器。
|
||
- 随着 iOS 10 引入的 **通用剪贴板** 功能,允许通过通用粘贴板在设备之间共享内容,开发人员可以管理数据过期和禁用自动内容传输。
|
||
|
||
确保 **敏感信息不会无意中存储** 在全局粘贴板上至关重要。此外,应用程序应设计为防止全局粘贴板数据被误用进行意外操作,鼓励开发人员实施措施以防止将敏感信息复制到剪贴板。
|
||
|
||
### 静态分析
|
||
|
||
对于静态分析,搜索源代码或二进制文件中的:
|
||
|
||
- `generalPasteboard` 以识别 **系统范围的通用粘贴板** 的使用。
|
||
- `pasteboardWithName:create:` 和 `pasteboardWithUniqueName` 用于创建 **自定义粘贴板**。验证是否启用了持久性,尽管这已被弃用。
|
||
|
||
### 动态分析
|
||
|
||
动态分析涉及钩住或跟踪特定方法:
|
||
|
||
- 监控 `generalPasteboard` 的系统范围使用。
|
||
- 跟踪 `pasteboardWithName:create:` 和 `pasteboardWithUniqueName` 的自定义实现。
|
||
- 观察已弃用的 `setPersistent:` 方法调用以检查持久性设置。
|
||
|
||
需要监控的关键细节包括:
|
||
|
||
- **粘贴板名称** 和 **内容**(例如,检查字符串、URL、图像)。
|
||
- **项目数量** 和 **数据类型**,利用标准和自定义数据类型检查。
|
||
- 通过检查 `setItems:options:` 方法来查看 **过期和本地选项**。
|
||
|
||
监控工具使用的一个示例是 **objection 的粘贴板监视器**,它每 5 秒轮询一次 generalPasteboard 以检查更改并输出新数据。
|
||
|
||
这是一个简单的 JavaScript 脚本示例,灵感来自 objection 的方法,每 5 秒读取并记录粘贴板的更改:
|
||
```javascript
|
||
const UIPasteboard = ObjC.classes.UIPasteboard
|
||
const Pasteboard = UIPasteboard.generalPasteboard()
|
||
var items = ""
|
||
var count = Pasteboard.changeCount().toString()
|
||
|
||
setInterval(function () {
|
||
const currentCount = Pasteboard.changeCount().toString()
|
||
const currentItems = Pasteboard.items().toString()
|
||
|
||
if (currentCount === count) {
|
||
return
|
||
}
|
||
|
||
items = currentItems
|
||
count = currentCount
|
||
|
||
console.log(
|
||
"[* Pasteboard changed] count: " +
|
||
count +
|
||
" hasStrings: " +
|
||
Pasteboard.hasStrings().toString() +
|
||
" hasURLs: " +
|
||
Pasteboard.hasURLs().toString() +
|
||
" hasImages: " +
|
||
Pasteboard.hasImages().toString()
|
||
)
|
||
console.log(items)
|
||
}, 1000 * 5)
|
||
```
|
||
## 参考文献
|
||
|
||
- [https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06h-testing-platform-interaction#testing-object-persistence-mstg-platform-8](https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06h-testing-platform-interaction#testing-object-persistence-mstg-platform-8)
|
||
- [https://hackmd.io/@robihamanto/owasp-robi](https://hackmd.io/@robihamanto/owasp-robi)
|
||
- [https://mas.owasp.org/MASTG/tests/ios/MASVS-PLATFORM/MASTG-TEST-0073/](https://mas.owasp.org/MASTG/tests/ios/MASVS-PLATFORM/MASTG-TEST-0073/)
|
||
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|