KeePass Memory Dump (CVE-2023-32784)
CVE-2023-32784 affects KeePass 2.x up to 2.53.1 and does not break the database's encryption: it recovers the master password from the process's memory. The cause is the custom SecureTextBoxEx control, the box where the password is typed: for every character entered it leaves a managed string on the heap holding the rest of the text, so the process ends up containing a ladder of strings that, read in order, reconstructs the password.
What comes back are the characters from the second one on: the first never ends up in memory that way. That is why the result is not a password but a list of candidates, one per possible first character.
There are three valid dump sources, and they are often already on disk without needing to be provoked:
- A process dump taken by hand (
procdump,Task Manager > Create dump file). - The hibernation file or the swap file.
- A crash dump somebody kept, which is the usual case on a box: a forgotten
KeePassDumpFull.dmpsitting next to the.kdbxin a backup directory.
Jorian Woltjer's extractor does the reconstruction:
wget https://github.com/JorianWoltjer/keepass-dump-extractor/releases/download/0.1.0/keepass-dump-extractor
./keepass-dump-extractor <dump.dmp> -dThe output is the ladder of fragments. Turned into a wordlist and run through a rule that tries every possible first character, the rest is cracking the database with the usual tools:
keepass2john <file.kdbx> > kdbx.hash
john --wordlist=<wordlist.txt> kdbx.hashOne detail that decides the box: an entry's password is not always what matters. KeePass entries have a notes field, and whole private keys often live there (a PuTTY-User-Key-File-3, for example), which get you in even when the entry's password is worth nothing.
Requirements. KeePass 2.x earlier than 2.54 (2.54 fixes the control by padding the heap with dummy text) and a memory dump of the process with the database open. KeePassXC, a separate implementation, is not affected. If the dump was taken before anyone typed the master password, there is nothing to recover.
How to detect it. Access to the KeePass process with memory-read rights is the signal: Sysmon Event ID 10 (ProcessAccess) against KeePass.exe with a GrantedAccess including PROCESS_VM_READ (0x0010), and particularly from procdump.exe, rundll32 comsvcs.dll MiniDump or taskmgr.exe. On disk, a .dmp appearing with KeePass in its name, and read access to .kdbx files from a process that is not the password manager.
Defence. Upgrade to KeePass 2.54 or later. Until then, close the database when it is not in use (the flaw needs the master to have been typed in that run), use the key file or the Windows account integration rather than a password alone, and disable process dumps for applications that handle secrets.
It connects with cracking a KeePass database, which is the step after, and with dumping a process's memory, the generic technique this is a named case of.
Machines where it's used
- KeeperHackTheBox