Brute Force
Alongside packet captures, MITM attacks, and the defences against them (TLS and SSH), this room covers a third class of attack: going after passwords.
Many protocols require authentication, which is proving who you claim to be. With a protocol such as POP3, the server should not hand over the mailbox before our identity is verified. The POP3 example from the Protocols and Servers room is repeated below. Here we are identified as the user frank, and the server authenticates us because we supply the correct password. The password is one way to handle authentication.
POP3 session over Telnet
pentester@TryHackMe$ telnet MACHINE_IP 110
Trying MACHINE_IP...
Connected to MACHINE_IP.
Escape character is '^]'.
+OK MACHINE_IP Mail Server POP3 Wed, 15 Sep 2021 11:05:34 +0300
USER frank
+OK frank
PASS D2xc9CgD
+OK 1 messages (179) octets
STAT
+OK 1 179
LIST
+OK 1 messages (179) octets
1 179
.
RETR 1
+OK
From: Mail Server
To: Frank
subject: Sending email with Telnet
Hello Frank,
I am just writing to say hi!
.
QUIT
+OK MACHINE_IP closing connection
Connection closed by foreign host.
Authentication can be achieved through one of the following, or a combination of two:
- Something you know, such as a password or PIN code.
- Something you have, such as a SIM card, RFID card, or USB dongle.
- Something you are, such as a fingerprint or iris.
This task focuses on attacks against passwords, i.e. something the target knows. Revisiting the earlier servers running Telnet, SSH, POP3, and IMAP, every one of them needed a password for access. Based on the 150 million usernames and passwords leaked in the 2013 Adobe breach, the top ten passwords were:
- 123456
- 123456789
- password
- adobe123
- 12345678
- qwerty
- 1234567
- 111111
- photoshop
- 123123
Only two of these relate to Adobe and its products; the rest are generic. You might expect this to have changed over the past decade, but 123456, 1234567, 12345678, and 123456789 are still common choices. Others still haven't realized that qwerty is not a secret, yet many use it as their password.
Types of password attack
Attacks against passwords are usually carried out by:
- Password Guessing: Guessing a password requires some knowledge of the target, such as their pet's name and birth year.
- Dictionary Attack: This approach expands on password guessing and attempts to include all valid words in a dictionary or a wordlist.
- Brute Force Attack: The most exhaustive and time-consuming attack, where an attacker can go as far as trying all possible character combinations. The work grows fast (exponential growth with the number of characters).
Dictionary attacks with Hydra
Over time, attackers have compiled list after list of leaked passwords from data breaches. One example is RockYou's list of breached passwords, which is on the AttackBox at /usr/share/wordlists/rockyou.txt. The choice of wordlist should depend on your knowledge of the target. A French user might pick a French word rather than an English one, so a French wordlist would be more promising there.
To try common passwords or wordlist entries automatically, we use THC Hydra. Hydra supports many protocols, including FTP, POP3, IMAP, SMTP, SSH, and all methods related to HTTP. The general syntax is:
hydra -l username -P wordlist.txt server service
-l username:-lprecedes theusername, i.e. the login name of the target.-P wordlist.txt:-Pprecedes thewordlist.txtfile, a text file containing the list of passwords to try with the provided username.serveris the hostname or IP address of the target server.serviceindicates the service you are launching the dictionary attack against.
Some concrete examples:
hydra -l mark -P /usr/share/wordlists/rockyou.txt MACHINE_IP ftpusesmarkas the username as it iterates over the provided passwords against the FTP server.hydra -l mark -P /usr/share/wordlists/rockyou.txt ftp://MACHINE_IPis identical to the previous example.MACHINE_IP ftpis the same asftp://MACHINE_IP.hydra -l frank -P /usr/share/wordlists/rockyou.txt MACHINE_IP sshusesfrankas the username as it tries to log in via SSH using the different passwords.
Optional arguments
-s PORTto specify a non-default port for the service in question.-Vor-vV, for verbose, makes Hydra show the username and password combinations being tried. This is convenient for seeing progress, especially when you are still not confident of your command-line syntax.-t nwhere n is the number of parallel connections to the target.-t 16creates 16 threads used to connect to the target.-d, for debugging, gives more detailed information about what's going on. The debugging output can save much frustration; for instance, if Hydra tries to connect to a closed port and times out,-dreveals this right away.
Once the password is found, you can issue CTRL-C to end the process. In TryHackMe tasks, any attack is expected to finish in less than five minutes; in real-life scenarios it would usually take longer. The verbosity and debugging options are handy when you want Hydra to keep you updated on its progress.
Mitigation
Attacks against login systems can be carried out efficiently with a tool like THC Hydra combined with a suitable wordlist. Mitigation can be sophisticated and depends on the target system. A few approaches:
- Password Policy: Enforces minimum complexity constraints on the passwords set by the user.
- Account Lockout: Locks the account after a certain number of failed attempts.
- Throttling Authentication Attempts: Delays the response to a login attempt. A couple of seconds of delay is tolerable for someone who knows the password, but it can severely hinder automated tools.
- Using CAPTCHA: Requires solving a question that is difficult for machines. It works well if the login page is via a graphical user interface (GUI). (CAPTCHA stands for Completely Automated Public Turing test to tell Computers and Humans Apart.)
- Requiring a public certificate for authentication: This works well with SSH, for instance.
- Two-Factor Authentication: Asks the user to provide a code available via other means, such as email, a smartphone app, or SMS.
- There are many other, more sophisticated approaches, some of which require established knowledge about the user, such as IP-based geolocation.
Combining several of the above is an excellent way to protect against password attacks.