[JS] cwe-327 (Weak or vulnerable cryptography usage) added#3977
[JS] cwe-327 (Weak or vulnerable cryptography usage) added#3977monkey-junkie wants to merge 8 commits intogithub:mainfrom
Conversation
Hi! |
asgerf
left a comment
There was a problem hiding this comment.
Hi @monkey-junkie, thanks for the contribution! This looks really interesting.
I'm not an expert in cryptography, but I think I understand the chosen-plaintext attack vector, and it would be great to have a query for that.
So far I just have a few initial comments and questions.
| ivBlock = call.(InvokeNode).getArgument(2).getALocalSource().getBasicBlock() and | ||
| alg = call.(InvokeNode).getArgument(0).toString() | ||
| | | ||
| createCihperBlock.length() != ivBlock.length() and |
There was a problem hiding this comment.
This doesn't looks right. The BasicBlock class has nothing to do with cryptography; it refers to the concept from compilers (see wikipedia page). I don't see why its length should matter.
Do I understand correctly that the OFB and CTR modes of AES become susceptible to chosen-plaintext attacks if subsequent encryption requests are made with the same IV? If so, you probably want to use getContainer instead of getBasicBlock:
call.getContainer() != call.getArgument(2).getALocalSource().getContainer()There was a problem hiding this comment.
Hi!
Yes, exactly, OFB and CTR with the static IV are vulnerable to CPA. I tried to use .legnth() method of BasicBlock to distinguish blocks with IV initialization and its actual usage. But now I can see, that I was wrong and I should use getContainer instead.
Thanks!
There was a problem hiding this comment.
I've updated pr according all your comments, @asgerf please review :)
javascript/ql/src/experimental/Security/CWE-327/BrokenSymmetricCrypto.ql
Outdated
Show resolved
Hide resolved
javascript/ql/src/experimental/Security/CWE-327/BrokenSymmetricCrypto.ql
Outdated
Show resolved
Hide resolved
javascript/ql/src/experimental/Security/CWE-327/BrokenSymmetricCrypto.ql
Outdated
Show resolved
Hide resolved
…cCrypto.ql Co-authored-by: Asger F <asgerf@github.com>
…cCrypto.ql Co-authored-by: Asger F <asgerf@github.com>
…cCrypto.ql Co-authored-by: Asger F <asgerf@github.com>
|
@monkey-junkie In case you didn't know:
|
asgerf
left a comment
There was a problem hiding this comment.
After studying this a little more I start to wonder if this should be moved to BrokenCryptoAlgorithm. The chosen-plaintext vector seemed really interesting at first, but now it seems to me these crypto algorithms are insecure even if the attacker can't choose the plaintext.
Two questions:
- Is there ever a valid reason to use ECB when an outsider can't control the plaintext?
- Is there ever a valid reason to reuse a given IV for multiple plaintexts?
If not, I think we can move these sinks into BrokenCryptoAlgorithm and just flag them regardless of whether the plaintext is tainted.
If there are valid reasons (and we could thus get FPs from BrokenCryptoAlgorithm), I'd appreciate it if the documentation is more specific to chosen-plaintext attacks rather than the generic "incorrect usage" term. For example, the @description could be:
Encrypting user-controlled plaintexts with ECB or with a reused IV enables an attacker to recover the secret key via chosen-plaintext attack.
(keep in mind I'm not a cryptographer so the above description may be wrong, in particular the part about actually recovering the key)
javascript/ql/src/experimental/Security/CWE-327/BrokenSymmetricCrypto.ql
Outdated
Show resolved
Hide resolved
javascript/ql/src/experimental/Security/CWE-327/BrokenSymmetricCrypto.ql
Outdated
Show resolved
Hide resolved
I think this is the mistake that Sony made in the Playstation 3 (article). |
…cCrypto.ql Co-authored-by: Asger F <asgerf@github.com>
…cCrypto.ql Co-authored-by: Asger F <asgerf@github.com>
Hi!
No.
According to RFC for CTR mode, "The same IV and key combination MUST NOT be used more than once" so, technically, it is safe to use static IV with unique encryption key per message, but unique encryption key is very rare case. In sum, I think you are right and whe should move query to |
Thanks. Please go ahead. |
|
Closing the PR due to inactivity, but feel free to reopen if you wish to continue work on it. Overall I think the ECB and reused-IV stuff could be useful to have in query suite in some form, so I'd be happy to see it re-opened. In retrospect I wish I had not suggested moving it into the non-experimental |


Hi team!
I've wrote detection of usage of weak block cipher algorithms like block ciphers in ECB mode (known as chosen plaintext attack) and for common crypto flaw - static IV for block ciphers.
Either of such flaws could led to sensitive data leak.
More information:
OWASP - https://owasp.org/www-community/vulnerabilities/Using_a_broken_or_risky_cryptographic_algorithm
OWASP cheatsheet - https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html
Real world example - https://www.ambionics.io/blog/prestashop-privilege-escalation
CPA - https://en.wikipedia.org/wiki/Chosen-plaintext_attack