Overview
After gaining initial access to a Linux system, post-exploitation focuses on credential harvesting, establishing persistence, lateral movement preparation, and avoiding detection. This page covers the most effective techniques used in real-world engagements.Sniffing Logon Passwords with PAM
Pluggable Authentication Modules (PAM) handle authentication for nearly all Linux services. A compromised root account can configure PAM to log every password used for login.Capturing Credentials via PAM Exec
Backdooring pam_unix.so
Modifyingpam_unix.so allows authentication with a universal backdoor password while normal authentication continues to work for all other users.
1
Locate the Authentication Directive
Find the line in
/etc/pam.d/common-auth that calls pam_unix.so.2
Modify pam_unix_auth.c Source Code
Add a conditional that grants access if a hardcoded password is used, otherwise proceeding with normal authentication.
3
Recompile and Replace
Compile the modified
pam_unix.so and replace it in the appropriate library directory.4
Test the Backdoor
Verify the backdoor password works across: login, SSH, sudo, su, and screensaver unlock.
Decrypting GPG Loot via Homedir Relocation
If you find encrypted.gpg files and a user’s ~/.gnupg folder but cannot decrypt due to permission/lock issues:
Common errors without this technique: “unsafe ownership on homedir”, “failed to create temporary file”, “decryption failed: No secret key”. The relocation resolves all three.
High-Value Credential Artifacts in HOME
Beyond shell history and SSH keys, these files frequently expose reusable credentials and tokens:Harvesting Credentials from Process Environment
When you gain code execution inside a service, the process often inherits sensitive environment variables:- App secrets:
GF_SECURITY_ADMIN_USER,GF_SECURITY_ADMIN_PASSWORD(Grafana) - API keys, DB URIs, SMTP credentials, OAuth secrets
- Proxy/TLS overrides:
http_proxy,https_proxy,SSL_CERT_FILE
Systemd Unit File Credential Extraction
Services launched by systemd may embed credentials asEnvironment= entries in unit files:
systemd-ask-password, use root-only EnvironmentFile, or use external secret managers.
Cron-Based Persistence with Loopback Mutex
A resilient persistence pattern used by sophisticated implants:Process Masquerading via prctl + argv Overwrite
Advanced implants hide by impersonating legitimate process names:Name: in /proc/<pid>/status against the real executable path. Look for loopback mutex listeners owned by processes with tiny/blank cmdlines.