~/hunting-linux

Hunting (Linux)

CPTS Notes4 min read

TL;DR

Users, admins, and services leave passwords in files, history, logs, memory, and browser stores. Hunting is searching the host for them, usually right after a foothold such as a web shell. Reading the hashes out of /etc/shadow is the sibling job in Looting (Linux).

Base the search on what the box is for. A web server keeps database passwords in its app configs. A database server may have no normal users at all.

Files

Search by extension, skip the system noise, and grep the hits for keywords. The find syntax is in Searching Files.

Configs (.conf, .config, .cnf):

# config files outside library and doc trees
find / \( -name "*.conf" -o -name "*.config" -o -name "*.cnf" \) 2>/dev/null | grep -v "lib\|fonts\|share\|core"
# lines with user or pass in every .cnf, comments dropped
for i in $(find / -name "*.cnf" 2>/dev/null | grep -v "doc\|lib"); do echo -e "\nFile: $i"; grep "user\|password\|pass" $i 2>/dev/null | grep -v "#"; done

Admins rename configs, so a file without one of these extensions can still be one.

Databases (.sql, .db, .sqlite):

find / \( -name "*.sql" -o -name "*.db*" -o -name "*.sqlite" \) 2>/dev/null | grep -v "doc\|lib\|headers\|share\|man"

Open a .db with sqlite3 <file>, then .tables and SELECT * FROM <table>;.

Notes: .txt files and files with no extension in home folders:

find /home/* -type f \( -name "*.txt" -o ! -name "*.*" \) 2>/dev/null # ! -name "*.*" has no dot in the name

Scripts hold the passwords they need to run unattended:

find / \( -name "*.py" -o -name "*.pl" -o -name "*.go" -o -name "*.jar" -o -name "*.c" -o -name "*.sh" \) 2>/dev/null | grep -v "doc\|lib\|headers\|share\|snap"

Cron jobs sometimes pass credentials on the command line:

cat /etc/crontab # system crontab
ls -la /etc/cron.*/ # cron.d, cron.daily, cron.hourly, cron.weekly, cron.monthly

How to abuse a cron job is in Privesc Primer.

SSH keys: a readable private key is a login. The search is in Privesc Primer.

History and logs

Shell history keeps passwords typed into commands. Check the shell startup files too:

tail -n5 /home/*/.bash* # last lines of every user's .bash_history, .bashrc, .bash_profile

Logs record logins, sudo commands, and user changes. Reading most of them needs root or the adm group.

Log Holds
/var/log/auth.log Logins and sudo (Debian, Ubuntu)
/var/log/secure Logins and sudo (Red Hat, CentOS)
/var/log/syslog, /var/log/messages General system activity
/var/log/faillog Failed logins
/var/log/cron Cron runs
/var/log/mail.log Mail server
/var/log/httpd, /var/log/apache2 Apache
/var/log/mysqld.log MySQL

Search every readable log for authentication events:

grep -riE "accepted|session opened|failed|password changed|new user|sudo|COMMAND=" /var/log/ 2>/dev/null

A password typed into the username prompt shows up in auth.log as a failed login for that “user”.

Memory and keyrings

Both tools need root.

mimipenguin dumps process memory and pulls cleartext passwords from GDM, LightDM, the GNOME keyring, vsftpd, Apache Basic auth, and OpenSSH sessions:

sudo python3 mimipenguin.py # Python version
sudo ./mimipenguin.sh # shell version, fewer targets

LaZagne covers far more sources: shadow hashes, GNOME Keyring, KWallet, browsers, WiFi, AWS, Docker, FileZilla, history files, SSH private keys, Grub, and environment variables. The module overview is in Hunting (Windows).

sudo python3 laZagne.py all # run all modules
python3 laZagne.py browsers # browsers only, as the current user

Browsers

Firefox keeps saved logins encrypted in the profile folder: logins.json holds the entries and key4.db holds the key. Without a master password, both decrypt offline.

ls -l ~/.mozilla/firefox/ | grep default # profile folders
jq . ~/.mozilla/firefox/<profile>/logins.json # saved sites and encrypted fields
python3 firefox_decrypt.py # pick a profile, print every login
python3 firefox_decrypt.py -l # -l list the profiles
python3 firefox_decrypt.py -c 2 /tmp/firefox/ # -c profile number, path is the folder with profiles.ini

firefox_decrypt needs Python 3.9 or later. If the target lacks it, copy ~/.mozilla/firefox/ to the attack host and point the script at the copy.

A credential found here often works for su, SSH, and other hosts, so test every one with Spraying and Defaults.