Finding Passwords in Logs and Shell History
Sooner or later it will happen: you type something after which you expect a password prompt then, without looking, you type the password. However, you fat-fingered the first command, and your password ended up in clear text in your shell history, maybe the system log, and who knows what remote syslog server.
Logs live forever. I’ve seen servers with logs that were older than the server (probably copied from the old server for some reason). With the help from remote
syslog and various real-time indexers like Splunk or Graylog, logs are almost indestructible. Access to log data is generally poorly controlled with
read permission granted to everyone more often than not.
All these reasons, combined with the fact that people make mistakes, make log files a valuable source of information for the hackers. It may seem that extracting strings that might be passwords from log data would be very challenging and time-consuming. Not so. Standard requirements for password strength make this task much more manageable.
Here’s a simple example to illustrate this point. Is this string a password:
password? What about this one:
P@ssw0rd1? See my point? Good, let’s continue.
Below is the script (also on GitHub) you can run on just about any modern Linux server to check users’
/var/log/messages for possible passwords. Naturally, you need to be
root to do this. You can modify the script to only look at log files you can access with your credentials.
If you’re a sysadmin and have access to configuration management tools like Salt or Ansible, you can run this script on multiple systems in parallel. Here’s an example of running the script via Salt CLI:
salt "prod-tomcat*" cmd.script "salt://scripts/bash_history_password_find.sh"
And below is sample output. The first three lines look like the user accidentally copy-pasted into command line an encryption key or somesuch. But the other four lines clearly contain two very stupid passwords for which
jjames will receive a beating.