In this lesson, we're going to talk about
different types of hash attacks.
We'll also explain how hashes are used
to support authentication and password storage.
We'll also discuss how hash security can be increased
through salting and key stretching.
First, let's look at collision attacks.
A collision attack occurs when two different inputs
produce the same hash value.
This can be bad news for the integrity of data,
because if an attacker can produce the same hash value
with a different input,
they can potentially manipulate data without detection.
One common type of collision attack is a birthday attack.
The birthday attack is based on a birthday paradox
and probability theory that states that
in a group of 23 people, there's a better than 50% chance
that two people will share the same birthday.
Similarly, with hash functions, finding two different inputs
that produce the same hash value is easier than expected.
This is because of the way hash functions compress data
into fixed size outputs.
If an attacker can find two different inputs
that hash into the same value,
they can substitute one for the other without detection.
For example, if an attacker can find two different passwords
that produce the same hash,
they can use either password to gain access to the system.
To demonstrate a birthday attack,
an attacker might use a tool like Hashcat
to find collisions with the following command,
hashcat -m 0 -a 3 -o collisions.txt
hash.txt and then we have a string of characters.
In this command,
the -m 0 option specifies the hash type, which is MD5.
The -a three specifies a brute forcing attack mode.
The -o collisions text specifies the output file
for the collisions that are found.
The hash.txt is the file containing the target hash.
And then the ?a?a?a?a?a
specifies the mask for the brute force search.
Next, let's explain how hashes are used
to support authentication and store passwords.
A hash function takes input such as a password
and produces a fixed size string of characters,
which appears random.
This hashed value is stored
instead of the plain text password.
When the user logs in, their password is hashed
and the hash is compared to the stored hash.
If they match, authentication is successful.
Hashes are critical
because they ensure that passwords are not stored
in plain text, which protects them
even if the database is compromised.
However, hash functions alone are not enough
to secure passwords against attacks like brute force
or dictionary attacks.
To increase hash security, techniques like salting
and key stretching are used.
Salting involves adding a unique random value
to each password before it is hashed.
This ensures that even if two users have the same password,
their hashes will be different.
Salts prevent attackers from using pre-computed tables,
known as rainbow tables, to crack hashes quickly.
For example, if a user password is password123,
and the salt value equals randomSalt,
the hash function will process randomSaltpassword123,
instead of just password123.
Key stretching is another technique used
to enhance hash security
and involves applying a hash function multiple times
to increase the CPU power required to hash each password.
This makes brute force
and dictionary attacks more time consuming
and resource intensive.
A common key stretching algorithm is PBKDF2.
For example, PBKDF2 applies repeatedly with the number
of integrations configurable
to balance security and performance.
So remember, collision attacks exploit the fact
that two different inputs can produce the same hash,
compromising data integrity.
Hashes are used to securely store passwords
and support authentication.
Techniques like salting and key stretching,
such as PBKDF2, significantly increase security hash
by adding randomness and computational effort.
Understanding these methods will help you implement robust
security practices in your pentest
and cybersecurity scenarios.