Working Exploits

From PS4 Developer wiki
Jump to: navigation, search

Contents

Hardware Exploits[edit]

PCIe man-in-the-middle attack[edit]

  • First done on 1.01 by failoverflow on PS4 launch !
  • Detailed at 33c3: 33c3 slides by Marcan
  • Permits kernel and userland dumping

WebKit/Userland Exploits[edit]

FW <= 5.50 - haveABadTime Type Confusion[edit]

Analysis[edit]

Project Zer0 Bug Description

Bug Description[edit]

When JSGlobalObject::haveABadTime() is called with arrays of a different JSGlobalObject type, type confusion can occur, leading to memory corruption.

Exploit Implementation[edit]

PS4 5.50 (WebKit Only)

Patched[edit]

Yes in 5.53 FW


FW <= 5.05 - setAttributeNodeNS Use-After-Free (UAF)[edit]

Analysis[edit]

Specter's setAttributeNodeNS Exploit Writeup

Bug Description[edit]

By forcing setAttributeInternal() to call setAttributeNodeNS() twice, an attribute node reference will be added twice to the list. When one is free()'d, the second attribute still contains a duplicate stale reference, leading to a use-after-free (UAF) scenario.

Exploit Implementation[edit]

PS4 5.05 WebKit + Kernel Exploit

Patched[edit]

Yes in 5.50 FW


FW <= 4.07 - Stack Uninitialized Read[edit]

Analysis[edit]

Specter's 4.0x WebKit Exploit Writeup

Bug Description[edit]

Via a specially crafted valueOf() function of an arguments.length() function, non-zero indexes of the stack-allocated array are not initialized, leading to a stack uninitialized read. This can be abused to store a reference that can later be re-obtained post-GC (garbage collection) yielding a use-after-free() (UAF) situation.

Exploit Implementation[edit]

[1] (mirror)

Patched[edit]

Yes in 4.50 FW

Tested[edit]

Works on 3.50.


FW <= 3.70 - JSArray.sort() Use-After-Free (UAF)[edit]

Analysis[edit]

PSVita HENKaku 3.60 webkit exploit writeup

Bug Description[edit]

When attempting to update a vector via sortCompactedVector() - data is written based on a pointer, though the pointer isn't re-updated nor nulled. When this memory in free()'d, the reference is maintained and thus memory corruption can occur.

Exploit Implementation[edit]

PSVita HENkaku by Molecule PS4 Playground 3.15-3.70 by Fire30

Patched[edit]

Yes in 4.00 FW

Tested[edit]

3.15, 3.50, 3.51, 3.55, 3.70


FW <= 2.03 - CSSSelector Heap Overflow (CVE-2014-1303)[edit]

Analysis[edit]

BlackHat EU 2014 'WebKit Everywhere - Secure Or Not?' slides

Bug Description[edit]

By forcing addRule() to be called on a CSS Selector via window.getMatchedCSSRules(), a 1-bit OOB write can be achieved and leveraged to corrupt heap memory.

Exploit Implementation[edit]

  • Currently only has an ROP PoC for firmware 2.03 by Fire30: PS4 2.03

Patched[edit]

Yes in 2.50 FW

Tested[edit]

  • 2.03

FW <= 1.76 - JSArray.sort() Heap Overflow (CVE-2012-3748)[edit]

Analysis[edit]

Exploit PoC by Vitaliy Toropov

Bug Description[edit]

By forcing the compare function to reduce the size of the array, trailing items will be written out of bounds (OOB write), leading to heap memory corruption.

Exploit Implementation[edit]

PSVita 2.60
PS4 playground 1.76 by CTurt

Patched[edit]

Yes in 2.00 FW

Userland securities[edit]

Userland ASLR[edit]

  • Very old firmwares (<= 1.05) don't have ASLR enabled, but it was introduced sometime before firmware 1.70. "Address Space Layout Randomization" (ASLR) is a security technique which causes the base addresses of modules to be different every time you start the PS4.
  • To defeat userland ASLR on FWs >=1.70, we can use the module imports table to find other modules address once we know SceWebkit2 address.

Module imports table cleaned before execution[edit]

  • Between 1.76 and 4.05, Sony did that to prevent webkit exploiters from defeating userland ASLR easily.
  • Now we have to dump entire userland sandboxed memory, and by studying it we can defeat ASLR:

1. Chose a function (ex: __stack_chk_fail) imported from LibKernel by SceWebkit2 2. Read pointer contained at the address where the call is done 3. Substract to this pointer the offset of the function (ex: __stack_chk_fail) in LibKernel module 4. This result is LibKernel base address. This method works for any imported module.

DEP / NX[edit]

  • "Data Execution Prevention" / "No eXecute" is enabled on all firmwares. It prevents allocating memory as both RW and RX at same time (RWX) so preventing us from writing shellcode to userland memory then executing it.
  • 2 ways to bypass this security: JiT vulnerability (FW <= 1.76) or ROP (all FWs).

JiT removed from webbrowser[edit]

  • On FW <= 1.76, you could map RWX memory from ROP by abusing the JiT functionality and the sys_jitshm_create and sys_jitshm_alias system calls. This however was fixed after 1.76, as WebKit has been split into two processes. One handles javascript compilation and the other handles other web page elements like image rendering and DOM. The second process will request JiT memory upon hitting JavaScript via IPC (Inter-Process Communication). Since we no longer have access to the process responsible for JiT, we can no longer (at least currently), map RWX memory for proper code execution unless the kernel is patched.
  • Workaround is to use ROP.

