Skip to content

Security - inadequate PRNG and trivially bruteforced mnemonic password #67

@erwanor

Description

@erwanor

Hello,

Issues:

Since the pin is a numeric string of length 7, the space of potential candidates is only 10^7. The wallet is using AES192 to encrypt the mnemonic using the pin as a shared secret. (https://github.com/mobius-network/wallet/blob/master/src/utils/encrypt.js#L4)

  const cipher = crypto.createCipher('aes192', password);

Since the attacker knows that the first k bytes of the mnemonic are going to match at least one word in the list of variations (https://github.com/mobius-network/wallet/blob/master/src/utils/generate-mnemonic-variations.js#L11) they only need to decrypt the first block (16 bytes) of the cipher and make an additional comparison of the first k < 16 (an extremely low constant factor) bytes.

I think your reasoning was that the overhead incurred by generating a public key from the candidate seed would be enough to discourage bruteforcing. That is not the case and the fact that you use a very poor source of entropy compounds this. The security of the pin should rely on appropriate cryptographic primitives like PBKFs anyway.

It takes less than a minute for a (really) naive Golang proof-of-concept to break it on my machine:

Recommendations:

  • Retire the wallet from the Apple/Android app stores until these issues are resolved

  • Always use cryptographically secure PRNGs [Edit: as far as the underlying libraries are sound, this is the case]

  • Closely follow BIP39 (https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) do not make your own crypto. [Edit: this is the case]

  • Increase the character set and length of the pin: alphanumeric string of 9 or 10 characters

  • Use a combination of password key derivation functions (e.g PBKDF2 with a large enough number of rounds) and AES256-GCM

  • Leverage secure enclaves/HSMs when the device allows it [Edit: this is at least partially the case]

  • Last but not least: Hire professional cryptographers to audit your code and recommend solutions (e.g NCC Cryptography services, LeastAuthority, etc.). These are really serious issues. As part of the Stellar ecosystem, I am sure Mobius team can ask for feedback/recommendations from Interstellar/SDF.

Security vulnerabilities happens all the time. It is unfortunate but they don't define you. It is all about how you respond to them! (i.e don't sue me lol)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions