Skip to main content

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.
This content is for authorized penetration testing and red team operations only. Always operate within the defined scope of your engagement.

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

Modifying pam_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.
Automate PAM backdooring with: https://github.com/zephrax/linux-pam-backdoor

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:
Quick triage:

Harvesting Credentials from Process Environment

When you gain code execution inside a service, the process often inherits sensitive environment variables:
What to look for:
  • 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
Many orchestration platforms pass all sensitive settings via environment variables. These are inherited by child processes and visible in any shell spawned within that process context.

Systemd Unit File Credential Extraction

Services launched by systemd may embed credentials as Environment= entries in unit files:
Example vulnerable unit file:
Hardening: Move secrets to 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:
Detection: Compare Name: in /proc/<pid>/status against the real executable path. Look for loopback mutex listeners owned by processes with tiny/blank cmdlines.

Quick Credential Discovery After Root

References