How to Detect Rogue Linux PAM Modules and Preload Hooks

Summary
A practical guide explains how root-level tampering with PAM modules or the dynamic linker preload file can capture credentials or alter authentication, and provides auditd, Sysmon for Linux, and Guardsix SIEM guidance to detect the changes.
Key points
- A rogue PAM module can capture passwords or affect authentication decisions when a root-level attacker adds the module and registers it in a service’s PAM configuration.
- A preload hook listed in /etc/ld.so.preload can load into programs before PAM, allowing credential interception or authentication tampering without changing PAM configuration.
- A lab example demonstrates a PAM module recording a typed password in plaintext while allowing the login to proceed normally.
- The guide provides auditd watch rules and Sysmon for Linux configuration guidance for monitoring PAM module directories, PAM configuration files, library directories, and /etc/ld.so.preload.
- Guardsix SIEM queries correlate file and process events to identify module creation, PAM configuration changes, and preload-file modifications.
- Detection coverage depends on configured telemetry; the stated auditd rules do not cover libraries first dropped in /tmp, /var/tmp, or /dev/shm.
- The article says two related Guardsix alerts will be available in a forthcoming alert release.
Article Details
- Defense Focus
- Detect tampering with Linux authentication through rogue PAM modules, PAM configuration changes, and dynamic linker preload hooks.
- Detection Methods
- Detect new files in PAM module directories and correlate their creation with PAM configuration changes.
- Monitor writes and attribute changes to /etc/pam.d/, /etc/pam.conf, /etc/security, library directories, and /etc/ld.so.preload.
- Correlate auditd PATH records with SYSCALL or PROCTITLE records using the shared record_id to identify the process, command, and user responsible.
- Hunt for new shared libraries and preload-file entries, then check whether login programs started after the preload setting changed.
- Treat a clean /etc/ld.so.preload file as inconclusive because rootkits may hide or redirect the file.
- Account for blind spots: the described rules do not record libraries dropped in /tmp, /var/tmp, or /dev/shm, and signature scanning alone may miss PAM backdoors.
- Data Sources
- auditd file, process, and PAM records forwarded through syslog and normalized as Unix.
- Sysmon for Linux file-creation events, when rules cover the relevant paths; normalized as UnixSysmon.
- Authentication messages from auth.log, received in syslog format, for module-load failures.
- Rule Types
- auditd path-watch rules for PAM configuration and /etc/ld.so.preload.
- auditd syscall rules for writes and attribute changes in PAM module and library directories.
- Sysmon for Linux file-creation rules covering PAM and library directories.
- Guardsix Query Language queries correlating auditd PATH, SYSCALL, and PROCTITLE records, and filtering package-manager activity.
- Platforms
- Linux
- Ubuntu 22.04
- RHEL 9
- Defensive Actions
- Configure auditd watches for PAM configuration files and directories, PAM module directories, library directories, and /etc/ld.so.preload.
- Add Sysmon for Linux file-creation rules for PAM configuration, module, and library paths; configure telemetry before relying on detections.
- Correlate file records with process and command-line records, and use an appropriately short time range for resource-intensive joins.
- Review writes around package-manager activity separately, while filtering expected package-manager changes where appropriate.
- Inspect temporary directories as well as the paths covered by the example rules, which do not monitor /tmp, /var/tmp, or /dev/shm.
- Do not rely on signature scanning alone or treat an apparently clean preload file as proof of a clean host.
MITRE ATT&CK
T1056.004 · Credential API HookingThe article describes a preload hook intercepting credential handling in a login program to capture typed passwords.T1556.003 · Pluggable Authentication ModulesThe article describes rogue PAM modules and configuration lines, replacement of pam_unix.so, modules that approve logins, and pam_exec scripts that capture passwords.T1556.006 · Multi-Factor AuthenticationRemoving the PAM configuration line that invokes a multi-factor authentication module disables that additional check.T1574.006 · Dynamic Linker HijackingA library named in /etc/ld.so.preload is loaded into programs ahead of PAM's library and can intercept login handling.
Malware
Medusaa different, hidden file instead of /etc/ld.so.preload, and Intezer's analysis of OrBit, a fork of the Medusa rootkit, describes it as still in the wild nearly four years on, with a 2025 build that can approve orOrBitthe loader to read a different, hidden file instead of /etc/ld.so.preload, and Intezer's analysis of OrBit, a fork of the Medusa rootkit, describes it as still in the wild nearly four years on, with a 2025 buildSkidmapMITRE records Skidmap doing this, with a version of pam_unix.so that accepts a backdoor password for all users.vlanyThe open-source vlany rootkit patches the loader to read a different, hidden file instead of /etc/ld.so.preload, and Intezer's analysis of OrBit, a fork of the Medusa rootkit, describes it as still in the wild nearly
