<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>DVWA on Raghunath Gopinath</title>
    <link>https://raghu.io/series/dvwa/</link>
    <description>Recent content in DVWA on Raghunath Gopinath</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Thu, 30 Apr 2026 20:36:05 +0530</lastBuildDate>
    <atom:link href="https://raghu.io/series/dvwa/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Lab Setup - Docker DVWA</title>
      <link>https://raghu.io/lab-setup-docker-dvwa/</link>
      <pubDate>Sat, 30 Jul 2022 07:42:00 +0000</pubDate>
      <guid>https://raghu.io/lab-setup-docker-dvwa/</guid>
      <description>Step-by-step guide to setting up a DVWA Docker lab environment for practicing web application security testing.</description>
      <content:encoded><![CDATA[<p>If you&rsquo;re interested in learning and practicing web application security
skills but not sure where to get started, this section will walk you
through setting up the lab environment of the DVWA docker image, which
is one of the practical vulnerable applications for learning web
application security skills.</p>
<h2 id="what-is-dvwa">What is DVWA?</h2>
<p>Damn Vulnerable web app or Damn Vulnerable Web Application (DVWA) is an
intentionally designed vulnerable application for pen-testers and
security experts in learning and testing web application security in a
legal environment. It is developed using PHP/MySQL and can be deployed
easily using an Apache server.</p>
<p><a href="https://github.com/digininja/DVWA">DVWA Git Repository</a></p>
<p>DVWA can be installed in multiple ways, such as using code from GitHub,
Vagrant, or a Docker image, etc.</p>
<blockquote>
<p>It is recommended to host the vulnerable applications in a host-only
environment to prevent compromising other systems on your network by
attackers.</p>
</blockquote>
<p>You can even view the source code or contribute to the DVWA project.
It&rsquo;s an open-source project.</p>
<p>For simplicity, we will be using our systems and pre-built docker DVWA
image, which is publicly available, rather than setting up the whole
stuff by ourselves. By running the DVWA docker container, we can save a
lot of time and jump-start learning application security and penetration
testing directly.</p>
<h2 id="requirements">Requirements</h2>
<ol>
<li><strong>Docker installed</strong> &amp; enabled on your Laptop/Desktop</li>
<li><strong>Any Operating System (OS)</strong> Linux/Windows/Mac</li>
</ol>
<p>I am a GNU/Linux user, so most of the commands you will see from here on
will be based on <strong>Linux (Debian)</strong>, and similar commands do apply to
other Linux flavors like Ubuntu and Mac with minor tweaks.</p>
<p>For Windows users, you can use either <strong>PowerShell</strong> or <strong>git Bash</strong>,
where similar commands can be executed, or even the Windows Subsystem
for Linux can also be used.</p>
<h2 id="verify-docker-setup">Verify Docker Setup</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">docker --version
</span></span></code></pre></div><p><strong>Output:</strong></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Docker version 20.10.17, build 100c701
</span></span></code></pre></div><p>If the output is similar to the above, it means the docker is installed
on your system and good to start.</p>
<p>For users whose docker is not installed, please visit the <a href="https://docs.docker.com/get-started/get-docker/">Get
Docker</a> page for
installation.</p>
<h2 id="manage-docker-as-non-root-users-linux-based-os-users">Manage Docker as Non-Root Users (Linux-based OS Users)</h2>
<p>For users who are using docker on Linux-based operating systems, we need
to take one more additional step to ensure we can manage the docker
image as non-root users.</p>
<p>After installation of docker, create a docker group and add the newly
created user to the docker group.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ sudo groupadd docker
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">$ sudo usermod -aG docker <span class="nv">$USER</span>
</span></span></code></pre></div><p>Now log out of the user account and log back in again to verify you are
now able to manage the docker instances from non-root users.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ docker run hello-world
</span></span></code></pre></div><p><strong>Output</strong>:</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="hello-world-docker.jpg"
         alt="Figure 1: Docker Hello World Output"/> <figcaption>
            <p>Figure 1: Docker Hello World Output</p>
        </figcaption>
</figure>

<p>The above output confirms that we can manage Docker with non-root user
privileges. More details can be found on the <a href="https://docs.docker.com/engine/install/linux-postinstall/">post-installation
docker</a> page
below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="/icons/balance.png"
         alt="Figure 2: Benefits of DVWA"/> <figcaption>
            <p>Figure 2: Benefits of DVWA</p>
        </figcaption>
</figure>

<h2 id="benefits-of-local-dvwa-environment">Benefits of Local DVWA Environment</h2>
<ul>
<li><strong>Practice</strong> any time.</li>
<li>Ability to test <strong>any customized payloads or exploits</strong>.</li>
<li>It can be used to test the <strong>effectiveness of Web Vulnerability
Scanners</strong> or <strong>Automated Tools</strong></li>
<li>It can be used for <strong>Teaching</strong>.</li>
<li>Ability to test custom <strong>security fixes</strong>.</li>
</ul>
<h2 id="running-dvwa-docker">Running DVWA docker</h2>
<p>I hope your Docker environment is configured so we can start working.
Here, we will use the Docker image, which has already been built and
hosted in the Docker Hub.</p>
<p>Damn Vulnerable Web Application Docker Image:
<a href="https://hub.docker.com/r/vulnerables/web-dvwa/">https://hub.docker.com/r/vulnerables/web-dvwa/</a></p>
<p><strong>Command</strong>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">docker run --rm -it -p 80:80 vulnerables/web-dvwa
</span></span></code></pre></div><p>The above command will download the docker image for the first time and
will start immediately on port <strong>80</strong> after downloading it. Click
<a href="http://localhost/">here</a> to verify.</p>
<blockquote>
<p>If you are using port &ldquo;80&rdquo; for some other service in your operating
system, you can change the docker container port to some random one
(say 8443). Update the -p value with -p 80:8443. Ensure the updated
port is used in the URL while accessing the DVWA web application.</p>
</blockquote>
<p>To manually view, open a browser and visit &ldquo;<a href="http://localhost/">http://localhost/</a>&rdquo;, you
should be able to see the output as shown below:</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="DVWA-Home-Screen.jpg"
         alt="Figure 3: DVWA Login Page"/> <figcaption>
            <p>Figure 3: DVWA Login Page</p>
        </figcaption>
</figure>

<p>The image will start displaying the console logs of the operations being
performed on the DVWA website for reference.</p>
<p>Stop the running Docker image anytime by typing <strong>Ctrl - c</strong> in your
console.</p>
<h2 id="dvwa-admin-password">DVWA Admin Password</h2>
<p>Now log into the application using Username <strong>admin</strong>, Password as
<strong>password</strong>, Navigate to Setup DVWA ⇾ click on Create/Reset Database
button.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Setup-DVWA.jpg"
         alt="Figure 4: Setting up DVWA"/> <figcaption>
            <p>Figure 4: Setting up DVWA</p>
        </figcaption>
</figure>

<figure class="mx-auto block text-center">
    <img loading="lazy" src="create-reset-db-dvwa.jpg"
         alt="Figure 5: DVWA database creation"/> <figcaption>
            <p>Figure 5: DVWA database creation</p>
        </figcaption>
</figure>

<p>We can observe that the database has been created with a users&rsquo; table.
Some sample data is also inserted into the tables for our testing
purposes.</p>
<h2 id="damn-vulnerable-web-app-walkthrough">Damn Vulnerable Web App Walkthrough:</h2>
<p>Log into the DVWA application and observe most of OWASP&rsquo;s top-known
vulnerabilities that have been created so you can get started. They are
displayed as shown below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="DVWA-Challenges-Overview.jpg"
         alt="Figure 6: DVWA Challenges Overview"/> <figcaption>
            <p>Figure 6: DVWA Challenges Overview</p>
        </figcaption>
</figure>

<p>Our practice lab environment is up and is good to go.</p>
<p>From the above screenshot, you can use the DVWA to practice and get
hands-on experience with known vulnerabilities, such as Brute Force,
Command Injection, CSRF, XSS, etc.</p>
<p>Click on any vulnerability in the left-side menu, and the application
will load the vulnerable page. All pages simulate close-to real-time
application behaviors and provide hints to help you narrow down and use
the correct type of vulnerable payloads for exploitation.</p>
<p>Remember that all our changes will be lost once you stop the DVWA docker
image. You might need to repeat the above steps when you start. This is
how the docker is designed, and it also allows us to begin with a fresh
environment without worrying about previous changes.</p>
<p>The docker image needs some more tweaks, but we will do them when needed
based on the type of attack we are discussing.</p>
<h2 id="dvwa-security-levels">DVWA Security Levels</h2>
<p>In the DVWA application, there are multiple levels to test any specific
vulnerability, ranging from Low to Medium to High and Impossible.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="DVWA-Levels.png"
         alt="Figure 7: DVWA Security Level"/> <figcaption>
            <p>Figure 7: DVWA Security Level</p>
        </figcaption>
</figure>

<p>These levels help you build skills by understanding each scenario.
First, you learn about the attack itself. Then, you will know how broken
fixes are implemented and how they can be bypassed. Lastly, you will
learn the best way to secure a particular functionality.</p>
<blockquote>
<p>The DVWA security levels are different for older versions. In the old
version, high is a good practice for fixing code.</p>
</blockquote>
<p>It is recommended that you go step by step. I still use it today to test
specific payloads before they are applied to real-time applications as
part of security testing.</p>
<h2 id="dvwa-view-source-and-view-help">DVWA View Source and View Help</h2>
<p>The DVWA application is mainly designed as a learning platform for
application security. It also allows us to view the backend code for
knowledge purposes.</p>
<blockquote>
<p>Remember, you might not have this option for real-world applications.
This is just for educational purposes only.</p>
</blockquote>
<p>Navigate to any vulnerability in the menu. Say the &ldquo;<strong>Brute Force</strong>&rdquo;
menu item in the sidebar. On the same page, click on the &ldquo;<strong>View
Source</strong>&rdquo; button at the bottom.</p>
<p>Similarly, the &ldquo;<strong>View Help</strong>&rdquo; button or &ldquo;<strong>More Information</strong>&rdquo; section
can be used if you struck somewhere as initial help.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="DVWA-View-Source-Help.png"
         alt="Figure 8: DVWA View Source or Help Information"/> <figcaption>
            <p>Figure 8: DVWA View Source or Help Information</p>
        </figcaption>
</figure>

<p>I hope the above information helps you to get started with a damn
vulnerable web app docker.</p>
<p>If you want to learn about some basic web foundations before jumping
into web security vulnerabilities, refer to the bookmarks below.</p>
<p>Security Foundations: <a href="/what-is-web-application-and-how-does-it-work/">What is Web Application and How does it
work?</a> Discover
the fundamentals of what is a web application, URLs, and popular web
application architectures. Gain insights into the core concepts that
drive the digital world forward. Begin your journey by establishing
strong security foundations.</p>
<p>Security Foundations: <a href="/http-basics-tutorial/">HTTP Basics
Tutorial</a> Uncover the
fundamentals of HTTP in this beginner-friendly way. HTTP Basics
Tutorials is a guide for those new to information security or diving
into web application security.</p>
<h2 id="faqs">FAQ&rsquo;s</h2>
<h3 id="how-to-log-into-a-damn-vulnerable-web-app-login">How to log into a damn vulnerable web app login?</h3>
<p>You can use the credentials like username as admin and password as
password.</p>
]]></content:encoded>
    </item>
    <item>
      <title>DVWA - Brute Force Attack and Prevention Explained</title>
      <link>https://raghu.io/dvwa-brute-force-attack-and-prevention-explained/</link>
      <pubDate>Fri, 30 Sep 2022 06:53:00 +0000</pubDate>
      <guid>https://raghu.io/dvwa-brute-force-attack-and-prevention-explained/</guid>
      <description>This detailed guide explains Brute Force Attacks, how they work, and ways to prevent them. You can also explore a demo to understand the concept better and discover effective prevention mechanisms to safeguard your online security.</description>
      <content:encoded><![CDATA[<p>Brute Force is one of the security vulnerabilities which is commonly
seen. This article will demonstrate the brute force attack on the Damn
Vulnerable Web Application - an intentionally designed vulnerable
application. In addition, it will cover how they work, the potential
impact, and effective ways to prevent and safeguard your online
security.</p>
<p>The following post is part of learning application security with the
DVWA application.</p>
<p>Before jumpstart, ensure the <a href="/lab-setup-docker-dvwa/">docker
DVWA</a> application is
enabled, configured, and accessible.</p>
<h2 id="what-is-a-brute-force-attack">What is a Brute Force Attack?</h2>
<p>A brute force attack is a trial-and-error method in which every possible
combination of commonly used words, usernames, and passwords is tried
out, hoping any of them will work.</p>
<p>Brute Force attacks are aimed at guessing commonly known files on the
web server, breaking into email accounts, guessing remote services SQL
or SSH server credentials (online), cracking password hashes (offline),
etc., to gain unauthorized access to sensitive data or compromise
security.</p>
<p>It would require a good amount of computing resources and <strong>time</strong>. #️⃣</p>
<p>The screenshot below from
<a href="https://www.cloudflare.com/img/learning/security/threats/brute-force-attack/brute-force-cracking-time.png?ref=raghu.io">Cloudflare</a>
demonstrates how long it can take to crack a password based on the
number of characters.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="brute-force-cracking-time.png"
         alt="Figure 1: BruteForce Attack Statistics - [[https://www.cloudflare.com/learning/bots/brute-force-attack/][Cloudflare]]"/> <figcaption>
            <p>Figure 1: BruteForce Attack Statistics - [[https://www.cloudflare.com/learning/bots/brute-force-attack/][Cloudflare]]</p>
        </figcaption>
</figure>

<p>Today&rsquo;s hardware helps us crack a hashed password of 5 characters or
fewer in seconds. The one with 12 characters or more, combining small
letters, upper-case letters, special characters, and numerics, takes
years to crack. The bigger the password, the more time it takes to crack
using a Brute Force attack.</p>
<blockquote>
<p>Think wisely, how much time you would like to spend for any brute
force attack. A day or two may be good, but years and decades may not
be worth enough.</p>
</blockquote>
<p>Speaking on behalf of security assessments, we will be spending days or
weeks. But attackers do have all the time they want.</p>
<h2 id="how-do-brute-force-attacks-work">How do Brute Force attacks work?</h2>
<p>Brute Force attacks are performed using automated tools or software. A
massive list of dictionaries containing common passwords, usernames,
words, etc., is generated and given to the tool as input.</p>
<p>The tool keeps interacting with the service and tries out the dictionary
entries one by one until a valid match is found, at which point it
stops.</p>
<p>During this process, the attacker uses large dictionary data sets until
the correct combination is discovered and successful access to
confidential resources is obtained.</p>
<p>From now on, we will use the &ldquo;<a href="https://portswigger.net/">Burp
Suite</a>&rdquo;
as an ideal tool for all our brute force attacks and to keep demos
focused. If you would like to learn more about the basics and usage of
the tool, Check out the following post on <a href="/burpsuite-overview/">BurpSuite
Overview</a>.</p>
<p>Next, I will be using a small custom dictionary of usernames and
passwords for fast brute-force results, which will be performed later.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">admin
</span></span><span class="line"><span class="cl">administrator
</span></span><span class="line"><span class="cl">user
</span></span><span class="line"><span class="cl">john
</span></span><span class="line"><span class="cl">dvwa
</span></span><span class="line"><span class="cl">bob
</span></span><span class="line"><span class="cl">alice
</span></span><span class="line"><span class="cl">root
</span></span><span class="line"><span class="cl">superuser
</span></span><span class="line"><span class="cl">super
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">admin
</span></span><span class="line"><span class="cl">admin123
</span></span><span class="line"><span class="cl">password
</span></span><span class="line"><span class="cl">password123
</span></span><span class="line"><span class="cl">user
</span></span><span class="line"><span class="cl">user123
</span></span><span class="line"><span class="cl">administrator
</span></span><span class="line"><span class="cl">passw0rd
</span></span><span class="line"><span class="cl">r3m3mb3rM3
</span></span><span class="line"><span class="cl">admin123$
</span></span></code></pre></div><h2 id="brute-force-attack---demo">Brute Force Attack - Demo</h2>
<p>The DVWA application has a Login page functionality that can be used to
brute-force and find the right match of user credentials, simulating the
attackers to compromise the application.</p>
<p>Let&rsquo;s go ahead and simulate the steps of an attacker and see if we can
break in.</p>
<p>In information security, it&rsquo;s all about chaining up every piece of
information you know, experimenting with it, and confirming if it works.
In short, it lies in your creativity when using the information.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="DVWA_BruteForce_Vulnerability.png"
         alt="Figure 2: DVWA Brute Force - Login Page"/> <figcaption>
            <p>Figure 2: DVWA Brute Force - Login Page</p>
        </figcaption>
</figure>

<p>At the moment, we do not have any information about the
username/password. All we see is a login page.</p>
<p>We will start with the Brute Force attack using the above dictionaries.</p>
<p>Let&rsquo;s start the BurpSuite tool and use the small custom dictionaries we
created above. The tool tests for all possible combinations, and this
method is scalable to thousands of combinations.</p>
<p>In the Burp Suite tool, navigate to the &ldquo;<strong>Proxy</strong>&rdquo; tab and click on the
&ldquo;<strong>Open Browser</strong>&rdquo; button. A Chromium browser will be launched and will
be displayed as shown below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BurpSuite-Chromium-Browser.png"
         alt="Figure 3: Burp Suite In-Built Chromium Browser"/> <figcaption>
            <p>Figure 3: Burp Suite In-Built Chromium Browser</p>
        </figcaption>
</figure>

<p>Log into the DVWA application using &ldquo;<strong>admin/password</strong>&rdquo; and navigate to
the &ldquo;<strong>Brute Force</strong>&rdquo; item in the menu.</p>
<p>Let&rsquo;s try some known username and password combinations.</p>
<p>Say &ldquo;<strong>administrator/admin123</strong>&rdquo;, &ldquo;<strong>admin/admin123</strong>&rdquo;,
&ldquo;<strong>user/user123</strong>&rdquo; etc. For all incorrect attempts, we keep getting the
&ldquo;<strong>Username and/or password incorrect</strong>.&rdquo; message.</p>
<p>Manually trying out is also known as a simple brute force attack, which
is painful and limits the knowledge to oneself. This approach is
time-consuming and isn&rsquo;t scalable.</p>
<p>If you found a valid login match this approach? <strong>Excellent. You
perfectly guessed it</strong>. 👍</p>
<p>In Burp Suite, we need to capture the Login request. I will enable the
Intercept option to capture a specific login request so we can perform
automated operations using it.</p>
<p>To enable it, navigate to Burp Suite &ldquo;<strong>Proxy</strong>&rdquo; tab ⇾ &ldquo;<strong>Intercept</strong>&rdquo; ⇾
toggle on the &ldquo;<strong>intercept off</strong>&rdquo; button. It immediately turns to
&ldquo;<strong>intercept on</strong>&rdquo; as displayed below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BurpSuite-Intercept-On.png"
         alt="Figure 4: BurpSuite Intercept &ldquo;Toggle On&rdquo;"/> <figcaption>
            <p>Figure 4: BurpSuite Intercept &ldquo;Toggle On&rdquo;</p>
        </figcaption>
</figure>

<p>Key in some random data in the username and password file, then click on
the &ldquo;<strong>Login</strong>&rdquo; button as shown below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce_enter_randomcreds.png"
         alt="Figure 5: Key in random credentials on the Login Page"/> <figcaption>
            <p>Figure 5: Key in random credentials on the Login Page</p>
        </figcaption>
</figure>

<p>Once the Burp Suite receives an intercept request, you should be able to
see the highlights immediately. Navigate to the &ldquo;<strong>Proxy</strong>&rdquo; tab. ⇾
&ldquo;<strong>Intercept</strong>&rdquo;. You should be able to see a request similar to the one
below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Login-Request.png"
         alt="Figure 6: Brute Force functionality Login Request"/> <figcaption>
            <p>Figure 6: Brute Force functionality Login Request</p>
        </figcaption>
</figure>

<p>An <strong>HTTP GET</strong> method is used, remember the GET method doesn&rsquo;t have a
message body. Therefore, all the parameters and values will be sent as a
URL.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">GET /vulnerabilities/brute/?username=admin&amp;password=testpassword&amp;Login=Login HTTP/1.1
</span></span></code></pre></div><p>Here, we are trying to access a page called &ldquo;<strong>/vulnerabilities/brute</strong>&rdquo;
and passing parameter values
&ldquo;<strong>username=admin&amp;password=testpassword&amp;Login=Login</strong>&rdquo; to perform the
login action required by the application.</p>
<p>If your credentials are valid, you will be able to log in successfully.
Otherwise, you will receive an invalid login error message.</p>
<p>Now, click on the &ldquo;<strong>Action</strong>&rdquo; button and select &ldquo;<strong>Send to Intruder</strong>&rdquo;.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce_Send_To_intruder.png"
         alt="Figure 7: Send to Intruder"/> <figcaption>
            <p>Figure 7: Send to Intruder</p>
        </figcaption>
</figure>

<p>Switch to the &ldquo;<strong>Intruder</strong>&rdquo; tab, and you should be able to see the same
request there. Under the &ldquo;<strong>Positions</strong>&rdquo; sub-tab, The tool automatically
detects where all the changeable values need to be placed and highlights
the five parameter values section for us.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Intruder-Payload.png"
         alt="Figure 8: Request Being Used as Payload"/> <figcaption>
            <p>Figure 8: Request Being Used as Payload</p>
        </figcaption>
</figure>

<p>I will clear all the payload locations and select only username and
password using the &ldquo;<strong>Clear</strong>&rdquo; and &ldquo;<strong>Add</strong>&rdquo; buttons beside.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce_Intruder_Choose_Payloads.png"
         alt="Figure 9: Select the Positions in a Request to autoamte payloads with dictionaries"/> <figcaption>
            <p>Figure 9: Select the Positions in a Request to autoamte payloads with dictionaries</p>
        </figcaption>
</figure>

<h2 id="types-of-brute-force-attacks">Types of Brute Force Attacks</h2>
<p>There are four brute-force attack types that are supported by the &ldquo;Burp
Suite&rdquo; tool.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Intruder-Attack-Types.png"
         alt="Figure 10: BurpSuite Intruder Attack Types"/> <figcaption>
            <p>Figure 10: BurpSuite Intruder Attack Types</p>
        </figcaption>
</figure>

<p><strong>Cluster Bomb</strong> best suits our requirements. Set the attack type to
&ldquo;<strong>Cluster Bomb</strong>&rdquo; and switch to the &ldquo;<strong>Payload</strong>&rdquo; sub-tab.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Choose-Intruder-Attack-Type.png"
         alt="Figure 11: BurpSuite Brute Force select Attack Type"/> <figcaption>
            <p>Figure 11: BurpSuite Brute Force select Attack Type</p>
        </figcaption>
</figure>

<p>In the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, select &ldquo;<strong>Payload Set 1</strong>&rdquo;, payload type
as &ldquo;<strong>simple list</strong>&rdquo; and paste all the contents in payload options
copied from the <strong>usernames.txt</strong> list.</p>
<p>This is for the &ldquo;<strong>Username</strong>&rdquo; values.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Intruder-Payload-Set-1.png"
         alt="Figure 12: Usernames Payload"/> <figcaption>
            <p>Figure 12: Usernames Payload</p>
        </figcaption>
</figure>

<p>Second, select the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, set &ldquo;<strong>Payload Set 2</strong>&rdquo;, set
the payload type as &ldquo;<strong>simple list</strong>&rdquo; and paste all the contents in
payload options copied from the <strong>passwords.txt</strong> list.</p>
<p>This is for the &ldquo;<strong>Password</strong>&rdquo; values.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Intruder-Payload-Set-2.png"
         alt="Figure 13: Password Payloads"/> <figcaption>
            <p>Figure 13: Password Payloads</p>
        </figcaption>
</figure>

<p>Observe that the request count is now set to 100. Using the two lists
now, we will be trying out 100 possible combinations.</p>
<p>Lastly, click the &ldquo;<strong>brute-force</strong>&rdquo; button at the top right to initiate
our brute-force attack.</p>
<blockquote>
<p>In the BurpSuite Community edition it prompts with a warning box as
some features are limited. Click &ldquo;Ok&rdquo; to continue.</p>
</blockquote>
<p>An intruder window pops up, and the payload information and request
status will be displayed below.</p>
<p>If you take a look, we can see we are getting a <strong>200</strong> status for each
request, which means &ldquo;<strong>200 Ok</strong>&rdquo;.</p>
<p>How do we know which payload combination worked and which hasn&rsquo;t?</p>
<p>One way is to click on each request with a <strong>200 Ok</strong> status, select the
&ldquo;<strong>Response</strong>&rdquo; sub-tab, and search for the string named &ldquo;<strong>Username
and/or password incorrect</strong>&rdquo;. We know this belongs to a failed login
attempt.</p>
<p>If the string isn&rsquo;t present, it means the credentials combination
worked, and that would be our match.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Attack-Results.png"
         alt="Figure 14: Brute Force Intruder Attack Results"/> <figcaption>
            <p>Figure 14: Brute Force Intruder Attack Results</p>
        </figcaption>
</figure>

<p>BurpSuite Intruder figured out there is one positive match on the bottom
right side of the screenshot. This is a time-consuming approach.</p>
<p>Focus on the size of the length as shown below. For all incorrect
attempts, the response message length is the same &ldquo;<strong>4666</strong>&rdquo;. Check one
of a different length, i.e., <strong>4704</strong>.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Worked-Combination-Intruder.png"
         alt="Figure 15: Brute Force Payload Match Found"/> <figcaption>
            <p>Figure 15: Brute Force Payload Match Found</p>
        </figcaption>
</figure>

<p>Observe whether the username/password combination &ldquo;<strong>admin/password</strong>&rdquo;
worked. Navigate to the response sub-tab, We can see the &ldquo;<strong>welcome to
the password protected area of admin</strong>&rdquo; message.</p>
<p><strong>Hurray!!</strong> we found the right password match! 👏</p>
<h3 id="password-match-verification">Password Match Verification</h3>
<p>It is always good practice to re-verify the security bug before we
report it.</p>
<p>Make sure all the Intercepts in the proxy tab are toggled to off. Then,
let&rsquo;s return to the brute force page and verify our match to confirm our
results.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Password-Match-Confirm.png"
         alt="Figure 16: Login Successful"/> <figcaption>
            <p>Figure 16: Login Successful</p>
        </figcaption>
</figure>

<p>Yep, our newly found password combination worked.</p>
<p><strong>Excellent!</strong> We found a security bug using a Brute-Force attack, i.e.,
a guessable username and password.</p>
<p>You were able to learn a quick way to Perform a Brute-Force attack using
DVWA.</p>
<p>I have used a short custom-built word list for demo purposes, Give a try
with other lists. Search for &ldquo;<strong>Brute-Force attack</strong>&rdquo; or &ldquo;<strong>Brute force
wordlist</strong>&rdquo;, and you will find many resources.</p>
<p><a href="https://github.com/topics/bruteforce-wordlist?ref=raghu.io">Here</a>
are some lists from Github.</p>
<h2 id="impact-of-brute-force-attacks">Impact of Brute Force Attacks</h2>
<p>The impact of a successful brute force attack can be severe.</p>
<ul>
<li>Unauthorized access to sensitive information.</li>
<li>Financial loss</li>
<li>Loss of organization&rsquo;s reputation</li>
<li>Leading to potential legal and financial repercussions for the
affected individuals or organizations.</li>
<li>Loss of customer trust, etc.</li>
</ul>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Fixing-BruteForce-Attack-Banner.png"
         alt="Figure 17: Preventing Brute Force Attacks"/> <figcaption>
            <p>Figure 17: Preventing Brute Force Attacks</p>
        </figcaption>
</figure>

<h2 id="preventing-brute-force-attacks">Preventing Brute Force Attacks</h2>
<p>Security Researchers and web application developers need to be familiar
with mitigation techniques. These skills can help them defend web
applications from malicious actors.</p>
<p>So, let&rsquo;s talk about some ways to detect it and then mitigate it.</p>
<h3 id="patterns-of-brute-force-attack">Patterns of Brute Force Attack</h3>
<p>Some of the common patterns can help to detect brute-force attacks on
our webserver.</p>
<ul>
<li>Too many requests originate from a single IP address within a minute
or hour.</li>
<li>Multiple logins of a single user account from a different IP address
and province.</li>
<li>Excessive usage of the server resources and bandwidth.</li>
<li>Increased number of failed login attempts of various usernames and
passwords.</li>
<li>Logged into multiple user accounts from a single IP address. (i.e.,
guessable default password) etc.</li>
</ul>
<p>The above is a small list targeting user credentials, but the patterns
vary for other resources.</p>
<h2 id="defending-brute-force-attacks">Defending Brute Force Attacks</h2>
<p>Brute force attacks are difficult to stop, but with good measures, we
can limit the attack surface.</p>
<figure>
    <img loading="lazy" src="/icons/question.png"/> 
</figure>

<h3 id="avoid-using-defaultguessable-passwords">Avoid Using Default/Guessable Passwords</h3>
<p>One of the most commonly exploited techniques says some application
servers come with pre-defined default passwords for the initially
created accounts. (Say &ldquo;admin/password&rdquo;)</p>
<p><a href="https://cirt.net/passwords/?ref=raghu.io">Default Password Database -
cirt.net</a></p>
<p>Some companies follow an initial password with the company name followed
by a number sequence. Say &ldquo;<strong>ABCCompany123</strong>&rdquo; or the special character
&ldquo;<strong>ABCCompany123$</strong>&rdquo;, some with established year appending at the end
with a prefix of the usernames &ldquo;<strong>Username2022</strong>&rdquo; etc.</p>
<p>These are all unknown until someone figures them out. Once figured out,
they are easy to try out with all the user accounts to which the user
account has access.</p>
<p>Additionally, prevent users from using passwords such as &ldquo;<strong>password</strong>&rdquo;,
&ldquo;<strong>admin123</strong>&rdquo;, &ldquo;<strong>12345</strong>&rdquo; etc.</p>
<figure>
    <img loading="lazy" src="/icons/limit.png"/> 
</figure>

<h3 id="limit-login-attempts">Limit Login Attempts</h3>
<p>One good practice is to limit the number of failed login attempts the
user is allowed to make. Beyond 7 failed login attempts, the account is
locked for a temporary time period. Like banks, beyond three failed
attempts, the user account will be locked out for 24 hours. Or</p>
<blockquote>
<p>👥The challenge with this type is that unauthorized users keep trying
with valid user accounts and lock out genuine users.</p>
</blockquote>
<figure>
    <img loading="lazy" src="/icons/pin-code.png"/> 
</figure>

<h3 id="enforce-a-strong-password-policy">Enforce a Strong Password Policy</h3>
<p>A best-designed password policy like the use of a combination of small
case letters, upper case letter, numerics, special characters will make
it hard to crack for attackers.</p>
<ul>
<li>Use of password managers wherever applicable.</li>
<li>Avoid re-using the same password.</li>
<li>The length of passwords is to be 8 or above.</li>
<li>Prevent the use of common dictionary words or guessable sequences.</li>
<li>Use of certificates for authentication rather than passwords.</li>
<li>Educate users about using a different password for all accounts.</li>
</ul>
<figure>
    <img loading="lazy" src="/icons/clock.png"/> 
</figure>

<h3 id="progressive-delay">Progressive Delay</h3>
<p>This is also the best technique where the wait time keeps on multiplying
with each failed login attempt.</p>
<p>Say, initially start with &ldquo;<strong>60 Seconds</strong>&rdquo; wait time at the first
attempt, then <strong>15 minutes</strong> of wait time for the second attempt, <strong>60
minutes</strong> for the third attempt, and so on it goes.</p>
<p>Generally, some applications multiply wait seconds by 60 for each failed
attempt.</p>
<h3 id="using-captcha">Using Captcha</h3>
<figure>
    <img loading="lazy" src="/icons/captcha.png"/> 
</figure>

<p>Captchas are used to filter automated bots or programs and prevent them
from abusing the services.</p>
<blockquote>
<p>🤖This is a bit of an inconvenience, but solving a captcha will help
verify that it&rsquo;s human and not automation.</p>
</blockquote>
<h3 id="multi-factor-authentication">Multi-Factor Authentication</h3>
<figure>
    <img loading="lazy" src="/icons/password.png"/> 
</figure>

<p>Adding additional layers of verification makes brute force attack very
tough. Using the OTP - One-time passcode, verification of token through
email, or Security Questions before logging in makes it more difficult
for attackers.</p>
<p>The attacker needs to compromise multiple sources to gain access to your
user accounts which is very tough but not impenetrable.</p>
<h3 id="storing-salted-password-hashes">Storing Salted Password Hashes</h3>
<figure>
    <img loading="lazy" src="/icons/password2.png"/> 
</figure>

<p>Even though our application is secured in all possible ways, some
third-party plugins or disgruntled employees may lead to compromise of
the application and say the attacker was able to gain access to all the
passwords in the database.</p>
<p>When a user enters the password say &ldquo;admin123&rdquo; it is not a good practice
to store it as plain text. It must be hashed and stored.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">hash(admin123) = GX8N365FMeK9hsRkW9Dl2S/ikcQ
</span></span></code></pre></div><p>Now add salt to the above hash. Where salt does not need to be a secret
text but a random text. ( say &ldquo;<strong>5MU63YzoOm7ig</strong>&rdquo;)</p>
<p>The Hash + Salt will be displayed as shown below</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">hash(admin123 + 5MU63YzoOm7ig ) = LL/0NIJmT2JcfCXkfOln62pj8Hw
</span></span></code></pre></div><p>The salted hashes make it much more difficult for attackers to crack the
passwords offline.</p>
<p>Even though the attackers have salted hashes, it would be tough for them
to crack and re-use them. Meanwhile, requesting the user to reset the
passwords in case of compromise makes it more secure.</p>
<h3 id="whitelisting">Whitelisting</h3>
<figure>
    <img loading="lazy" src="/icons/regulation.png"/> 
</figure>

<p>Whitelisting or Allowing a list is an approach of letting only what you
trust and blocking all the rest from accessing.</p>
<p>Let&rsquo;s say for high privileged admin user accounts, employ a way to
whitelist the login&rsquo;s from known IP addresses or authorized VPNs and
restrict all others from accessing admin features.</p>
<p>This reduces a huge attack surface.</p>
<h3 id="using-web-application-firewalls">Using Web application firewalls</h3>
<figure>
    <img loading="lazy" src="/icons/firewall.png"/> 
</figure>

<p>Configuring and using Web Application Firewalls (WAFs) protects web
applications from a wide range of attacks, such as brute force attacks,
denial of service attacks, and malicious input filtering, etc. Examples:
AWS WAF, Cloudflare WAF, etc.</p>
<p>More information on blocking brute force attacks can be found on the
<a href="https://owasp.org/www-community/controls/Blocking_Brute_Force_Attacks?ref=raghu.io">Blocking Brute Force Attacks OWASP
site</a>.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Understanding the basics of brute-force attacks and their potential
impacts is crucial for safeguarding against cyber threats. By
implementing robust security measures, such as strong password policies,
multifactor authentication, and network monitoring, individuals and
organizations can mitigate the risk of falling victim to a brute-force
attack.</p>
<p>Using of captcha&rsquo;s can be inconvinient feature, but use it cautiously to
prevent automated bots or from automated attacks. Hope by this you are
familiar with what a brute force attack is and how it can be exploited.</p>
<p>Keep Learning!! 😄</p>
]]></content:encoded>
    </item>
    <item>
      <title>DVWA Brute Force Attack - Medium Severity</title>
      <link>https://raghu.io/dvwa-brute-force-attack-medium-severity/</link>
      <pubDate>Wed, 03 Aug 2022 06:22:22 +0000</pubDate>
      <guid>https://raghu.io/dvwa-brute-force-attack-medium-severity/</guid>
      <description>This detailed post explains Brute-Force Attacks&amp;#39; Medium severity using DVWA and how partial security fixes can be bypassed. You can also explore a demo to better understand the concept and discover and optimize your attack with the BurpSuite tool.</description>
      <content:encoded><![CDATA[<p>I hope you are familiar with brute-force attacks by now.</p>
<p>In the current section, we will explore a bit more about the Brute Force
attack and options available in the BurpSuite tool for effectively
identifying successful brute-force attempts.</p>
<p>If you haven&rsquo;t read the previous article about the Brute Force attack,
feel free to refer to the bookmark below.</p>
<p><a href="/dvwa-brute-force-attack-and-prevention-explained/">DVWA - Brute Force Attack and Prevention
Explained</a></p>
<h2 id="dvwa-brute-force-vulnerability---demo">DVWA Brute Force Vulnerability - Demo</h2>
<p>Imagine we found a vulnerability and reported it to the DVWA development
team. The team reverted, claiming the security flaw was fixed.</p>
<blockquote>
<p>Trust but Verify</p>
</blockquote>
<p>It is always a good practice to re-verify and ensure that the
vulnerability is mitigated as per best practices. Let&rsquo;s verify.</p>
<p>Log into the DVWA application. In the sidebar, scroll to the bottom of
the page and click on &ldquo;<strong>DVWA Security</strong>&rdquo;. A page will load as shown
below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="DVWA_SecurityLevel_Medium.png"
         alt="Figure 1: Choosing DVWA Security Level to Medium"/> <figcaption>
            <p>Figure 1: Choosing DVWA Security Level to Medium</p>
        </figcaption>
</figure>

<p>Set the security level to &ldquo;<strong>Medium</strong>&rdquo; and click on the <strong>Submit</strong>
button. Ensure it is updated and displayed on the left side at the
bottom of the page.</p>
<p>Launch the BurpSuite tool, navigate to the &ldquo;<strong>Proxy</strong>&rdquo; tab, and click on
the &ldquo;<strong>Open Browser</strong>&rdquo; button.</p>
<p>Visit the DVWA application, Select the &ldquo;<strong>Brute Force</strong>&rdquo; vulnerability,
and then enter any random credentials as discussed in the previous
article.</p>
<p>Enable the intercept option and capture the login request displayed, as
shown below. Observe that the security parameter value is set to
<strong>medium</strong> in line 16.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Login-Request-Medium.png"
         alt="Figure 2: Brute Force Login Reqest Medium"/> <figcaption>
            <p>Figure 2: Brute Force Login Reqest Medium</p>
        </figcaption>
</figure>

<p>Similar to the previous lesson, click on &ldquo;<strong>Action</strong>&rdquo; and select &ldquo;<strong>Send
to Intruder</strong>&rdquo;. Set the attack type to &ldquo;<strong>Cluster bomb</strong>&rdquo;, clear all
fields, and add only the username and password value fields for
inserting custom payloads.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Intruder-Position-Slection-Medium.png"
         alt="Figure 3: The intruder with a user athentication request"/> <figcaption>
            <p>Figure 3: The intruder with a user athentication request</p>
        </figcaption>
</figure>

<p>For the current scenario, we will use the same Word list of common
usernames and passwords. Save the text files onto your system or use
copy-paste to load the information in the payloads tab.</p>
<p><strong>usernames.txt</strong></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">admin
</span></span><span class="line"><span class="cl">administrator
</span></span><span class="line"><span class="cl">user
</span></span><span class="line"><span class="cl">john
</span></span><span class="line"><span class="cl">dvwa
</span></span><span class="line"><span class="cl">bob
</span></span><span class="line"><span class="cl">alice
</span></span><span class="line"><span class="cl">root
</span></span><span class="line"><span class="cl">superuser
</span></span><span class="line"><span class="cl">super
</span></span></code></pre></div><p><strong>passwords.txt</strong></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">admin
</span></span><span class="line"><span class="cl">admin123
</span></span><span class="line"><span class="cl">password
</span></span><span class="line"><span class="cl">password123
</span></span><span class="line"><span class="cl">user
</span></span><span class="line"><span class="cl">user123
</span></span><span class="line"><span class="cl">administrator
</span></span><span class="line"><span class="cl">passw0rd
</span></span><span class="line"><span class="cl">r3m3mb3rM3
</span></span><span class="line"><span class="cl">admin123$
</span></span></code></pre></div><p>In the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, select &ldquo;<strong>Payload Set 1</strong>&rdquo;, payload type
as &ldquo;<strong>simple list</strong>&rdquo;, and paste all the contents in <strong>payload options</strong>
copied from the <strong>usernames.txt</strong> list. (For username values)</p>
<p>Second, select the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, set &ldquo;<strong>Payload Set 2</strong>&rdquo;, and
payload type as &ldquo;<strong>simple list</strong>&rdquo;, and paste all the contents in
<strong>payload options</strong> copied from the <strong>passwords.txt</strong> list. (For
password field values)</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Payload-Set-Medium.png"
         alt="Figure 4: Brute Force Attack - Intruder Payloads Set"/> <figcaption>
            <p>Figure 4: Brute Force Attack - Intruder Payloads Set</p>
        </figcaption>
</figure>

<p>The steps were similar to the previous one.</p>
<p>If you remember, in the previous Intruder attack summary, we needed to
go through each request, select the response message, and look out for
the message &ldquo;<strong>Username and/or password incorrect</strong>&rdquo;.</p>
<p>We earlier used the &ldquo;<strong>Length</strong>&rdquo; size option to drill down and focus on
the one with a different size.</p>
<p>The Intruder tool provides us with a better way to do it, called
&ldquo;<strong>Grep - Match</strong>&rdquo;, which helps us to find a specific string in the HTTP
response body using grep and flags it. A more suitable way to view the
results.</p>
<p>In the &ldquo;<strong>Intruder</strong>&rdquo; tab, click on the &ldquo;<strong>Options</strong>&rdquo; sub-tab and scroll
down to &ldquo;<strong>Grep - Match</strong>&rdquo;, then click on the &ldquo;<strong>Clear</strong>&rdquo; button.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Intruder-Grep-Match-Clear.png"
         alt="Figure 5: Burp Suite Grep - Match"/> <figcaption>
            <p>Figure 5: Burp Suite Grep - Match</p>
        </figcaption>
</figure>

<p>If prompts for confirmation, click on &ldquo;<strong>Yes</strong>&rdquo; to clear.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Intruder-Grep-Match-Clear.png"
         alt="Figure 6: Grep Match Clear Confirmation"/> <figcaption>
            <p>Figure 6: Grep Match Clear Confirmation</p>
        </figcaption>
</figure>

<p>In &ldquo;<strong>Grep-Match</strong>&rdquo;, type &ldquo;<strong>incorrect</strong>&rdquo; in a text area and click on
the &ldquo;<strong>Add</strong>&rdquo; button. This word is taken from the invalid user
credentials error message &ldquo;Username and/or password <strong>incorrect</strong>&rdquo;.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Intruder-Grep-Match-Add-Incorrect.png"
         alt="Figure 7: Grep Match Custom String"/> <figcaption>
            <p>Figure 7: Grep Match Custom String</p>
        </figcaption>
</figure>

<p>Make sure &ldquo;<strong>Flag result items with responses matching these
expressions</strong>.&rdquo; is enabled and confirm &ldquo;<strong>incorrect</strong>&rdquo; string is added.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Intruder-Grep-Match-Incorrect.png"
         alt="Figure 8: Grep Match for &ldquo;Incorrect&rdquo; string"/> <figcaption>
            <p>Figure 8: Grep Match for &ldquo;Incorrect&rdquo; string</p>
        </figcaption>
</figure>

<p>Match type &ldquo;<strong>Simple string</strong>&rdquo; suffixed our current requirement.</p>
<p>Finally, click on the &ldquo;<strong>Start attack</strong>&rdquo; button and let us verify
whether the brute-force vulnerability is fixed or not.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Start-Attack-Intruder-Options.png"
         alt="Figure 9: Intruder Start Attack"/> <figcaption>
            <p>Figure 9: Intruder Start Attack</p>
        </figcaption>
</figure>

<p>A new window pops up, and all the Intruder attack summaries will be
displayed. Now, an additional row named &ldquo;<strong>incorrect</strong>&rdquo; is added.</p>
<p>You can see that our grep match pattern is working, as we are able to
view the match count in the &ldquo;<strong>incorrect</strong>&rdquo; row updated for each
request.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Brute-Force-Intruder-Attack-Medium-Result.png"
         alt="Figure 10: Brute Force Attack Result"/> <figcaption>
            <p>Figure 10: Brute Force Attack Result</p>
        </figcaption>
</figure>

<p>If you closely observe, there is one problem. It is slow compared to the
previous brute-force attack.</p>
<p>It seems the DVWA development team added a small delay, but it&rsquo;s still
not stopping us from performing a Brute Force attack.</p>
<p>It took more time than before, but we found a valid password match again
using the brute-force attack.</p>
<p>The one where the &ldquo;<strong>incorrect</strong>&rdquo; count is empty. i.e.,
<strong>admin/password</strong>. As displayed in the above screenshot.</p>
<p>Scroll down to check for the response body and observe a message.
&ldquo;<strong>Welcome to the password protected area of admin</strong>&rdquo;.</p>
<p>Yay!! The vulnerability still remains open. Let&rsquo;s report it back to the
DVWA dev team. 😄</p>
<h2 id="dvwa-informational-optional">DVWA Informational (Optional)</h2>
<p>We are testing this in a DVWA, an intentionally vulnerable environment.
The application also allows us to view the backend code for knowledge
purposes.</p>
<blockquote>
<p>Remember you might not have this option in real-world applications.</p>
</blockquote>
<p>Navigate to the &ldquo;<strong>Brute Force</strong>&rdquo; menu item in the sidebar. On the same
page click on the &ldquo;<strong>View Source</strong>&rdquo; button at the bottom of the page.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Medium-Attack-Page-View-Source.png"
         alt="Figure 11: Brute Force View Source"/> <figcaption>
            <p>Figure 11: Brute Force View Source</p>
        </figcaption>
</figure>

<p>A pop-up window will be loaded, and the code will be displayed.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Sleep-Code.png"
         alt="Figure 12: Brute Force Medium Source Code"/> <figcaption>
            <p>Figure 12: Brute Force Medium Source Code</p>
        </figcaption>
</figure>

<p>Observe that the application delays <strong>2</strong> seconds before sending the
response message back to the client for all failed logins.</p>
<p>In general, the vulnerability can be mitigated in many ways, but
industry best practices should be adhered to.</p>
]]></content:encoded>
    </item>
    <item>
      <title>DVWA Brute Force Attack - High Severity</title>
      <link>https://raghu.io/dvwa-brute-force-attack-high-severity/</link>
      <pubDate>Thu, 04 Aug 2022 11:44:26 +0000</pubDate>
      <guid>https://raghu.io/dvwa-brute-force-attack-high-severity/</guid>
      <description>This detailed post explains Brute-Force Attacks&amp;#39; High severity using DVWA and how improper security fixes can be bypassed. You can also explore a demo to understand the concept better and discover and optimize your attack with the BurpSuite tool.</description>
      <content:encoded><![CDATA[<p>This section will be a kind of recap of the Brute Force vulnerability
covered so far and some additional fine-tuning options available in the
BurpSuite tool.</p>
<h2 id="required-tool-set">Required Tool Set</h2>
<ol>
<li>A working DVWA docker image will be needed.</li>
<li>BurpSuite Community Edition tool.</li>
<li>Wordlists (username.txt and password.txt)</li>
</ol>
<p>If you are unable to follow any of the sections, refer back to the
earlier posts.</p>
<p><a href="/dvwa-brute-force-attack-and-prevention-explained/">DVWA - Brute Force Attack and Prevention
Explained</a>
This detailed guide explains Brute Force Attacks, how they work, and
ways to prevent them.</p>
<p><a href="/dvwa-brute-force-attack-medium-severity/">DVWA Brute Force Attack - Medium</a>
This detailed post explains Brute-Force Attacks&rsquo; Medium severity using
DVWA and how partial security fixes can be bypassed.</p>
<h2 id="dvwa-brute-force-vulnerability---demo">DVWA Brute Force Vulnerability - Demo</h2>
<p>Log into your DVWA environment, and click on the &ldquo;<strong>Security level</strong>&rdquo;
menu on the left sidebar.</p>
<p>Select &ldquo;<strong>High</strong>&rdquo; and click on the submit button, as shown below, to
ensure the Security Level is updated.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Brute-Force-Security-Level-High.png"
         alt="Figure 1: Setting DVWA Security Level to High"/> <figcaption>
            <p>Figure 1: Setting DVWA Security Level to High</p>
        </figcaption>
</figure>

<h2 id="re-testing-scenario">Re-testing Scenario</h2>
<p>Imagine the development team returning again and informing you that the
vulnerability is fixed and needs re-verification.</p>
<p>Let&rsquo;s go ahead and repeat all the steps.</p>
<ol>
<li>Launch the BurpSuite Community Tool.</li>
<li>Navigate to the &ldquo;<strong>Proxy</strong>&rdquo; tab -&gt; &ldquo;<strong>Intercept</strong>&rdquo; sub-tab and
click on the &ldquo;<strong>Open Browser</strong>&rdquo;</li>
<li>Once the Chromium browser is launched, login to the DVWA application
using admin credentials.</li>
<li>Visit the &ldquo;<strong>Brute Force</strong>&rdquo; link in the menu.</li>
<li>Switch to the Burp Suite &ldquo;<strong>Proxy</strong>&rdquo; tab, select the &ldquo;<strong>Intercept</strong>&rdquo;
sub-tab, and toggle &ldquo;<strong>Intercept is Off</strong>&rdquo; to enable it.</li>
<li>Enter the random values in the username and password fields, then
click on &ldquo;<strong>Login</strong>&rdquo;.</li>
<li>The &ldquo;<strong>Intercept</strong>&rdquo; captured login request will be displayed below.</li>
</ol>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-High-Request.png"
         alt="Figure 2: Brute Force Login Request - Security Level High"/> <figcaption>
            <p>Figure 2: Brute Force Login Request - Security Level High</p>
        </figcaption>
</figure>

<p>In line number 1, the test values are placed in the username and
password fields. In line 16, the security level parameter is set to
<strong>high</strong>.</p>
<p>Additionally, a new &ldquo;<strong>user_token</strong>&rdquo; is being passed in the
URL parameter compared to the previous requests.</p>
<p>A copy of the previous request is provided below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BruteForce-Login-Request-Medium.png"
         alt="Figure 3: Brute Force Login Request - Security Level Medium"/> <figcaption>
            <p>Figure 3: Brute Force Login Request - Security Level Medium</p>
        </figcaption>
</figure>

<ol>
<li>
<p>Click on the &ldquo;<strong>Action</strong>&rdquo; button or <strong>right-click</strong> and select
&ldquo;<strong>Send to the Intruder</strong>&rdquo;.</p>
</li>
<li>
<p>In payload positions, &ldquo;<strong>Clear</strong>&rdquo; all the selected payload
placeholders and then select the &ldquo;<strong>Username</strong>&rdquo; value field and the
&ldquo;<strong>Password</strong>&rdquo; value field by clicking the &ldquo;<strong>Add</strong>&rdquo; button for
placing custom payloads.</p>
</li>
</ol>
<figure>
    <img loading="lazy" src="BurpSuite-Intruder-Brute-Force-High.png"/> 
</figure>

<p>Choose the attack type to &ldquo;<strong>Cluster bomb</strong>&rdquo;</p>
<p>The same word list of common usernames and passwords can be used for the
current scenario. Save the text files onto your system or use copy-paste
to load the information in the payloads tab.</p>
<p><strong>usernames.txt</strong></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">admin
</span></span><span class="line"><span class="cl">administrator
</span></span><span class="line"><span class="cl">user
</span></span><span class="line"><span class="cl">john
</span></span><span class="line"><span class="cl">dvwa
</span></span><span class="line"><span class="cl">bob
</span></span><span class="line"><span class="cl">alice
</span></span><span class="line"><span class="cl">root
</span></span><span class="line"><span class="cl">superuser
</span></span><span class="line"><span class="cl">super
</span></span></code></pre></div><p><strong>passwords.txt</strong></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">admin
</span></span><span class="line"><span class="cl">admin123
</span></span><span class="line"><span class="cl">password
</span></span><span class="line"><span class="cl">password123
</span></span><span class="line"><span class="cl">user
</span></span><span class="line"><span class="cl">user123
</span></span><span class="line"><span class="cl">administrator
</span></span><span class="line"><span class="cl">passw0rd
</span></span><span class="line"><span class="cl">r3m3mb3rM3
</span></span><span class="line"><span class="cl">admin123$
</span></span></code></pre></div><p>In the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, select &ldquo;<strong>Payload Set 1</strong>&rdquo;, set the
payload type as &ldquo;<strong>simple list</strong>&rdquo;, and paste all the contents in
<strong>payload options</strong> copied from the <strong>usernames.txt</strong> list.</p>
<p>Second, select the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, set &ldquo;<strong>Payload Set 2</strong>&rdquo;, set
the payload type as &ldquo;<strong>simple list</strong>&rdquo; and paste all the contents in
payload options copied from the <strong>passwords.txt</strong> list.</p>
<p>Switch to the &ldquo;<strong>Options</strong>&rdquo; sub-tab and enable the &ldquo;<strong>Grep - Match</strong>&rdquo;
with the &ldquo;<strong>incorrect</strong>&rdquo; string. so we can understand which requests
have failed.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Intruder-Grep-Match-Incorrect.png"
         alt="Figure 4: Intruder Grep Match - Incorrect string"/> <figcaption>
            <p>Figure 4: Intruder Grep Match - Incorrect string</p>
        </figcaption>
</figure>

<p>Lastly, click on &ldquo;<strong>Start Attack</strong>&rdquo; and monitor the results.</p>
<figure>
    <img loading="lazy" src="Brute-Force-Intuder-Start-Attack-High.png"/> 
</figure>

<h3 id="failed-intruder-attack-results">Failed Intruder Attack Results</h3>
<figure>
    <img loading="lazy" src="Brute-Force-Intruder-Failed-Results.png"/> 
</figure>

<p>Only in one response was the &ldquo;username and/or password incorrect&rdquo; string
found.</p>
<p>For all other requests, we are getting &ldquo;<strong>302</strong>&rdquo; status codes instead of
&ldquo;<strong>200 OK</strong>&rdquo;, which means something is not working and our brute force
attack is failing.</p>
<p>Now, shall we assume that the &ldquo;<strong>Vulnerability is fixed</strong>&rdquo; and close the
security flaw?</p>
<figure>
    <img loading="lazy" src="/icons/thinking.png"/> 
</figure>

<p>Well, we can close it. But this is a strange scenario in which we don&rsquo;t
see errors or warnings.</p>
<p>Let&rsquo;s analyze more thoroughly and see what exactly is happening here.
and why we are getting &ldquo;<strong>302 Found</strong>&rdquo; redirects.</p>
<blockquote>
<p>Remember, you can automate only if application behaviour is
consistent.</p>
</blockquote>
<p>Re-submit the username and password with new random values on the Brute
Force login page and intercept the login request.</p>
<figure>
    <img loading="lazy" src="Brute-Force-Login-Request-High.png"/> 
</figure>

<p>Analyzing with the BurpSuite Tool without going to the browser gives us
more control over the HTTP messages. Therefore, I want to view the HTTP
response messages in the Burp Suite itself.</p>
<p>Let&rsquo;s enable the option to Intercept and view the &ldquo;<strong>Response</strong>&rdquo;
messages received from the server before sending them to the Browser.</p>
<p>Visit the &ldquo;<strong>Proxy</strong>&rdquo; tab -&gt; Select &ldquo;<strong>Options</strong>&rdquo; sub-tab, scroll down
to &ldquo;<strong>Intercept Server Responses</strong>&rdquo; and enable &ldquo;<strong>Intercept responses
based on the following rules</strong>&rdquo; as displayed below.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BurpSuite-Enable-Intercept-Server-Response.png"
         alt="Figure 5: BurpSuite Proxy - Enable Intercept Server Responses"/> <figcaption>
            <p>Figure 5: BurpSuite Proxy - Enable Intercept Server Responses</p>
        </figcaption>
</figure>

<p>Switch to the &ldquo;<strong>Intercept</strong>&rdquo; sub-tab under the &ldquo;<strong>Proxy</strong>&rdquo; tab and
click on the &ldquo;<strong>Forward</strong>&rdquo; button.</p>
<p>The &ldquo;<strong>Forward</strong>&rdquo; button will send the request to the server and now
start &ldquo;<strong>Intercept</strong>&rdquo; immediate HTTP &ldquo;<strong>Response</strong>&rdquo; received from the
server and display it as shown below.</p>
<figure>
    <img loading="lazy" src="BruteForce-Intruder-Response.png"/> 
</figure>

<p>By clicking on the &ldquo;<strong>Forward</strong>&rdquo; button again, the response is now sent
to the browser.</p>
<p>Toggle the proxy &ldquo;<strong>Intercept is on</strong>&rdquo; to disable it.</p>
<p>Use the BurpSuite &ldquo;Chromium browser&rdquo; session, manually try for random
username/passwords say &ldquo;<strong>administrator/admin123</strong>&rdquo;,
&ldquo;<strong>admin/admin123</strong>&rdquo;, &ldquo;<strong>user/user123</strong>&rdquo; etc.. with 4 or 5 incorrect
credentials.</p>
<p>For all incorrect attempts, we keep getting the &ldquo;<strong>Username and/or
password incorrect.</strong>&rdquo; message.</p>
<p>This confirms that the &ldquo;<strong>Brute Force</strong>&rdquo; attack still does exist, which
means the Vulnerability remains Open. Yay!!. :)
<img loading="lazy" src="/icons/success.png"></p>
<p>Now the question is, why is our <strong>Intruder</strong> tool unable to pick it up?</p>
<p>Let&rsquo;s review all the previous HTTP messages and see if we can find any
patterns.</p>
<p>The Burp Suite HTTP message history can be found under the &ldquo;<strong>Proxy</strong>&rdquo;
tab -&gt; &ldquo;<strong>HTTP history</strong>&rdquo; sub-tab.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="BurpSuite-Proxy-HTTP-History.png"
         alt="Figure 6: BurpSuite HTTP History"/> <figcaption>
            <p>Figure 6: BurpSuite HTTP History</p>
        </figcaption>
</figure>

<p>Observing the HTTP GET requests that we have manually tried, the
username and password values are being passed, but one parameter value
keeps on changing in the &ldquo;<strong>URL</strong>&rdquo; section.</p>
<p>Remember a new parameter is being passed on the Login request? Yes,
&ldquo;<strong>user_token</strong>&rdquo;.</p>
<figure>
    <img loading="lazy" src="/icons/idea.png"/> 
</figure>

<p>The &ldquo;<strong>user_token</strong>&rdquo; keeps updating for each request.
Therefore, we cannot use the same &ldquo;user_token&rdquo; for all HTTP
requests.</p>
<p>This is the reason our tool fails. If we perform brute force manually,
<strong>it works!</strong></p>
<h3 id="finding-the-origin-of-user_token">Finding the origin of &ldquo;user_token&rdquo;</h3>
<p>Let&rsquo;s find out from where the &ldquo;<strong>user_token</strong>&rdquo; is being set
and updated.</p>
<p>In the case of HTTP, it can be set in Headers, Response Bodies, or
Cookies. Let&rsquo;s review the HTTP responses received one by one.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Brute-Force-Response-User-Token.png"
         alt="Figure 7: Finding User Token"/> <figcaption>
            <p>Figure 7: Finding User Token</p>
        </figcaption>
</figure>

<p>After a thorough review Of one of the requests from <strong>HTTP history</strong>, I
was able to find out it is being set in &ldquo;<strong>HTTP Response Body</strong>&rdquo;</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-html" data-lang="html"><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&#39;hidden&#39;</span> <span class="na">name</span><span class="o">=</span><span class="s">&#39;user_token&#39;</span> <span class="na">value</span><span class="o">=</span><span class="s">&#39;90f9f7a06213b032dbe9e5d1d4717ce0&#39;</span> <span class="p">/&gt;</span>
</span></span></code></pre></div><p>The code is a simple HTML tag that is hidden in the background of the
&ldquo;Login&rdquo; page and passed every time when the user submits &ldquo;<strong>username</strong>&rdquo;
and &ldquo;<strong>password</strong>&rdquo; credentials.</p>
<p>Based on the above request, the HTML input tag is dynamically generated
on the fly with an updated &ldquo;<strong>user_token</strong>&rdquo;.</p>
<p>We found the source! Can you automate it with Burp Intruder? <strong>Yes</strong></p>
<p>One more important point to discuss before we proceed.
<img loading="lazy" src="/icons/process.png"></p>
<h2 id="choosing-the-intruder-attack-type">Choosing the Intruder Attack Type</h2>
<p>Guess what the attack type could be here?</p>
<p>Cluster Bomb? <strong>NO</strong></p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Pitch-Fork--Cluster-Bomb.png"
         alt="Figure 8: Pitchfork vs Cluster Bomb"/> <figcaption>
            <p>Figure 8: Pitchfork vs Cluster Bomb</p>
        </figcaption>
</figure>

<p>Remember what the &ldquo;<strong>Cluster bomb</strong>&rdquo; does? It tries out all possible
permutations and combinations by varying the first &ldquo;<strong>Payload 1</strong>&rdquo; and
keeping the &ldquo;<strong>Payload 2</strong>&rdquo; standard, then jumps to the next
permutation.</p>
<blockquote>
<p>A big challenge here is, you cannot keep the
&ldquo;<strong>user_token</strong>&rdquo; same for multiple requests.</p>
</blockquote>
<p>Therefore, the &ldquo;cluster bomb&rdquo; doesn&rsquo;t meet our requirements.</p>
<h3 id="what-about-pitchfork">What about &ldquo;Pitchfork&rdquo;?</h3>
<p>Yes, the &ldquo;<strong>Pitchfork</strong>&rdquo; option helps in the current scenario. Takes the
first payload from &ldquo;<strong>Payload set 1</strong>&rdquo; and the first payload from
&ldquo;<strong>Payload set 2</strong>&rdquo; and then iterates through.</p>
<p>Overall, our current wordlist of <strong>usernames</strong> and <strong>passwords</strong>
generates only 10 possible payload requests, as shown below.</p>
<p>We could definitely miss our valid combination match. i.e.,
&ldquo;<strong>admin/password</strong>&rdquo;.</p>
<p>So, to brute force from here on, we need to use the username, which
definitely exists on the server. (say &ldquo;<strong>admin</strong>&rdquo;)</p>
<p>The DVWA dev team gave us a good challenge. Let&rsquo;s put in additional
efforts to perform the Brute Force attack.</p>
<h2 id="fine-tuning-the-intruder-payload">Fine-tuning the Intruder Payload</h2>
<p>Repeat all the steps from step 1 to step 7 mentioned above, from the
launching of the BurpSuite to sending the new log-in request to the
intruder.</p>
<blockquote>
<p>Use a completely new intercepted Login request, else intruder is bound
to fail.</p>
</blockquote>
<figure>
    <img loading="lazy" src="Brute-Force-Intruder-Select-Payloads-Custom.png"/> 
</figure>

<p>Choose the &ldquo;<strong>Pitchfork</strong>&rdquo; attack type and select two payload positions.
i.e. <em>password</em> value field and <strong>user_token</strong> value field
as displayed above.</p>
<p>This time for payloads, the first position will be of the password value
field and the second position will be of the user_token value
field.</p>
<p>Select the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, set &ldquo;Payload Set <strong>1</strong>&rdquo;, payload type
as &ldquo;<strong>simple list</strong>&rdquo; and paste the <strong>passwords.txt</strong> list contents into
payload options.</p>
<p>Second, select the &ldquo;<strong>Payloads</strong>&rdquo; sub-tab, set &ldquo;Payload Set <strong>2</strong>&rdquo;, and
payload type as &ldquo;<strong>recursive grep</strong>&rdquo; from the list. This is for the
&ldquo;<strong>user_token</strong>&rdquo; field.</p>
<figure>
    <img loading="lazy" src="Brute-Force-Intruder-Recursive-Grep-Payload.png"/> 
</figure>

<p>The &ldquo;<strong>recursive grep</strong>&rdquo; is used when you want to extract specific data
from the previous response and use it in the request as a payload.</p>
<p>The &ldquo;<strong>Grep - Extract</strong>&rdquo; feature is used to find specific strings based
on the pattern or use regular expressions to get useful information from
the HTTP response.</p>
<figure class="mx-auto block text-center">
    <img loading="lazy" src="Grep-Extract.png"
         alt="Figure 9: Grep Extract - Add"/> <figcaption>
            <p>Figure 9: Grep Extract - Add</p>
        </figcaption>
</figure>

<p>Next, go to the &ldquo;<strong>Intruder</strong>&rdquo; tab -&gt; &ldquo;<strong>Options</strong>&rdquo; sub-tab, scroll
down to &ldquo;<strong>Grep Extract</strong>&rdquo; and click on the &ldquo;<strong>Add</strong>&rdquo; button.</p>
<p>A new window named &ldquo;Define extract grep item&rdquo; is loaded.</p>
<p>In the &ldquo;<strong>Define extract grep item</strong>&rdquo; window, click on the &ldquo;<strong>Fetch
Response</strong>&rdquo; button on the right side.</p>
<figure>
    <img loading="lazy" src="Brute-Force-Intruder-Fetch-Response.png"/> 
</figure>

<p>The &ldquo;<strong>Fetch response</strong>&rdquo; will take the currently configured request in
the &ldquo;<strong>fetch</strong>&rdquo; tab and fetch, the server response for it.</p>
<p>Once the HTTP response is loaded, Using the mouse select the
user_token value then select only the value string highlighted
as shown below.</p>
<figure>
    <img loading="lazy" src="Grep-Extract-Copy-Brute-Force-Payload.png"/> 
</figure>

<p>The &ldquo;<strong>Start after expression</strong>&rdquo; and &ldquo;<strong>End at delimiter</strong>&rdquo; values will
be auto-populated. Just click on the &ldquo;<strong>OK</strong>&rdquo; button to proceed.</p>
<figure>
    <img loading="lazy" src="Grep-Extract-Brute-Force-Pitchfork.png"/> 
</figure>

<p>Use &ldquo;<strong>Ctrl - c</strong>&rdquo; to copy the token value
&ldquo;<strong>1802dab0e42ee4ef48e71d491981abb1</strong>&rdquo; will be used for updating initial
payload.</p>
<p>Switch back to the Intruder Payloads section. Observe the &ldquo;<strong>Grep
Extract</strong>&rdquo; pattern updated and displayed in &ldquo;Payload Options&rdquo;.</p>
<figure>
    <img loading="lazy" src="Brute-Force-Intruder-Payload-Set-2.png"/> 
</figure>

<p>Now, set the &ldquo;<strong>initial payload for first request</strong>&rdquo; value as the one we
copied earlier, the latest token &ldquo;<strong>1802dab0e42ee4ef48e71d491981abb1</strong>&rdquo;.</p>
<p>All set, but there is one more thing to do.</p>
<blockquote>
<p>Remember, a new user_user token can be fetched only when you
send each request one by one after updating. If thrown multiple
concurrent requests at once than we can&rsquo;t get correct user token in
sequence.</p>
</blockquote>
<p>In the &ldquo;Intruder&rdquo; tab &ldquo;<strong>Resource Pool</strong>&rdquo; is a place where we can
fine-tune the number of threads to use or delay between requests etc.</p>
<p>Navigate to the &ldquo;<strong>Intruder</strong>&rdquo; tab and select the &ldquo;<strong>Resource Pool</strong>&rdquo;
sub-tab. Select &ldquo;<strong>Create new resource pool</strong>&rdquo; named &ldquo;Brute Force
Attack - High&rdquo;.</p>
<figure>
    <img loading="lazy" src="Brute-Force-Intruder-Resource-Pool-Set.png"/> 
</figure>

<p>Set the &ldquo;<strong>Maximum concurrent requests</strong>&rdquo; to <strong>1</strong>.</p>
<p>Done, we have configured our intruder and now click to &ldquo;<strong>Start
attack</strong>&rdquo; button.</p>
<figure>
    <img loading="lazy" src="Brute-Force-Intruder-Attack-Summary-High.png"/> 
</figure>

<p><strong>Wow!! finally accomplished</strong>. 😄</p>
<p>The intruder configuration works, and we no longer see the &ldquo;<strong>302
Found</strong>&rdquo; redirect status codes being displayed.</p>
<p>Observe the user_token value taken from the previous response
field, displayed under the &ldquo;value&rdquo; row and updated in the request as the
&ldquo;Payload 2&rdquo;. The fine-tuning worked!</p>
<p>Let&rsquo;s check the one with of different length &ldquo;<strong>4792</strong>&rdquo; and Yes, We
found our credentials match (<strong>admin/password</strong>).</p>
<p>The &ldquo;<strong>Grep - Match</strong>&rdquo; flags can also be enabled.</p>
<p><strong>Well done!!</strong> 🎉</p>
<p>Thus, the Brute force vulnerability still remains open.</p>
<p>We have covered a lot of ground here to exploit the Brute Force attack.
Re-visit the article and keep practicing until you become familiar with
it.</p>
<p>Check out the below article to learn more about prevention techniques.</p>
<p><a href="/dvwa-brute-force-attack-and-prevention-explained/">DVWA - Brute Force Attack and Prevention
Explained</a></p>
]]></content:encoded>
    </item>
    <item>
      <title>Mitigating Command Injection</title>
      <link>https://raghu.io/mitigating-command-injection/</link>
      <pubDate>Wed, 10 Aug 2022 09:47:10 +0000</pubDate>
      <guid>https://raghu.io/mitigating-command-injection/</guid>
      <description>Mitigation Recommendations for Command Injection Vulnerability</description>
      <content:encoded><![CDATA[<p>In this post, we will be covering the ways available to mitigate the
command injection vulnerability.</p>
<p>Firstly, we will go through the standard practices that are generally
used for mitigating the command injection vulnerabilities, followed by
we will be covering how the vulnerability has been fixed in the DVWA
application.</p>
<figure>
    <img loading="lazy" src="/icons/firewall1.png"/> 
</figure>

<h2 id="avoid-calling-os-command-directly">Avoid Calling OS Command Directly</h2>
<p>One of the most effective ways is to avoid calling all the system
commands directly by taking from the user input.</p>
<p>Using the <strong>built-in library functions</strong> is a good option, as it
performs the tasks intended without tampering.</p>
<p>In our command injection examples, the application takes the domain
name, and IP address then followed by we could append the additional
system commands. The application doesn&rsquo;t filter and is directly passed
on to the server for execution.</p>
<p>If you were able to view the source code, the
&ldquo;<strong>shell_exec()</strong>&rdquo; function in PHP is being used for taking
all our user inputs and passing them to the server.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">shell_exec<span class="o">(</span> <span class="s1">&#39;ping -c 4&#39;</span> . USER_INPUT <span class="o">)</span><span class="p">;</span>
</span></span></code></pre></div><p>The <strong>escapeshellcmd()</strong> or <strong>escapeshellarg()</strong> can be used instead of
&ldquo;<strong>shell_exec()</strong>&rdquo; to prevent command injection. What it does
is, it passes everything within a single quote ensuring to run all of
one text rather than breaking it into multiple commands.</p>
<p>If you think, in your current scenario you can not avoid it but that&rsquo;s
the only way to go ahead. then there are other ways to mitigate it.
<img loading="lazy" src="/icons/regulation.png"></p>
<h2 id="whitelisting">Whitelisting</h2>
<p>As we covered whitelisting earlier. Whitelisting is an approach of
letting only what you trust and rejecting all the unknown.</p>
<ul>
<li>Allowing only the valid characters, like small case letters, upper
case letters, and numerics.</li>
<li>Limiting only the special characters which are supposed to be used.
(say, allow period &ldquo;.&rdquo; and reject all)</li>
<li>Only allowing the system command that the user is supposed to use.</li>
</ul>
<p>In the command injection &ldquo;<strong>high</strong>&rdquo; example, we say the blacklisting is
being used to filter a lot of characters, where the &lsquo;<strong>|</strong>&rsquo; <strong>OR</strong> and
<strong>SPACE</strong> operator are being filtered than of &ldquo;<strong>|</strong>&rdquo; only OR operator.</p>
<p>Blacklisting can be used but is more of an error-prone approach.</p>
<figure>
    <img loading="lazy" src="/icons/input.png"/> 
</figure>

<h2 id="strong-input-validation">Strong Input Validation</h2>
<p>Validating the inputs in conjunction with whitelisting provides a strong
defense.</p>
<p>Treating every input from the client can be tampered with, verifying the
inputs and ensuring it is clean from all types of malicious payloads.</p>
<p>A <strong>parameterization</strong> is an option where the command and the input data
can be segregated using a structured mechanism. This helps in quoting
the input data before processing.</p>
<p>Never escape the user input with metacharacters directly as it is more
error-prone.</p>
<p>Additionally, the <strong>Regular Expressions</strong> can also be used for filtering
the input before processing.</p>
<figure>
    <img loading="lazy" src="/icons/access.png"/> 
</figure>

<h2 id="least-privilege-user-account">Least Privilege User Account</h2>
<p>Use a user account with minimal privileges to execute the needed system
operations on the server rather than one having admin privileges.</p>
<figure>
    <img loading="lazy" src="/icons/bug.png"/> 
</figure>

<h2 id="command-injection---fix-dvwa">Command Injection - Fix (DVWA)</h2>
<p>Let&rsquo;s see how the vulnerability was fixed in the DVWA application.</p>
<p>Log into the DVWA application and set the security level to
&ldquo;<strong>Impossible</strong>&rdquo;.</p>
<p>Navigate to the &ldquo;<strong>Command Injection</strong>&rdquo; and click on the &ldquo;<strong>View
Source</strong>&rdquo; button at the bottom.</p>
<blockquote>
<p>Note, only the partial code is displayed below.</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-php" data-lang="php"><span class="line"><span class="cl"><span class="c1">// Split the IP into 4 octects
</span></span></span><span class="line"><span class="cl"><span class="nv">$octet</span> <span class="o">=</span> <span class="nx">explode</span><span class="p">(</span> <span class="s2">&#34;.&#34;</span><span class="p">,</span> <span class="nv">$target</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// Check IF each octet is an integer
</span></span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">if</span><span class="p">(</span> <span class="p">(</span> <span class="nx">is_numeric</span><span class="p">(</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span> <span class="nx">is_numeric</span><span class="p">(</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span> <span class="nx">is_numeric</span><span class="p">(</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span> <span class="nx">is_numeric</span><span class="p">(</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span> <span class="nx">sizeof</span><span class="p">(</span> <span class="nv">$octet</span> <span class="p">)</span> <span class="o">==</span> <span class="mi">4</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">// If all 4 octets are int&#39;s put the IP back together.
</span></span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="nv">$target</span> <span class="o">=</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">.</span> <span class="s1">&#39;.&#39;</span> <span class="o">.</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">.</span> <span class="s1">&#39;.&#39;</span> <span class="o">.</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">.</span> <span class="s1">&#39;.&#39;</span> <span class="o">.</span> <span class="nv">$octet</span><span class="p">[</span><span class="mi">3</span><span class="p">];</span>
</span></span><span class="line"><span class="cl">  <span class="c1">// Determine OS and execute the ping command.
</span></span></span></code></pre></div><p>Code Snippet 1: Command Injection - Mitigation</p>
<p>In the above screenshot, the developer now has removed all types of
blacklisting approaches and moved to a whitelist.</p>
<p>At the moment, only numeric IP addresses and a special character of a
dot are allowed and reject all the other input.</p>
<p>This reduces the attack surface to a greater extent for exploitation.</p>
<p>More information about the mitigation techniques can be found on the <a href="https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html?ref=raghu.io">OS
Command Injection Defense - OWASP Cheat
Sheet.</a></p>
<p>I Hope, Now you can secure your web applications from the command
injection vulnerabilities. Thank you! :)</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
