Objective: Use John the Ripper to crack Linux password hashes from the /etc/shadow
file, and learn how to secure password storage to prevent such attacks.
Scenario: The /etc/shadow
file in Linux stores hashed passwords for user accounts. Attackers who gain access to this file can attempt to crack the hashes to reveal plaintext passwords. Your task is to simulate this process using John the Ripper and implement measures to strengthen password security.
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.
- A wordlist for dictionary-based attacks (e.g.,
rockyou.txt
).
Lab Steps
Step 1: Extract Password Hashes
- Copy the
/etc/shadow
file (requires root privileges):sudo cat /etc/shadow > shadow.txt
- Extract the corresponding
/etc/passwd
file:cat /etc/passwd > passwd.txt
- Use the
unshadow
command to combine the files into a format readable by John the Ripper:unshadow passwd.txt shadow.txt > hashes.txt
Step 2: Perform a Dictionary Attack
- Run John the Ripper with a wordlist:
john --wordlist=/path/to/wordlist.txt hashes.txt
- Replace
/path/to/wordlist.txt
with the location of your wordlist.
- Replace
- Monitor the cracking process:
john --show hashes.txt
- Example output:
user1:password123
- Example output:
Step 3: Perform a Brute-Force Attack
- If the dictionary attack fails, use a brute-force attack:
john --incremental hashes.txt
- Monitor progress and record any successfully cracked passwords.
Step 4: Test Cracked Passwords
- Log in as the user with the cracked password:
su - <username>
- Verify access and attempt to escalate privileges if applicable:
sudo -l
Solution
Explanation:
- The
/etc/shadow
file contains hashed passwords, which can be cracked offline if an attacker gains access. - Tools like John the Ripper use dictionary and brute-force attacks to recover plaintext passwords.
Prevention:
- Use Strong Hashing Algorithms:
- Configure Linux to use bcrypt or Argon2 instead of SHA-512:
authconfig --passalgo=bcrypt --update
- Configure Linux to use bcrypt or Argon2 instead of SHA-512:
- Enforce Password Complexity:
- Use
libpam-pwquality
to enforce strong password policies:sudo apt install libpam-pwquality
- Configure
/etc/security/pwquality.conf
with rules such as:minlen=12 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1
- Use
- Restrict Access to
/etc/shadow
:- Ensure only root can read the file:
chmod 600 /etc/shadow
- Ensure only root can read the file:
- Audit User Accounts:
- Regularly review accounts for weak or default passwords.
Testing and Verification
- Attempt to crack hashes after applying stronger hashing algorithms to confirm the increased difficulty.
- Test password policies by creating user accounts with weak passwords and verifying they are rejected.
- Confirm that
/etc/shadow
is restricted to root access only.
Reflection
This exercise demonstrates how attackers can crack Linux password hashes and highlights the importance of strong password policies and secure storage practices. By applying these techniques, you can protect user credentials and enhance system security.
0 Comments