
Proof-of-concept exploit for CVE-2020-27949, demonstrating arbitrary memory read/write in macOS processes via DTrace fasttrap ioctl without elevated permissions.
The /dev/fasttrap device for creating trap nodes in user-space processes for
the pid and objc providers has the permissions 666. In contrast to
/dev/dtrace, which is also 666, fasttrap lacks a permission check. This
allows any process to issue a FASTTRAPIOC_MAKEPROBE or FASTTRAPIOC_GETINSTR
ioctl.
An attacker can create probes in any other process for any memory
location using FASTTRAPIOC_MAKEPROBE. On activation of these probes, the
values at the specified memory location is replaced with a trap instruction
(0xCC on x86) and the original value is placed in a shadow memory. Retrieving
the original value is possible with the FASTTRAPIOC_GETINSTR ioctl. This
allows the attacker to read arbitrary memory of another process by placing
multiple traps.
This vulnerability is tracked as CVE-2020-27949, fixed in macOS Big Sur 11.1, Security Update 2020-001 Catalina, Security Update 2020-007 Mojave .
0xCC on x86) to any memory
location of other processes executed under DTrace without elevated permissions.
Even writing memory to processes running as root is possible. As part of other
instructions or jump addresses, the victim's control flow can be altered,
allowing escalation of privileges.As a user, I expect that enabling DTrace only allows processes with root
permissions to trace, instrument, or modify other processes. DTrace is a
valuable tool for administrative tasks offering tools like dtruss, iotop,
etc.
Our victim (target) is an executable running as root. The
attacker (memaccess) is an executable running with regular user
permissions. The tracing script libc_monitor.d records the number of calls to
functions in the libsystem_c.dylib shared object (this is just a
simple example of an administrative script a machine owner might run).
libc_monitor.d).FASTTRAPIOC_GETINSTR to read the memory values of the
created probes.Step 4 replaces memory in the victim process with the trap instruction value. Depending on the application, an attacker can use this to write a previously known value to a critical memory location. For example, the attacker could control the seed of an RNG or replace cryptographic keys in a process.
Note: The attacker never requires elevated or root permissions.
Note 2: Self-written DTrace scripts are not required. For example, dapptrace
also uses the pid provider to trace any function.
Implement privilege checks in /dev/fasttrap like in /dev/dtrace or remove
the world-writable permission.
Note: We did not check the released fix.
target and follow the instructions on-screen