Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Linux Authentication

Summary

Linux uses Pluggable Authentication Modules (PAM) for authentication. The key modules (pam_unix.so, pam_unix2.so) are located in /usr/lib/x86_64-linux-gnu/security/ on Debian-based systems. PAM handles user information, authentication, sessions, and password changes.

Key Files

FilePurposePermissions
/etc/passwdUser account infoWorld-readable
/etc/shadowPassword hashesRoot only
/etc/security/opasswdPrevious passwordsRoot only

/etc/passwd

Contains user information in seven colon-separated fields:

htb-student:x:1000:1000:,,,:/home/htb-student:/bin/bash
FieldDescription
UsernameLogin name
Passwordx = hash in shadow file; empty = no password
UIDUser ID
GIDPrimary group ID
GECOSUser info (name, phone, etc.)
HomeHome directory path
ShellDefault login shell

Security Note: If password field contains an actual hash (rare, old systems) or the file is writable, this is a critical vulnerability.


/etc/shadow

Stores password hashes with nine colon-separated fields:

htb-student:$y$j9T$3QSBB6CbHEu...SNIP...f8Ms:18955:0:99999:7:::
FieldDescription
UsernameLogin name
PasswordHashed password
Last changeDays since epoch of last change
Min ageMinimum days between changes
Max ageMaximum days before change required
WarningDays before expiry to warn
InactivityDays after expiry until disabled
ExpirationAbsolute expiry date
ReservedUnused

Special Password Values:

  • ! or * = Unix password login disabled (other methods may work)
  • Empty = No password required

Hash Format

$<id>$<salt>$<hashed>
IDAlgorithm
1MD5
2aBlowfish
5SHA-256
6SHA-512
sha1SHA1crypt
yYescrypt (modern default)
gyGost-yescrypt
7Scrypt

/etc/security/opasswd

PAM stores previous passwords here to prevent reuse. Contains comma-separated historical hashes per user:

cry0l1t3:1000:2:$1$HjFAfYTG$qNDkF0zJ3v8ylCOrKB0kt0,$1$kcUjWZJX$E9uMSmiQeRh4pAAgzuvkq1

Note: Older hashes (e.g., MD5 $1$) are easier to crack and may reveal password patterns.


Cracking Linux Credentials

Using unshadow

Combine passwd and shadow files for cracking:

sudo cp /etc/passwd /tmp/passwd.bak
sudo cp /etc/shadow /tmp/shadow.bak
unshadow /tmp/passwd.bak /tmp/shadow.bak > /tmp/unshadowed.hashes

Cracking with hashcat

hashcat -m 1800 -a 0 /tmp/unshadowed.hashes rockyou.txt -o /tmp/unshadowed.cracked

Cracking with John the Ripper

John’s single crack mode is ideal for this scenario as it uses GECOS/username data:

john --single /tmp/unshadowed.hashes

Or with a wordlist:

john --wordlist=rockyou.txt /tmp/unshadowed.hashes

Common Hashcat Modes for Linux

ModeAlgorithm
500MD5crypt ($1$)
1800SHA-512crypt ($6$)
7400SHA-256crypt ($5$)
3200bcrypt ($2a$)