keepasshttp icon indicating copy to clipboard operation
keepasshttp copied to clipboard

Security problem for remote users

Open Quiark opened this issue 9 years ago • 12 comments

Hi, can't get the author's email but there's a security issue affecting users who allow remote connections to KeePassHttp.

@pfn, please contact me at [email protected] for details.

For users: make sure you don't enable remote connections to the plugin. In Options - Advanced - Host, it should be localhost

Quiark avatar Jan 29 '16 02:01 Quiark

I was looking into starting to use KeePass as the password manager and first thing I searched for was browser integration. I think KeePassHttp is a very useful tool but when I looked deeper I found some issues.

Description

The communication between KeePass and the browser plugin is encrypted using AES 256. The implementation in KeepassHttp is not secure though. Attackers who are able to capture this encrypted traffic and send requests to the server can manage to decrypt captured passwords. Users who don't enable any remote connection and only stay on localhost for both client and server should be fine, others could be in trouble.

The fundamental problem is that the integrity of the encrypted entries is not protected using an authenticated MAC, authenticated encryption mode or a signature. This allows for the CBC padding oracle attack to be executed remotely to decrypt any encrypted entry that was captured earlier.

Leaking entire passwords to remote attackers is of course a serious problem but its impact is limited by the default setting to not allow remote connections. Furthermore, the padding oracle attack requires a few thousands requests to be executed, each of which pops an error tooltip on the targeted user's desktop. This doesn't mean that the user is protected though, a coworker could execute this attack when the target is away from the computer for example.

Leaving this particular vulnerability aside, the project's GitHub description says that KeepassHttp exposes password entries securely. I think most users, especially as the project reaches a wider user base, will just take that for granted and not pay attention to the caveat that the first key exchange is totally unprotected.

CBC padding oracle attack:

  • http://www.thoughtcrime.org/blog/the-cryptographic-doom-principle/
  • http://robertheaton.com/2013/07/29/padding-oracle-attack/
  • http://cryptopals.com/sets/3/challenges/17/

Cryptographic best practices:

  • https://gist.github.com/tqbf/be58d2d39690c3b366ad

Suggested fix

Short-term mitigation: An update for KeepassHttp that disables remote access completely or at least strongly warns users about this danger. Direct users in how to securely perform the association (with a disconnected computer).

Proper fix: Use cryptography best practices or, even better, use a TLS connection with self-generated certificates that the user confirms on both ends. Cryptography best practices in this case would be:

  • each encrypted item must be also verified for authenticity using keyed HMAC, AES-GCM or a digital signature
  • any errors inside the server handlers should not be detailed in the response. Just return a generic 503 message
  • watch out for timing attacks that can give out the same information as error messages
  • the Verifier field is completely useless because attacker can reuse the one that she captured earlier
  • ideally the entire message should be encrypted with authentication, not only some fields

Quiark avatar Feb 01 '16 15:02 Quiark

TLS will never be implemented for the plugin.

On Mon, Feb 1, 2016 at 7:16 AM Roman Plášil [email protected] wrote:

I was looking into starting to use KeePass as the password manager and first thing I searched for was browser integration. I think KeePassHttp is a very useful tool but when I looked deeper I found some issues. Description

The communication between KeePass and the browser plugin is encrypted using AES 256. The implementation in KeepassHttp is not secure though. Attackers who are able to capture this encrypted traffic and send requests to the server can manage to decrypt captured passwords. Users who don't enable any remote connection and only stay on localhost for both client and server should be fine, others could be in trouble.

The fundamental problem is that the integrity of the encrypted entries is not protected using an authenticated MAC, authenticated encryption mode or a signature. This allows for the CBC padding oracle attack to be executed remotely to decrypt any encrypted entry that was captured earlier.

Leaking entire passwords to remote attackers is of course a serious problem but its impact is limited by the default setting to not allow remote connections. Furthermore, the padding oracle attack requires a few thousands requests to be executed, each of which pops an error tooltip on the targeted user's desktop. This doesn't mean that the user is protected though, a coworker could execute this attack when the target is away from the computer for example.

Leaving this particular vulnerability aside, the project's GitHub description says that KeepassHttp exposes password entries securely. I think most users, especially as the project reaches a wider user base, will just take that for granted and not pay attention to the caveat that the first key exchange is totally unprotected.

CBC padding oracle attack:

  • http://www.thoughtcrime.org/blog/the-cryptographic-doom-principle/
  • http://robertheaton.com/2013/07/29/padding-oracle-attack/
  • http://cryptopals.com/sets/3/challenges/17/

Cryptographic best practices:

  • https://gist.github.com/tqbf/be58d2d39690c3b366ad

Suggested fix

Short-term mitigation: An update for KeepassHttp that disables remote access completely or at least strongly warns users about this danger. Direct users in how to securely perform the association (with a disconnected computer).