Syscalls removed[edit]

Syscall 0 disabled[edit]

  • Between 1.76 and 4.05, Sony has removed system call 0, so we can no longer call any system call we like by specifying the call number in the rax register.
  • We will have to use wrappers from the libkernel.sprx module provided to us to access system calls.

bpf_write function stripped out of the kernel[edit]

  • On 4.70, bpfwrite() was stripped out of the kernel entirely to patch kernel vulnerability exploited in 4.55 kexploit.

bpf_open function blocked for unprivileged processes[edit]

  • On 5.50, opening BPF has been blocked for unprivileged processes such as WebKit and other apps/games. It's still present in the sandbox, however attempting to open it will fail and yield EPERM. This aims blocking bpf exploits like the 4.55 and 5.05 kexploit.

Kernel Exploits[edit]

FW <= 5.05 - BPF Race Condition (Yielding Double Free())[edit]

Analysis[edit]

Specter's Writeup of the 5.05 BPF Race Condition

Bug Description[edit]

Again due to improper locking, two threads can enter the BPF "SETWF" ioctl command handler. While the bug is similar to that of 4.55, the method of attack is slightly different. Since write() was removed for BPF in 4.70, instead of triggering a use-after-free with write() - "SETWF" is ran in parallel via threading. Eventually, both calls will copy the same pointer to the stack, leading to both threads free()'ing the same pointer, poisoning the freelist. This can later be leveraged via heap spraying to corrupt heap memory to obtain arbitrary code execution in supervisor mode (ring0).

Exploit Implementation[edit]

PS4 5.05 WebKit + Kernel Exploit
PS4 5.05 WebKit + Kernel Exploit Source

Patched[edit]

Yes in 5.50FW


FW <= 4.55 - BPF Race Condition (Yielding UaF)[edit]

Analysis[edit]

Specter's Writeup of the 4.55 BPF Race Condition

Bug Description[edit]

Due to improper locking, two threads can enter the BPF ioctl command handlers for setting a new write filter (SETWF) and setting a filter (SETIF). Both threads will reference the same pointer. In specially crafted situations, one thread could free() this pointer while the other thread executes it as a filter post-validation. This allows an unprivileged user to obtain an out-of-bounds (OOB) write on the stack, leading to arbitrary code execution in supervisor mode (ring0).

Exploit Implementation[edit]

PS4 4.55 WebKit + Kernel Exploit
PS4 4.55 WebKit + Kernel Exploit Source

Patched[edit]

Yes in 4.70FW


FW <= 4.05 - NamedObj Type Confusion (namedobj - Adieu)[edit]

Analysis[edit]

fail0verflow's Writeup on the 1.01-4.05 Kernel Exploit
Specter's Writeup on his 4.05 implementation

Bug Description[edit]

Type confusion in the namedobj system once exploited can lead to an arbitrary free() allowing an attacker to craft a use-after-free() (UAF) situation to corrupt kernel memory. This can be leveraged to eventually obtain an arbitrary code execution primitive in supervisor mode (ring0).

Exploit Implementation[edit]

PS4 4.05 WebKit + Kernel Exploit

Patched[edit]

Yes in 4.06 FW


FW <= 1.76 - Dynamic Library Prepare Close (dlclose)[edit]

  • Discovered by CTurt. Privately implemented thanks to qwertyoruiopz. CTurt published a writeup then the exploit was publicly implemented by kR105 and on another side by Zer0xFF and Bigboss (psxdev).

Analysis[edit]

Analysis of sys_dynlib_prepare_dlclose PS4 kernel heap overflow (by CTurt with the help of qwertyoruiopz)

Bug Description[edit]

Integer overflow in the sys_dynlib_prepare_dlclose() system call can lead to a heap overflow causing memory corruption, allowing an attacker to obtain code execution in supervisor mode (ring0).

Exploit Implementation[edit]

Public release by kR105

Patched[edit]

Yes in 2.00 FW


FW <= 1.76 - BadIRET[edit]

Analysis[edit]

  • Ported from FreeBSD 9 to PS4 by CTurt.

Hacking the PS4, part 3 - Kernel exploitation (by CTurt)
NVD Bug Description

Bug Description[edit]

Faults associated with the stack segment (SS) register are not handled properly, allowing unprivileged users to trigger an IRET instruction that accesses a GS Base from userland memory, providing an attacker with a method of privilege escalation.

Source[edit]

CVE-2014-9322
Public binary

Patched[edit]

Yes in 2.00 FW

Implementation[edit]

(mirror)

Kernel securities[edit]

Kernel ASLR[edit]

  • At some point after the 1.76 FW, ASLR (Address Space Layout Randomization) was enabled in the kernel.
  • This means that to properly exploit the kernel to escalate privileges, an information disclosure vulnerability will most likely be needed to defeat ASLR and locate the kernel in memory.

Kernel SMAP[edit]

  • In 5.0x FW and above, "Supervisor Mode Access Prevention" (SMAP), a new custom mitigation was added to the kernel to prevent exploiters from pivoting the stack pointer into userland memory (attempting to do so will crash the system).
  • A new exploitation strategy is needed for running kROP (kernel ROP) chains, such as qwertyoruiopz method used in the 5.05 BPF kernel exploit:

We need to get our ROP chain into kernel memory. To do this, qwertyoruiopz decided to go with the method he used on the iPhone 7 - essentially using JOP to push a bunch of stack frames onto the kernel stack, and memcpy()'ing the chain into RSP.