KeePass
MITRE ATT&CK™ Credentials from Password Stores: Password Managers - Technique T1555.005
Theory
Password managers generate and securely store passwords of various services, safeguarding them under a single master password. This master password serves as the key to access all the stored passwords within the password manager.
Examples of Password Manager applications:
Third-party: KeePass, 1Password, LastPass
However, misconfiguration and security flaws are found in these applications that let us access stored data. Various tools could be used during the enumeration stage to get sensitive data in password manager applications used by Internet browsers and desktop applications.
Practice
Enumeration
KeePwn (Python) can be used to remotely identify hosts that run KeePass on a target environment.
# Search by files
python3 KeePwn.py search -u <ADMIN_ACCOUNT> -p <PASSWORD> -d <DOMAIN> -tf ./targets.txt
# Search by processes + csv output
python3 KeePwn.py search -u <ADMIN_ACCOUNT> -p <PASSWORD> -d <DOMAIN> -tf ./targets.txt --threads 4 --get-process --found-only --output keepwn_out.csvNetExec (Python) can also be used to remotly check if keepass is installed on the target environment.
nxc smb <TARGETS> -u <ADMIN_ACCOUNT> -p <PASSWORD> -M keepass_discoverKeePass Plugin Abuse
KeePass features a plugin framework which can be abused to load malicious DLLs into KeePass process, allowing attackers with administrator rights to easily export the database (see: KeeFarceRebornPlugin).
KeePwn (Python) can be used to abuse this KeePass Plugin feature, exporting the database in cleartext.
By compiling the KeeFarceRebornPlugin project, and copying the DLL into the plugins directory (located at at KeePass root, namely "C:\Program Files\KeePass Password Safe 2\Plugins" for a global install), we can abuse KeePass Plugin.
Export the database using malicious plugin:
Export the database by hijacking a legit plugin DLL (requires an existent plugin in use):
KeePass Trigger Abuse - CVE-2023-24055
We can modify the KeePass.config.xml file to create malicious triggers that automatically exported database entries to accessible locations.
This KeePass Trigger Abuse, identified as CVE-2023-24055 only affects KeePass versions 2.53 and earlier.
Cracking KDBX Database Master Password
Cracking Master Password - Manually
If we gained access to the keepass database, we may be able to extract it and crack the master database password.
Keepass database is stored as a .kdbx file, we can search for such files using following commands:
One we exfiltrate the database to our attacking computer, we can start by using keepass2john and save the output hase a crackable hash.
Then, we may crack the master password using hashcat. See this page for more details about cracking passwords.
Now, we can open the database using kpcli and dump passwords
Extract Passphrase from Memory - CVE-2023-32784
As described by @vdohney, it is possible to retrieve the database's master password in memory
This KeePass Abuse, identified as CVE-2023-32784 only affects KeePass versions priot to 2.54.
Fisrt, perform a process dump of the running KeePass
Retrieve the process dump as well as the .KDBX containing the encrypted database (e.g. through SMB).
KeePwn (Python) can then be used to search for potential master password candidates in dumps. Because the resulting strings will (by design) be incomplete, the module can also be used to bruteforce the missing first character against a specified KDBX file.
KeePassXC is also subject to such exploits.
Fisrt, perform a process dump of the running KeePassXC
Retrieve the process dump as well as the .KDBX containing the encrypted database (e.g. through SMB).
KeePass-the-Hash can then be used to search for composite key-like strings from a KeePassXC process dump.
KeePass DLL Injection
KeeFarceReborn is a standalone DLL that exports databases in cleartext once injected in the KeePass process.
After compiling the DLL, we may use Donut to convert it to a shellcode and use it with any injection technique.
Post-injection steps
Once the injection is performed, you will see debug messages being printed in MessageBox (which should obviously be removed when used in a real penetration testing scenario) then find the exported database in the current user's %APPDATA% (choosed by default, as KeePass will be sure to have write access). The exported XML file can later be imported in any KeePass database without asking for a password
Resources
Last updated
Was this helpful?