LightningMods

Untitled

Oct 3rd, 2018
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. void *sys_unjail(struct thread *td) {
  2.  
  3. struct ucred* cred;
  4. struct filedesc* fd;
  5.  
  6. void* kbase = 0;
  7. uint8_t* kernel_ptr;
  8. void** got_prison0;
  9. void** got_rootvnode;
  10.  
  11.  
  12. fd = td->td_proc->p_fd;
  13. cred = td->td_proc->p_ucred;
  14.  
  15. uint64_t fw_version = 0x999;
  16.  
  17. if (!memcmp((char*)(&((uint8_t*)__readmsr(0xC0000082))[-KERN_505_XFAST_SYSCALL]), (char[4]) { 0x7F, 0x45, 0x4C, 0x46 }, 4)) {
  18.  
  19. kbase = &((uint8_t*)__readmsr(0xC0000082))[-KERN_505_XFAST_SYSCALL];
  20.  
  21.  
  22. fw_version = 0x505;
  23.  
  24. }
  25.  
  26. else if (!memcmp((char*)(&((uint8_t*)__readmsr(0xC0000082))[-KERN_455_XFAST_SYSCALL]), (char[4]) { 0x7F, 0x45, 0x4C, 0x46 }, 4)) {
  27.  
  28. kbase = &((uint8_t*)__readmsr(0xC0000082))[-KERN_455_XFAST_SYSCALL];
  29.  
  30. fw_version = 0x455;
  31. }
  32.  
  33. else if (!memcmp((char*)(&((uint8_t*)__readmsr(0xC0000082))[-KERN_455_XFAST_SYSCALL]), (char[4]) { 0x7F, 0x45, 0x4C, 0x46 }, 4)) {
  34.  
  35. kbase = &((uint8_t*)__readmsr(0xC0000082))[-KERN_455_XFAST_SYSCALL];
  36.  
  37. fw_version = 0x455;
  38.  
  39. }
  40. else if (!memcmp((char*)(&((uint8_t*)__readmsr(0xC0000082))[-KERN_405_XFAST_SYSCALL]), (char[4]) { 0x7F, 0x45, 0x4C, 0x46 }, 4)) {
  41. fw_version = 0x405;
  42.  
  43. }
  44. else return -1;
  45.  
  46. if (fw_version == 0x505) {
  47.  
  48. int(*printfkernel)(const char *fmt, ...) = (void *)(kbase + 0x436040);
  49. printfkernel("Syscall 9 Unjail invoked\n");
  50. printfkernel("FW Version 5.05 Detected\n");
  51. }
  52.  
  53. else if (fw_version == 0x405) {
  54.  
  55. int(*printfkernel)(const char *fmt, ...) = (void *)(kbase + KERN_405_PRINTF);
  56. printfkernel("FW Version 4.05 Detected\n");
  57.  
  58. }
  59. else if (fw_version == 0x455) {
  60.  
  61. int(*printfkernel)(const char *fmt, ...) = (void *)(kbase + KERN_455_PRINTF);
  62. printfkernel("Syscall 9 Unjail invoked\n");
  63. printfkernel("FW Version 4.55 Detected\n");
  64.  
  65. }
  66. else if (fw_version == 0x501) {
  67.  
  68. int(*printfkernel)(const char *fmt, ...) = (void *)(kbase + KERN_501_PRINTF);
  69. printfkernel("Syscall 9 Unjail invoked\n");
  70. printfkernel("FW Version 5.05 Detected\n");
  71. }
  72. else return -1;
  73.  
  74.  
  75. if (fw_version == 0x405) {
  76.  
  77.  
  78. // Kernel pointers resolving
  79.  
  80. kernel_ptr = (uint8_t*)kbase;
  81. got_prison0 = (void**)&kernel_ptr[KERN_405_PRISON_0];
  82. got_rootvnode = (void**)&kernel_ptr[KERN_405_ROOTVNODE];
  83.  
  84. }
  85. else if (fw_version == 0x455) {
  86.  
  87. // Kernel pointers resolving
  88.  
  89. kernel_ptr = (uint8_t*)kbase;
  90. got_prison0 = (void**)&kernel_ptr[KERN_455_PRISON_0];
  91. got_rootvnode = (void**)&kernel_ptr[KERN_455_ROOTVNODE];
  92.  
  93. }
  94. else if (fw_version == 0x501) {
  95.  
  96. // Kernel pointers resolving
  97.  
  98. kernel_ptr = (uint8_t*)kbase;
  99. got_prison0 = (void**)&kernel_ptr[KERN_501_PRISON_0];
  100. got_rootvnode = (void**)&kernel_ptr[KERN_501_ROOTVNODE];
  101.  
  102. }
  103. else if (fw_version == 0x505) {
  104.  
  105. // Kernel pointers resolving
  106.  
  107. kernel_ptr = (uint8_t*)kbase;
  108. got_prison0 = (void**)&kernel_ptr[KERN_505_PRISON_0];
  109. got_rootvnode = (void**)&kernel_ptr[KERN_505_ROOTVNODE];
  110.  
  111. }
  112. else return -1;
  113.  
  114. cred->cr_uid = 0;
  115. cred->cr_ruid = 0;
  116. cred->cr_rgid = 0;
  117. cred->cr_groups[0] = 0;
  118. cred->cr_prison = *got_prison0;
  119. fd->fd_rdir = fd->fd_jdir = *got_rootvnode;
  120.  
  121. // Escalate ucred privs, needed for userland access to the filesystem e.g mounting & decrypting files
  122.  
  123. void *td_ucred = *(void **)(((char *)td) + 304); // p_ucred == td_ucred
  124.  
  125. uint64_t *sonyCred = (uint64_t *)(((char *)td_ucred) + 96);
  126. *sonyCred = 0xffffffffffffffff;
  127.  
  128. // sceSblACMgrGetDeviceAccessType
  129. *(uint64_t *)(td_ucred + 0x60) = 0xFFFFFFFFFFFFFFFF;
  130. *(uint64_t *)(td_ucred + 0x58) = 0x3801000000000013;
  131. *(uint64_t *)(td_ucred + 0x68) = 0xFFFFFFFFFFFFFFFF;
  132.  
  133. uint64_t *sceProcessAuthorityId = (uint64_t *)(((char *)td_ucred) + 88);
  134. *sceProcessAuthorityId = 0x3800000000000010; // SceShellcore paid
  135. // sceSblACMgrHasSceProcessCapability
  136.  
  137. uint64_t *sceProcCap = (uint64_t *)(((char *)td_ucred) + 104);
  138. *sceProcCap = 0xffffffffffffffff; // Max capability
  139.  
  140. if (fw_version == 0x505) {
  141.  
  142. // Kernel pointers resolving
  143.  
  144. kernel_ptr = (uint8_t*)kbase;
  145. got_prison0 = (void**)&kernel_ptr[KERN_505_PRISON_0];
  146. got_rootvnode = (void**)&kernel_ptr[KERN_505_ROOTVNODE];
  147.  
  148. int(*copyout)(const void *kaddr, void *uaddr, size_t len);
  149.  
  150. copyout = (void *)(kbase + KERN_505_COPYOUT);
  151.  
  152. cpu_disable_wp();
  153.  
  154. *(uint8_t *)(kbase + 0xFCD48) = 3; // VM_PROT_DEFAULT;
  155. *(uint8_t *)(kbase + 0xFCD56) = 3; // VM_PROT_DEFAULT;
  156.  
  157. // patch vm_map_protect check
  158. memcpy((void *)(kbase + 0x1A3C08), "\x90\x90\x90\x90\x90\x90", 6);
  159.  
  160. // Disable ptrace check
  161.  
  162. kernel_ptr[0x30D9AA] = 0xEB;
  163.  
  164. // Disable process aslr
  165. *(uint16_t*)&kernel_ptr[0x194875] = 0x9090;
  166.  
  167. // Allow sys_dynlib_dlsym in all processes.
  168. *(uint16_t *)(kbase + 0x237F3B) = 0x01C1;
  169. //*(uint16_t *)(kbase + 0x237F3B) = 0x101C;
  170.  
  171. // Don't restrict dynlib information.
  172. *(uint64_t *)(kbase + 0x2B2620) = 0x9090909090C3C031;
  173.  
  174. // Allow usage of mangled symbols in dynlib_do_dlsym().
  175. *(uint16_t *)(kbase + 0x2AFB47) = 0x9090;
  176. *(uint16_t *)(kbase + 0x2AFB47 + 2) = 0x9090;
  177. *(uint16_t *)(kbase + 0x2AFB47 + 4) = 0x9090;
  178.  
  179. *(uint32_t *)(kbase + 0x19ECEB0) = 0;
  180.  
  181. *(uint8_t*)(kbase + 0x117B0) = 0xB0;
  182. *(uint8_t*)(kbase + 0x117B1) = 0x01;
  183. *(uint8_t*)(kbase + 0x117B2) = 0xC3;
  184.  
  185. *(uint8_t*)(kbase + 0x117C0) = 0xB0;
  186. *(uint8_t*)(kbase + 0x117C1) = 0x01;
  187. *(uint8_t*)(kbase + 0x117C2) = 0xC3;
  188.  
  189. *(uint8_t*)(kbase + 0x13F03F) = 0x31;
  190. *(uint8_t*)(kbase + 0x13F040) = 0xC0;
  191. *(uint8_t*)(kbase + 0x13F041) = 0x90;
  192. *(uint8_t*)(kbase + 0x13F042) = 0x90;
  193. *(uint8_t*)(kbase + 0x13F043) = 0x90;
  194.  
  195. cpu_enable_wp();
  196. }
  197. else if (fw_version == 0x455) {
  198.  
  199.  
  200. kernel_ptr = (uint8_t*)kbase;
  201. got_prison0 = (void**)&kernel_ptr[KERN_455_PRISON_0];
  202. got_rootvnode = (void**)&kernel_ptr[KERN_455_ROOTVNODE];
  203.  
  204. int(*copyout)(const void *kaddr, void *uaddr, size_t len);
  205.  
  206. copyout = (void *)(kbase + KERN_455_COPYOUT);
  207.  
  208. cpu_disable_wp();
  209.  
  210.  
  211. *(uint8_t*)(kbase + 0x143BF2) = 0x90; //0x0F
  212. *(uint8_t*)(kbase + 0x143BF3) = 0xE9; //0x84
  213. *(uint8_t*)(kbase + 0x143E0E) = 0x90; //0x74
  214. *(uint8_t*)(kbase + 0x143E0F) = 0x90; //0x0C
  215.  
  216. cpu_enable_wp();
  217.  
  218. }
  219.  
  220. return 0;
  221.  
  222. }
Advertisement
Add Comment
Please, Sign In to add comment