Linux Post-Exploitation
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Let's configure a PAM module to log each password each user uses to login. If you don't know what is PAM check:
For further details check the original post. This is just a summary:
Technique Overview: Pluggable Authentication Modules (PAM) offer flexibility in managing authentication on Unix-based systems. They can enhance security by customizing login processes but also pose risks if misused. This summary outlines a technique to capture login credentials using PAM, alongside mitigation strategies.
Capturing Credentials:
A bash script named toomanysecrets.sh
is crafted to log login attempts, capturing the date, username ($PAM_USER
), password (via stdin), and remote host IP ($PAM_RHOST
) to /var/log/toomanysecrets.log
.
The script is made executable and integrated into the PAM configuration (common-auth
) using the pam_exec.so
module with options to run quietly and expose the authentication token to the script.
The approach demonstrates how a compromised Linux host can be exploited to log credentials discreetly.
For further details check the original post. This is just a summary:
The Pluggable Authentication Module (PAM) is a system used under Linux for user authentication. It operates on three main concepts: username, password, and service. Configuration files for each service are located in the /etc/pam.d/
directory, where shared libraries handle authentication.
Objective: Modify PAM to allow authentication with a specific password, bypassing the actual user password. This is particularly focused on the pam_unix.so
shared library used by the common-auth
file, which is included by almost all services for password verification.
pam_unix.so
:Locate the Authentication Directive in the common-auth
file:
The line responsible for checking a user's password calls pam_unix.so
.
Modify Source Code:
Add a conditional statement in the pam_unix_auth.c
source file that grants access if a predefined password is used, otherwise, it proceeds with the usual authentication process.
Recompile and Replace the modified pam_unix.so
library in the appropriate directory.
Testing:
Access is granted across various services (login, ssh, sudo, su, screensaver) with the predefined password, while normal authentication processes remain unaffected.
You can automate this process with https://github.com/zephrax/linux-pam-backdoor
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)