SHA3 Buffer Overflow
The SHA-3 reference implementation in XKCP, and copies of it in Python, PHP, PyPy, pysha3, Ruby's sha3 and XKCP, mishandled very large update lengths, causing a buffer overflow. An attacker could crash the process, cause an infinite loop, and the author says a crafted file could lead to arbitrary code execution and break the hash's security properties.
Published on mouha.be
Over the past few months, I’ve been coordinating the disclosure of a new vulnerability that I’ve found. Today is the disclosure date, so I am excited that I can finally talk about what I’ve been working on!
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely an integer overflow in the length/offset tracking of the SHA-3 update routine, so a very large input length wraps and the buffer bounds check is defeated.
Impact
The process can crash with a segmentation fault or hang in an infinite loop, and the author states a specially constructed file can result in arbitrary code execution and that hash properties such as preimage and collision resistance can be violated.
What the attacker needed
Ability to supply very large input to a SHA-3 API
The fix
The affected projects released fixes, with bug reports and a commit listed for Python, PHP, PyPy, pysha3, Ruby's sha3 and XKCP.
How it was found
- Create a SHA-3-224 hash context.
- Feed it one byte of data.
- Feed it a further 4294967295 bytes of data.
- Finish the hash and print the digest, which triggers the crash.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A hash function turns data into a short fingerprint, and SHA-3 is one widely used standard. The C code behind it kept a running count of how much data had been fed in, and with a huge amount of data that count wrapped around, so the program wrote past the end of its memory buffer. That can crash the program, hang it, or in the worst case let an attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.