Credentials hunting
Application Configuration Files
Searching files with findstr
We can use findstr to search from patterns across many types of files.
Search File Contents with PowerShell
Search File Contents with cmd
Dictionary Files
Chrome Dictionary Files
For example, sensitive information such as passwords may be entered in an email client or a browser-based application, which underlines any words it doesn't recognize. The user may add these words to their dictionary to avoid the distracting red underline.
Browser Credentials
Retrieving Saved Credentials from Chrome
Users often store credentials in their browsers for applications that they frequently visit. We can use a tool such as SharpChrome to retrieve cookies and saved logins from Google Chrome.
Note: Credential collection from Chromium-based browsers generates additional events that could be logged and identified as 4983
, 4688
, and 16385
, and monitored by the blue team.
Sticky Notes Passwords
People often use the StickyNotes app on Windows workstations to save passwords and other information, not realizing it is a database file. This file is located at C:\Users\<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite
and is always worth searching for and examining.
Looking for StickyNotes DB Files:
We can copy the three plum.sqlite* files down to our system and open them with a tool such as DB Browser for SQLite and view the Text
column in the Note
table with the query
Viewing Sticky Notes Data Using PowerShell
This can also be done with PowerShell using the https://github.com/RamblingCookieMonster/PSSQLite:
Viewing strings to View DB File Contents
We can also copy them over to our attack box and search through the data using the strings
command, which may be less efficient depending on the size of the database.
Kali attacking machine:
Unattended Installation Files
Unanttend.xml
Unattended installation files may define auto-logon settings or additional accounts to be created as part of the installation. Passwords in the unattend.xml
are stored in plaintext or base64 encoded.
Although these files should be automatically deleted as part of the installation, sysadmins may have created copies of the file in other folders during the development of the image and answer file.
PowerShell History File
Starting with Powershell 5.0 in Windows 10, PowerShell stores command history to the file:
Confirming PowerShell History Save Path:
Get the content with Get-Content (gc):
Taking this further, if we are local admin we can read the files for all users with this one-liner:
PowerShell Credentials
PowerShell credentials are often used for scripting and automation tasks as a way to store encrypted credentials conveniently. The credentials are protected using DPAPI, which typically means they can only be decrypted by the same user on the same computer they were created on.
Take, for example, the following script Connect-VC.ps1
, which a sysadmin has created to connect to a vCenter server easily:
Decrypting PowerShell Credentials: If we have gained command execution in the context of this user or can abuse DPAPI, then we can recover the cleartext credentials from encrypted.xml
. The example below assumes the former:
Cmdkey saved credentials
The cmdkey command can be used to create, list, and delete stored usernames and passwords.
We can also attempt to reuse the credentials using runas
to send ourselves a reverse shell as that user, run a binary, or launch a PowerShell or CMD console with a command such as:
Querying the Registry for AutoLogon Credentials
Windows stores AutoLogon credentials in the registry, under a specific path. You can retrieve this information by querying the registry directly.
You can access the relevant registry keys for AutoLogon credentials using PowerShell via Evil-WinRM.
1. First way: Use PowerShell to Read Registry Keys
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
2. Second way: Check the Registry for AutoLogon Credentials directly:
3. Search the System for Plaintext Credentials: Sometimes credentials are stored in files or scripts. You can search the filesystem for potential matches using PowerShell.
4. Dump the Registry and Analyze Offline: If allowed, you can export the registry hive and analyze it locally.
5. Use Built-in Tools: Run cmdkey
to List Stored Credentials.
6. Check Scheduled Tasks: Sometimes credentials are stored in scheduled tasks.
7. Putty sessions
Output:
Next, we look at the keys and values of the discovered session "kali%20ssh
":
Output:
Wifi
If we obtain local admin access to a user's workstation with a wireless card, we can list out any wireless networks they have recently connected to.
Retrieving Saved Wireless Passwords: Depending on the network configuration, we can retrieve the pre-shared key (Key Content
below) and potentially access the target network.
Password Managers
Many companies provide password managers to their users. This may be in the form of a desktop application such as KeePass
, a cloud-based solution such as 1Password
, or an enterprise password vault such as Thycotic
or CyberArk
.
Some password managers such as KeePass
are stored locally on the host. If we find a .kdbx
file on a server, workstation, or file share, we know we are dealing with a KeePass
database which is often protected by just a master password. If we can download a .kdbx
file to our attacking host, we can use a tool such as keepass2john to extract the password hash and run it through a password cracking tool such as Hashcat or John the Ripper.
If we gain access to a domain-joined system in the context of a domain user with a Microsoft Exchange inbox, we can attempt to search the user's email for terms such as "pass," "creds," "credentials," etc. using the tool MailSniper.
Other files
In an Active Directory environment, we can use a tool such as Snaffler to crawl network share drives for interesting file extensions such as .kdbx
, .vmdk
, .vdhx
, .ppk
, etc.
Some other files we may find credentials in include the following: