THC Hydra is a powerful tool to use against login forms. It can perform brute force and dictionary attacks against different types of applications and services.
When a web application relies on usernames and passwords as its only line of defense, a pentester or a malicious user can use Hydra to perform a dictionary attack against it. This will allow them to retrieve the credentials of existing users that they may then use to gain unauthorized access to a restricted page.
Hydra can attack not only web forms, but also many other protocols, including SSH, SMB, FTP, and many others. However, in this article, we will only focus on attacking a web application login form.
Downloading THC Hydra
Hydra is compatible with Windows, macOS, and Linux.
If you are using Kali Linux, then you should already have Hydra installed.
If not, then you can download it by visiting the official Github repository of the product and checking for the latest release.
Once the download is complete, you can compile and install Hydra by running the following commands in sequence:
./configure make make install
You might also need to install some dependencies for Hydra to work without issues.
Here is the command to run for Debian-based distributions. You should look for the equivalent libraries for your distribution if these do not work for you.
apt-get install libssl-dev libssh-dev libidn11-dev libpcre3-dev libgtk2.0-dev libmysqlclient-dev libpq-dev libsvn-dev firebird-dev libmemcached-dev libgpg-error-dev libgcrypt11-dev libgcrypt20-dev
In order to have a web application against which we can test Hydra, I will be using DVWA. This is a vulnerable web application that you can use to test your hacking skills legally against a real target. You can go ahead and download it if you want to reproduce the steps that I will cover here in your own environment. Otherwise, you can just follow along.
So now that we have everything ready and set, let’s go ahead and start.
Identifying the Form Parameters
Ok, so now we are going to attack the following login form:
It is located on my local machine in the following URL: http://localhost/DVWA/vulnerabilities/brute/
The first thing we need to do is to identify the form parameters, and also the method that is used. There are many ways you can do this.
For our case, we are going to check the source code of the page and then try to locate the code block that is associated with our login form.
Here is what we got :
So, what can we deduce from this?
First of all, we can tell that the form uses the GET method.
We also know that when submitted, the form redirects to the same page (We can deduce this from the “#” value that is assigned to “action”).
And finally, we know that we have three parameters:
- username: This will have the username value.
- password: This will have the password value.
- Login: This is associated with the submit button, and will have a fixed value of ‘Login‘
Getting a Wordlist
Whenever you intend to perform a dictionary attack using THC Hydra, you will have two options.
Depending on the information that you may or may not have gained on your target, you can either :
- Provide Hydra with two files, (also called wordlists): One that contains a list of candidate usernames, and the other containing candidate passwords;
- Or, if you are lucky enough to know a username, you can provide it only with one wordlist for the passwords along with a single username. Note that you can also do the opposite, meaning that you can provide a single password and a wordlist for possible users (which can be useful during a password spraying attack).
For our case, we do not know the username, so we will use option 1 and therefore we will provide 2 wordlists.
When we launch hydra, it will try all combinations of users and passwords that exist in these 2 wordlists.
If you do not have a wordlist for usernames and passwords, you can download what you need from SecLists. This is a collection of wordlists for all sorts of dictionary attacks.
Writing the THC Hydra Command
Now that we have all the elements that we need, let’s create our Hydra command.
The syntax for running hydra to brute force a login form is as follow:
hydra -L USERFILE -P PASSWORDFILE DOMAIN/IP METHOD "REDIRECTIONURL:PARAMETERS:FAILMESSAGE:H=COOKIES"
Here is what each element means:
- USERFILE : The wordlist for candidate usernames.
- PASSWORDFILE : The wordlist for candidate passwords.
- DOMAIN/IP : The domain name or the IP address of the target web application. For our case, that’s “localhost”.
- METHOD : Since we have a GET method, we’ll use here http-get-form. If we had POST, we would have used http-post-form.
- REDIRECTIONURL : This is the complete url to where form redirects us after pressing submit. So, for our case, we’ll use ‘/DVWA/vulnerabilities/brute/’.
- PARAMETERS : This is where we will type in our parameters. This will equal the following : “username=^USER^&password=^PASS^&Login=Login”, where ^USER^ and ^PASS^ are placeholders for the values in the username and password wordlists respectively.
- FAILMESSAGE : This is the error message that the web application shows when we type in incorrect credentials. This is how Hydra will know that it got the correct username and password. To get this message, we can simply fill in the form with incorrect credentials. When we try to do this on our target, we get the following message:
- COOKIES : This value is not always necessary, but sometimes it can be required. For example, if you need to be authenticated to access your target page, then you need to provide Hydra with the cookies related to your authenticated session. Otherwise, it wouldn’t be able to access the page. So to retrieve the value to use for the cookie, you should right-click on the web page and select Inspect. On the developer tools that appear, select the storage option, and then click on cookies (This method may differ depending on your web browser). By following this process, here is what I got:
Launching the Attack
Now, our command should look something like this :
I have added the -V flag at the end of the command for a verbose output. This tells Hydra to show on the screen, not only the found credentials, but also all the failed attempts.
When we launch our command, we should see Hydra trying a combination of usernames and passwords.
After a few attempts, Hydra finds the correct username and password.
As this post demonstrates, we were successful here because the username and password were ridiculously simple. If there was enough complexity, it would have taken us a lot more time to find the correct credentials.
THC Hydra was developed as a proof of concept to demonstrate how easy it is to hack passwords. It supports many capabilities and includes a lot of modules with interesting features. We have barely scratched the surface in this article.
If you want to get a wider grasp of what Hydra is capable of, I invite you to read the help :