Proper fix: Use cryptography best practices or, even better, use a TLS connection with self-generated certificates that the user confirms on both ends. Cryptography best practices in this case would be:

  • each encrypted item must be also verified for authenticity using keyed HMAC, AES-GCM or a digital signature
  • any errors inside the server handlers should not be detailed in the response. Just return a generic 503 message
  • watch out for timing attacks that can give out the same information as error messages
  • the Verifier field is completely useless because attacker can reuse the one that she captured earlier
  • ideally the entire message should be encrypted with authentication, not only some fields

— Reply to this email directly or view it on GitHub https://github.com/pfn/keepasshttp/issues/258#issuecomment-178012219.

pfn avatar Feb 01 '16 17:02 pfn

Also, at this point, I would appreciate any forks to fix this, as I do not plan on investing any significant time to maintain the browser trio (I absolutely hate browser development).

On Mon, Feb 1, 2016 at 9:08 AM Perry Nguyen [email protected] wrote:

TLS will never be implemented for the plugin.

On Mon, Feb 1, 2016 at 7:16 AM Roman Plášil [email protected] wrote:

I was looking into starting to use KeePass as the password manager and first thing I searched for was browser integration. I think KeePassHttp is a very useful tool but when I looked deeper I found some issues. Description

The communication between KeePass and the browser plugin is encrypted using AES 256. The implementation in KeepassHttp is not secure though. Attackers who are able to capture this encrypted traffic and send requests to the server can manage to decrypt captured passwords. Users who don't enable any remote connection and only stay on localhost for both client and server should be fine, others could be in trouble.

The fundamental problem is that the integrity of the encrypted entries is not protected using an authenticated MAC, authenticated encryption mode or a signature. This allows for the CBC padding oracle attack to be executed remotely to decrypt any encrypted entry that was captured earlier.

Leaking entire passwords to remote attackers is of course a serious problem but its impact is limited by the default setting to not allow remote connections. Furthermore, the padding oracle attack requires a few thousands requests to be executed, each of which pops an error tooltip on the targeted user's desktop. This doesn't mean that the user is protected though, a coworker could execute this attack when the target is away from the computer for example.

Leaving this particular vulnerability aside, the project's GitHub description says that KeepassHttp exposes password entries securely. I think most users, especially as the project reaches a wider user base, will just take that for granted and not pay attention to the caveat that the first key exchange is totally unprotected.

CBC padding oracle attack:

  • http://www.thoughtcrime.org/blog/the-cryptographic-doom-principle/
  • http://robertheaton.com/2013/07/29/padding-oracle-attack/
  • http://cryptopals.com/sets/3/challenges/17/

Cryptographic best practices:

  • https://gist.github.com/tqbf/be58d2d39690c3b366ad

Suggested fix

Short-term mitigation: An update for KeepassHttp that disables remote access completely or at least strongly warns users about this danger. Direct users in how to securely perform the association (with a disconnected computer).

Proper fix: Use cryptography best practices or, even better, use a TLS connection with self-generated certificates that the user confirms on both ends. Cryptography best practices in this case would be:

  • each encrypted item must be also verified for authenticity using keyed HMAC, AES-GCM or a digital signature
  • any errors inside the server handlers should not be detailed in the response. Just return a generic 503 message
  • watch out for timing attacks that can give out the same information as error messages
  • the Verifier field is completely useless because attacker can reuse the one that she captured earlier
  • ideally the entire message should be encrypted with authentication, not only some fields

— Reply to this email directly or view it on GitHub https://github.com/pfn/keepasshttp/issues/258#issuecomment-178012219.

pfn avatar Feb 01 '16 17:02 pfn

I use KeePassHttp remotely and completely agree with @Quiark. Keyed authentication is crucial in our case. @pfn thanks for the great software, I'm sure someone that's enjoys browser Dev could help take care of this. Nice post @Quiark!

Morphlin avatar Mar 24 '16 13:03 Morphlin

This is high priority! https://github.com/keepassxreboot/keepassxc/issues/147

I can't believe that the password is been exchanged in plain text in the associate request!

TheZ3ro avatar Jan 13 '17 19:01 TheZ3ro

First of all, this is over localhost. If you can be sniffed over localhost, your security has already be broken, game over.

Secondly, this is documented. If you are wanting to use keepasshttp over the Internet, you should add keys manually. Keepasshttp does not work over non localhost by default

On Fri, Jan 13, 2017, 11:29 AM TheZ3ro [email protected] wrote:

This is high priority! keepassxreboot/keepassxc#147 https://github.com/keepassxreboot/keepassxc/issues/147

I can't believe that the password is been exchanged in plain text in the associate request!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pfn/keepasshttp/issues/258#issuecomment-272525922, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfQxYVsIjDR2gKIDlwB6iza6EhRAyhoks5rR9CngaJpZM4HO5MN .

