If exploited, these flaws can allow attackers to gain unauthorized access to sensitive information or generally cause problems
A vulnerability (already cataloged under CVE-2022-37454) has been identified in the implementation of the SHA-3 cryptographic hash function (Keccak), offered in the XKCP (eXtended Keccak Code Package).
The identified vulnerability can cause a buffer overflow during the processing of formed data. The problem stems from a bug in the code of a specific SHA-3 implementation, not a vulnerability in the algorithm itself.
The XKCP package is promoted as the official implementation of SHA-3, developed with the help of the Keccak development team, and is used as the basis for functions to work with SHA-3 in various programming languages ​​(for example, the XKCP code is used in the Python hashlib module, the Ruby digest-sha3 package, and the PHP hash_* functions).
According to the researcher who identified the problem, he was able to use the vulnerability to violate the cryptographic properties of the hash function and find the first and second preimages, as well as determine collisions.
The reason for segmentation fault is that scripts will try to write more data to a buffer than it can hold. Such a vulnerability is known as a buffer overflow, which OWASP describes as "probably the best-known form of software security vulnerability."
A small variant of the code will cause an infinite loop: just replace 4294967295 with 4294967296. Note the similarity to CVE-2019-8741, another vulnerability I found that affected the firmware of over 1.400 billion Apple devices, which also caused a loop infinite.
Furthermore , the creation of a prototype exploit has been announced, which allows for code execution by calculating the hash of a specially crafted file. Potentially, the vulnerability can also be used to attack digital signature verification algorithms using SHA-3 (e.g., Ed448). Details of the attack methods are expected to be published later, after the widespread removal of the vulnerability.
This kind of behavior is not supposed to happen in "safe" languages ​​like Python and PHP, since they check that all read and write operations are within the buffer bounds. However, the problem is that the vulnerability is present in the underlying "insecure" C language...
It is not yet clear how the vulnerability affects existing applications in practice , since for the problem to manifest itself in the code, cyclic block hash calculation must be used, and one of the processed blocks must be approximately 4 GB in size (at least 2^32 – 200 bytes).
When processing the input data at once (without sequential calculation of the hash by parts), the problem does not appear. As a simpler protection method, it is proposed to limit the maximum size of the data involved in one iteration of the hash calculation.
The vulnerable code was published in January 2011, so it took more than a decade to find this vulnerability. It seems to be difficult to find vulnerabilities in cryptographic implementations, even though they play a critical role in the overall security of a system. (Perhaps people aren't even looking for such vulnerabilities, since neither this vulnerability in XKCP nor the Apple vulnerability mentioned above are eligible for any bug bounty programs!)
The vulnerability stems from an error in the processing of input data blocks . Due to an incorrect comparison of values ​​with the "int" type, an incorrect size of the pending data is determined, causing the queue to be written outside the allocated buffer.
Specifically, it was noted that the comparison involved the use of the expression " partialBlock + instance->byteIOIndex ", which, with large component values, led to an integer overflow. Additionally, there was an incorrect encoding of "(unsigned int)(dataByteLen - i)" in the code, which caused an overflow on systems with a 64-bit size_t type.
Finally, if you are interested in learning more about this , you can find the details at the following link.