Attacker with access to XML config can trigger keepass.exe to obtain passwords
cve.mitre.org
cve.mitre.org
If they didn't modify the config, they could presumably use one of a plethora of tactics to extract data directly from keepass.exe's memory.
"When porting code to .NET Core, consider that the contents of the array are not encrypted in memory. The general approach of dealing with credentials is to avoid them and instead rely on other means to authenticate, such as certificates or Windows authentication."
Which I read as: "If writing a program in C#, assume the memory can be read by apps on the same device."
1: https://learn.microsoft.com/en-us/windows/win32/api/memoryap...
> While KeePass is running, sensitive data is stored encryptedly in the process memory. This means that even if you would dump the KeePass process memory to disk, you could not find any sensitive data. For performance reasons, the process memory protection only applies to sensitive data; sensitive data here includes for instance the master key and entry passwords, but not user names, notes and file attachments. Note that this has nothing to do with the encryption of database files; in database files, all data (including user names, etc.) is encrypted. [...]
Suppose we want to look inside process #1234, we just open the file /proc/1234/mem and suppose we know we want the value at address #003e0f20 we just seek to that address and read however much we want.
Unlike a typical data file the memory map has holes in it, so we do need to know where we're going, but that's OK the Linux kernel also provides information about what is in there and where it is, so e.g. we can root around specifically in the program's heap.
On recent Linux distros, by default you can't ptrace (or read memory via /proc/x/mem etc) of non-child processes https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama....
This is why RCE type exploits are super dangerous.
There probably won't ever be a solution for this unless we get a completely rewritten Windows / Linux with pure security in mind.
I wonder if any VC would invest in a startup to build a secure OS.
Most peoples definition of security is to have improved access control such that unauthorized access cannot happen. The openbsd definition of security is closer to "build it correctly so that it operates correctly". openbsd access control is actually fairly limited and rudimentary.
Basically, as soon as local access has been gained by an attacker you can not longer trust anything unless you have unusual protections such as locking down the shell/desktop configuration, or disallowing running binaries from ~, which isn't the case for most systems, and even those protections are tricky to be 100% foolproof. That you can't change the system itself is irrelevant if you can trick the user in to running something outside of the usual system, which is usually quite easy.
Attach a debugger to the browser, intercept password field input events.
Or KeePass doesn't have browser integration by default so just listen to clipboard events at an OS level.
Listening to global clipboard events at the OS level is a permission I have to explicitly grant.
The first rules out Linux (unless this is a SELinux thing?).
The second rules out Windows/Mac OS/Linux with X11.
The upstream KeePass application does not support mobile operating systems. It barely supports non-Windows, which is why when most people say they use KeePass they mean KeePassXC
If an attacker already has write-access to local files he could also replace keepass.exe or install a keylogger.
If this happens, it's already too late.. this CVE is a joke!
Another recent example is https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-2405... which is for a purely theoretical exploit - not even a PoC - with the only 'sources' being Reddit/Twitter scaremongering, and 'support forum posts' that quote these exact same Twitter threads.
That CVE isn't just a disagreement, it's a warning. Avoid security related software from people who enjoy keeping a security edge over the unwashed masses who aren't in the know, who don't get a kick out of locking down. Because that's why they keep the unsafe defaults, they keep them because they enjoy going the extra mile for their own safety. That is, unless they (also) have worse reasons for keeping unsafe defaults, but, well, Hanlon to the rescue.
Full disclosure, I sell a premium KP2 plugin and would hate for users to have to reinstall KP2 or go through extra hoops to use my plugin.
What threats did you think keepass was defending against exactly?
But:
1. Ease of use is a security concern - if it's a pain in the ass to use a security measure, users won't.
2. There's also attacks that for whatever reason aren't able to achieve persistence, but are able to obtain files. Let's imagine a browser or scp or rsync or whatever exploit that tricks it into uploading unintended files. These cases will be blocked by KeePass but not by your .csv
3. Users want to sync their password database via untrusted means (e.g. cloud providers). This is easier when the database is itself encrypted. (This attack targets the application config, not the database config, which is a strange choice to sync).
Similar, a virus-scanner will look intensively at exe-files and access to keyboard-input, but not so much at some random configuration, which is supposed to change all the time anyway.
KeePassXC has not replicated the automation ("Triggers") system of KeePass, so there's unlikely to be a similar action to take using KeePassXC's config file
If someone can edit the XML they could also just add a plugin that exports everything on load? Plugs are trivial to write and have access to everything automatically if they exist on disk in the plugins directory.
So, the attacker modifies the config file, then the user eventually uses the password manager as usual, and then a file in disk with all plain text passwords is generated and subsequently read by the attacker.
I guess the point here is you don't need a memory read vulnerability.
Can someone more knowledgeable confirm?
Given that dumping a cleartext password list is a legitimate thing you might want to do, and being a plugin (or setting) a somewhat acceptable way of achieving this, the issue here is that, as it is, the user is not being unequivocally made aware of what happened.
So yeah, I agree, in any case the feature, as it is implemented, is completely unacceptable.
Granted you need local access to modify the config, but generally the .kdbx is stored (securely) on some shared environment. Grabbing that would mean you could export passwords at your leisure in this setup?
Keepass will (by default) not ask for the password a second time before exporting - but you have to decrypt the database once before it can be exported.
So this is not a risk if your threat model is "attacker obtains a copy of my .kdbx", but it is a risk if your threat model is "attacker can modify .kdbx without me noticing, and can access my local computer or a mounted network disk to read the exported passwords".
If an attacker can modify your local install, you've lost anyway....
No, the threat model is "the attacker can modify config file", which for default installation also means "the attacker can modify the executable".
They're proposing that the author change the application so that it pops up a dialog whenever the KeePass application is directed to export the decrypted document.
I'm not a KeePass dev, but with a bit of search and pattern recognition, it looks like this export feature is implemented in KeePass-2.53-Source\KeePass\DataExchange\ExportUtil.cs:
public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider fileFormat,
IOConnectionInfo iocOutput, IStatusLogger slLogger)
{
PwDatabase pd = pwExportInfo.ContextDatabase;
...
// [IF CONFIG FILE DOESN'T ALLOW EXPORTING WITHOUT KEY]
if(!AppPolicy.Current.ExportNoKey && (pd != null))
{
// [THEN ASK FOR IT AGAIN]
if(!KeyUtil.ReAskKey(pd, true)) return false;
}
...
Stream s = (bFileReq ? IOConnection.OpenWrite(iocOutput) : null);
try { bResult = fileFormat.Export(pwExportInfo, s, slLogger); }
finally { if(s != null) s.Close(); }
}
They're complaining that an evil maid attack can turn off `AppPolicy.Current.ExportNoKey` and set it up to export the document silently. They want it to read: public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider fileFormat,
IOConnectionInfo iocOutput, IStatusLogger slLogger)
{
PwDatabase pd = pwExportInfo.ContextDatabase;
...
// [ALWAYS ASK FOR MASTER PASSWORD AGAIN BEFORE EXPORTING]
if(!KeyUtil.ReAskKey(pd, true)) return false;
...
Stream s = (bFileReq ? IOConnection.OpenWrite(iocOutput) : null);
try { bResult = fileFormat.Export(pwExportInfo, s, slLogger); }
finally { if(s != null) s.Close(); }
}
They've even gone so far as to ask the author to create a "KeePass Essentials" version, which removes the export feature, plugins, and configuration files entirely:https://sourceforge.net/p/keepass/feature-requests/2704/#b3c...
But they ignore that with write access to the application directory, an attacker can just change the application to not show that dialog at all.
There is a global configuration file at "C:\Program Files\KeePass Password Safe 2\KeePass.config.xml" but by default, this one just contains a directive to use the user's configuration. This one also needs elevated privileges to edit.
The user's configuration file is at "C:\Users\<username>\AppData\Roaming\KeePass\KeePass.config.xml"
So if you want to avoid an attacker being able to change the user's configuration without elevation, then you can just change the security settings of that last file, e.g. by taking away the user write permission.
However, the user is probably launching the KeePass executable via some sort of shortcut. For example, a pinned shortcut on the taskbar. This would also be a user file, at "C:\Users\<username>\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\KeePass 2.lnk"
So if the attacker can modify the user's files, then they can probably also modify that shortcut, e.g. to point at a modified copy of keepass. This shows that the behavior of the "real" KeePass application is probably not very relevant here. It is difficult to defend against an attacker with that level of access.
If an evil maid has access to make such a change, wouldn't it be easier to just replace keepass.exe with custom version? The source is already available. Just call this function after successful login - ignoring XML configuration, "KeePass Essentials" version, etc.
Being able to sliently make my password manager insecure is a big issue. It should be right up there with the LastPass hacks.
Also, are you envisioning setting up a new, non-administrative user account for that person, or just logging on using your own account and then handing over the keyboard and mouse like most people would do?
Wouldn't you prefer a tool that doesn't try to defend against scenarios it knows it isn't strong enough to handle?
Bypass options that are considered enough of a problem to give the legitimate user ways to disable then and they are just as hidden as the bypasses themselves. And default to not disabled.
If it is backed up with, say, Dropbox, then someone getting access to that could trigger a data export when the user enters the master password next time. And then pick up the data from the synced folder.
This would widen the attack surface from needing local access. Am I missing anything?
On the other hand a lot of people store dotfiles on the cloud, at which point if somebody gets access it's probably easier to stole the information by modifying something like the .bashrc file.
I don't see how you can protect from this kind of "attack".
I need to explicitly grant my IDE permission to debug other processes every time, so reading the passwords is memory isn't a slam dunk either.
And I can assure you, I have full write access to my files.
Most responses look at one installation of keepass and that you already need to have access to a user. On the other hand in an enterprise environment it is most likely way easier to modify a configuration file than changing anything (without being monitored/alarmed) in the context of the user.
An possible attack scenario might be to change the default startup-script to generate (or manipulate) the xml and after a few minutes try to upload the exported file to a remote location. Sounds like a promising way to get passwords from many users without the need to do anything on a per user basis.
I'm not saying that with the same rights you might also have the right to do stuff as the user, but it might be less prone to detection this way.
I'm a Mac app developer, so I can store secrets in the Keychain. The keychain is pretty secure, and it's hard for an attacker to extract information from the keychain.
But there are a number of ways that could be used to trick my app into revealing passwords if the attacker could change configuration files.
Of course, when the attacker has full access to the local computer, then there are other ways the attacker could extract the data. But what if the attacker only had a way to write a file to an arbitrary path? Then they could use that to reveal passwords.
The only way I can think of to avoid security holes like this is to use configuration files that are signed with a key derived from the password, but that may cause different issues.
windows and linux desktops are just a bunch of programs running in shared memory and disk space. every program can read or modify the data of any other (see ReadProcessMemory, WriteProcessMemory (ptrace for linux)). simple. all these people claiming that there is an issue simply don't realize this simple fact (well, some do, but they're just even more wrong). the worst part is that devs often give into this nonsense, like they did in all those nightmarish hellscape 2003 pseudosecurity laden programs. gotta love when some program prevents me from doing something for "security" when it actually does not make security any better but is just pandering to some charlatans' concerns.
It ludicrous that the relevant bits of this XML file are not protected by the master key.
Maybe something like the first time a particular database is opened, KeePass could ask the user to approve the settings in the config file, and if so, add a cryptographic signature based on the config file hash and the database's master key to a separate config file that stored a list of those signatures and the config settings that were present when they were generated.[1] The next time the same database is opened, KeePass would only re-prompt if the signature no longer matched. That way, if the config file changed separately, the user could get a warning popup highlighting what had changed.
[1] Alternatively, have everything in one file, and strip the "existing signatures" block before generating the hash, but it seems safer to use a separate file.
So if I'm understanding, a common usage pattern for Keepass is keeping the kdbx on a shared drive (OneDrive, Dropbox, etc.) Someone with read/write access to a bunch of Dropbox shares could perform this exploit on a bunch of kdbx files so that it will write plaintext files to the share, then wait and collect the passwords. It would be hard to hide the attack but it would be incredibly damaging.
So I'm not sure the assertion that this requires local access is correct. It sounds like it only needs access to a shared filesystem that contains a kdbx, and I think it is reasonable to expect Keepass to be secure against that.
Such a trash response from a provider of software thats supposed to protect sensitive data.