Hunting (Linux)
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
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 treesfind / \( -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 droppedfor 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 "#"; doneAdmins 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 nameScripts 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 crontabls -la /etc/cron.*/ # cron.d, cron.daily, cron.hourly, cron.weekly, cron.monthlyHow 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_profileLogs 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/nullA 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 versionsudo ./mimipenguin.sh # shell version, fewer targetsLaZagne 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 modulespython3 laZagne.py browsers # browsers only, as the current userBrowsers
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 foldersjq . ~/.mozilla/firefox/<profile>/logins.json # saved sites and encrypted fieldspython3 firefox_decrypt.py # pick a profile, print every loginpython3 firefox_decrypt.py -l # -l list the profilespython3 firefox_decrypt.py -c 2 /tmp/firefox/ # -c profile number, path is the folder with profiles.inifirefox_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.