---
title: "8. Credential hunting win&unix"
date: 2024-08-10
draft: false
---

# windows
`Credential Hunting` is the process of performing detailed searches across the file system and through various applications to discover credentials.

Assume initial access to a workstation through RDP.

Whether we end up with access to the GUI or CLI, we know we will have some tools to use for searching but of equal importance is what exactly we are searching for. Here are some helpful key terms we can use that can help us discover some credentials:
![](/img/Pasted image 20240809223442.png|600)
Let's use some of these key terms to search on the IT admin's workstation.

## LaZagne
https://github.com/AlessandroZ/LaZagne - quickly discover credentials that web browsers or other installed applications may insecurely store. 
It would be beneficial to keep a [standalone copy](https://github.com/AlessandroZ/LaZagne/releases/) of Lazagne on our attack host so we can quickly transfer it over to the target. `Lazagne.exe` will do just fine for us in this scenario.

`start lazagne.exe all`
All included modules. `-vv` flag for verbose

## findstr
`findstr /SIM /C:"password" *.txt *.ini *.cfg *.config *.xml *.git *.ps1 *.yml`

---
There are thousands of tools & key terms we could use to hunt for credentials on Windows operating systems. Know that which ones we choose to use will be primarily based on the function of the computer. If we land on a Windows Server OS, we may use a different approach than if we land on a Windows Desktop OS. Always be mindful of how the system is being used, and this will help us know where to look.

- Passwords in Group Policy in the SYSVOL share
- Passwords in scripts in the SYSVOL share
- Password in scripts on IT shares
- Passwords in web.config files on dev machines and IT shares
- unattend.xml
- Passwords in the AD user or computer description fields
- KeePass databases --> pull hash, crack and get loads of access.
- Found on user systems and shares
- Files such as pass.txt, passwords.docx, passwords.xlsx found on user systems, shares, [Sharepoint](https://www.microsoft.com/en-us/microsoft-365/sharepoint/collaboration)

---
# linux cred hunting

assuming foothold ofc
some example sources to search for creds: 

| **`Files`**  | **`History`**        | **`Memory`**         | **`Key-Rings`**            |
| ------------ | -------------------- | -------------------- | -------------------------- |
| Configs      | Logs                 | Cache                | Browser stored credentials |
| Databases    | Command-line History | In-memory Processing |                            |
| Notes        |                      |                      |                            |
| Scripts      |                      |                      |                            |
| Source codes |                      |                      |                            |
| Cronjobs     |                      |                      |                            |
| SSH Keys     |                      |                      |                            |
Above all, it is crucial to keep in mind how the system works, its focus, what purpose it exists for, and what role it plays in the business logic and the overall network.


We should look for, find, and inspect several categories of files one by one. Configuration files are the core of the functionality of services on Linux distributions. Usually, the configuration files are marked with the following three file extensions (`.config`, `.conf`, `.cnf`). However, these configuration files or the associated extension files can be renamed, which means that these file extensions are not necessarily required. These categories are the following:

- Configuration Files
- Databases
- Notes
- Cronjobs
- SSH Keys
- Scripts

## linux find configuration files
```bash
for l in $(echo ".conf .config .cnf");do echo -e "\nFile extension: " $l; find / -name *$l 2>/dev/null | grep -v "lib\|fonts\|share\|core" ;done
```

**Configuration files with passwords** 
```bash
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
```
We can apply this simple search to the other file extensions as well. Additionally, we can apply this search type to databases stored in files with different file extensions, and we can then read those.

**Databases**
```bash
for l in $(echo ".sql .db .*db .db*");do echo -e "\nDB File extension: " $l; find / -name *$l 2>/dev/null | grep -v "doc\|lib\|headers\|share\|man";done
```

**Notes** 
```bash
find /home/* -type f -name "*.txt" -o ! -name "*.*"
```

**Scripts** 
```bash
for l in $(echo ".py .pyc .pl .go .jar .c .sh");do echo -e "\nFile extension: " $l; find / -name *$l 2>/dev/null | grep -v "doc\|lib\|headers\|share";done
```

**SSH Keys**
Since the SSH keys can be named arbitrarily, we cannot search them for specific names. However, their format allows us to identify them uniquely because, whether public key or private key, both have unique first lines to distinguish them.
```bash
grep -rnw "PRIVATE KEY" /home/* 2>/dev/null | grep ":1"
```
-- Swap `/home/*` for a broader search. 

Likewise, for public keys: 
```bash
grep -rnw "ssh-rsa" /home/* 2>/dev/null | grep ":1"
```

**History files**
In the history of the commands entered on Linux distributions that use Bash as a standard shell, we find the associated files in `.bash_history`. Nevertheless, other files like `.bashrc` or `.bash_profile` can contain important information.

Bash history: 
```bash
tail -n5 /home/*/.bash*
```

**Logs**
The entirety of log files can be divided into four categories:

|**Application Logs**|**Event Logs**|**Service Logs**|**System Logs**|
|---|---|---|---|

Some important log files: 

| **Log File**          | **Description**                                    |
| --------------------- | -------------------------------------------------- |
| `/var/log/messages`   | Generic system activity logs.                      |
| `/var/log/syslog`     | Generic system activity logs.                      |
| `/var/log/auth.log`   | (Debian) All authentication related logs.          |
| `/var/log/secure`     | (RedHat/CentOS) All authentication related logs.   |
| `/var/log/boot.log`   | Booting information.                               |
| `/var/log/dmesg`      | Hardware and drivers related information and logs. |
| `/var/log/kern.log`   | Kernel related warnings, errors and logs.          |
| `/var/log/faillog`    | Failed login attempts.                             |
| `/var/log/cron`       | Information related to cron jobs.                  |
| `/var/log/mail.log`   | All mail server related logs.                      |
| `/var/log/httpd`      | All Apache related logs.                           |
| `/var/log/mysqld.log` | All MySQL server related logs.                     |
Covering the analysis of these log files in detail would be inefficient in this case. So at this point, we should familiarize ourselves with the individual logs, first examining them manually and understanding their formats. However, here are some strings we can use to find interesting content in the logs:

```bash
for i in $(ls /var/log/* 2>/dev/null);do GREP=$(grep "accepted\|session opened\|session closed\|failure\|failed\|ssh\|password changed\|new user\|delete user\|sudo\|COMMAND\=\|logs" $i 2>/dev/null); if [[ $GREP ]];then echo -e "\n#### Log file: " $i; grep "accepted\|session opened\|session closed\|failure\|failed\|ssh\|password changed\|new user\|delete user\|sudo\|COMMAND\=\|logs" $i 2>/dev/null;fi;done
```

**Cache, memory**
Many applications and processes work with credentials needed for authentication and store them either in memory or in files so that they can be reused.
- system-required creds for logged-in users; creds stored in browsers

We use `mimipenguin` to make memory dumps easier - however, requires root/admin permissions. 
https://github.com/huntergregal/mimipenguin
```bash
sudo python3 mimipenguin.py
```

lazagne also works!

| Wifi           | Wpa_supplicant | Libsecret  | Kwallet    |
|----------------|----------------|------------|------------|
| Chromium-based | CLI            | Mozilla    | Thunderbird|
| Git            | Env_variable   | Grub       | Fstab      |
| AWS            | Filezilla      | Gftp       | SSH        |
| Apache         | Shadow         | Docker     | KeePass    |
| Mimipy         | Sessions       | Keyrings   |            |
For example, Keyrings are used for secure storage and management of passwords on Linux distributions.

```bash
sudo python2.7 laZagne.py all
```

**Browsers**
firefox
```bash
ls -l .mozilla/firefox/ | grep default 
cat .mozilla/firefox/1bplpd86.default-release/logins.json | jq .
```
https://github.com/unode/firefox_decrypt

Lazagne also can do this: 

```bash
python3 laZagne.py browsers
```
