Rooting Android Without Magisk or Kernelsu
For the special one-off situations when you can’t use magisk or kernelsu, or if you really don’t want to use existing root solutions, you can get root with a backdoor’d kernel image.
Security warning
THIS IS NOT SOMETHING YOU SHOULD USE ON YOUR DAILY-DRIVER / IMPORTANT PHONE.
You have been warned
This is a “we have kernelsu at home” solution. It only gives you uid-0 and gid-0, but with selinux it won’t be of much use.(atleast for now)
You should probably use kernelsu or magisk, but if you don’t want to use that you patch a backdoor into your kernel to get root.
Requirements
-
Kernel source from your device vendor (some vendors like vivo / oppo dont do this)
-
Ability to read and flash boot.img
This can be achieved either with fastboot, or using something like
edl.
Rough Steps
- Get Kernel sources
- Add backdoor into kernel that sets your process’s cred to root creds.
- Compile kernel
- Get
boot.imgfrom phone / stock firmware online. - Repack boot.img with custom kernel
- Flash it to device (note: fastboot flash boot boot.patched.img dint work for me, I used alternate method to flash partitions)
Compiling backdoor into kernel
- Get kernel sources
- Add your backdoor into kernel. I backdoor’d
setresuid
DIFF
|
|
- Get your toolchain (arm-linux-eabi for armv7, aarch64-linux-eabi for aarch64 (armv8))
- Compile your kernel with proper defconfig and proper toolchain
SH
|
|
- After this step, your compiled kernel will be ready. For armv7, it’s usually
zImage-dtb. For aarch64 it’s usuallyImage.gz-dtbor smth. It will be insideout/$ARCH/arm/boot.
Repack boot.img
- Get your
boot.imgfrom phone I used edl.py to interact with device in edl mode. For brevity, I’ve shrinked commands.
SH
|
|
-
Unpack boot.img with
unpack_bootimg --mkbootimgIt outputs a set of flags, copy it. -
Replace
kernelwith your compiled kernel -
Repack the boot.img with
mkbootimgUse the flags that you got earlier from step 1. -
Flash it to your device’s boot partition
Popping root shell
Trigger your backdoor to get root.
C
|
|