This is an exploit for a vulnerability CVE-2024-48336 in Magisk app that allows a local app to silently gain root access without user consent.
Vulnerability was initially reported by @vvb2060 and PoC-ed by @canyie. It has been fixed in Canary 27007.
Demo video for exploit this vulnerability to silently obtaining root privileges and granting root to any app: https://github.com/canyie/MagiskEoP/blob/main/screen-20220302-093745.mp4
Steps to reproduce this vulnerability:
- Install vulnerable Magisk app builds on a device that has no GMS preinstalled
- Install this exploit app
- Force stop Magisk app and this exploit app
- Open Magisk app
- Open this exploit app, type your commands and press Execute to execute them with root privileges
Name: Magisk App Arbitrary Code Execution Vulnerability
Alias: Magisk Privilege Escalation Vulnerability
Product: Magisk
CVE: CVE-2024-48336
Reporter: @vvb2060
Initial Report Date: 2024-08-01
Patch Date: 2024-08-21
Disclosure Date: 2024-08-24
Affected Versions: Manager v7.0.0 ~ Canary 27006
First Patched Versions: Canary 27007
Issue/Bug report: topjohnwu/Magisk#8279
Patch CL: https://github.com/topjohnwu/Magisk/commit/c2eb6039579b8a2fb1e11a753cea7662c07bec02
Bug-introducing CL: https://github.com/topjohnwu/Magisk/commit/920b60da19212dd8d54d27ada77a30067ce50de6
Bug Class: Unsafe Dynamic External Code Loading
Weakness Enumerations:
- CWE-386: Symbolic Name not Mapping to Correct Object
- CWE-829: Inclusion of Functionality from Untrusted Control Sphere
The install() function of ProviderInstaller.java in Magisk App before canary version 27007 does not verify the GMS app before loading it, which allows a local untrusted app with no additional privileges to silently execute arbitrary code in the Magisk app and escalate privileges to root via a crafted package, aka Bug #8279. User interaction is not needed for exploitation.
Old Android versions do not support some algorithms. To make Magisk work properly on these platforms, it tries to load conscrypt from GMS by calling createCallingContext(). Check this link for more details: https://t.me/vvb2060Channel/692
However, GMS is not always preinstalled on all devices. Magisk assumes that loading code from GMS is always safe, however attackers can create a fake malicious app with the same package name. When Magisk app is launched, malicious code will get executed in Magisk app. Since Magisk app is always granted root access, this allows attackers to silently gain root access and execute arbitrary code with root privileges without user acceptance.
- Devices with no GMS preinstalled
- Devices with broken signature verification implementation (e.g. Disabled by CorePatch)
Note: This issue is fixed in Canary 27007 by ensuring GMS is a system app before loading it. However, it's still possible to exploit this issue on devices with pre-installed GMS but have broken signature verification implementations (e.g. CorePatch).
Note 2: Although a fix for this issue is present in the official Magisk app, there are many other instances of similar code exist in other apps without a proper fix such as this and this. This potentially allows an arbitrary code execution in vulnerable apps and potentially allows attackers to gain root access again if it is granted to victim apps.