<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Elvin Gentiles on Medium]]></title>
        <description><![CDATA[Stories by Elvin Gentiles on Medium]]></description>
        <link>https://medium.com/@elvin.gentiles?source=rss-10d84fbceb2f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*wsPQ6y6r1oUjy6N50NHRuA.jpeg</url>
            <title>Stories by Elvin Gentiles on Medium</title>
            <link>https://medium.com/@elvin.gentiles?source=rss-10d84fbceb2f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:38:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elvin.gentiles/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Bypassing Android’s RootBeer Library (Part 2)]]></title>
            <link>https://medium.com/secarmalabs/bypassing-androids-rootbeer-library-part-2-30beb0676c0b?source=rss-10d84fbceb2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/30beb0676c0b</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[root-android-phone]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Elvin Gentiles]]></dc:creator>
            <pubDate>Mon, 15 Jun 2020 08:15:12 GMT</pubDate>
            <atom:updated>2020-06-15T08:15:12.296Z</atom:updated>
            <content:encoded><![CDATA[<p>In the first part of this post, I discussed one method to bypass RootBeer Library through code manipulation. However, installing and running a modified/patched application is not always possible. This happens when an application contains protections such as anti-tampering and/or integrity checks.</p><p>If patching an application is not working, then how can we change an application’s behaviour? In this post, I’ll discuss how to change an application’s process during runtime through dynamic instrumentation using <a href="https://frida.re/"><strong>Frida</strong></a>. The goal of this post is the same, and that is to bypass all the root-detection checks used by RootBeer library.</p><p>Let’s start by identifying the functions responsible for the root-detection checks used by RootBeer. As you can see below, the <strong><em>doInBackground()</em></strong> function of the <strong>RootCheckTask</strong> (<em>com.scottyab.rootbeer.sample.CheckRootTask</em>) class can be used to identify the different functions/checks used by the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKuS4LbyMsuQfllgPpOHjg.png" /><figcaption>A Snippet of the Different Functions Used by RootBeer</figcaption></figure><p>The goal here is to “hook” these functions by injecting a JavaScript code into the application’s process, and change their return value to “<strong>false</strong>”.</p><p>As a simple example, let’s force RootBeer to give the “<strong>NOT ROOTED</strong>” result. This can be done with the following JS code to hook the <strong><em>isRooted()</em></strong> function and change its return value to “<strong>false</strong>”.</p><pre>Java.perform(function(){<br>    // Create an instance of the RootBeer class<br>    var RootBeer = Java.use(&quot;com.scottyab.rootbeer.RootBeer&quot;);<br>    <br>    // Hook the isRooted() function<br>    RootBeer.isRooted.overload().implementation = function(){<br>        // Change the return value to &quot;false&quot;<br>        return false<br>    };<br>});</pre><p>Once the script has been saved, execute Frida and load the script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*kdOhRQ5PDOHiwXFGBS712A.png" /><figcaption>Executing Frida and Loading the JS Script</figcaption></figure><p>Injecting the JS code into RootBeer’s process resulted into the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DfHUKInjjqTcXb61iMpfbA.png" /><figcaption>Result Before and After Using the Frida Script</figcaption></figure><p>If we want to bypass all the checks, we need to hook all the relevant functions and force their return value to “<strong>false</strong>”. The following quick and dirty script can be used to obtain the result that we’re after:</p><pre>Java.perform(function(){<br>    var RootBeer = Java.use(&quot;com.scottyab.rootbeer.RootBeer&quot;);<br>    var Utils = Java.use(&quot;com.scottyab.rootbeer.util.Utils&quot;);   <br>    <br>    RootBeer.detectRootManagementApps.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.detectPotentiallyDangerousApps.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.detectTestKeys.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.checkForBusyBoxBinary.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.checkForSuBinary.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.checkSuExists.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.checkForRWPaths.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.checkForDangerousProps.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.checkForRootNative.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.detectRootCloakingApps.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    Utils.isSelinuxFlagInEnabled.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.checkForMagiskBinary.overload().implementation = function(){<br>        return false;<br>    };<br>    <br>    RootBeer.isRooted.overload().implementation = function(){<br>        return false;<br>    };<br>});</pre><blockquote><strong>Tip:</strong> You can edit and save your script while Frida is running. This way, you don’t have to keep executing the same Frida command every time.</blockquote><p>After loading the above script with Frida and running the application, it can be seen that all checks were bypassed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RvGO2QtrG6TKe2hpcOUCMQ.png" /><figcaption>Successfully Bypassed All RootBeer’s Checks</figcaption></figure><h3>Final Thoughts</h3><p>It should be noted that Frida will not work at all times as there are applications which use protections, such as anti-tampering and anti-reversing techniques, that will detect Frida’s presence. If this is the case, you need to find a way to bypass these additional protections first or look for another method which does not involve Frida.</p><p>Lastly, if you’re not confident in writing your own Frida script, do not worry because there are ready-to-use Frida scripts which are hosted in <a href="https://codeshare.frida.re/browse"><strong>Frida CodeShare</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30beb0676c0b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secarmalabs/bypassing-androids-rootbeer-library-part-2-30beb0676c0b">Bypassing Android’s RootBeer Library (Part 2)</a> was originally published in <a href="https://medium.com/secarmalabs">Secarma Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparison of Different Android Root-Detection Bypass Tools]]></title>
            <link>https://medium.com/secarmalabs/comparison-of-different-android-root-detection-bypass-tools-8fd477251640?source=rss-10d84fbceb2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fd477251640</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[research]]></category>
            <dc:creator><![CDATA[Elvin Gentiles]]></dc:creator>
            <pubDate>Wed, 27 May 2020 22:33:22 GMT</pubDate>
            <atom:updated>2020-05-27T22:33:22.020Z</atom:updated>
            <content:encoded><![CDATA[<p>When testing Android applications, it is recommended to use a rooted device to perform the assessment efficiently and thoroughly. However, some applications have an additional layer of protection, which prevents an application from running on a rooted device. When presented with this scenario, one of the restrictions a tester need to overcome is the root-detection mechanism used by the application.</p><p>Several tools already exist to defeat an application’s root-detection mechanisms. But which one performs best? To answer this question, I decided to perform a comparison between these root-detection bypass tools. The goal of this experiment is to identify which tool performs best and to help analysts to have a “go-to” tool when bypassing an app’s root-detection implementation.</p><p>The target application used here is <a href="https://play.google.com/store/apps/details?id=com.scottyab.rootbeer.sample&amp;hl=en"><strong>RootBeer Sample (v0.8)</strong></a>; a sample app which utilises <a href="https://github.com/scottyab/rootbeer"><strong>RootBeer</strong></a> library.</p><h3>What is RootBeer?</h3><p><a href="https://github.com/scottyab/rootbeer"><strong>RootBeer</strong></a> is an open-source library which can be used by developers to verify the integrity of an Android device and check whether it is rooted or not. RootBeer performs the following checks as an indication of root:</p><ul><li>Presence of apps used to manage superuser/root access <em>(e.g. “eu.chainfire.supersu” and “com.topjohnwu.magisk”)</em></li><li>Installation of apps that require root <em>(e.g. “com.keramidas.TitaniumBackup” and “com.chelpus.luckypatcher”)</em></li><li>Detection of root-cloaking apps which can hide the root status of a device <em>(e.g. “com.devadvance.rootcloak2”)</em></li><li>Review of the build properties (android.os.Build.TAGS) for test-keys</li><li>Locations of binaries, such as busybox and su, which are usually present in a rooted device <em>(e.g. &quot;/system/xbin/&quot; and &quot;/su/bin/&quot;)</em></li><li>Analysis of system folders that should not be writable <em>(e.g. “/system”)</em></li><li>Look up of system properties that can only be changed when the device is rooted <em>(e.g. “ro.debuggable” and “ro.secure”)</em></li></ul><h3>Test Setup</h3><p>The following Android device was used for this experiment:</p><ul><li><strong>Device:</strong> Lenovo P8 (TB-8703F)</li><li><strong>Android Version:</strong> Pie (9.0)</li><li><strong>ROM:</strong> PixelExperience</li></ul><p>This device was installed with the following applications which use and require root permissions:</p><ul><li><a href="https://github.com/topjohnwu/Magisk">Magisk</a></li><li><a href="https://github.com/ElderDrivers/EdXposed">EdXposed</a></li><li><a href="https://play.google.com/store/apps/details?id=ru.meefik.busybox">BusyBox</a></li><li><a href="https://play.google.com/store/apps/details?id=com.keramidas.TitaniumBackup">Titanium Backup</a></li><li><a href="https://www.luckypatchers.com/">Lucky Patcher</a></li><li><a href="https://f-droid.org/en/packages/com.matoski.adbm/">ADBManager</a></li></ul><p>As a baseline for this experiment, <strong>RootBeer Sample</strong> was executed without any root-detection bypass tool used. Using this setup, 6/11 checks failed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhzbOR_g6UpovzIBcrpDLg.png" /><figcaption>Result Taken from the Baseline Setup (6/11)</figcaption></figure><h3>Root-Detection Bypass Tools</h3><p>This experiment only covered the following well-known and open-source root-detection bypass tools:</p><ul><li><a href="https://repo.xposed.info/module/com.devadvance.rootcloak2">RootCloak</a></li><li><a href="https://github.com/jakev/unrootbeer">UnRootBeer</a></li><li><a href="https://codeshare.frida.re/@dzonerzy/fridantiroot/">Fridantiroot</a></li><li><a href="https://github.com/sensepost/objection">Objection</a></li><li><a href="https://github.com/topjohnwu/Magisk">Magisk</a></li><li><a href="https://www.didgeridoohan.com/magisk/MagiskHide">MagiskHide</a></li></ul><h4><strong>Tool #1: RootCloak</strong></h4><p><a href="https://repo.xposed.info/module/com.devadvance.rootcloak2">RootCloak</a> is a very popular Xposed module that can be used to hide the root status of a device. Even though the module’s repo page states “<em>with 5.x and 6.x support</em>” and my device was running Android 9.0, I still tried it.</p><p>RootCloak is very simple to use. Just add the target application (<strong>RootBeer Sample</strong> in this case) and you’re good to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uPIyaGgomgCNqZbH0mFrcA.png" /><figcaption>Adding RootBeer Sample to RootCloak</figcaption></figure><p>Surprisingly, RootCloak bypassed some checks used by RootBeer library. Even though there’s no official statement that the module supports Android 9.0, it still worked. Using RootCloak, 7/11 checks were bypassed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqZcOv8st8ZL90bPy-fgZQ.png" /><figcaption>RootCloak Result (7/11)</figcaption></figure><h4><strong>Tool #2: UnRootBeer</strong></h4><p>The next tool is <a href="https://github.com/jakev/unrootbeer">UnRootBeer</a>, which is another Xposed module specifically developed to disable the checks performed by RootBeer library. To use this tool, just install the <a href="https://github.com/jakev/unrootbeer/raw/master/out/jakev.unrootbeer-debug.apk">APK file</a>, and reboot the device to activate the module.</p><p>As seen from the result below, UnRootBeer performed better than RootCloak as it passed 8/11 checks. While this tool was specifically developed to bypass the checks being performed by RootBeer library, it is not surprising that it failed some checks because this tool has not been updated for quite some time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hclWr6lxHG6TfCPPJs-HFA.png" /><figcaption>UnRootBeer Result (8/11)</figcaption></figure><blockquote>Be wary though because while three checks failed, the result still says <strong>NOT ROOTED</strong>. The goal of this experiment is to pass all RootBeer library checks.</blockquote><h4><strong>Tool #3: Fridantiroot</strong></h4><p>The next tool involves <a href="https://frida.re/">Frida</a>, which is a dynamic instrumentation toolkit that can be used to tamper an application’s process. For this experiment, the publicly available JS script (<a href="https://codeshare.frida.re/@dzonerzy/fridantiroot/">Fridantiroot</a>) was used. However, this script didn’t work on my device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QOj8OrLFfH6JTvSvRZ1OAA.png" /><figcaption>Error Upon Running Fridantiroot</figcaption></figure><p>Luckily, I found a <a href="https://gist.github.com/pich4ya/0b2a8592d3c8d5df9c34b8d185d2ea35">modified version of Fridantiroot</a> which worked on my device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5nqLJSB40h-tPuaRwswcw.png" /><figcaption>Running the Modified Version of Fridantiroot</figcaption></figure><p>The result was very surprising because it almost passed all the checks, with a score of 10/11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bON3yWy6YNXadBlbywPujQ.png" /><figcaption>Fridantiroot Result (10/11)</figcaption></figure><blockquote>Please note that one of the checks failed and yet the app still considered it as <strong>NOT ROOTED</strong>.</blockquote><h4><strong>Tool #4: Objection</strong></h4><p><a href="https://github.com/sensepost/objection">Objection</a> is a runtime toolkit, powered by Frida. Using the command android root disable, objection will attempt to bypass an app&#39;s root-detection mechanism.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q70QfPlNUh-aTrO5bv0tHQ.png" /><figcaption>Running Objection’s “android root disable” Command</figcaption></figure><p>As seen below, objection’s root-detection bypass command didn’t provide a pleasing result, as it only passed 5 out of 11 checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0e_cHafu73-xwzKvnjEF5w.png" /><figcaption>Objection Result (5/11)</figcaption></figure><h4><strong>Tool #5: Magisk Hide</strong></h4><p>One of the features of <a href="https://github.com/topjohnwu/Magisk">Magisk</a> is <a href="https://www.didgeridoohan.com/magisk/MagiskHide">Magisk Hide</a>, which can be used to bypass root-detection and system integrity checks.</p><p>Since Magisk v20.4, Magisk Hide is disabled by default. To enable this feature, open <strong><em>Magisk Manager</em></strong>, click <strong><em>Settings</em></strong> from the sidebar, toggle ON the <strong><em>Magisk Hide</em></strong> option, and restart the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wINAnwWFhcbiA8V2sM5A0Q.png" /><figcaption>Enabling Magisk Hide</figcaption></figure><blockquote>Take note that <strong>Magisk Hide</strong> and <strong>Frida</strong> do not work well together. To use one of them, the other one must be disabled first.</blockquote><p>Bypassing an app’s root-detection mechanism is as simple as adding the app to the Hide list (just like in RootCloak).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XCN6FI6L0ijjbhoZytujaQ.png" /><figcaption>Adding RootBeer Sample to Magisk Hide List</figcaption></figure><p>After adding <strong>RootBeer Sample</strong> to Magisk Hide, the result was a near-perfect score, with 10 out of 11 checks passed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pceVoOGrOnL-BYMzS95TjA.png" /><figcaption>MagiskHide Result (10/11)</figcaption></figure><h4><strong>Tool #5: Hiding Magisk Manager</strong></h4><p>Looking back at the result of using Magisk Hide, only the first check (Root Management Apps) failed. This was because one of the checks used by RootBeer library is to look for the presence of root management apps, such as <strong>Magisk Manager</strong> (com.topjohnwu.magisk).</p><p>Since Magisk v20.1, a new feature was introduced that could repackage Magisk Manager with a random package and app names. To use this feature, click the <strong><em>Settings</em></strong> option from the sidebar, click the <strong><em>Hide Magisk Manager</em></strong> option, and select Magisk Manager’s new app name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2g2-Npw1x1xTADHgK_8-Og.png" /><figcaption>Hiding Magisk Manager</figcaption></figure><p>After doing the above steps and using this feature, Magisk Manager’s package name changed to a random one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RCB054fJ5FnauDlGM6H3kg.png" /><figcaption>Before and After Hiding Magisk Manager</figcaption></figure><p>So how did it perform? Well, it did not do well and only 7 checks passed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dotc8ZLnvy9jT1SbTfxteg.png" /><figcaption>“Hide Magisk Manager” Result (7/11)</figcaption></figure><h4><strong>Tool #5: Magisk Hide + Hiding Magisk Manager</strong></h4><p>Since Magisk Hide and Hide Magisk Manager are both features of Magisk, why not use both features at the same time? It turned out that this was what we’re aiming for. The result was outstanding! The result stating that it is <strong>NOT ROOTED</strong> was valid since all checks passed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IbHw7O2je18V57GJ4D6yCg.png" /><figcaption>Magisk Hide + Hiding Magisk Manager Result (11/11)</figcaption></figure><h3>Results</h3><p>For ease of viewing, the following table summarizes the results obtained from this experiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aVhaVDKuEH054CfcL7zdTg.png" /><figcaption>Summary of Results</figcaption></figure><p>Among all the tools covered in this experiment, only Magisk’s features (Magisk Hide and Hiding Magisk Manager) gave the best result.</p><h3>Final Thoughts</h3><p>While the goal of this experiment is to have a “go-to” tool when bypassing root-detection mechanisms, testers should be aware that the results gathered here will not always be the same against every application. This is because app developers can modify and improve the RootBeer library by adding more checks, or they could use their custom anti-root solutions. Thus, I encourage analysts to also learn how to reverse engineer an application and bypass an app’s root-detection manually.</p><p>Lastly, no root-detection mechanism can ever be perfect. That’s why it is recommended to implement additional security measures to make a bypass more difficult to achieve. Such measures include the use of run-time protections, as well as anti-reversing and anti-tampering solutions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fd477251640" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secarmalabs/comparison-of-different-android-root-detection-bypass-tools-8fd477251640">Comparison of Different Android Root-Detection Bypass Tools</a> was originally published in <a href="https://medium.com/secarmalabs">Secarma Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bypassing Android’s RootBeer Library (Part 1)]]></title>
            <link>https://medium.com/secarmalabs/bypassing-androids-rootbeer-library-part-1-a5f93918660d?source=rss-10d84fbceb2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5f93918660d</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[root-android-phone]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[research]]></category>
            <dc:creator><![CDATA[Elvin Gentiles]]></dc:creator>
            <pubDate>Wed, 27 May 2020 11:45:48 GMT</pubDate>
            <atom:updated>2020-06-08T13:11:05.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bypassing Android’s RootBeer Library — Part 1</h3><p>In my previous post, I made a comparison between the different well-known and open-source root-detection bypass tools for Android. In that post, I encouraged analysts to learn how to reverse engineer an application and bypass an application’s protection manually.</p><p>This post is a follow up on how to bypass the different checks used by RootBeer library by changing the application’s process through code manipulation.</p><p>Before you could modify an application’s code, you need to first have a copy of the APK file. After downloading the application (<a href="https://play.google.com/store/apps/details?id=com.scottyab.rootbeer.sample"><strong>RootBeer Sample</strong></a>) from the Play Store, the following series of commands can be used to extract the APK file from the Android device:</p><pre>$ adb shell pm path com.scottyab.rootbeer.sample<br>$ adb pull &lt;apk-path&gt;</pre><p>If you’re like me and do not like typing series of commands, the easiest way to retrieve an APK file from a device is by using <a href="https://github.com/Hamz-a/frida-android-helper"><strong>Frida Android Helper</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6lw53U4pfqvTkCU4UB-mQ.png" /><figcaption>Retrieving an Application’s APK File with Frida Android Helper</figcaption></figure><p>Once you have a copy of the APK file, decompile it using <a href="https://ibotpeaches.github.io/Apktool/"><strong>apktool</strong></a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*JDa6ptcrntsW8XXRsOlpeg.png" /><figcaption>Decompiling the APK File with apktool</figcaption></figure><blockquote><strong>Tip 1:</strong> Sometimes, rebuilding a decompiled application results in an error. One way to fix that error is by removing the file <strong>1.apk </strong>(shown above) before rebuilding the app.</blockquote><blockquote><strong>Tip 2: </strong>If an error related to “resources” shows during the building process, try excluding the resources during the decompilation by using the -r flag (shown below).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*LwgqNvLk5RaSwaxh5G1c5w.png" /><figcaption>Excluding Resources During Decompilation</figcaption></figure><p>Reading smali code is not as easy as reading java code. So if you’re not comfortable with smali, you can open the APK file in <a href="https://github.com/skylot/jadx"><strong>jadx-gui</strong></a><strong> </strong>to view its java equivalent and use it as a reference to gain better understanding:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dX8S8VtvbHz8il41pNn7kg.png" /><figcaption>Using jadx-gui to Analyse an Application’s Code</figcaption></figure><p>Looking at the <strong>RootBeer</strong> (<em>com.scottyab.rootbeer.RootBeer</em>) class, there exists a function called <strong><em>isRooted()</em></strong> which, as per its name, is responsible for identifying whether the device is rooted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*I0TPMil15SHfjyW7ZSNe3g.png" /><figcaption>Snippet of the <strong>RootBeer </strong>Class</figcaption></figure><p>The equivalent smali code of this class is located in /decompiled/smali/com/scottyab/rootber/RootBeer.smali. From this smali code, the <strong><em>isRooted()</em></strong><em> </em>function is located on line <strong>1084 </strong>(as shown below):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jPyVrNC1QyaZ8UNGLYU5iQ.png" /><figcaption>Snippet of the isRooted Function</figcaption></figure><p>On line <strong>1158</strong>, it can be seen that the <strong><em>isRooted()</em></strong> function returns whatever value the variable v0 holds. To force this function to return the value of <strong>false</strong>, just change the value of the variable v0from <strong>0x1 </strong>to <strong>0x0 </strong>(shown in line <strong>1155</strong>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*8TC8Si-DioeCwUSyvPo53w.png" /><figcaption>Forcing isRooted() Function to Return “False”</figcaption></figure><p>After doing the necessary changes, rebuild the application using apktool:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*pQbf2hPqn2_QSJlRcXIoOw.png" /><figcaption>Rebuilding the Modified Application</figcaption></figure><p>Before installing the application, make sure to sign it using your own certificate or a debug certificate. To sign the application easily, you can use <a href="https://github.com/patrickfav/uber-apk-signer"><strong>uber-apk-signer</strong></a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*6DHLlBOd0na7WCDOe8csWg.png" /><figcaption>Signing the Application with a Debug Certificate</figcaption></figure><p>Using the modified application, it can be seen that we’ve successfully forced the result to “<strong>NOT ROOTED”</strong> (see the right image below). However, nothing changed with the different checks used by RootBeer; some of the checks still failed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GM-yP__l_fgGluhoGb_F7g.png" /><figcaption>Result of Modifying the APK File</figcaption></figure><p>This happened because we only modified one function of the application and forced it to return as “<strong>NOT ROOTED”</strong>. To pass all the checks used by the RootBeer library, we need to modify and bypass all the relevant functions.</p><p>So how can we find all these functions? If we look at the <strong>RootCheckTask</strong> (<em>com.scottyab.rootbeer.sample.CheckRootTask</em>) class, there’s a function called <strong><em>doInBackground()</em></strong> which can be used to identify the different functions/checks used by RootBeer. This list of functions can be used as a reference to determine which smali code/files to modify:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKuS4LbyMsuQfllgPpOHjg.png" /><figcaption>A Snippet of the Different Functions Used by RootBeer</figcaption></figure><p>The following lists the changes that were made to the relevant classes and functions to bypass all of RootBeer’s checks.</p><blockquote><strong>Note: bold </strong>text in the code snippets below signifies the changes that were made.</blockquote><h4><strong>RootBeer</strong> <strong>(<em>com.scottyab.rootbeer.RootBeer</em>)</strong> Class</h4><ul><li><strong><em>detectRootManagementApps()</em></strong><em> — </em>inserted return v0.</li></ul><pre>.method public detectRootManagementApps()Z<br>    .locals 1</pre><pre>    const/4 v0, 0x0<br>    <strong>return v0</strong></pre><pre>[...]</pre><ul><li><strong><em>detectPotentiallyDangerousApps() </em></strong><em>— </em>inserted return v0.</li></ul><pre>.method public detectPotentiallyDangerousApps()Z<br>    .locals 1</pre><pre>    const/4 v0, 0x0<br><strong>    return v0</strong></pre><pre>[...]</pre><ul><li><strong><em>detectTestKeys()</em></strong><em> — </em>changed const/4 v0, 0x1 to const/4 v0, 0x0.</li></ul><pre>.method public detectTestKeys()Z<br>[...]</pre><pre>    const/4 v0, 0x0</pre><pre>    goto :goto_0</pre><pre>    :cond_0<br>    <strong>const/4 v0, 0x0</strong></pre><pre>    :goto_0<br>    return v0</pre><ul><li><strong><em>checkForBusyBoxBinary()</em></strong><em> — </em>changed move-result v0 to const/4 v0, 0x0.</li></ul><pre>.method public checkForBusyBoxBinary()Z<br>[...]</pre><pre>    <strong>const/4 v0, 0x0</strong></pre><pre>    return v0<br>.end method</pre><ul><li><strong><em>checkForSuBinary() </em></strong><em>— </em>changed move-result v0 to const/4 v0, 0x0.</li></ul><pre>.method public checkForSuBinary()Z<br>[...snipped...]</pre><pre>    <strong>const/4 v0, 0x0</strong></pre><pre>    return v0<br>.end method</pre><ul><li><strong>checkSuExists()</strong><em> — </em>inserted return v0.</li></ul><pre>.method public checkSuExists()Z<br>    .locals 6</pre><pre>    const/4 v0, 0x0<br>    <strong>return v0</strong><br>    const/4 v1, 0x0</pre><pre>[...]</pre><ul><li><strong><em>checkForRWPaths()</em></strong> —inserted return v1.</li></ul><pre>.method public checkForRWPaths()Z<br>    .locals 16</pre><pre>    .line 301<br>    invoke-direct/range {p0 .. p0}, Lcom/scottyab/rootbeer/RootBeer;-&gt;mountReader()[Ljava/lang/String;</pre><pre>    move-result-object v0</pre><pre>    const/4 v1, 0x0<br>    <strong>return v1</strong></pre><pre>[...]</pre><ul><li><strong><em>checkForDangerousProps() </em></strong>— changed const/4 v4, 0x1 to const/4 v4, 0x0.</li></ul><pre>.method public checkForDangerousProps()Z<br>[...]</pre><pre>    invoke-static {v4}, Lcom/scottyab/rootbeer/util/QLog;-&gt;v(Ljava/lang/Object;)V</pre><pre>    <strong>const/4 v4, 0x0</strong></pre><pre>    goto :goto_1</pre><pre>    :cond_2<br>    add-int/lit8 v2, v2, 0x1</pre><pre>    goto :goto_0</pre><pre>    :cond_3<br>    return v4<br>.end method</pre><ul><li><strong><em>checkForRootNative()</em></strong> — changed const/4 v1, 0x1 to const/4 v1, 0x0.</li></ul><pre>.method public checkForRootNative()Z<br>[...]</pre><pre>    if-lez v0, :cond_2</pre><pre>    <strong>const/4 v1, 0x0</strong></pre><pre>    :catch_0<br>    :cond_2<br>    return v1<br>.end method</pre><ul><li><strong><em>detectRootCloakingApps()</em></strong> — changed const/4 v0, 0x1 to const/4 v0, 0x0.</li></ul><pre>.method public detectRootCloakingApps()Z<br>[...]</pre><pre>    :cond_1<br>    :goto_0<br>    <strong>const/4 v0, 0x0</strong></pre><pre>    :goto_1<br>    return v0<br>.end method</pre><ul><li><strong>checkForMagiskBinary()</strong> — changed move-result v0 to const/4 v0, 0x0.</li></ul><pre>.method public checkForMagiskBinary()Z<br>[...]</pre><pre>    <strong>const/4 v0, 0x0</strong></pre><pre>    return v0<br>.end method</pre><h4>Utils (com.scottyab.rootbeer.util) Class</h4><ul><li><strong><em>isSelinuxFlagInEnabled()</em></strong> — inserted return v0.</li></ul><pre>.method public static isSelinuxFlagInEnabled()Z<br>    .locals 6</pre><pre>    const/4 v0, 0x0<br>    <strong>return v0</strong><br>[...]</pre><p>After doing the above changes, the last thing to do is to rebuild, resign, and re-install the modified application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ID4wQ67334M-QKc6pqdhjA.png" /><figcaption>Rebuilding, Resigning, and Re-installing the Modified Application</figcaption></figure><p>Though the process of modifying the application’s code took quite some time, it’s worth the effort as it resulted in all the checks being bypassed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8RRiQIdpn_AW3CXcQZDXQ.png" /><figcaption>Successfully Bypassed All RootBeer’s Checks</figcaption></figure><h3>Final Thoughts</h3><p>The way I modified the application’s code <em>(e.g. inserting </em><em>return v0 after a few lines of the beginning of a function)</em> is not the only way to do it. We all think differently and each of us could come up with different ways on how to solve a problem. So it doesn’t matter how you do your modifications as long as you’re getting the results that you’re aiming for.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5f93918660d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secarmalabs/bypassing-androids-rootbeer-library-part-1-a5f93918660d">Bypassing Android’s RootBeer Library (Part 1)</a> was originally published in <a href="https://medium.com/secarmalabs">Secarma Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>