Skip to main content
Be Bitwise

Android Exploitation & Rooting

Mobile Exploitation Techniques · Mobile Exploitation track

8 min read

In this module

The Rooting Landscape

Android rooting plays out very differently from iOS jailbreaking because Android ships with an official (if grudgingly offered) path to elevated access: bootloader unlocking. iOS treats any deviation from Apple's security model as a hostile act to be stamped out. Android acknowledges that device owners may legitimately want full control, and offers them a route to it — at a cost.

Bootloader Unlocking

Most Android devices support OEM unlocking, a process that unlocks the bootloader to allow booting unsigned or custom-signed images. The exact dance varies by manufacturer, but the broad shape is the same:

  1. Enable "OEM unlocking" in Developer Settings.
  2. Boot into the bootloader (fastboot mode).
  3. Execute fastboot oem unlock or fastboot flashing unlock.
  4. The device factory resets, wiping all user data.

The mandatory factory reset is a deliberate security design. A stolen device can't have its bootloader unlocked just to scrape data off it, because the data is destroyed before the bootloader will accept custom images at all.

bash
# Standard bootloader unlock process
$ adb reboot bootloader
$ fastboot flashing unlock
# WARNING: This will erase all user data
# Device wipes and reboots with unlocked bootloader
$ fastboot flash boot magisk_patched.img
$ fastboot reboot

With an unlocked bootloader, the device owner can flash custom boot images, recovery partitions, and entire custom ROMs. The catch is what unlocking gives up:

  • Verified Boot warnings: Android Verified Boot (AVB) reports one of four boot states: green (locked, verified against the OEM key), yellow (locked, verified against a user-installed key), orange (unlocked) and red (verification failed). An unlocked device boots in orange and shows a warning screen.
  • Verification no longer stops you: In the orange state the bootloader still checks the images, but it boots them even if the check fails, so a modified boot or system image will run. dm-verity itself keeps running on the system partitions unless you deliberately disable it in vbmeta; what changes is that a failure is no longer fatal, and the orange state is reported to the TEE and shows up in key attestation.
  • Some apps refuse to run: Banking apps, payment services, and DRM-protected content may detect the unlocked bootloader and refuse to function.
Bootloader Unlock Trade-off

Android's bootloader unlock is a deliberate security trade-off: it grants full device control but enforces a factory reset (protecting prior user data), disables Verified Boot protections, and triggers device integrity warnings, but verification failures stop being fatal. Unlike iOS jailbreaking, it does not require exploiting a vulnerability - it is an intended (though discouraged) feature.

Magisk: Systemless Root

Magisk is the dominant rooting solution on modern Android. Its big trick is systemless root: it gets you root without ever touching the system partition, so the system partitions still verify and dm-verity has nothing to complain about. (The boot image it patches does fail verification, which is why it needs an unlocked bootloader in the first place.)

How Magisk Works

Magisk operates by patching only the boot image (boot.img):

  1. The user extracts the device's boot image and patches it with the Magisk app.
  2. The patched boot image is flashed via fastboot.
  3. At boot, Magisk's modified init process executes before Android's normal init.
  4. Magisk creates a filesystem overlay using bind mounts. Root binaries (su, Magisk Manager) are stored on a separate partition (typically /data) and bind-mounted into the filesystem at runtime.
  5. The original system partition remains completely untouched.

Because the system partition is never modified, dm-verity verification passes. That doesn't make the device look stock, though. Play Integrity's stronger verdicts now rely on hardware-backed key attestation, which reports the unlocked (orange) boot state directly, and apps can still sniff out root through other tells.

Zygisk: Per-App Injection

Zygisk is Magisk's module for injecting code into the Zygote process, the parent from which every Android app is forked. By hooking Zygote, Magisk modules get to modify app behaviour on a per-app basis.

Zygisk enables:

  • DenyList: Selectively hiding Magisk's changes from specific apps (banking apps, games with anti-cheat). It replaced the older MagiskHide, which was removed in Magisk v24 (2022); fuller hiding now relies on third-party Zygisk modules.
  • Module injection: Loading custom code into app processes for modification, hooking, or analysis.
  • Selective root: Granting root access only to specific, trusted apps.

Magisk isn't the only option any more. KernelSU and APatch take a different route, patching the kernel itself (KernelSU as a kernel module or built-in patch, APatch by patching the kernel image) and managing root from there, which changes what root-detection code can see.

Play Integrity (formerly SafetyNet)

Google's Play Integrity API (successor to SafetyNet Attestation) lets apps verify the integrity of the device they're running on. The API hands back three levels of verdict:

  • MEETS_BASIC_INTEGRITY: The device is not obviously tampered with (may still be rooted with sophisticated hiding).
  • MEETS_DEVICE_INTEGRITY: The device passes CTS (Compatibility Test Suite) and has a locked bootloader.
  • MEETS_STRONG_INTEGRITY: The device has hardware-backed attestation confirming an unmodified boot chain.

Banking apps, payment services, and DRM systems lean on these verdicts to refuse service on rooted or modified devices. The cat-and-mouse between Magisk's hiding capabilities and Play Integrity's detection rolls on with no end in sight.

Historical Android Exploits

Before bootloader unlocking became widely available, Android rooting relied on exploiting kernel vulnerabilities:

  • Towelroot (2014): Exploited CVE-2014-3153, a futex use-after-free in the Linux kernel. One bug, root on a huge swathe of Android devices, all because it lived in the mainline kernel rather than a vendor-specific driver.
  • Dirty COW (2016): CVE-2016-5195, a race condition in the kernel's copy-on-write mechanism. A mainline Linux kernel bug that hit Android squarely. An unprivileged process could grab write access to read-only memory mappings, opening the door to privilege escalation.
  • Dirty Pipe (2022): CVE-2022-0847, a vulnerability in the kernel's pipe subsystem that let attackers overwrite data in arbitrary read-only files. Affected Android 12 devices running kernel 5.8 or later.