pfn avatar Jan 13 '17 19:01 pfn

You are right but lot of implementation out there are listening on 0.0.0.0 The documentation is not very specific (or I'm missing something other than the Readme.md ?) and you should specify that it's limited to localhost usage.

TheZ3ro avatar Jan 13 '17 20:01 TheZ3ro

@pfn do you think you can address this? I'm willing to help implementing an alternative key exchange protocol (I said alternative so both can be supported and maybe let user chose to use the secure one with an option in passIFox/chromeIPass)

First of all, this is over localhost. If you can be sniffed over localhost, your security has already be broken, game over.

Anyway what you said here is a "bad" simplification of reality. If an attacker can sniff on localhost, and the key is exchanged properly, this won't leak my password! (if he does have a keylogger/clipboard-stealer but the user use KeePassHTTP and leave his database closed this the attacker can't do anything) Even if my PC is compromised I hope my password will still be safe and private. This is the scope of a password manager.

TheZ3ro avatar Jan 23 '17 23:01 TheZ3ro

No, this is false, once an attacker has compromised your system sufficiently to sniff localhost traffic, they will have access to everything. Being able to sniff localhost implies root access and full capability to dump memory.

Only thing I would support would allowing for an easier method to exchange keys out of band. (ie showing a dialog for manual key entry, and having the browser extensions show their keys)

Any "secured" method of key exchange would require extensive and invasive user interaction to enable.

The only fixes I'm interested in are for any padding Oracle issues as implied by the referenced thread. This should be solvable by catching exceptions and not returning an error response.

On Mon, Jan 23, 2017, 3:24 PM TheZ3ro [email protected] wrote:

@pfn https://github.com/pfn do you think you can address this? I'm willing to help implementing an alternative key exchange protocol (I said alternative so both can be supported and maybe let user chose to use the secure one with an option in passIFox/chromeIPass)

First of all, this is over localhost. If you can be sniffed over localhost, your security has already be broken, game over.

Anyway what you said here is a "bad" simplification of reality. If an attacker can sniff on localhost, and the key is exchanged properly, this won't leak my password! (if he does have a keylogger/clipboard-stealer but the user use KeePassHTTP and leave his database closed this the attacker can't do anything) Even if my PC is compromised I hope my password will still be safe and private. This is the scope of a password manager.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pfn/keepasshttp/issues/258#issuecomment-274650847, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfQxXOEEEYUMuaCZrwKV5_MafWbt_Cjks5rVTalgaJpZM4HO5MN .

pfn avatar Jan 24 '17 02:01 pfn

Hey, i wanted to report the same issue. I wrote a CTF challenge and exploit for this vulnerability. The fix for the padding oracle attack is pretty easy (you don't have to move away from CBC even if GCM would be a better AES mode): Just don't tell the client if there was an Padding Exception during decryption.

This is implemented right for the decryption of the encrpyted IV (Nonce) in Protocol.cs (line 25: TestRequestVerifier). As you can see there is a try catch surrounding the decryption of the nonce. If there is an exception the client will get a 200 and no 500 response. Decrypting the encrpyted url does indeed return the exception to the client (KeePassHttp.cs line 86). To fix this vuln add a try catch to the KeePassHttp.cs like in Protocol.cs

If you need further explanations or help please ask!

kmille avatar Sep 14 '18 08:09 kmille

With a fix like this you still run the risk of having a timing or other side channel. The only correct fix is having authentication on the ciphertext using either HMAC or GCM or other authenticated mode.

pá 14. 9. 2018 v 17:11 odesílatel busbauen [email protected] napsal:

Hey, i wanted to report the same issue. I wrote a CTF challenge and exploit for this vulnerability. The fix for the padding oracle attack is pretty easy (you don't have to move away from CBC even if GCM would be a better AES mode): Just don't tell the client if there was an Padding Exception during decryption.

This is implemented right for the decryption of the encrpyted IV (Nonce) in Protocol.cs (line 25: TestRequestVerifier). As you can see there is a try catch surrounding the decryption of the nonce. If there is an exception the client will get a 200 and no 500 response. Decrypting the encrpyted url does indeed return the exception to the client (KeePassHttp.cs line 86). To fix this vuln add a try catch to the KeePassHttp.cs like in Protocol.cs

If you need further explanations or help please ask!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pfn/keepasshttp/issues/258#issuecomment-421273758, or mute the thread https://github.com/notifications/unsubscribe-auth/AADmw8ZTfVdrBU8DcAb2rwmzO5Fkrv4nks5ua2pAgaJpZM4HO5MN .

Quiark avatar Sep 14 '18 09:09 Quiark

That's right. But the fix for the easy and reliable way to exploit the vuln does not hurt anyone.

kmille avatar Sep 16 '18 17:09 kmille