Looting (Linux)
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
TL;DR
Linux logins go through PAM, and the pam_unix.so module keeps local accounts in three files:
/etc/passwd, /etc/shadow, and /etc/security/opasswd. With root, copy them to your attack host and
crack the hashes in Cracking. Searching the host for cleartext passwords is the
sibling job in Hunting (Linux).
Where credentials live
| File | Holds | Readable by |
|---|---|---|
/etc/passwd |
One line per account, seven fields | Everyone |
/etc/shadow |
Password hashes and ageing, nine fields | root |
/etc/security/opasswd |
Old hashes PAM keeps to block password reuse | root |
/etc/passwd
htb-student:x:1000:1000:,,,:/home/htb-student:/bin/bash| Field | Example |
|---|---|
| Username | htb-student |
| Password | x |
| UID | 1000 |
| GID | 1000 |
| GECOS (full name, comments) | ,,, |
| Home directory | /home/htb-student |
| Shell | /bin/bash |
The password field decides what to do next:
x: the hash is in/etc/shadow.- A hash: old systems kept it here, and everyone can read it. Crack it.
- Empty: no password.
suto that user logs in without a prompt.
A writable /etc/passwd gives root: empty root’s password field, or add a UID 0 user. The steps are in
Privesc Primer.
/etc/shadow
htb-student:$y$j9T$3QSBB6CbHEu...SNIP...f8Ms:18955:0:99999:7:::| Field | Example |
|---|---|
| Username | htb-student |
| Password | $y$j9T$3QSBB6CbHEu...f8Ms |
| Last change (days since 1970) | 18955 |
| Min age | 0 |
| Max age | 99999 |
| Warning period | 7 |
| Inactivity period | empty |
| Expiration date | empty |
| Reserved | empty |
A password field of ! or * blocks password login. The account can still log in with an SSH key or
Kerberos. An empty field means no password.
The hash reads $<id>$<salt>$<hash>. The ID names the algorithm:
| ID | Algorithm | hashcat -m |
|---|---|---|
1 |
MD5 | 500 |
2a |
Blowfish (bcrypt) | 3200 |
5 |
SHA-256 | 7400 |
6 |
SHA-512 | 1800 |
sha1 |
SHA1crypt | |
y |
yescrypt | |
gy |
gost-yescrypt | |
7 |
scrypt |
Debian, Ubuntu, and Kali use yescrypt by default. hashcat has no yescrypt mode. John cracks it with
--format=crypt, which calls the system’s own crypt(), so run it on a host that uses yescrypt.
/etc/security/opasswd
sudo cat /etc/security/opasswdcry0l1t3:1000:2:$1$HjFAfYTG$qNDkF0zJ3v8ylCOrKB0kt0,$1$kcUjWZJX$E9uMSmiQeRh4pAAgzuvkq1The fields are the username, the UID, the number of old passwords, and the old hashes, separated by
commas. Old hashes are often MD5 ($1$), which cracks far faster than the current one. The old
passwords show the user’s pattern, such as Summer2023! to Summer2024!, so feed it to
Wordlists.
Crack the hashes
Copy both files and join them for John:
sudo cp /etc/passwd /tmp/passwd.baksudo cp /etc/shadow /tmp/shadow.bakunshadow /tmp/passwd.bak /tmp/shadow.bak > /tmp/unshadowed.hashes # passwd fields plus shadow hashes, one line per userjohn --single /tmp/unshadowed.hashes # candidates from username and GECOSjohn --wordlist=/usr/share/wordlists/rockyou.txt /tmp/unshadowed.hashesFor hashcat, keep only user:hash lines and pass --username:
sudo awk -F: '$2 ~ /^\$/ {print $1":"$2}' /etc/shadow > hashes.txt # accounts with a hashhashcat -m 1800 -a 0 --username hashes.txt /usr/share/wordlists/rockyou.txt # --username ignore the user: prefixSingle crack mode and the speed of each algorithm are in Cracking.