Bypass root + Frida

Bypass Android root protection with frida.

1. Install frida and root your emulator/device

2. Use frida scripts to bypass (fast way)

It works in the hardest applications. So, you need to create a file called "frida.js", and paste the code below.

Next, after installing the target apk on your mobile device, you need to start frida server and execute the script from your attacker machine.

For more details about frida, you can check the next section.

3. Dynamic analysis and frida script (manual)

Many times, when the root protection is made manually, it's difficult to bypass the protection. In that scenarios, you need:

  • Analyse the APK java code to understand how and where the root validation is performed

  • Create a frida specially crafted script to bypass it

Souce-code analysis

To start, we can use an online decompiler like this:

or just doing it by using the tool dex2jar:

My favorite approach is: jadx Java decompiler:

There is also a prepared VM you can find with all the tools installed called Mobexler:

After that, using the ByteCode Viewer or JADX, you can export your project (source files) and use Visual Studio Code in order to analyze the code and taking advantage of cross-references, and all the available plugins to better understand the Android code. For instance, you can also install a Java Decompiler plugin.

Finding the root validation

By using the "Search" feature, we try to get some information about where the root function is called.

and ... we got it! 😇

We can see that an object (r0) is returned if the "Device is rooted", and r0 is returned with "none" when the device is not rooted. Next, we are presenting the general block of code we analyzed.

To bypass this protection, we need to:

  • Create the target path: Package of the class + Add the "public enum g" + Add the target class (d.a.a.a.c.g.g$e)

  • Implement the code on the target method (doProcedure)

  • Create an object from "d.a.a.a.c.g.a" to return something using its constructor

We can see the constructor can be "empty" or we can passing it 5 args. Analysing the code we can understand that. For instance:

Frida script (hook)

Now, it's time to write our frida script:

another approach overloading the method:

To execute it:

and, we got it! We bypassed root validations!😎

BONUS - PATCH the APK

Instead using frida, we can patch directly the APK using this approach:

So, we just need, in this case, changing the content of the r2 (v2 smali) variable.

Before

After

After that, we need to follow the steps to build the APK, sign it and align it. 😎

Last updated

Was this helpful?