Integer overflow in XKCP Keccak SHA-3 reference implementation leads to buffer overflow

Note: This data is for reference and cybersecurity research purposes only.CyStack advises users not to use this information for unlawful purposes.

Overview

Original source data

The Keccak XKCP SHA-3 reference implementation before fdc6fef has an integer overflow and resultant buffer overflow that allows attackers to execute arbitrary code or eliminate expected cryptographic properties. This occurs in the sponge function interface.

Affected products and scope

The XKCP reference implementation itself, in builds from before the upstream fix. Downstream, the record lists PHP, Python, PyPy, the pysha3 package and a Ruby sha3 gem, plus Debian and Fedora, where the affected code is carried in distribution packages. Because the flaw lives in a bundled hashing library, the practical question is which services link or embed Keccak and SHA-3 code rather than which product name you recognise. The record does not enumerate unaffected configurations.

Technical details

Keccak is the permutation family behind SHA-3. Its sponge construction absorbs input in fixed-size blocks: the caller supplies input and a length, the implementation tracks how much has been absorbed, and arithmetic on those counters decides where the next block is written. The record states that this arithmetic can overflow in the XKCP reference implementation and that the overflow leads to a buffer overflow in the sponge function interface. In plain terms, a length calculation wraps around to a small number, a bounds check passes, and the copy that follows writes past the end of its buffer. The record does not name the specific function, variable or input path involved, so public detail on exactly which argument has to be attacker controlled is limited.

Exploitability

Scored as remotely reachable, with no privileges and no user interaction required, which describes the worst case: an application that passes attacker-influenced data into the sponge interface. In practice reachability depends on whether the application lets a remote party control the length or size arguments of the hashing call; a service that hashes a fixed-size value on its own is not exposed in the same way. The record notes public exploit material and a patch. No confirmed exploitation in the wild is recorded.

Technical impact

Two outcomes are described. The first is arbitrary code execution in the process that performs the hash, since an out-of-bounds write in native code can often be turned into control flow hijack given a favourable memory layout. The second is loss of the cryptographic properties the hash is supposed to provide, meaning the output can no longer be trusted as a faithful digest of the input. The record does not say which outcome occurs under which conditions, and it does not describe an exploit chain.

Business impact

Anything that hashes data with an affected build sits in the blast radius: password storage, signature and integrity checks, token generation, content addressing. Where code execution is achieved, the attacker acts with the privileges of the process doing the hashing, which in a web stack is often the whole application. Where execution is not achieved, the quieter outcome damages trust: hashes that no longer match, signature checks that pass or fail for the wrong reasons, and derived keys weaker than the design assumes. Teams should care if they run PHP, Python, PyPy or Ruby services that call SHA-3 or SHAKE, or if they ship appliances and container images built on Debian or Fedora.

Remediation

Update to a build that includes the upstream XKCP fix, and take the corresponding distribution updates for Debian and Fedora rather than patching the library by hand. Where you depend on PHP, Python, PyPy, pysha3 or the Ruby sha3 gem, move to a release that carries the fixed implementation. The record offers no workaround. If you cannot update yet, the interim measure is to stop passing externally supplied lengths into SHA-3 or SHAKE calls, and to treat any SHA-3 output produced by an affected build as untrusted.

Detection

Look for bundled or vendored Keccak implementations in your dependency inventory, including copies compiled into language runtimes and container base images, since those are easy to miss. On the runtime side, watch for crashes or memory errors in processes that hash data, particularly around SHA-3 and SHAKE calls. Where the application exposes hashing to remote input and you keep request logs, review for unusually large or wrapped-around length values reaching those paths. Recomputing a sample of stored hashes and comparing them against what is on disk will also show whether output has been silently corrupted.

Sources (23)
Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.