Towelroot and Dirty COW both turned into public rooting tools. The kernel bugs that matter now tend to turn up in targeted spyware chains instead, and more and more of them live in code that only Android devices run:

  • Bad Binder (2019): CVE-2019-2215, a use-after-free in Binder, Android's IPC driver. Linux had fixed it in December 2017 without a CVE, so the fix never reached many Android kernels. Project Zero reported it in September 2019 after Google's Threat Analysis Group found evidence it was being exploited in the wild, and it was patched in the October 2019 Android bulletin. Binder is reachable from almost every app and even from inside Chrome's renderer sandbox, which makes it an ideal second stage after a browser bug.
  • GPU drivers: every app can talk to the GPU, and the kernel drivers are big, complex and maintained by the chip vendor on its own schedule. Arm's Mali driver (CVE-2021-28663, CVE-2023-4211) and Qualcomm's Adreno driver (CVE-2023-33106, CVE-2023-33107) have all been reported as exploited in the wild. A fix has to travel from the vendor through each phone maker before it reaches users, which can take months.
Kernel Vulnerability Rooting

Before mainstream bootloader unlocking, Android rooting relied on exploiting Linux kernel vulnerabilities. Bugs like Towelroot (futex UAF), Dirty COW (copy-on-write race), and Dirty Pipe (pipe splice overwrite) provided privilege escalation from unprivileged apps to root. These exploits highlight that Android's security depends on the security of the underlying Linux kernel.

Memory Tagging Extension (MTE)

ARM's Memory Tagging Extension (MTE, ARMv8.5-A onwards) is one of the meatiest recent hardware mitigations on Android. MTE assigns a random 4-bit tag to each 16-byte memory granule and stashes a matching tag in the pointer's upper bits.

On every memory access, the hardware checks that the pointer's tag matches the memory granule's tag. This detects:

  • Use-after-free: Freed memory receives a new random tag, so stale pointers have a mismatched tag.
  • Buffer overflows: Adjacent allocations have different tags, so an overflow into the next allocation triggers a tag mismatch.

The pointer tag sits in bits 59:56 (highlighted below), and each granule's tag sits in separate tag memory. This heap uses 24-byte chunks. Press Write past end on A: offset 24 is outside the chunk but still inside A's last granule, so MTE misses it. Then write A at offset 32, the first byte of B, and it faults. Finish by freeing A and writing through the stale pointer.

Memory tagging: catch overflows and use-after-free

Every 16-byte granule has a 4-bit tag, and every pointer carries a 4-bit tag in bits 59:56. Each load and store compares the two. Allocate, write, free and reuse chunks, then watch which bugs the hardware sees.

Tag-check mode

Heap granules and their tags

  1. +0x00
    F
    A
  2. +0x10
    F
    A
  3. +0x20
    C
    B
  4. +0x30
    C
    B
  5. +0x40
    0
    unused
  6. +0x50
    0
    unused

Offsets from the heap base 0x0000721A403000 (illustrative). Each chunk is 24 bytes in 2 granules. Tag 0 marks memory that was never handed out.

Pointers

  • A0x0F0000721A403000live · tag F
  • B0x0C0000721A403020live · tag C
Valid accesses
0
Bugs caught
0
Bugs missed
0

Note. malloc(24) returned B = 0x0C0000721A403020. Its 2 granules now carry tag C.

Event log
  1. Note: malloc(24) returned A = 0x0F0000721A403000. Its 2 granules now carry tag F.
  2. Note: malloc(24) returned B = 0x0C0000721A403020. Its 2 granules now carry tag C.
Why 4 bits is enough, mostly

Top Byte Ignore means the CPU leaves bits 63:56 out of address translation, so the tag rides along for free. Four bits give 16 tags, and a stale or wild pointer whose tag is effectively random matches its target 6.3% of the time (1 in 16). Those bugs get through.

Adjacent overflows don't rely on luck. Like Android's Scudo allocator, this one never gives a chunk the same tag as the granules on either side, so running off the end of a chunk into the next granule always faults. It also retags freed memory with a different tag, so a use-after-free right after free() always faults. Once the slot is reused, the new tag is random again.

MTE can't see inside a granule. With a chunk size that isn't a multiple of 16, the bytes between the end of the chunk and the end of its last granule share its tag. Sync mode stops the bad access before it lands; async mode is cheaper but lets it land and reports later without an address. Asymmetric mode, not shown here, checks reads synchronously and writes asynchronously.

Pixel 8 and later phones have MTE in hardware, but stock Android doesn't turn it on by default: developers can enable it under Developer options, and GrapheneOS switches it on for its own code and many user apps.

MTE is no silver bullet, though. Research like TikTag (2024) showed that speculative execution side channels can leak MTE tags, letting an attacker pin down the correct tag before actually touching memory. That demotes MTE from a hard wall to a mitigation that just raises the cost of exploitation. A familiar pattern in this corner of computing.

CFI: Control Flow Integrity

Android has shipped LLVM Control Flow Integrity (CFI) since Android 8.1 for the media stack and Android 9.0 for the kernel. CFI validates that indirect function calls actually land on valid function entry points, slamming the door on attackers redirecting control flow to arbitrary code. CFI sits alongside MTE in Android's defence-in-depth stack against memory corruption.