World Library  
Flag as Inappropriate
Email this Article

Length extension attack

Article Id: WHEBN0036667216
Reproduction Date:

Title: Length extension attack  
Author: World Heritage Encyclopedia
Language: English
Subject: Merkle–Damgård construction, VMAC, SIMD (hash function), NaSHA, CWC mode
Collection:
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Length extension attack

In cryptography and computer security, length extension attacks are a type of attack when certain types of hashes are misused as message authentication codes, allowing for inclusion of extra information.

This attack can be done on hashes with construction H(secretmessage)[1] when message and the length of secret is known. Algorithms like MD5 and SHA-1 that are based on the Merkle–Damgård construction are susceptible to this kind of attack.[2][3][4] Note that since HMAC doesn't use the construction H(keymessage), HMAC hashes using susceptible algorithms are not prone to length extension attacks.[5] The SHA-3 algorithm is not susceptible to this attack. [6]

Explanation

The vulnerable hashing functions work by taking the input message, and using it to transform an internal state. After all of the input has been processed, the hash digest is generated by outputting the internal state of the function. It is therefore possible to reconstruct the internal state from the hash digest, which can then be used to process the new data. In this way one may extend the message and compute the hash that is a valid signature for the new message.

Example

A server for delivering waffles of a specified type to a specific user at a location could be implemented to handle requests of the given format:

Original Data: count=10&lat=37.351&user_id=1&long=-119.827&waffle=eggo
Original Signature: 6d5f807e23db210bc254a28be2d6759a0f5f5d99

The server would perform the request given (to deliver a waffle of type eggo to the given location for user 1) only if the signature is valid for the user. The signature used here is a MAC, signed with a key not known to the attacker. (This example is also vulnerable to a replay attack, by sending the same request and signature a second time.)

It is possible for an attacker to modify the request, in this example switching the requested waffle from "eggo" to "liege." This can be done by taking advantage of a flexibility in the message format: duplicate content in the query string give preferences to the latter value. This flexibility does not indicate an exploit in the message format, because the message format was never designed to be cryptographically secure in the first place, without the signature algorithm to help it.

Desired New Data: count=10&lat=37.351&user_id=1&long=-119.827&waffle=eggo&waffle=liege

In order to sign this new message, typically the attacker would need to know the key the message was signed with, and generate a new signature by generating a new MAC. However, with a length extension attack, it is possible to feed the hash (the signature given above) into the state of the hashing function, and continue where the original request had left off, so long as you know the length of the original request. In this request, the original key's length was 14 bytes, which could be determined by trying forged requests with various assumed lengths, and checking which length results in a request that the server accepts as valid.

The message as fed into the hashing function is often padded, as many algorithms can only work on input messages whose lengths are a multiple of some given size. The content of this padding is always specified by the hash function used. The attacker must include all of these padding bits in his forged message before the internal states of his message and the original will line up. Thus, the attacker constructs a slightly different message using these padding rules:

New Data: count=10&lat=37.351&user_id=1&long=-119.827&waffle=eggo\x80\x00\x00
          \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
          \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
          \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
          \x00\x00\x00\x02&waffle=liege

This message includes all of the padding that was appended to the original message inside of the hash function before his payload (in this case, a 0x80 followed by a number of 0x00s and a message length appended at the end). The attacker knows that the state behind the hashed key/message pair for the original message is identical to that of new message up to the final "&." The attacker also knows the hash digest at this point, which means they know the internal state of the hashing function at that point. It is then trivial to initialize a hashing algorithm at that point, input the last few characters, and generate a new digest which can sign his new message without the original key.

New Signature: 0e41270260895979317fff3898ab85668953aaa2

By combining the new signature and new data into a new request, the server will see the forged request as a valid request due to the signature being the same as it would have been generated if the password was known.

This attack has mostly been used for forging signed data, but it does have other possibilities.[7]

Implementations

One tool which uses OpenSSL to implement this attack for various hash algorithms is HashPump. This tool supports the Length Extension Attack for MD5, SHA1, SHA256 and SHA512. SHA224 and SHA384 are not vulnerable to this attack due to their reduced output of their state variables, instead of all their state variables. Another tool is Hash Extender. [7]

References

  1. ^ [1]
  2. ^ [2]
  3. ^ Flickr API Signature Forgery Vulnerability
  4. ^ [3]
  5. ^ [4]
  6. ^ Keccak team. "Strengths of Keccak - Design and security". Retrieved 30 January 2013. Unlike SHA-1 and SHA-2, Keccak does not have the length-extension weakness, hence does not need the HMAC nested construction. Instead, MAC computation can be performed by simply prepending the message with the key. 
  7. ^ a b Wallace, Brian. "Hash Length Extension Attack". 
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.