<?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 The Offensive Labs on Medium]]></title>
        <description><![CDATA[Stories by The Offensive Labs on Medium]]></description>
        <link>https://medium.com/@theoffensivelabs?source=rss-2474fa46025a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WbwHVGMqn1bs9GRT6PXxWQ.jpeg</url>
            <title>Stories by The Offensive Labs on Medium</title>
            <link>https://medium.com/@theoffensivelabs?source=rss-2474fa46025a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 17:14:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@theoffensivelabs/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[Journey to Web Application Penetration Testing]]></title>
            <link>https://theoffensivelabs.medium.com/journey-to-web-application-penetration-testing-5476c6fadacb?source=rss-2474fa46025a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5476c6fadacb</guid>
            <category><![CDATA[hacking-training]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[bugbounting]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[web-application-security]]></category>
            <dc:creator><![CDATA[The Offensive Labs]]></dc:creator>
            <pubDate>Wed, 16 Mar 2022 17:44:44 GMT</pubDate>
            <atom:updated>2022-03-16T17:44:44.676Z</atom:updated>
            <content:encoded><![CDATA[<p>Web Application is one platform that is widely used. As it is something that people use daily, it can easily be a target for hackers. Every person using the internet goes to a website for some work or the other. Furthermore, we can not deny that now and then, a website is getting hacked. For a security professional who wants to get into web application penetration testing, it becomes crucial to understand how a web application works and examine the test cases for its security.</p><p>This article focuses on anyone willing to start their cyber security career with web application penetration testing. So, let us get started.</p><p>We will start with understanding what penetration testing means concerning a pentester’s point of view. So a security professional, on getting a web application for testing, the first thing they need to understand is the scope. Now, what do we mean by scope?</p><p>When you are given a URL or an IP address to perform security testing, an organization defines the extent to which you have the permission to access and perform security testing. There are three kinds of testing — Black Box Testing, Gray Box Testing, and White Box Testing. In black-box testing, the security professional has the URL or the IP address of the website and nothing else. The professional has to bypass any authentication and access controls in order to gain further access. In the case of gray box testing, the individual is provided with the account’s credentials and the URL or the IP. Furthermore, in white box testing, the individual any authentication and access controls in order gain further access. So if you have heard about source code review, this is one of the areas where it comes into the picture.</p><p>Once we understand the scope of the application, the next step involves enumeration or information gathering. This is the most crucial step in penetration testing. The more information you have about your scope, the more apparent it becomes to perform security testing. If you can give ample time to this step, you will connect the dots in the later phases with more clarity. Now what kind of information will you be looking for?</p><p>Information such as what kind of technology the website is dependent on — is it built from a CMS or some other template or solely created by a developer. What kind of backend technologies is it based on? Is it PHP? Python? Is it even using any backend language? Is there a database? Not just the technical aspects, you need to understand the behavior of the website, the goals of the website, why it has been created? Is it a social networking site, a regular educational website, or something else? What kind of information is it dealing with? What kind of APIs is it using? The more information you can gather, the easier it becomes to move ahead with the next step.</p><p>So the next step is vulnerability scanning — where you try to leverage the information you gathered from the previous step and move forward. Let me brief it up with a few examples — Now, if you see an input point that is just supposed to take names as input, you try to play with the field and see what other kinds of information, characters, numbers, etc., accept. You will have to analyze whether it shows any suspicious behavior or provides any output that it should not be giving. Errors may end up giving many details about the server. You may try different tools to analyze these things. BurpSuite is one of the popular ones, where you can explore the requests, study the headers and body and see what kind of response you are getting. Understanding the manual approach helps you move ahead with the tools-based approach.</p><p>The second step helps you figure out what kind of vulnerabilities the website might be affected with, so you start exploiting those vulnerabilities to gain access to their accounts or to their server in an unauthorized manner. Once you gain access, you have to ensure that you can maintain the access. The final step is analysis and reporting.</p><p>The first two steps are crucial, which help you with identifying the test cases that you need to perform against the website.</p><p>It can and will bring legal implications if we perform these processes on a website without prior permission. If you accidently find a vulnerability in a website, you should report it to the respective organization using their responsible disclosure or a bounty program if one exists.</p><p>There are various intentionally vulnerable labs for you to practice your skills legally — DVWA, XVWA, OWASP Juice Shop, Acunetix, TryHackMe, HackTheBox, and more. Some of them even provide you with an intentionally vulnerable website to determine the test cases on your own to find out the vulnerabilities. Some tools that you can use along with Burpsuite are Nessus, Wireshark, Gobuster directory scanner, amass, Metasploit, etc. There are also tools available to scan for specific kinds of vulnerabilities. Sqlmap, XSSstrike, XXExploiter are some examples of such tools.</p><p>Having certifications on your resume will be an added advantage as it can help during the initial screening process. Although certifications are good to have, the focus should be on understanding the concepts instead of just getting the cert. Some certifications that you may focus on are Offensive Security Certified Professional(OSCP), OSWE(Offensive Security Web Expert), GIAC Web Application Defender and Certified Application Security Engineer — CASE by EC Council.</p><p>It may seem difficult in the beginning, you may fall a lot into rabbit holes, but with patience and practice, and constant research, you will be able to identify the vulnerabilities on your own and exploit them.</p><p>Check out our course on <a href="https://theoffensivelabs.com/p/web-security-101">Web Application Penetration Testing</a> which covers most basics you need to kickstart your journey as a penetration tester . Use Code WEBART30 during checkout to get 30% discount on the course</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5476c6fadacb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Path To Become a Pentester]]></title>
            <link>https://theoffensivelabs.medium.com/learning-path-to-become-a-pentester-6ebbbbffe44?source=rss-2474fa46025a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ebbbbffe44</guid>
            <category><![CDATA[burpsuite]]></category>
            <category><![CDATA[web-application-security]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[The Offensive Labs]]></dc:creator>
            <pubDate>Mon, 21 Feb 2022 01:01:12 GMT</pubDate>
            <atom:updated>2022-02-21T01:02:22.033Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLYarcj_5FWBAw2XKvlgvQ.png" /></figure><p>Getting into cybersecurity is quite an adventure. It may look fascinating and convincing to many ordinary people; however, it requires a lot of hard work, patience, and continuous learning of new technical aspects of the application that you need to be working on. To become a hacker, or to be more precise, becoming a Pentester, is something that many newbies look forward to.</p><p>This article will start with comprehending the learning paths that need to be followed to become a Pentester.</p><p>As it is always said — Clear Your Basics. The first step always starts with clearing out your basics. The base of your learning has to be very strong, and this forms a strong pillar for getting into penetration testing. One should be very clear about the facts behind having security. Data is a massive thing in today’s internet world, and an organization has to take care of all security measures necessary to maintain the safety of their data. Understanding the CIA ( Confidentiality, Integrity, Availability) Triad helps you get acquainted with the whys of security for an application.</p><p>There are several topics that a security enthusiast should be acquainted with. They are networking, OS, Protocols, Basic programming, Linux, Google Hacking Database, to name a few. These will be required in any domain you wish to be moving to for performing penetration testing — be it a web application, mobile application, hardware, IoT, Blockchain, DevSecOps, and many more.</p><p>For a beginner, it is imperative to read about different kinds of vulnerabilities and the attack scenarios that are very common. For starters, the individual can go through the old attack scenarios, first of all theoretically, to understand the flow. Once the individual has clarity on the theoretical concepts, they can solve some intentionally vulnerable applications. It is crucial to remember that a penetration tester finds the flaws and then the vulnerabilities of an application and should be able to exploit it.</p><p>Not every individual is aware of the kind of applications they want to be working on. And also, not every individual can learn all the aspects of every application present. What is required at this stage is to explore more, read more and find your area of interest. It will, of course, be very vague in the beginning. Still, you can always follow the process of elimination. Once you are well acquainted with basics at a reasonable level, start eliminating the domains you are not interested in. This will help you focus on your area of interest more. Even if you don’t figure out your area of interest at this stage, that is completely fine. You can keep exploring. And while studying, use your theoretical knowledge to perform hands-on attacks on vulnerable applications.</p><p>You can always start with solving labs readily available like Hack The Box, TryHackMe, RootMe, Vulnhub, and more. Even their walkthroughs are available. You can start with going through the walkthroughs but solving the machines independently. While going through the walkthrough, try to understand how and why the attacker followed the given steps. You need to learn how to google correctly to clear your doubts. Google Hacking Database is one platform that can provide you immense knowledge about the vulnerability and the corresponding exploit. This is one go-to tool for a penetration tester. While solving a lab, try to learn both the manual and the tool-based approach. You can try to write your own script while going through the walkthroughs. This will give you more ideas on the subject and gradually you will start getting acquainted with the work.</p><p>At this stage, you may be aware of the kinds of vulnerabilities, the attack scenarios, the exploits, and all other methodologies. Still, a penetration tester is aware of the test cases they should perform on a specific application. The individual should ask themselves — why only one specific vulnerability can be tested against an application even though several different vulnerabilities exist. For example, if an application uses NoSql, there is no usage of trying typical SQL injection test cases against it. And what do we need to do to examine this? The individual should perform a lot of enumeration before performing any test scenarios. This marks the very initial and most crucial step in penetration testing. They should be aware of the technologies used for running an application and based on that, different test cases can be followed accordingly. The individual should understand how the application is working at all levels — as far as possible.</p><p>You may use your learnings to gain some certifications as well. Some certifications that you can aim for, as a beginner, are CEH, OSCP, CompTIA Security+, ECSA. Of course, your knowledge will speak for you, but certifications will label your learning and make it easier for you to get selected while looking for a job or internship.</p><p>While concluding, it is essential to understand that becoming a Pentester requires continuous learning and patience. You can not expect to become a penetration tester unless you know the back and forth of the application, have gathered all necessary information, and know how to google them. It does take time, but you definitely learn something new with every step. And if you are passionate about learning, it will be a lot of fun for you.</p><p>Check out our course on <a href="https://theoffensivelabs.com/p/web-security-101">Web Application Penetration Testing</a> which covers most basics you need to kickstart your journey as a penetration tester . Use Code WEBART30 during checkout to get 30% discount on the course</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ebbbbffe44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bypassing Root Detection and Emulator Detection in Android Apps using Frida]]></title>
            <link>https://theoffensivelabs.medium.com/bypassing-root-detection-and-emulator-detection-in-android-apps-using-frida-e938109e468c?source=rss-2474fa46025a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e938109e468c</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[mobile-security]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[frida]]></category>
            <category><![CDATA[android-security]]></category>
            <dc:creator><![CDATA[The Offensive Labs]]></dc:creator>
            <pubDate>Wed, 31 Mar 2021 07:59:12 GMT</pubDate>
            <atom:updated>2021-03-31T08:24:29.079Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction:</h3><p>Root Detection is one of the most common client-side protection techniques used by Android Application developers. During a penetration test, it is often required to bypass root detection to be able to effectively pentest the application. In this article, we are going to cover root detection and emulator detection bypass techniques, which can be helpful for both pentesters as well as developers. First, we will begin by understanding what root detection and emulator detection are and then we will go through some bypass techniques for these.</p><h3>What is root detection?</h3><p>To understand root detection, let us first understand what rooting is. Rooting is the process of obtaining the highest privileges possible on the operating system. In android, rooting gives the ability to alter or replace system applications, files, and settings, run specialized applications (“apps”) that require administrator-level permissions.</p><p>Root detection is the process of detecting if a device is rooted. This is typically done when launching the application. Sometimes the root checks are implemented in the apps in such a way that the application will not respond or it will exit when it is run on a rooted device.</p><h3>What is emulator detection?</h3><p>When a security professional performs vulnerability assessments on mobile applications, some of them use emulators like Genymotion or the ones that come inbuilt with AndroidStudio. Some Application developers choose to implement the code to detect whether the application is being run on an emulator or android device. There are several ways emulator detection can be implemented such as by retrieving the hardware information.</p><p>A pentester needs to go through the source code by using reverse engineering with the help of tools like apktool or jadx. This will help him/her understand where and what type of detection is implemented.</p><h3>Why should developers implement root/emulator detection as a security measure?</h3><p>When an application is run on a rooted device, any malicious application running on the device will be able to access the data associated with our application, which is otherwise restricted in non rooted devices. Therefore developers need to implement complex code for detection of the root process in the device where the application is getting launched. Similarly, developers can use different techniques to detect if the app is being run on an emulator. Implementing emulator detection checks will force a user to use the app only on a physical device, which is reasonably safe from a security standpoint.</p><h3>Introduction to Frida</h3><p>Frida is an open-source dynamic instrumentation toolkit, which implements JavaScript code injection by writing code directly into process memory, along with a powerful API that provides a lot of useful functionality, including calling and hooking native functions and injecting structured data into memory.</p><p>By using frida we can inject the javascript code at runtime and bypass many checks which are implemented by developers such as root detection, SSL pinning, emulator detection etc. In this section of the article, we will discuss how to bypass root detection and emulator detection by using frida.</p><p>We will use<a href="https://github.com/satishpatnayak/AndroGoat"> androgoat</a>, which is an intentionally vulnerable android app for this demonstration.</p><h3>Bypassing Root detection using frida</h3><p>In our lab setup, the Androgoat android application is installed to demonstrate the step by step process to bypass root detection.</p><p><strong>Step 1:</strong> First, we will begin by using an emulator i.e virtual device from android studio for the demonstration. While exploring the application, there is a button named root detection which is intentionally designed to check if the device is rooted or not.</p><p>As shown in the following image, there is a toast message shown when the CHECK ROOT button is clicked. The message “Device is rooted” confirms that we are running the app on a rooted device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*hkjKLAWnYeC_FIHG" /></figure><p><strong>Step 2: </strong>Pentester often needs to check the root detection code implemented by the developer by reverse engineering the target app, which is androgoat.apk in this case. This can be done using jadx or jd-gui.</p><p>Below is the code snippet in which the developer wants to check the existence of su binaries,superuser.apk, Xposed framework etc. These binaries and supersuer.apk are only found in rooted devices, and if these binaries and superuser.apk are present in the defined directory then the function isRooted() will return a boolean value true indicating that the device is rooted.</p><blockquote>public final boolean isRooted()</blockquote><blockquote>{</blockquote><blockquote>String[] arrayOfString = new String[13];</blockquote><blockquote>int i = 0;</blockquote><blockquote>arrayOfString[0] = “/system/app/Superuser/Superuser.apk”;</blockquote><blockquote>arrayOfString[1] = “/system/app/Superuser.apk”;</blockquote><blockquote>arrayOfString[2] = “/sbin/su”;</blockquote><blockquote>arrayOfString[3] = “/system/bin/su”;</blockquote><blockquote>arrayOfString[4] = “/system/xbin/su”;</blockquote><blockquote>arrayOfString[5] = “/data/local/xbin/su”;</blockquote><blockquote>arrayOfString[6] = “/data/local/bin/su”;</blockquote><blockquote>arrayOfString[7] = “/system/sd/xbin/su”;</blockquote><blockquote>arrayOfString[8] = “/system/bin/failsafe/su”;</blockquote><blockquote>arrayOfString[9] = “/data/local/su”;</blockquote><blockquote>arrayOfString[10] = “/su/bin/su”;</blockquote><blockquote>arrayOfString[11] = “re.robv.android.xposed.installer-1.apk”;</blockquote><blockquote>arrayOfString[12] = “/data/app/eu.chainfire.supersu-1/base.apk”;</blockquote><blockquote>boolean bool = false;</blockquote><blockquote>int j = arrayOfString.length;</blockquote><blockquote>while (i &lt; j)</blockquote><blockquote>{</blockquote><blockquote>bool = new File(arrayOfString[i]).exists();</blockquote><blockquote>if (bool) {</blockquote><blockquote>return bool;</blockquote><blockquote>}</blockquote><blockquote>i += 1;</blockquote><blockquote>}</blockquote><blockquote>return bool;</blockquote><blockquote>}</blockquote><p><strong>Step 3: </strong>Now, by using frida we can bypass this root detection functionality of the target android application. To do this, we need to write JavaScript code, which can be injected into the app’s runtime by using frida.</p><p>The code snippet shows that the implementation of isRooted function always returns true. As we can notice, the java function isRooted() is given a new implementation by specifying the package name and class name i.e owasp.sat.agoat and RootDetectionActivity respectively. The return value for this function isRooted() is set to be false. The androgoat’s original code returns true when root detection is successful. So we are returning the value as false during runtime to bypass this.</p><blockquote>‘use strict’</blockquote><blockquote>if(Java.available){</blockquote><blockquote>Java.perform(function(){</blockquote><blockquote>try{</blockquote><blockquote>var Activity = Java.use(“owasp.sat.agoat.RootDetectionActivity”);</blockquote><blockquote>Activity.isRooted.implementation = function() {</blockquote><blockquote>return false;</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>catch(error){</blockquote><blockquote>console.log(“[-] Error Detected”);</blockquote><blockquote>console.log((error.stack));</blockquote><blockquote>}</blockquote><blockquote>});</blockquote><blockquote>}</blockquote><blockquote>else {</blockquote><blockquote>console.log(“ “)</blockquote><blockquote>console.log(“[-] Java is Not available”);</blockquote><blockquote>}</blockquote><p><strong>Step 4: </strong>Now we can save his code as rootdetect.js and inject the code using frida. Note that we should start the frida server in the emulator through adb shell before injecting the frida script into the app. The following figure shows that Frida server is started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*uCYJs6GCUH5lrLhH" /></figure><p><strong>Step 5:</strong> Now, it’s time to inject the javascript code using frida. The script will provide a new definition to the function and when it is invoked, it will always return the value as false.</p><p>Let us run frida and load the script as shown in the following command. The launched application will be in paused state and running the command %resume will resume the application’s execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/0*uUx6bg3Vbwbfr99n" /></figure><p>After injecting the frida script shown earlier into the app, we can observe that the root detection is bypassed. Access the application installed on the emulator and click the button “CHECK ROOT”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/0*bq2btVY-bJ5BCo3U" /></figure><p>The preceding image shows the toast message Device is not Rooted indicating that we have successfully bypassed root detection.</p><h3>Bypassing Emulator detection using frida</h3><p>Now that we have discussed how to bypass Root Detection in Androgoat Android application, let us discuss how we can use the same technique to bypass emulator detection in Androgoat.</p><p>As shown earlier, the Androgoat android application is installed to demonstrate the step by step process to bypass emulator detection in our lab setup,</p><p><strong>Step 1:</strong> First, we will begin by using an emulator i.e virtual device from android studio for the demonstration. While exploring the application, there is a button named emulator detection, Inside which there is a button which is for checking emulator i.e “Check emulator”. It is obvious that this button is checking whether the application is running on an emulator or not.</p><p>As shown in the following image, there is a toast message shown when the CHECK EMULATION button is clicked. The message “This is Emulator” confirms that we are running the app on an emulator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/0*pcNXkC9hwrZ1QGd1" /></figure><p><strong>Step 2: </strong>Like we did earlier, we will need to check the emulator detection code implemented by the developer by reverse engineering the target app using tools like jadx or jd-gui.</p><p>Below is the code snippet in which the developer is checking if the app is running on an emulator.</p><blockquote>public final boolean isEmulator()</blockquote><blockquote>{</blockquote><blockquote>Object localObject = new StringBuilder();</blockquote><blockquote>((StringBuilder)localObject).append(Build.FINGERPRINT);</blockquote><blockquote>((StringBuilder)localObject).append(Build.DEVICE);</blockquote><blockquote>((StringBuilder)localObject).append(Build.MODEL);</blockquote><blockquote>((StringBuilder)localObject).append(Build.BRAND);</blockquote><blockquote>((StringBuilder)localObject).append(Build.PRODUCT);</blockquote><blockquote>((StringBuilder)localObject).append(Build.MANUFACTURER);</blockquote><blockquote>((StringBuilder)localObject).append(Build.HARDWARE);</blockquote><blockquote>localObject = ((StringBuilder)localObject).toString();</blockquote><blockquote>if (localObject != null)</blockquote><blockquote>{</blockquote><blockquote>localObject = ((String)localObject).toLowerCase();</blockquote><blockquote>Intrinsics.checkExpressionValueIsNotNull(localObject, “(this as java.lang.String).toLowerCase()”);</blockquote><blockquote>CharSequence localCharSequence1 = (CharSequence)localObject;</blockquote><blockquote>CharSequence localCharSequence2 = (CharSequence)”generic”;</blockquote><blockquote>boolean bool = false;</blockquote><blockquote>if ((StringsKt.contains$default(localCharSequence1, localCharSequence2, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”unknown”, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”emulator”, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”sdk”, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”vbox”, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”genymotion”, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”x86&quot;, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”goldfish”, false, 2, null)) || (StringsKt.contains$default((CharSequence)localObject, (CharSequence)”test-keys”, false, 2, null))) {</blockquote><blockquote>bool = true;</blockquote><blockquote>}</blockquote><blockquote>return bool;</blockquote><p>In the preceding code snippet, isEmulator() is checking for some values from the device configuration. If the extracted configuration contains strings like emulator, unknown, sdk, vbox, genymotion the device will be considered an emulator and the function return a boolean value true indicating that the app is running on an emulator.</p><p><strong>Step 3: </strong>Once again, let us see the steps to bypass this check using frida. Let us first ensure that the frida server is running on the emulator as shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*KVCAcpa5hITtlBDW" /></figure><p><strong>Step 4: </strong>Following is the frida script written to bypass the emulator detection check in Androgiat. The script has a custom implementation for the method isEmulator within the class owasp.sat.agoat.EmulatorDetectionActivity. Every time the isEmulator method is triggered in the app, this custom implementation will be executed. This implementation always returns false fooling the emulator detection check.</p><blockquote>‘use strict’</blockquote><blockquote>if(Java.available){</blockquote><blockquote>Java.perform(function(){</blockquote><blockquote>try{</blockquote><blockquote>var Activity = Java.use(“owasp.sat.agoat.EmulatorDetectionActivity”);</blockquote><blockquote>Activity.isEmulator.implementation = function() {</blockquote><blockquote>return false;</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>catch(error){</blockquote><blockquote>console.log(“[-] Error Detected”);</blockquote><blockquote>console.log((error.stack));</blockquote><blockquote>}</blockquote><blockquote>});</blockquote><blockquote>}</blockquote><blockquote>else {</blockquote><blockquote>console.log(“ “)</blockquote><blockquote>console.log(“[-] Java is Not available”);</blockquote><blockquote>}</blockquote><p><strong>Step 5: </strong>Let us save this code as “emulator detection.js” and inject this js file into the application’s runtime using the following command.</p><p>frida -l “emulator detection.js” -U -f owasp.sat.agoat</p><p>Running this command will launch the application and the execution will be paused. We can type the command %resume to resume the execution of the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/0*CnZlD_C7IQSrHGu4" /></figure><p>After running the preceding commands, we can observe that the emulator detection is bypassed. Access the application installed on the emulator and click the button “CHECK EMULATOR”. If everything went as expected, we should observe the toast message “This is not an Emulator” as shown in the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/0*GEK3cM0hu8bsNxmh" /></figure><p>The preceding figure shows that we have successfully bypassed emulator detection in Androgoat application.</p><h3>Conclusion:</h3><p>It is apparent that client-side protections such as root detection and emulator detection can be great to have but they may be easily bypassed using tools like Frida. Complex root detection implementations can slow down the attackers a bit, and such implementations should be considered by developers even though no client-side protections are foolproof. We have also seen the power of Frida in this article. It can help us write powerful scripts to play with the app’s runtime.</p><p>If you would like to learn more about Android Security check out our course on <a href="https://www.theoffensivelabs.com/p/hacking-and-pentesting-android-applications/?coupon_code=FLASH40&amp;preview=logged_out">“Hacking and Pentesting Android Applications”</a></p><p>This article was written by <a href="https://www.linkedin.com/in/sushma-ahuja-284907157/">Sushma Ahuja </a>for <a href="http://www.theoffensivelabs.com/">The Offensive Labs.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e938109e468c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker escape using mounted docker.sock]]></title>
            <link>https://theoffensivelabs.medium.com/docker-escape-using-mounted-docker-sock-6d5a74d6b783?source=rss-2474fa46025a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d5a74d6b783</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[docker-security]]></category>
            <category><![CDATA[devsecops]]></category>
            <dc:creator><![CDATA[The Offensive Labs]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 06:17:26 GMT</pubDate>
            <atom:updated>2021-03-31T08:24:27.147Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Docker socket is a UNIX socket that acts as a backbone for managing your containers. When you type any Docker commands using your doctor client, your Docker client basically interacts with this Docker socket and manages your containers.</p><p>When you download Docker images from the Docker Hub and when you start containers using those images, the developer of the image may ask you to mount /var/run/docker.sock into the container. This may be required for some legitimate reasons, but we should be aware of the dangers that this feature brings with it.</p><p>Some of the legitimate reasons could be, you are starting a container and you want to manage other containers from that container, and obviously it requires access to your Docker socket. Similarly, you are running a tool that is going to audit all your doctor containers running on the host. When you are running this tool as a docker container obviously it needs to access Docker socket to be able to interact with other containers running on your host. While these are some of the legitimate reasons to have docker.sock mounted on your container, as mentioned earlier we should always be aware of the dangers that it brings.</p><h4><strong>Container escape using docker.sock</strong></h4><p>Let us see an example of how this feature can be abused.</p><p>Let us assume that as an attacker we have gotten a shell on a container where docker.sock is mounted. With that assumption, we are only inside the container and we have a docker.sock mounted onto the container. Using this access, our goal is to be able to access a file that is on the host machine and accessible only by the root user. We will try to access the file named crackme.txt which is present inside the root directory on the host machine.</p><p>Let us first create a directory called dockersock and change our working directory to dockersock using the following command.</p><pre>~$ mkdir dockersock<br>~$ cd dockersock</pre><p>Now, let us simulate the attack by obtaining a shell on a container, and let’s make sure that docker.sock is mounted onto the container. To do that, we will be using the alpine image and we are going to spin up a container using the following command.</p><pre>~$ docker run -itd -v /var/run/docker.sock:/var/run/docker.sock alpine</pre><p>In the preceding command, we can see that we are using the docker run command and mounting the /var/run/docker.sock onto the container using -v.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*Aq-tJgFhDAyTRTkaCnq6cw.jpeg" /></figure><p>From the preceding image, we can see that the container has started. Let us use the docker ps command to get the container id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*pQyHM_fHim-CTeL-v4HxNg.jpeg" /></figure><p>From the preceding image, we can see that the container id is 3570ce8a4068. Let us use the following command to get a shell on the container.</p><pre>~$ docker exec -it 3570ce8a4068</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*7sP_Y4N0RQ5SKJpBK_V2Uw.jpeg" /></figure><p>Let us confirm that we have docker.sock mounted onto the container. To do that let us type the following command.</p><pre>~$ ls /var/run/docker.sock</pre><p>It looks as follows on the container shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*S-msVg2WnqutT6ecEIp-ag.jpeg" /></figure><p>The preceding image confirms that docker.sock has been mounted onto the container. To be able to use this docker socket, we need to have Docker client installed on this container. Let us check if the docker socket is already available on the alpine image by typing docker. We get the following output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*TmQC6rT0c16oR9bFTnJRog.jpeg" /></figure><p>From the preceding image, we can see that docker client is not available. Before we install docker client, let us do apk update using the following command.</p><pre>/# apk update</pre><p>Now, let us type the following command to install docker client onto the container.</p><pre>~$ apk add -U docker</pre><p>We get the following output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*vKaGjkqftzcamhhm8NJndg.jpeg" /></figure><p>Docker installation is now complete, and we should be able to run docker commands. Using this docker client and the docker socket mounted onto the container, we can simply spin up another container on the host and mount the root directory of the host machine onto the newly started container and then get a shell on the newly started container to be able to access the root directory of the host. To do that, let us type the following command.</p><pre>~$ docker -H unix:///var/run/docker.sock run -it -v /:/test:ro -t alpine sh</pre><p>In the above command, we have specified the location of docker.sock which is /var/run/docker.sock and used -v to be able to mount the root directory of the host under the container that we are now starting and we named it test on the container. So, the root directory of the host machine is going to be mounted into a directory called test on the container. Finally, we pass sh as an argument so that we will directly get a shell on the container that we are now starting.</p><p>The command should run successfully as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*7EPuNMEHJROXhtnfLqYqvw.jpeg" /></figure><p>Let us navigate to the test folder as this is where we have mounted the root directory of the host machine and change the directory to root and type ls as shown in the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*0EoLNaORuj1eQj06uftf9Q.jpeg" /></figure><p>This is the indication that we have gotten foothold onto the host machine’s file system. Let us now check the contents of the crackme.txt file using the cat command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*UQXd1rK1mxcsNZub_lqPdQ.jpeg" /></figure><p>This is how we can docker.sock which is mounted onto the container can be abused to be able to gain foothold onto the docker host.</p><p><strong>Conclusion:</strong></p><p>Docker containers are being heavily used in the IT industry and it is extremely important to be aware of some of the security sensitive features they come with as they may pose serious security risk to the organizations when exploited.</p><p>If you like to learn more about docker security check out our course on <a href="https://www.theoffensivelabs.com/courses/hacking-and-securing-docker-containers?coupon_code=FLASH40&amp;preview=logged_out">“Hacking and Securing Docker Containers”</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d5a74d6b783" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>