Objective: Use offline dictionary-based or brute-force techniques to crack password hashes stored in the /etc/shadow
file, and understand how to secure password storage against such attacks.
Scenario: The /etc/shadow
file on Linux systems contains hashed passwords for user accounts. If an attacker gains access to this file, they can attempt to crack the password hashes using offline techniques. Your task is to simulate this process using tools like John the Ripper and Hashcat, and implement strategies to secure password storage.
Lab Setup
- Environment:
- A Linux system with access to the
/etc/shadow
and/etc/passwd
files.
- A Linux system with access to the
- Tools Required:
John the Ripper
orHashcat
for cracking passwords.- A wordlist (e.g.,
rockyou.txt
) for dictionary attacks.
Lab Steps
Step 1: Obtain the /etc/shadow
File
- View the contents of
/etc/shadow
(requires root privileges):sudo cat /etc/shadow
- Example entry:
user:$6$randomsalt$hashedpassword:18446:0:99999:7:::
$6$
: Indicates the SHA-512 hashing algorithm.randomsalt
: The salt used for hashing.hashedpassword
: The actual hashed password.
- Example entry:
- Extract the relevant entries and save them to a file:
sudo cat /etc/shadow | grep user > hashes.txt
- Obtain the corresponding
/etc/passwd
entry for user account information:cat /etc/passwd | grep user
Step 2: Prepare for Cracking
- Combine the
/etc/passwd
and/etc/shadow
files into a format readable by cracking tools:unshadow /etc/passwd /etc/shadow > combined.txt
unshadow
combines the two files into a format suitable for tools like John the Ripper.
Step 3: Perform a Dictionary Attack
- Use John the Ripper to perform a dictionary attack:
john --wordlist=/path/to/wordlist.txt combined.txt
- Replace
/path/to/wordlist.txt
with the path to your wordlist (e.g.,rockyou.txt
).
- Replace
- Monitor progress and results:
john --show combined.txt
- Example output:
user:password123
- Example output:
Step 4: Perform a Brute-Force Attack
- If the dictionary attack fails, use a brute-force attack:
john --incremental combined.txt
- This method tries all possible combinations of characters and can take significantly longer.
- Monitor the cracking process and record any discovered passwords.
Step 5: Use Hashcat for Advanced Cracking
- Identify the hash type:
- SHA-512 corresponds to Hashcat mode
1800
.
- SHA-512 corresponds to Hashcat mode
- Use Hashcat to crack the hash with a dictionary:
hashcat -m 1800 -a 0 hashes.txt /path/to/wordlist.txt
- For a brute-force attack:
hashcat -m 1800 -a 3 hashes.txt ?a?a?a?a?a
- Replace
?a?a?a?a?a
with the desired length and character set.
- Replace
Solution
Explanation:
- The
/etc/shadow
file stores password hashes, which can be cracked offline if accessed by attackers. - Tools like John the Ripper and Hashcat use dictionary and brute-force attacks to recover plaintext passwords.
Prevention:
- Use Strong Hashing Algorithms:
- Ensure passwords are hashed using secure algorithms like SHA-512, bcrypt, or Argon2.
- Enforce Salting:
- Salt ensures that even if two users have the same password, their hashes will differ.
- Implement Strong Password Policies:
- Require long and complex passwords with a mix of characters.
- Example password policy:
sudo apt install libpam-pwquality
Configure/etc/security/pwquality.conf
with rules such as:minlen=12 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1
- Restrict Access to
/etc/shadow
:- Ensure only the root user can read the file:
chmod 600 /etc/shadow
- Ensure only the root user can read the file:
- Use Two-Factor Authentication:
- Add an extra layer of security to user accounts.
Testing and Verification
- Test password policies by creating user accounts with weak passwords and verifying they are rejected.
- Attempt to crack the hashes after implementing stronger hashing and salting mechanisms to confirm the difficulty of cracking.
- Verify that only root can access the
/etc/shadow
file.
Reflection
This exercise demonstrates how attackers can crack password hashes using offline techniques and highlights the importance of securing password storage. By completing this lab, you’ve gained insights into strengthening authentication mechanisms on Linux systems.
0 Comments