Dictionary and Brute-Force Based
This section discusses offline attacks, including dictionary, brute-force, and rule-based attacks.
Dictionary attack
A dictionary attack is a technique used to guess passwords by using well-known words or phrases. The dictionary attack relies entirely on pre-gathered wordlists that were previously generated or found. It is important to choose or create the best candidate wordlist for your target in order to succeed in this attack. Let’s explore performing a dictionary attack using what you’ve learned in the previous tasks about generating wordlists. We will showcase an offline dictionary attack using hashcat, which is a popular tool to crack has@hes.
Let’s say that we obtain the following hash f806fc5a2a0d5ba2471600758452799c, and want to perform a dictionary attack to crack it. First, we need to know the following at a minimum:
1- What type of hash is this?
2- What wordlist will we be using? Or what type of attack mode could we use?
To identify the type of hash, we could a tool such as hashid or hash-identifier. For this example, hash-identifier believed the possible hashing method is MD5. Please note the time to crack a hash will depend on the hardware you’re using (CPU and/or GPU).
-a
0 sets the attack mode to a dictionary attack
-m 0
sets the hash mode for cracking MD5 hashes; for other types, run hashcat -h
for a list of supported hashes.
f806fc5a2a0d5ba2471600758452799c
this option could be a single hash like our example or a file that contains a hash or multiple hashes.
/usr/share/wordlists/rockyou.txt
the wordlist/dictionary file for our attack
We run hashcat
with --show
option to show the cracked value if the hash has been cracked:
As a result, the cracked value is rockyou
.
Brute-Force attack
Brute-forcing is a common attack used by the attacker to gain unauthorized access to a personal account. This method is used to guess the victim’s password by sending standard password combinations. The main difference between a dictionary and a brute-force attack is that a dictionary attack uses a wordlist that contains all possible passwords.
In contrast, a brute-force attack aims to try all combinations of a character or characters. For example, let’s assume that we have a bank account to which we need unauthorized access. We know that the PIN contains 4 digits as a password. We can perform a brute-force attack that starts from 0000 to 9999 to guess the valid PIN based on this knowledge. In other cases, a sequence of numbers or letters can be added to existing words in a list, such as admin0, admin1, .. admin9999.
For instance, hashcat has charset options that could be used to generate your own combinations. The charsets can be found in hashcat help options.
The following example shows how we can use hashcat
with the brute-force attack mode with a combination of our choice.
-a 3
sets the attacking mode as a brute-force attack
?d?d?d?d
the ?d tells hashcat to use a digit. In our case, ?d?d?d?d for four digits starting with 0000 and ending at 9999
--stdout
print the result to the terminal
Now let’s apply the same concept to crack the following MD5 hash: 05A5CF06982BA7892ED2A6D38FE832D6
a four-digit PIN number.
Rule-based
Rule-Based attacks
Rule-Based attacks are also known as hybrid attacks. Rule-Based attacks assume the attacker knows something about the password policy. Rules are applied to create passwords within the guidelines of the given password policy and should, in theory, only generate valid passwords. Using pre-existing wordlists may be useful when generating passwords that fit a policy — for example, manipulating or ‘mangling’ a password such as ‘password’: p@ssword
, Pa$$word
, Passw0rd
, and so on.
For this attack, we can expand our wordlist using either hashcat
or John the ripper
. However, for this attack, let’s see how John the ripper
works. Usually, John the ripper has a config file that contains rule sets, which is located at /etc/john/john.conf
or /opt/john/john.conf
depending on your distro or how john was installed. You can read /etc/john/john.conf
and look for List.Rules
to see all the available rules:
We can see that we have many rules that are available for us to use. We will create a wordlist with only one password containing the string tryhackme, to see how we can expand the wordlist. Let’s choose one of the rules, the best64 rule, which contains the best 64 built-in John rules, and see what it can do!
--wordlist=
to specify the wordlist or dictionary file.
--rules
to specify which rule or rules to use.
--stdout
to print the output to the terminal.
|wc -l
to count how many lines John produced.
By running the previous command, we expand our password list from 1 to 76 passwords. Now let’s check another rule, one of the best rules in John, KoreLogic. KoreLogic uses various built-in and custom rules to generate complex password lists. For more information, please visit this website here. Now let’s use this rule and check whether the Tryh@ckm3 is available in our list!
The output from the previous command shows that our list has the complex version of tryhackme, which is Tryh@ckm3. Finally, we recommend checking out all the rules and finding one that works the best for you. Many rules apply combinations to an existing wordlist and expand the wordlist to increase the chance of finding a valid password!
Custom Rules
John the ripper has a lot to offer. For instance, we can build our own rule(s) and use it at run time while john is cracking the hash or use the rule to build a custom wordlist!
Let’s say we wanted to create a custom wordlist from a pre-existing dictionary with custom modification to the original dictionary. The goal is to add special characters (ex: !@#$*&) to the beginning of each word and add numbers 0-9 at the end. The format will be as follows:
[symbols]word[0-9]
We can add our rule to the end of john.conf:
[List.Rules:THM-Password-Attacks]
specify the rule name THM-Password-Attacks.
Az
represents a single word from the original wordlist/dictionary using -p.
"[0-9]"
append a single digit (from 0 to 9) to the end of the word. For two digits, we can add "[0-9][0-9]"
and so on.
^[!@#$]
add a special character at the beginning of each word. ^
means the beginning of the line/word. Note, changing ^ to $ will append the special characters to the end of the line/word.
Now let’s create a file containing a single word password to see how we can expand our wordlist using this rule.
We include the name of the rule we created in the John command using the —rules option. We also need to show the result in the terminal. We can do this by using —stdout as follows:
NOTE: for format [symbol][dictionary word][0-9][0-9]
, the rule is: Az"[0-9][0-9]" ^[!@#$]