<?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 Mohannad Handoumeh on Medium]]></title>
        <description><![CDATA[Stories by Mohannad Handoumeh on Medium]]></description>
        <link>https://medium.com/@Handoumeh?source=rss-ffe4a870e2d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*C9v4MzHw2MiMxvmxRY0aZQ.jpeg</url>
            <title>Stories by Mohannad Handoumeh on Medium</title>
            <link>https://medium.com/@Handoumeh?source=rss-ffe4a870e2d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:00:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Handoumeh/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[PwnSec CTF 2025 Mobile — RudeFrida]]></title>
            <link>https://medium.com/@Handoumeh/pwnsec-ctf-2025-mobile-rudefrida-8356fcf69264?source=rss-ffe4a870e2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8356fcf69264</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[frida]]></category>
            <category><![CDATA[mobile-pentesting]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mohannad Handoumeh]]></dc:creator>
            <pubDate>Fri, 06 Mar 2026 20:29:18 GMT</pubDate>
            <atom:updated>2026-03-06T20:29:18.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fs5eOAwTb1cD8fZUAQUCKw.png" /></figure><p>Well, it is the second PwnSec CTF, I have created three mobile challenges, and all three challenges are meant to be solved using Frida, which are <strong>CuteFrida</strong>, <strong>RudeFrida, </strong>and <strong>FreakyFrida</strong>.</p><p><strong>RudeFrida</strong> was my personal favorite. It requires reverse engineering a shared library and understanding how root and Frida detections work to bypass those protections. Once bypassed, the final step is to successfully call the flag function.</p><p>Now, let’s open the library using Ghidra.</p><p>In the <strong>JNI_OnLoad, </strong>there is a function being called, which is <strong>FridaCheck</strong>, from the name of the function, it is a protection against Frida.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bbcfWzatqKkhloyXBBqQg.png" /></figure><p>As shown in the image below, the function <strong>FridaCheck </strong>is trying to open “/proc/net/tcp”; this file is a kernel interface that lists all active <strong>TCP IPv4 connections. </strong>By parsing this file, the app can identify if the default Frida server ports (<strong>27042</strong> or <strong>27043</strong>) are active. If a match is found, the app terminates.</p><p>This kind of protection is weak and can be bypassed by just running Frida on diffrent port than the default ports, but for our case here we will use Frida.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79pA4uhZ5dIFymg7xXIg7Q.png" /></figure><p>I have also implemented another Frida protection, this time it is using the initialization function. Initialization functions are special functions in programming that are responsible for setting up the initial state of a system. These functions are called at the beginning of the code.</p><p>As shown in the image, the initialization function is creating a new thread to execute a function <strong>FUN_00161250,</strong> which is our second layer of the Frida detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oMK7iVbp9YjL7z3r2_UwzQ.png" /></figure><p>The function <strong>FUN_00161250 </strong>is opening “/proc/self/maps” file, which is a special read-only file that provides a “map” of the current process’s memory layout. the content of the file will be into the vaiable “<strong>__stream</strong>”, after that it will call the function <strong>strstr </strong>with two values “<strong>__stream</strong>” variable and the word <strong>frida</strong>, <strong>strstr </strong>function returns a pointer to the first index of a specified substring in another string, so basically it will check if the word <strong>Frida </strong>is in the variable <strong>“__stream”, </strong>if the word <strong>Frida </strong>found it will exit the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bLyZ_kk2x7O6mNfkvYDD0A.png" /></figure><p>For bypassing these two protections using Frida, it can be done by only hooking the <strong>strstr </strong>and making the return value of it to be zero, that why we can bypass Frida protection.</p><p>In this simple script, we are hooking the strstr function, and after that, in the “<strong>OnLeave</strong>”, which executes immediately after <strong>strstr</strong> finishes its work but before the result is sent back to the calling function, we will replace the return value of the strstr function to be a zero, this way it will always returns false and wont exit the application<strong>.</strong></p><p>In my solution, I took the “lazy” route by forcing <strong>strstr </strong>to <strong>always</strong> return zero. In a real-world app, this might break legitimate functionality that relies on string searching. A better approach would be to check the arguments in onEnter and only return zero if the search string matches the Frida ports or signatures. But for this challenge this methods work fine.</p><pre>Interceptor.attach(Module.findExportByName(null, &quot;strstr&quot;), {<br><br>    onEnter: function (args) {<br>    },<br>    onLeave: function (retval) {<br>        retval.replace(0);<br>    }<br>});</pre><p>Now we have the root detection check, one of the JNI functions, which is “<strong>Java_com_pwnsec_RudeFrida_MainActivity_stringFromJNI</strong>” is calling the root detection function <strong>is_rooted_simple.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ZWXnzVtOfIL7dRnWJ0G7Q.png" /></figure><p>Well, for the <strong>is_rooted_simple </strong>function, we can see that it is checking on the subinary to check if the mobile device is rooted or not using the <strong>access </strong>function, and if the su binary is found, it will exit the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1O7QmM8o75GpJ8LE9c_3g.png" /></figure><p>For this <strong>access </strong>function, we do not need to force the return value to be zero, like with <strong>strstr</strong>. Instead, we manipulate the memory so that the <strong>access </strong>function checks a non-existent file rather than checking the su binary—gaslighting the check into believing the su binary is not in there.</p><p>In the Frida code, the script first hooks the <strong>access </strong>function from the libc library<strong>, </strong>but before checking the value of the function, I have added this line of code.</p><pre>Memory.protect(args[0], Process.pointerSize, &#39;rwx&#39;);</pre><p>By default, most memory segments in a running application are marked as <strong>Read-Only</strong> or <strong>Read/Execute</strong> for security reasons. In this code, what we are doing is to change the protection to <strong>Read, Write, </strong>and<strong> Execute. </strong>The purpose here is to be able to make changes to the memory.</p><p>After that, we store the value passed to the <strong>access</strong> function and check whether it contains /su. If it does, we manipulate the memory so that the <strong>access </strong>function attempts to read /system/nonexisting instead of the original path.</p><pre>Interceptor.attach(Module.findExportByName(&quot;libc.so&quot;, &quot;access&quot;), {<br>    onEnter: function (args) {<br>        Memory.protect(args[0], Process.pointerSize, &#39;rwx&#39;);<br>        var path = args[0].readCString();<br>        if (path.indexOf(&quot;/su&quot;) &gt;= 0) {<br>            console.log(`Manipulating su path...`);<br>            args[0].writeUtf8String(&quot;/system/nonexisting&quot;);<br>        }<br>        console.log(`access: ${args[0].readCString()}`);<br>    }, onLeave: function (retval) {<br>        console.log(`access onleave: ${retval}`);<br>    }<br>})</pre><p>Now, by running both scripts, we will be able to bypass Frida and root detection and make the application run without any issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KN1MlGNGMxji1Jtzo-zwVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*ezKiBHNAuINRxwcsPeLpUQ.gif" /></figure><p>Now, for the last step, getting the flag.</p><p>To get the flag, we need to find where it is being called, but the only issue here is that the function is not being called anywhere in the application. It is neither called from the Java layer nor referenced by any JNI function within the shared library. A function called <strong>get_flag </strong>is<strong> </strong>just existsing in the void of the shared library alone. Well, that’s sad.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKbShZMUvdUv0bGMfKA9qw.png" /></figure><p>But, it can be called using Frida of course, but let&#39;s break down what the function does.</p><p>From the code, we can see that the function takes two integer parameters when it is called. These two parameters are combined together, and if the resulting value equals <strong>1337</strong>, the function proceeds to decrypt the flag and then prints it to the logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4U7nxgv2k2pVciQRku8ewA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aP7G6eubTDbOCbw0OD4X2g.png" /></figure><p>So, we are not only going to call the function, but we also need to pass two integers whose sum must equal <strong>1337</strong>.</p><pre>function getflag() {<br>    var libBase = Module.findBaseAddress(&quot;libRudefrida.so&quot;);<br>    if (!libBase) {<br>        console.log(&quot;[-] libRudefrida.so not loaded yet&quot;);<br>        return false;<br>    }<br><br>    console.log(&quot;[+] libRudefrida.so base: &quot; + libBase);<br>    var test = libBase.add(0x618e0);<br>    console.log(&quot;[+] Target address: &quot; + test);<br>    var new_ptr = new NativePointer(test);<br>    const myVoidFunction = new NativeFunction(new_ptr, &#39;void&#39;, [&#39;int&#39;, &#39;int&#39;]);<br>    myVoidFunction(1000, 337);<br>    return true;<br>}<br><br><br>setTimeout(function () {<br>    if (getflag()) {<br>        console.log(&quot;[+] Function called successfully!&quot;);<br>    } else {<br>        console.log(&quot;[-] Failed to call function - library not loaded&quot;);<br>    }<br>}, 1000); </pre><p>First, the script tries to find the <strong>base address</strong> of the shared library:</p><p>Module.findBaseAddress(&quot;libRudefrida.so&quot;)</p><p>Next, the script calculates the address of the function by adding its <strong>offset</strong> to the base address:</p><p>var test = libBase.add(0x618e0);</p><p>This gives us the exact memory address of the function we want to call.</p><p>We obtained the function’s offset from <strong>Ghidra</strong>, as shown in the image below. However, the address displayed in Ghidra includes the default image base used during analysis. To get the correct runtime offset, we subtract <strong>0x10000</strong> from the address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLQY5VlzUX0zdfGPJn_64w.png" /></figure><p>After that, we create a pointer to this address and define it as a callable function using Frida:</p><p>new NativeFunction(new_ptr, &#39;void&#39;, [&#39;int&#39;, &#39;int&#39;])</p><p>This tells Frida that the function returns nothing (void) and takes <strong>two integers</strong> as parameters.</p><p>Then the function is called:</p><p>myVoidFunction(1000, 337);</p><p>These two numbers were chosen because their sum is <strong>1337</strong>, which satisfies the condition inside the function and triggers the flag decryption.</p><p>Finally, the script runs after a <strong>1-second delay</strong> using setTimeout. This delay ensures that the shared library is loaded before the script tries to access it.</p><p>By combining this with the protections we created to bypass the <strong>Frida</strong> and <strong>root detection</strong> checks, we end up with the final script below.</p><p>By the way, I used <strong>Frida version 16</strong> while solving this challenge. It can also be solved using <strong>Frida version 17</strong>, but some players ran into issues with it… <em>cough cough</em> <em>skill issue</em>… and complained that I didn’t mention the version requirement.</p><pre>Interceptor.attach(Module.findExportByName(null, &quot;strstr&quot;), {<br><br>    onEnter: function (args) {<br>    },<br>    onLeave: function (retval) {<br>        retval.replace(0);<br>    }<br>});<br><br>Interceptor.attach(Module.findExportByName(&quot;libc.so&quot;, &quot;access&quot;), {<br>    onEnter: function (args) {<br>        Memory.protect(args[0], Process.pointerSize, &#39;rwx&#39;);<br>        var path = args[0].readCString();<br>        if (path.indexOf(&quot;/su&quot;) &gt;= 0) {<br>            console.log(`Manipulating su path...`);<br>            args[0].writeUtf8String(&quot;/system/nonexisting&quot;);<br>        }<br>        console.log(`access: ${args[0].readCString()}`);<br>    }, onLeave: function (retval) {<br>        console.log(`access onleave: ${retval}`);<br>    }<br>})<br><br>function getflag() {<br>    var libBase = Module.findBaseAddress(&quot;libRudefrida.so&quot;);<br>    if (!libBase) {<br>        console.log(&quot;[-] libRudefrida.so not loaded yet&quot;);<br>        return false;<br>    }<br><br>    console.log(&quot;[+] libRudefrida.so base: &quot; + libBase);<br>    var test = libBase.add(0x618e0);<br>    console.log(&quot;[+] Target address: &quot; + test);<br>    var new_ptr = new NativePointer(test);<br>    const myVoidFunction = new NativeFunction(new_ptr, &#39;void&#39;, [&#39;int&#39;, &#39;int&#39;]);<br>    myVoidFunction(1000, 337);<br>    return true;<br>}<br><br><br>setTimeout(function () {<br>    if (getflag()) {<br>        console.log(&quot;[+] Function called successfully!&quot;);<br>    } else {<br>        console.log(&quot;[-] Failed to call function - library not loaded&quot;);<br>    }<br>}, 1000); </pre><p>And we got the flag in the log of the mobile device yaaaaay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N9jWSPSxoyFsIrc8nMLKjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*wIxOEGOz2mP9rXvKr8M17A.gif" /></figure><p>Well, what we learned today is that anything can be hooked using frida even if it is in the shared library. That does not mean the protections can’t be bypassed if you didn’t manage to bypass the protections from the library. Then, I have bad news for you :).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*N4z3thAAKlcjlWz712c7Rw.gif" /></figure><p>Happy hacking yall. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8356fcf69264" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PwnSec CTF 2024 Mobile]]></title>
            <link>https://medium.com/@Handoumeh/pwnsec-ctf-2024-mobile-1b373affd69b?source=rss-ffe4a870e2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b373affd69b</guid>
            <dc:creator><![CDATA[Mohannad Handoumeh]]></dc:creator>
            <pubDate>Sat, 16 Nov 2024 15:56:09 GMT</pubDate>
            <atom:updated>2024-11-18T06:07:16.413Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*Z1DWWQsiMj6eRUfDZq5weA.png" /></figure><p>This is the first CTF for PwnSec Team, In this CTF I made 4 mobile challenges.</p><p>ezmobile which is a beginner challenge, FireInTheHole easy challenge, FireStorm medium challenge and Snake hard challenge. Let’s begin, shall we.</p><h4><strong>1- ezmobile</strong></h4><p>ezmobile is a beginner-level mobile challenge, in this challenge first, you need to use Jadix to reverse the APK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*paBklCJGI0Txe5QnaDUWsw.png" /></figure><p>After decompiling the APK, we noticed a “FlagCheck” function. The function is making a comparison, it takes an input and compares it with the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QJPGf0HeIrRe4l2eTiluuw.png" /></figure><p>The flag is being called from the “strings.xml” file which can be located in the resources folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6HXn74ZhPYWE8kOG3dgqtA.png" /></figure><p>It’s base64 encoded, using cyberchef you can decode it and get the flag.</p><p><strong>FLAG: PWNSEC{w3lp_n07h!ng_Sp3Ci4l_Just_4_Fl4g_!n_7h3_s7r!ng5_xml_f!l3}</strong></p><h4><strong>2- FireInTheHole</strong></h4><p>It’s an easy challenge based on a Firebase misconfiguration and an AES decryption for the files located in the assets, the Real-Time database of the Firebase has no restrictions and can be accessed.</p><p>I am starting by decompiling the mobile APK and analyze the android manifest XML file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4zfPRdtr2cVraTt-YS5Ayw.png" /></figure><p>From the AndroidManifest we find there are two activities, MainActivity and Decrypter. The MainActivity doesn’t have anything useful let’s check the Decrypter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vkBPJ2xnTh1le5Ecr_d7hQ.png" /></figure><p>The Decrypter activity makes getAssets function to open the file “one.txt” from the assets folder of the mobile application, also it executes functions that will get the key and IV. After that, it calls the decrypt function with the content of “one.txt”, decoded key, and decode IV.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_Ol6KPgqxUl5PwEtm5IGw.png" /></figure><p>The decrypt function is doing an AES decryption, from what we had it is decrypting the content of the “one.txt” file with the key and IV, the problem is the key and IV are not in the APK itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFUFiM9V8RRjwD2wY9PjMg.png" /></figure><p>By checking the “strings.xml” file from the resources, there is a Firebase database URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0gfztQ_9ct-PBkW1jgbHtg.png" /></figure><p>In Firebase, there is a common misconfiguration that leads to accessing the database by just going to “.json”, from the Firebase we will find the key and IV for the AES decryption.</p><p>Now by assembling all the pieces together, we can decrypt the files that are in the assets folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PCfJFS_809uU7Ei8TZ8jGg.png" /></figure><p><strong>FLAG: PWNSEC{Y0uR_F!r3_L4ck5_d!sciplin3}</strong></p><h4><strong>3- FireStorm</strong></h4><p>On this challenge you need to use Frida to solve it, in this challenge, you need to use Frida to force a function in the mobile application to work in order to get the password, after that you will find a Firebase config in the strings.xml file with an email, you need to use the password you got and the email to authenticate to the firebase database to get the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvC_hTa7kLyoKyTYF5NkOA.png" /></figure><p>There is a Password function that will get strings from the strings.xml file and from these strings, a random string will be passed to a function called “generateRandomStrings”, this function is from the native library “firestorm”.</p><p>The password function is not being called, so what we need is to use Frida to hook this function to get the value of the password.</p><pre>Java.perform(function() {<br>    function getPassword() {<br>        Java.choose(&#39;com.pwnsec.firestorm.MainActivity&#39;, {<br>            onMatch: function(instance) {<br>                console.log(&quot;MainActivity instance found: &quot; + instance);<br>                try {<br>                    var pass = instance.Password();<br>                    console.log(&quot;FireBase Password: &quot; + pass);<br>                } catch (e) {<br>                    console.log(&quot;Error occurred: &quot; + e);<br>                }<br>            },<br>            onComplete: function() {<br>                console.log(&quot;Search completed. Exiting script.&quot;);<br><br>            }<br>        });<br>    }<br><br>    // Delay execution to ensure the app is fully started<br>    setTimeout(getPassword, 4000); // Adjust the delay as needed (4000 ms = 4 seconds)<br>});</pre><p>In this Javascript code, it will force the Password function to be executed and then it will print the results of the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDEjZCugY42-MYXpdwOmaA.png" /></figure><p>Nice we got the password, now for the next part the password will be used to authenticate with the Firebase database, firebase cofiguration is found in the “strings.xml” file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tM0Lvpx9QSUxnp07H87x_Q.png" /></figure><p>In the “strings.xml”, we have the firebase configuration and a firebase email, so we have an email and we have extracted a password using Frida, now we need to authenticate to the Firebase database using email and the password.</p><pre>import pyrebase<br>import requests<br><br><br>config = {<br>  &quot;apiKey&quot;: &quot;AIzaSyAXsK0qsx4RuLSA9C8IPSWd0eQ67HVHuJY&quot;,<br>  &quot;authDomain&quot;: &quot;firestorm-9d3db.firebaseapp.com&quot;,<br>  &quot;databaseURL&quot;: &quot;https://firestorm-9d3db-default-rtdb.firebaseio.com&quot;,<br>  &quot;storageBucket&quot;: &quot;firestorm-9d3db.appspot.com&quot;,<br>  &quot;projectId&quot;: &quot;firestorm-9d3db&quot;<br>}<br><br><br>firebase = pyrebase.initialize_app(config)<br><br><br>auth = firebase.auth()<br>email = &quot;TK757567@pwnsec.xyz&quot;<br>password = &quot;C7_dotpsC7t7f_._In_i.IdttpaofoaIIdIdnndIfC&quot;<br>user = auth.sign_in_with_email_and_password(email, password)<br><br>db = firebase.database()<br><br>#FLAG will be printed <br>print(db.get(user[&#39;idToken&#39;]).val()) </pre><p><strong>FLAG: PWNSEC{C0ngr4ts_Th4t_w45_4N_345y_P4$$w0rd_t0_G3t!!!_0R_!5_!t???}</strong></p><h4><strong>4- Snake</strong></h4><p>Snake is a mobile application that has multiple protection, root detection, and Frida detection, so solving the challenge using Frida is not an option here. The idea of the challenge is a Deserialization attack using the yml file that the application is reading from the external storage to call and execute the class that generates the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ESJmNxVkl8xmgxhYtncVZg.png" /></figure><p>Using Jadix, we noticed that there is a root detection in the application that will prevent the application from working in a rooted device or emulator.</p><p>So we need to decompile the mobile application using any apktool or apklab then patch the smali code to be able to bypass the root detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*lRFaMr8-VypzzDxSPgW0Qw.png" /></figure><p>Nice, the application perfectly working now and it is asking for permission to have access to the external storage you need to give access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnQXl5Hv5T6vVl0tFrvS0w.png" /></figure><p>By analyzing the application more we can see that there is a function is defining an intent and from the intent it is receiving an extra string “SNAKE” and there is a condition that makes sure that there is an extra string “SNAKE” with the value of “BigBoss”.</p><p>If the condition is valid, it will go to the external storage and try to find a folder called Snake, and it will check if the yaml file “Skull_Face.yml” is in the folder or not.</p><p>If the yaml file is in the snake folder in the external storage it will load the content of the yaml file and print it in the logs of the mobile device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZfSHWAVqeSGd_PTdSeCQg.png" /></figure><p>Analyzing the APK more and more you will also find another class called BigBoss, in this call it is going to load a library and call the function “stringFromJNI”, there is also another function called “Bigboss” which will receive a string and that string will be passed to the “stringFromJNI” function, depending on that string which needs to be the string “Snaaaaaaaaaaaaaake” it will print the flag in the logs.</p><p>But the main issue here is how to call this function, because there is nothing that is calling this class also Frida can’t be used here because of the Frida detection thet is in the library.</p><p>The answer is in the yaml file, The yaml file is being loaded by a library called snakeyaml, I used a vulnerable version of it that is affected with Deserialization vulnerability.</p><p><a href="https://www.greynoise.io/blog/cve-2022-1471-snakeyaml-deserialization-deep-dive">CVE-2022-1471: SnakeYAML Deserialization Deep Dive | GreyNoise Blog</a></p><p>So we need to build a payload in the “skull_Face.yml” file that will call the “BigBoss” class and passing “Snaaaaaaaaaaaaaake” as a string to it.</p><p>We need to create “snake” folder in the external storage with the file “skull_Face.yml” and inside the yaml file, we need to put this payload.</p><pre>!!com.pwnsec.snake.BigBoss [&quot;Snaaaaaaaaaaaaaake&quot;]</pre><p>After that, using adb we need to call the MainActivity with an Extra called “SNAKE” and a “BigBoss”.</p><pre>adb shell am start -n com.pwnsec.snake/.MainActivity -e SNAKE BigBoss</pre><p>The flag will be printed in the logs of the mobile device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nozT8wiZpa2XFcNdOFUTKg.png" /></figure><p><strong>FLAG: PWNSEC{W3&#39;r3_N0t_T00l5_0f_The_g0v3rnm3n7_0R_4ny0n3_3ls3}</strong></p><p>Hope you have enjoyed this CTF, next year challenges will be harder and with new ideas.</p><p>Thanks for you participating, see you next year :) .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b373affd69b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OWASP UnCrackable 3 Android Application]]></title>
            <link>https://medium.com/h7w/owasp-uncrackable-3-android-application-bd25b3646acb?source=rss-ffe4a870e2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd25b3646acb</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-pentesting]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[frida]]></category>
            <dc:creator><![CDATA[Mohannad Handoumeh]]></dc:creator>
            <pubDate>Thu, 12 Sep 2024 10:36:47 GMT</pubDate>
            <atom:updated>2024-09-28T00:13:01.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*fr7qyjoCTJFq2wK2DrbXtw.jpeg" /></figure><p>Continuing the OWASPs Uncrackable challenges that I have started before by solving Uncrackable 1 and Uncrackable 2 challenges, I will continue solving Uncrackable 3.</p><p>What is special in this challenge?</p><ul><li>It has anti-tampering protection, so we can’t bypass root detection by tampering the smali code as in the previous challenges.</li><li>It has Frida protection, the mobile application will be terminated if Frida is being used.</li></ul><p>Ok, let’s start hacking through the mobile application.</p><p>I started by installing the mobile application into Genymotion emulator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*ahyJGozNNjn4oQvrluPNfA.png" /></figure><p>After running the application, a pop-up came out which say that “Rooting or tampering detected” which is because the Android device is rooted.</p><p>Let’s reverse-engineer the mobile application and see what is the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hcRoWtM8qU_ljDiCyQyreA.png" /></figure><p>By tracing the message that popped up, we found that there is an if statement that checks on 6 methods if they are not equal to 0, if they are not equal to 0 it will call the method <strong>showDialog </strong>with a string as shown in the image.</p><p>The methods that we will check on are the <strong>checkroot </strong>methods, lets first view the <strong>showDialog</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPsPXqR5wWEMJMf63qFfOQ.png" /></figure><p>By viewing the <strong>showDialog </strong>method, it will create a pop-up message with the string that has been passed to it as a title when the method is called and set a message, and it has an “OK” button that will exit from the mobile application after clicking it.</p><p>Ok, let’s get back to the <strong>checkroot </strong>methods that are being called from the <strong>RootDetection </strong>class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGk9ik2aus2-bovNz7xXYA.png" /></figure><p>From what we got from the class, it has 3 root detection methods, the first one will check on the “su” binary in the mobile device, the second will check on the build-tags of the mobile device if it contain a string called “test-keys” and the third one will check on a specific binaries and files inside of the mobile device.</p><p>These methods can be bypassed easily by using Frida.</p><pre>Java.perform(function(){<br>    let RootDetection = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>    RootDetection.checkRoot1.implementation = function(){<br>        console.log(&quot;[+] Bypassing the first Root Detection check&quot;)<br>        return false<br>    }<br>    RootDetection.checkRoot2.implementation = function(){<br>        console.log(&quot;[+] Bypassing the second Root Detection check&quot;)<br>        return false<br>    }<br>    RootDetection.checkRoot3.implementation = function(){<br>        console.log(&quot;[+] Bypassing the third Root Detection check&quot;)<br>        return false<br>    } <br>})</pre><p>This code will hook the 3 <strong>checkroot </strong>methods and it will make them return false. Let’s use this code using Frida on the mobile application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JO8GvhxZaverGsOOv-_drw.png" /></figure><p>After running Frida with the JS code to bypass the root protection, Frida and the mobile application crashed which is strange. Went through mobile device logs using logcat to see what did go wrong and found this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0F18Bx0ZubXlf8W5N0nbig.png" /></figure><p>From the logs, we notice at first that it is giving us the same message from Frida, and also in the red square we notice that from the libfoo.so shared library it is calling goodbye function.</p><p>Going through the APK again, we found that the application is loading a shared library “foo”, which is the same library that we saw in the logs of the mobile device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*NNORLOkWOHCjAoI83kcWBg.png" /></figure><p>After using <strong>apktool </strong>to decompile the APK, used <strong>ghidra </strong>to reverse-engineer the shared library and analyze it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*HM2h1W6ij3JUXdgtoXKyDg.png" /></figure><p>First I checked the function that I have found in the logs of the mobile device and found that goodbye function will only exit the mobile application, but where is this function is being called?</p><p>After analyzing the library found that there is <strong>_INIT_0</strong> function which is an initialization function, Initialization functions are special functions in programming that are responsible for setting up the initial state of a system, these functions are being called at the beginning of the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*IUvdiXV9cDT4wYGK7MRuxQ.png" /></figure><p>As shown in the image, the _INIT0_ function is creating a new thread to execute a function “<strong>FUN_001037c0</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UjMhzq0YAaagE4KlJg9lMA.png" /></figure><p>By analyzing the function, we see that the goodbye function is being called from this function.</p><p>Also, we see that the function is opening “/proc/self/maps” file from the mobile device in <strong>read mode</strong>, then it does a loop and reads the content of the file, line by line and store it into “<strong>acStack_238</strong>” variable, after that it will call the function <strong>strstr </strong>with two values “<strong>acStack_238</strong>” variable and the word <strong>frida</strong>, <strong>strstr </strong>function returns a pointer to the first index of a specified substring in another string, so basically it will check if the word <strong>Frida </strong>is in the variable <strong>“acStack_238”, </strong>if the word F<strong>rida </strong>found it will break from the loop and call the goodbye function and exit from the mobile application.</p><p>So can this protection be bypassed?</p><p>The answer is yes, and of course by using Frida.</p><p>Using Frida we can hook the function <strong>strstr </strong>and replace the return value of this function to always be 0, by doing this it will not break out from the loop and it won’t call the goodbye function.</p><pre>Java.perform(function(){<br>    var strstr_fun = Module.findExportByName(null,&quot;strstr&quot;)<br>    Interceptor.attach(strstr_fun,{<br>        onEnter : function(args){<br>             this.frida = ptr(args[0]).readCString()<br>             if (this.frida.indexOf(&quot;frida&quot;)&gt;=0){<br>                console.log(&quot;[+] frida have been detected&quot;)<br>                }<br>        },<br>        onLeave: function(retval){<br>            retval.replace(0)<br>        }<br>    })<br>    let RootDetection = Java.use(&quot;sg.vantagepoint.util.RootDetection&quot;);<br>    RootDetection.checkRoot1.implementation = function(){<br>        console.log(&quot;[+] Bypassing the first Root Detection check&quot;)<br>        return false<br>    }<br>    RootDetection.checkRoot2.implementation = function(){<br>        console.log(&quot;[+] Bypassing the second Root Detection check&quot;)<br>        return false<br>    }<br>    RootDetection.checkRoot3.implementation = function(){<br>        console.log(&quot;[+] Bypassing the third Root Detection check&quot;)<br>        return false<br>    } <br>})</pre><p>In this code, we’re chaining two methods: the first one bypasses Frida detection, and the second one bypasses root detection.</p><p>We bypassed Frida protection by hooking the <strong>strstr </strong>function to inspect its arguments and manipulate its return value, let’s explain more.</p><pre>var strstr_fun = Module.findExportByName(null, &quot;strstr&quot;)</pre><p>This line uses Frida’s Module.findExportByName to locate the strstr function in the target process.</p><pre>Interceptor.attach(strstr_fun,{<br>        onEnter : function(args){<br>             this.frida = ptr(args[0]).readCString()<br>             if (this.frida.indexOf(&quot;frida&quot;)&gt;=0){<br>                console.log(&quot;[+] frida has been detected&quot;)<br>                }<br>        }</pre><p>Then it will attach an interceptor on the location of <strong>strstr </strong>function.</p><p><strong>onEnter</strong> is executed when the <strong>strstr</strong> function is called, it will read the string from memory at the pointer args[0] and converts it to a readable C string, then stores it into<strong> “</strong>this.frida” variable.</p><p>If the word Frida is in the <strong>“</strong>this.frida” variable it will print that “Frida has been detected”.</p><pre>onLeave: function(retval){<br>            retval.replace(0)<br>        }</pre><p><strong>onLeave </strong>is executed after <strong>strstr </strong>finishes, after that it will replace the <strong>retval (return value) </strong>to always be 0, if the value of the <strong>strstr </strong>always returns 0 it will bypass the Frida protection and won’t break out from the loop nor call the goodbye function.</p><p>Let’s try executing the code using Frida.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dH8dO6pPRbFrBduj0vxaIQ.png" /></figure><p>Great, we managed to bypass Frida protection and root detection.</p><p>Now after we managed to bypass Frida detection and root detection, we need to figure out the secret string.</p><p>Let’s get back to the code of the APK and analyze it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0d2QK_A68AKlgBYrJjLKfQ.png" /></figure><p>At the beginning of the class, we noticed that it is creating a global variable <strong>xorkey</strong>, from the name of the variable it will be used to make an xor operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9KX4rByw6JfGJfhYDakUfg.png" /></figure><p>As we can see in the onCreate function, it will call the <strong>init</strong> function and pass the <strong>xorkey</strong> variable to it.</p><p>The <strong>init </strong>is being called from the libfoo.so shared library<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*sE6cAC6VS9wde4qmtJY6aw.png" /></figure><p>The <strong>init </strong>function will store the<strong> xorkey </strong>value into<strong> </strong>the <strong>_src </strong>variable, and then it will call<strong> </strong>the <strong>strncpy f</strong>unction, it will copy the value of<strong> _src </strong>into a<strong> </strong>destination buffer “DAT_00107040”.</p><p>So basically, it will store that value of the <strong>xorkey</strong> into a buffer to use it later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0H0HRCkZpCDhiNOGncZ0Q.png" /></figure><p>Continuing analyzing the APK code, we found the method that will check on our input, it will pass our input into <strong>check_code </strong>method<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o9B2DzoDKrHQcUnJiZjKyw.png" /></figure><p>The <strong>check_code</strong> method will take our input and pass it to <strong>bar </strong>function which is a function that is being called from the shared library libfoo.so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*SfqlBtMkiVuo-BdcziUAGw.png" /></figure><p>The bar function will call <strong>FUN_001012c0the</strong> function and pass<strong> the local_48 </strong>variable, then it will use two variables <strong>lVar2</strong> and <strong>iVar1</strong>, <strong>lVar2</strong> will be our input and <strong>iVar1</strong> the length of our input, it will check the length of our input if the length is 24 it will proceed to the while do loop.</p><p>In the loop, it will make an if statement, in the if statement it will make an xor operation between the buffer “DAT_00107040” which has the value of the <strong>xorkey </strong>and <strong>local_48 </strong>variable, and then it will compare our input with the results of the xor operation<strong>.</strong></p><p>Now we need to analyze <strong>FUN_001012c0 </strong>to see<strong> </strong>what the value that will be stored in<strong> local_48.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*gBHDL48NAPAbt_HIidKOYA.png" /></figure><p>The function has a lot of operations in it, but we only need this part of the code, it will store these hex values into <strong>param_1</strong> variable.</p><p>So, if we took these hex values and xor it with the <strong>xorkey </strong>we should get the secret string<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eFEoZ9rpZK4ihWxKnLD09g.png" /></figure><p>By using <strong>CyberChef</strong>, we used “Swap endianness” to reverse the order of the bytes, then we used “From Hex” and finally we used the “XOR” operation with <strong>xorkeythe</strong> value we found in the APK and managed to get the secret string (making owasp great again).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*aipGxwXCWe856q4praLQyw.png" /></figure><p>And solved!!</p><h3>Conclusion</h3><ul><li>Implementing weak Frida protection can be bypassed easily with Frida.</li><li>Don’t use weak encryption method such as xor operation.</li><li>Always check the initialization function in the shared library.</li></ul><p>Happy reading :).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd25b3646acb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/h7w/owasp-uncrackable-3-android-application-bd25b3646acb">OWASP UnCrackable 3 Android Application</a> was originally published in <a href="https://medium.com/h7w">T3CH</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Abusing Anonymous Login on Firebase]]></title>
            <link>https://medium.com/h7w/abusing-anonymous-login-on-firebase-91416ce2fd36?source=rss-ffe4a870e2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/91416ce2fd36</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[mobile-application]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-pentesting]]></category>
            <dc:creator><![CDATA[Mohannad Handoumeh]]></dc:creator>
            <pubDate>Mon, 01 Jul 2024 16:55:15 GMT</pubDate>
            <atom:updated>2024-08-20T20:46:16.343Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*7lDnfWyu2yN7xzb0BWA1qw.png" /></figure><p>Through my path in cybersecurity and mobile penetration testing, Firebase is one of the things that is a must to check if it is configured in the mobile application which sometime can be abused.</p><p>Firebase is a platform developed by Google for creating mobile and web applications. It provides various services such as authentication, real-time databases, hosting, cloud storage, and more, making it easier for developers to build high-quality apps quickly.</p><p>We are going to talk about how to abuse real-time databases using anonymous login.</p><p>Anonymous auth in Firebase allows users to sign in to firebase applications using a temporary anonymous account. This feature is useful for applications that want to offer users a seamless experience without requiring them to create an account upfront but this feature can also be dangerous to the firebase and can be abused.</p><p>I have created a firebase project and set up a rule for the firebase real-time database.</p><pre><br>{<br>  &quot;rules&quot;: {<br>    &quot;.read&quot;:&quot;auth.uid != null&quot;,<br>    &quot;.write&quot;:false<br>  }<br>}</pre><p>In this rule, users who are only are authenticated can read the database and write privileges on the real-time database is set to false which means none have write permissions on the real-time database.</p><p>After that, I have enabled anonymous login from the authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z316cpkKbQiltjGObRrUZw.png" /><figcaption>Anonymous Login</figcaption></figure><p>From this firebase project, I have created a mobile application challenge previously with this firebase configuration.</p><p><a href="https://github.com/TK757567/Mobile_Challenge">GitHub - TK757567/Mobile_Challenge</a></p><p>Downloaded the APK on my kali machine and started by decompiling it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jqK0VEYpiSEvSugAMBQwUw.png" /><figcaption>Decompilation</figcaption></figure><p>After deompiling the APK, we will find the firebase configuration inside of <strong>res/values/strings.xml</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gfog6uHehy72eS0a0qvQfQ.png" /><figcaption>strings.xml</figcaption></figure><p>These are the configuration that are needed to get make an anonymous authentication to the real-time database to read the database.</p><p>We can make use of these configurations and build dart project to make an anonymous login and read the database.</p><p>First we need to create a new dart project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I1jAUQ06hR2Cc1ZKD__q2A.png" /></figure><p>After creating our dart project, we need to download <strong>firebase_dart </strong>package, insert the package inside of <strong>pubspec.yaml </strong>and insert the command<strong> <em>dart pub get</em></strong> in the terminal to download the package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-J9yRRw3W_9FTNJUxbxLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qw-xSuwKjhwCcVPWPkExkw.png" /></figure><p>After downloading the package, created a dart code that will use the firebase configurations that have been retrived from the APK and make anonymous login to read the database.</p><p>In the dart code we need these configurations from the APK.</p><ul><li>firebase_database_url</li><li>google_api_key</li><li>google_app_id</li><li>google_storage_bucket</li><li>project_id</li><li>authdomain (which is project_id with the domain firebaseapp.com)</li></ul><pre>import &#39;dart:convert&#39;;<br>import &#39;dart:io&#39;;<br>import &#39;dart:typed_data&#39;;<br><br>import &#39;package:firebase_dart/auth.dart&#39;;<br>import &#39;package:firebase_dart/core.dart&#39;;<br>import &#39;package:firebase_dart/database.dart&#39;;<br>import &#39;package:firebase_dart/implementation/pure_dart.dart&#39;;<br>import &#39;package:firebase_dart/storage.dart&#39;;<br><br>void main() async {<br>  FirebaseDart.setup();<br><br>  var options = FirebaseOptions(<br>    appId: &quot;1:945306155278:android:9a8149819a7989d29a7f5f&quot;,<br>    apiKey: &quot;AIzaSyBAkl5qQptzhYzIailgx6kIOI63p3cKGGo&quot;,<br>    messagingSenderId: &quot;&quot;,<br>    authDomain: &quot;tk-test-129ad-default-rtdb.firebaseapp.com&quot;,<br>    databaseURL: &quot;https://tk-test-129ad-default-rtdb.firebaseio.com&quot;,<br>    storageBucket: &quot;tk-test-129ad.appspot.com&quot;,<br>    projectId: &quot;tk-test-129ad&quot;<br>      );<br><br>  var app = await Firebase.initializeApp(options: options);<br>  var auth = FirebaseAuth.instanceFor(app: app);<br>  await auth.signInAnonymously();<br>  var database = FirebaseDatabase(app: app);<br>  var dbRef = database.reference();<br>  var snap = await dbRef.once();<br><br>  print(&#39;Flag : ${snap.value}&#39;);<br>}</pre><p>After running the dart script we will get the flag from the real-time database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*fJerb4Kvjo7Cb_Y8AwITrw.png" /></figure><h3>Conclusion</h3><p>Anonymous login can have significant security risks if not managed carefully and will lead attackers to abuse the firebase database by making anonymous login to read the database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91416ce2fd36" width="1" height="1" alt=""><hr><p><a href="https://medium.com/h7w/abusing-anonymous-login-on-firebase-91416ce2fd36">Abusing Anonymous Login on Firebase</a> was originally published in <a href="https://medium.com/h7w">T3CH</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OWASP UnCrackable Android Apps]]></title>
            <link>https://medium.com/@Handoumeh/owasp-uncrackable-android-apps-8ce396b18b86?source=rss-ffe4a870e2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ce396b18b86</guid>
            <dc:creator><![CDATA[Mohannad Handoumeh]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 14:01:09 GMT</pubDate>
            <atom:updated>2024-01-09T08:45:39.671Z</atom:updated>
            <content:encoded><![CDATA[<p>OWASPs UnCrackable are applications that were created by OWASP as challenges for the MASTG course, the challenges are good practice for exploiting mobile applications by reverse engineering the applications and bypassing protections such as protection against rooted devices.</p><p>In this blog, I’ll be solving <strong>UnCrackable1</strong> and <strong>UnCrackable2 A</strong>ndroid applications by tampering APK and using Frida to bypass root detection and hook the secrets using Frida.</p><h3>UnCrackable1</h3><p>For the first application, I started by downloading the APK into my emulator which is a rooted Android device. The application did not work because the APK had protection against rooted devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*ql6xv9GI1DqefLdppYT0lQ.png" /></figure><p>We need to reverse-engineer the APK to analyze how the application works and how the application detects the rooted Android device. I used APKLab to decompile and reverse-engineer the APK.</p><p>As shown in the below image, in the <strong>AndroidManifest.xml</strong> there is only one activity which is <strong><em>sg.vantagepoint.uncrackable1.MainActivity.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-peCTOkFTYA7MngKlgcCA.png" /></figure><p>After analyzing <strong><em>sg.vantagepoint.uncrackable1.MainActivity </em></strong>found that when the <strong>OnCreate </strong>has 2 checks, one checks for the rooted device by calling and checking 3 methods (<strong>c.a(), c.b(), </strong>and<strong> c.c()</strong>), and the other checks if the app is debuggable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mFSK_fOzRcX9ZH9f-R51HQ.png" /></figure><p>The first method <strong>c.a(), </strong>checks if the files in the PATH environment contain the <strong><em>su</em></strong> binary. In the second method <strong>c.b()</strong>, it checks if the Build Tag in the Android device is not null and if it contains the value <strong><em>test-key. </em></strong>The third and last method <strong>c.c(), </strong>checks for specific applications and binaries that can be used to have root privileges on the Android device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vqg6lXmVF4MC3KRuYOYLsQ.png" /></figure><h4>Code Tampering and Reverse Engineering Secret String</h4><p>The first method that will be used to bypass these checks will be code tampering.</p><p>In this method, the <strong>smali </strong>file which has the root detection checks (<strong>c.smali</strong>) will be modified to bypass the root detection. In every method there if statement “<strong>if-eqz v4, :cond_0&quot;</strong>, referring to the <a href="http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html"><strong>Dalvik opcodes</strong></a><strong> </strong>this if statement means <strong>Jumps to cond_0 if v4==0. v4 is an integer value</strong>.</p><p>As shown in the below image, if the value of <strong>v4 </strong>is not equal to 0, it will set a value for <strong>v0 </strong>to 1 and return <strong>v0, </strong>in this case, it means that the Android Device is rooted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5XUzJ_65kK3tKU2vOtamyg.png" /></figure><p>This if statement is applied in the 3 methods that check for root detection.</p><p>We can bypass root detection by changing the if statement to <strong>if-nez </strong>or changing the value of the <strong>v0 </strong>to 0 instead of 1, we need to apply these changes in the 3 methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wcpws_I2oORjhhME6HvfNg.png" /><figcaption>Method a</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6E1JX_D0bCrCLcpAJHexwQ.png" /><figcaption>Method b</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vRo8UmRiluzAP6qouGV91g.png" /><figcaption>Method c</figcaption></figure><p>After modifying the smali code, I recompiled the APK and installed it in the Android emulator and we successfully bypassed root detection through code tampering.</p><p>After bypassing root detection, the application needs a secret string, let’s see if we can get the secret string through reverse engineering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*-CKx7VyWmEX_eUkcH-_qxA.png" /></figure><p>Through reverse engineering the APK, there is a method called <strong>verify, </strong>in this method,<strong> </strong>it takes our input and puts it in a variable called<strong> obj</strong>,<strong> </strong>then it calls another method with variable<strong> obj <em>(a.a(obj))</em> </strong>to check if our input matches the secret string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5pgJdTOiOrjEUOcnUE_3Nw.png" /></figure><p>After that, I checked the <strong><em>a.a()</em></strong> method that is being called to verify if our input matches the secret string.</p><p>As shown in the image below, there is an encrypted data in base64 and a string which looks like a hex value. The base64 is being decoded and the hex value is being converted from hex to ASCII by calling the <strong>b</strong> method. After that, <strong><em>sg.vantagepoint.a.a.a </em></strong>method is called with the hex value but it is defined as a string, <strong>b </strong>method converts this string to a hex.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pemaw9kVqex7brmYN3DAvQ.png" /></figure><p>After taking a look at <strong><em>sg.vantagepoint.a.a.a</em></strong>, it looks like it is an AES decryption method that uses the hex value as a key and the decoded base64 as the encrypted data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpmVtcxsCTgO4eQQ96KwEA.png" /></figure><p>We can use <a href="https://gchq.github.io/CyberChef/"><strong>CyberChef</strong></a><strong> </strong>to decrypt the encrypted data, and the secret string is “<strong>I want to believe</strong>” as shown in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4AMO576CWDbuonziOqlleA.png" /></figure><p>Now we have successfully got the secret key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*PyPOpdJ_bULueR6U4vST1g.png" /></figure><h4>Frida</h4><p>Now for the fun part, in the second method, I will be using Frida to bypass root detection and hook the secret string.</p><p>As shown before, the 3 methods that check for if the Android device is rooted will return True if the device is rooted, in this case, we can use Frida to make these methods return false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tTA-Wlfd2ukEYIIYDK-0eg.png" /></figure><p>Here is the code that I used to bypass these checks.</p><pre>Java.perform(function(){<br><br><br>    var root = Java.use(&quot;sg.vantagepoint.a.c&quot;)<br>    root.a.implementation = function(){<br>        console.log(&quot;[+] Bypassed first check&quot;)<br>        return false<br>    }<br><br>    root.b.implementation = function(){<br>        console.log(&quot;[+] Bypassed second check&quot;)<br>        return false<br>    }<br>    root.c.implementation = function(){<br>        console.log(&quot;[+] Bypassed third check&quot;)<br>        return  false<br>    }<br>})</pre><p>Let’s now run the script using Frida on the application, the code worked and the root detection has been bypassed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VakMT_LrP52Bsoi8yxqdOg.png" /></figure><p>Now for the next step, we need to use Frida to hook the secret string, the secret string is being decrypted in the <strong><em>sg.vantagepoint.a.a.a.</em></strong> As shown in the below image, the method is getting 2 variables, <strong>bArr</strong> which is the key, and <strong>bArr2</strong> which is the encrypted secret key, using Frida we can hook the decrypted secret string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpmVtcxsCTgO4eQQ96KwEA.png" /></figure><p>The code bypasses root detection and hooks the secret string.</p><pre>Java.perform(function(){<br><br><br>    var root = Java.use(&quot;sg.vantagepoint.a.c&quot;)<br>    root.a.implementation = function(){<br>        console.log(&quot;[+] Bypassed first check&quot;)<br>        return false<br>    }<br><br>    root.b.implementation = function(){<br>        console.log(&quot;[+] Bypassed second check&quot;)<br>        return false<br>    }<br>    root.c.implementation = function(){<br>        console.log(&quot;[+] Bypassed third check&quot;)<br>        return  false<br>    }<br><br>    var flag = Java.use(&quot;sg.vantagepoint.a.a&quot;)<br>    flag.a.implementation=function(Key,enc){<br>        console.log(&quot;[+] Key : &quot;+Key)<br>        console.log(&quot;[+] Encrypted secret string : &quot;+enc)<br>        var secret_string = this.a(Key,enc)<br>        console.log(&quot;[+] secret string: &quot;+secret_string)<br>        return secret_string<br>        <br>    }<br>})</pre><p>After bypassing root detection, the code uses “<strong>sg.vantagepoint.a.a” </strong>and calls the method <strong>a, </strong>“<strong>flag.a.implementation=function(Key, enc)</strong>”, the <strong>enc </strong>variable is the encrypted data, and the <strong>key </strong>is the key to decrypt the encrypted data. After that, it recalls the method <strong>a</strong> and passes with it the encrypted data and the key, saving the value of the method into <strong>secret_string </strong>variable which will be the secret string.</p><p>After running the code using Frida, the secret string will be hooked after we enter the verify method is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_lst1Atlmv7RA5-pk3oSw.png" /></figure><p>As shown, the secret string is in decimal, let’s modify the code so it prints the secret string in ASCII.</p><pre>Java.perform(function(){<br><br><br>    var root = Java.use(&quot;sg.vantagepoint.a.c&quot;)<br>    root.a.implementation = function(){<br>        console.log(&quot;[+] Bypassed first check&quot;)<br>        return false<br>    }<br><br>    root.b.implementation = function(){<br>        console.log(&quot;[+] Bypassed second check&quot;)<br>        return false<br>    }<br>    root.c.implementation = function(){<br>        console.log(&quot;[+] Bypassed third check&quot;)<br>        return  false<br>    }<br><br>    var flag = Java.use(&quot;sg.vantagepoint.a.a&quot;)<br>    flag.a.implementation=function(x,y){<br>        console.log(&quot;[+] Key : &quot;+x)<br>        console.log(&quot;[+] Encrypted secret string : &quot;+y)<br>        var secret_string = this.a(x,y)<br>        var secret_string_in_ASCII = &#39;&#39;<br>        for (var i = 0;i&lt;secret_string.length;i++){<br>            secret_string_in_ASCII+=String.fromCharCode(secret_string[i])<br>        }<br>        console.log(&quot;[+] secret string: &quot;+secret_string_in_ASCII)<br>        return secret_string<br>    }<br>})</pre><p>After running the code, we successfully hooked the secret string using Frida.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_1cT6R9rF68W7sUn7b-3Ag.png" /></figure><h3>UnCrackable2</h3><p>The second application is the same as the first application, the only difference is that the application uses a shared library to check our input with the secret string.</p><h4>Reverse Engineering the APK</h4><p>As the first application, I used APKLab to decompile and reverse-engineer the APK.</p><p>For the <strong>MainActivity, </strong>some new methods and functions are different such as <strong>System.loadLibrary(“foo”); </strong>this function is used to load a shared library, and new class <strong>CodeCheck.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lA1IX2eLubRFYGYD1ay9Dg.png" /></figure><p>After analyzing the <strong>MainActivity</strong>,<strong> </strong>the code creates an instance of the <strong>CodeCheck</strong> class and assigns it to the <strong>m</strong> variable of the current object.</p><p>It uses the <strong>m </strong>variable and calls method <strong>a</strong> with our input to check if it matches the secret string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G215P8JiE2J-_dNUxWaSCg.png" /></figure><p>After taking a look at <strong>CodeCheck</strong> class, it is calling a method called <strong>bar</strong> that is not a class nor a function in the <strong>java_src</strong> file, it is a function that is being called from the shared library <strong>libfoo.so</strong> that it has been loaded before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sg1G6F41D4YfpvO3S5n-Wg.png" /></figure><p>I used <strong>Ghirda </strong>to decompile and reverse the shared library. After decompiling, I was able to analyze the <strong>bar</strong> function, which takes our input and compares it with the secret string (the hex values).</p><p>We can use the lame to get the secret string by converting the hex values to ASCII using <a href="https://gchq.github.io/CyberChef/"><strong>CyberChef</strong></a>. (The Lame Method)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DElRe_F9ERLhaUFaebPwGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hAYH9gQrZmyQ60bFOqXiPw.png" /></figure><p>Now we have the secret string which is <strong>Thanks for all the fish</strong>, now we need to bypass the root detection for the application and then enter the secret string.</p><pre>Java.perform(function(){<br><br><br>    var root = Java.use(&quot;sg.vantagepoint.a.b&quot;)<br>    root.a.implementation = function(){<br>        console.log(&quot;[+] Bypassed first check&quot;)<br>        return false<br>    }<br><br>    root.b.implementation = function(){<br>        console.log(&quot;[+] Bypassed second check&quot;)<br>        return false<br>    }<br>    root.c.implementation = function(){<br>        console.log(&quot;[+] Bypassed third check&quot;)<br>        return  false<br>    }<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zrwcpnCXUmwdbPG0hhBRew.png" /></figure><h4>Frida</h4><p>Back to the fun part, this time we will use Frida to hook the secret string from the shared library by hooking <strong>strncmp</strong> function and get the value of the secret string when it is comparing it with our input. (The Giga Chad Method).</p><p>Using <strong>Ghidra</strong>, we see that it has 2 checks to return true. First, it checks if the length of our input is 23 characters. Second, it calls <strong>strncmp</strong> function to comapre our input with the secret string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0lG8lPQAZfvPvFvA3L7pmA.png" /></figure><p>Using Frida, I was able to hook the secret string from the <strong>strncmp</strong> function.</p><p>The below code is getting the address of the <strong>strncmp </strong>from <strong>libfoo.so</strong>, after that it checks if the first argument in the <strong>strncmp </strong>is <strong>free palestinepalestine</strong>, if it returns true it will print out the second argument which is the secret string.</p><pre>Java.perform(function(){<br><br><br>    var root = Java.use(&quot;sg.vantagepoint.a.b&quot;)<br>    root.a.implementation = function(){<br>        return false<br>    }<br>    root.c.implementation = function(){<br>        return false<br>    }<br>    root.b.implementation= function(){<br>        return false<br>    }<br>    var strncmp = Module.findExportByName(&quot;libfoo.so&quot;,&quot;strncmp&quot;);<br>    console.log(&quot;find strcmp:&quot;,strncmp);<br>    Interceptor.attach(strncmp,{<br>        onEnter(args) {<br>           if(ptr(args[0]).readCString().indexOf(&quot;free palestinepalestine&quot;)&gt;=0){<br>            console.log(&quot;secret : &quot;+ptr(args[1]).readCString())<br>           }<br>        }})<br><br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5-fGgQ2d2YKvEZHWfqkmA.png" /></figure><h3>Remediation</h3><ul><li>The mobile app must be able to detect at runtime that code has been added or changed from what it knows about its integrity at compile time.</li><li>You can also sign the mobile application with a code-signing certificate.</li><li>Implement protection against Frida, this will prevent attackers from hooking variables and bypassing protections.</li></ul><h3>Conclusion</h3><ul><li>Root protection can be bypassed in different ways.</li><li>Frida is a strong tool that can used to hook variables and change the value of variables.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ce396b18b86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>