Length extension attack

In cryptography and computer security, a length extension attack is a type of attack where an attacker can use Hash(message1) and the length of message1 to calculate Hash(message1 message2) for an attacker-controlled message2, without needing to know the content of message1. This is problematic when the hash is used as a message authentication code with construction Hash(secretmessage),[1] and message and the length of secret is known, because an attacker can include extra information at the end of the message and produce a valid hash without knowing the secret. Algorithms like MD5, SHA-1 and most of SHA-2 that are based on the Merkle–Damgård construction are susceptible to this kind of attack.[1][2][3] Truncated versions of SHA-2, including SHA-384 and SHA-512/256 are not susceptible,[4] nor is the SHA-3 algorithm.[5] HMAC also uses a different construction and so is not vulnerable to length extension attacks.[6] Lastly, just performing Hash(messagesecret) is enough to not be affected.

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 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 ten waffles 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.[note 1]

It is possible for an attacker to modify the request in this example by switching the requested waffle from "eggo" to "liege." This can be done by taking advantage of a flexibility in the message format if duplicate content in the query string gives preference 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 the length of the original request is known. 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 their forged message before the internal states of their 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\x28&waffle=liege

This message includes all of the padding that was appended to the original message inside of the hash function before their payload (in this case, a 0x80 followed by a number of 0x00s and a message length, 0x228 = 552 = (14+55)*8, which is the length of the key plus the original message, 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 he knows 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.

Notes

  1. ^ This example is also vulnerable to a replay attack, by sending the same request and signature a second time.

References

  1. ^ a b Vũ, Hoàng (2012-03-30). "MD5 Length Extension Attack Revisited - Vũ's Inner Peace". Archived from the original on 2014-10-29. Retrieved 2017-10-27.
  2. ^ Duong, Thai; Rizzo, Juliano (2009-09-28). "Flickr's API Signature Forgery Vulnerability" (PDF). Retrieved 2023-03-18.
  3. ^ Meyer, Christopher (2012-07-30). "Hash Length Extension Attacks". Retrieved 2017-10-27.
  4. ^ Bostrom, Michael (2015-10-29). "size_t Does Matter: Hash Length Extension Attacks Explained" (PDF). Retrieved 2020-11-23.
  5. ^ Keccak Team. "Strengths of Keccak - Design and security". Retrieved 2017-10-27. 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.
  6. ^ Lawson, Nate (2009-10-29). "Stop using unsafe keyed hashes, use HMAC". Retrieved 2017-10-27.

Read other articles:

Economy of LondonLondon is the largest urban economy in Europe[1] and, alongside New York, the city in the world most integrated with the global economy.[2]StatisticsPopulation8,796,628 (2021)[3]GDP£526.5 billion (2021)[3]GDP per capita£59,855 (2021)[3]Labour force4,829,000 / 76.1% in employment (Oct–Dec 2023)[a][4]Labour force by occupation List 34.5% Professional 16.6% Associate professional 12.5% Managers, directors and senior o…

BonziBuddy Gambar promosi BonziBuddyTipeperangkat lunak Versi pertama1999GenreAdware, spywareKarakterBonzi Buddy LisensiFreewareKarakteristik teknisSistem operasiMicrosoft WindowsPlatformWindows Sunting di Wikidata  • Sunting kotak info • L • BBantuan penggunaan templat ini BonziBuddy, (dibaca /bɒnzibʌdiː/ bon-zee-bud-ee) adalah freeware asisten virtual desktop yang diciptakan oleh Joe dan Jay Bonzi. Atas pilihan pengguna, BonziBuddy akan berbagi lelucon dan fakta, mengel…

Czech politician Miloslav VlčekPresident of the Chamber of Deputies of the Czech RepublicIn office14 August 2006 – 30 April 2010Preceded byLubomír ZaorálekSucceeded byMiroslava NěmcováMember of the Chamber of DeputiesIn office1 June 1996 – 30 April 2010 Personal detailsBorn (1961-02-01) 1 February 1961 (age 63)Konice, CzechoslovakiaPolitical partyČSSDSpouseSoňa Vlčková Miloslav Vlček (born 1 February 1961) is a Czech politician who was the Member of the Czech…

Constituency of the National Assembly of Pakistan NA-215 Tharparkar-IIConstituencyfor the National Assembly of PakistanRegionKaloi, Diplo, Mithi and Islamkot Tehsils and Chachro Tehsil (partly) of Tharparkar DistrictElectorate415,109 [1]Current constituencyMember(s)VacantCreated fromNA-229 Tharparkar-I NA-215 Tharparkar-II (این اے-215، تھرپارکر-2) is a constituency for the National Assembly of Pakistan.[2] Members of Parliament 2018-2022: NA-222 Tharparkar-II Electi…

بطولة ويمبلدون 1884 - فردي السيدات جزء من بطولة ويمبلدون 1884  البلد المملكة المتحدة لبريطانيا العظمى وأيرلندا  التاريخ 1884  الرياضة كرة المضرب  البطل(ة) مود واتسون الوصيف(ة) ليليان واتسون النتيجة 6-8 6-3 6-3   بطولة ويمبلدون 1885 - فردي السيدات  تعديل مصدري - تعديل   في ب…

منتخب البوسنة والهرسك تحت 21 سنة لكرة القدم بلد الرياضة البوسنة والهرسك  الفئة كرة قدم تحت 21 سنة للرجال  [لغات أخرى]‏  رمز الفيفا BIH  مشاركات تعديل مصدري - تعديل   منتخب البوسنة والهرسك تحت 21 سنة لكرة القدم هو الممثل الرسمي لالبوسنة والهرسك في بطولات كرة القدم …

River and power stations in Scotland River MoristonThe River Moriston looking downstream from Torgyle BridgeLocation of the mouth within Scottish HighlandsLocationCountryScotlandPhysical characteristicsSource  • locationLoch Cluanie • coordinates57°08′35″N 5°00′06″W / 57.1430°N 5.0016°W / 57.1430; -5.0016 Mouth  • locationLoch Ness • coordinates57°12′35″N 4°36′12″W…

1961 American crewed sub-orbital spaceflight Mercury-Redstone 4Astronaut Gus Grissom climbs into Liberty Bell 7Mission typeTest flightOperatorNASAMission duration15 minutes, 37 seconds[1]Range262.50 nautical miles (486.15 km)Apogee102.76 nautical miles (190.31 km) Spacecraft propertiesSpacecraftMercury No.11ManufacturerMcDonnell AircraftLaunch mass2,835 pounds (1,286 kg) CrewCrew size1MembersVirgil I. GrissomCallsignLiberty Bell 7 Start of missionLaunch dateJuly 21, 1961, …

US Supreme Court justice since 2017 (born 1967) Gorsuch redirects here. For the surname, see Gorsuch (surname). Neil GorsuchOfficial portrait, 2017Associate Justice of the Supreme Court of the United StatesIncumbentAssumed office April 10, 2017Appointed byDonald TrumpPreceded byAntonin ScaliaJudge of the United States Court of Appeals for the Tenth CircuitIn officeAugust 8, 2006 – April 9, 2017Appointed byGeorge W. BushPreceded byDavid M. EbelSucceeded byAllison H. EidPrincipal De…

Scientology front group The Way to Happiness Foundation InternationalLogo of foundationTypeNon-profit organizationHeadquarters201 E. Broadway,Glendale, CaliforniaOfficial language EnglishParent organizationAssociation for Better Living and Education (ABLE)AffiliationsChurch of ScientologyWebsiteThe Way to Happiness The Way to Happiness is a 1980 booklet written by science-fiction author and Scientology founder L. Ron Hubbard listing 21 moral precepts. The booklet is distributed by The Way to Hap…

Pour les articles homonymes, voir Thunder. Thunder d'Oklahoma City Généralités Noms précédents SuperSonics de Seattle1967–2008 Fondation 1967 Couleurs Salle Paycom Center19 599 places Siège Oklahoma City Oklahoma États-Unis Championnat actuel NBA Propriétaire Professional Basketball Club (en) Manager Sam Presti Entraîneur Mark Daigneault Palmarès principal National[1] 11979 Maillots       Association       Icon       Statement Ac…

Large gulf at the northern tip of the Red Sea Gulf of AqabaGulf of Eilatخَلِيج الْعَقَبَة (Arabic)מפרץ אילת (Hebrew)The Sinai Peninsula with the Gulf of Aqaba to the east and the Gulf of Suez to the westGulf of AqabaLocationWest AsiaCoordinates28°45′N 34°45′E / 28.750°N 34.750°E / 28.750; 34.750TypeGulfPrimary inflowsRed SeaBasin countriesEgypt, Israel, Jordan, and Saudi ArabiaMax. length160 km (99 mi)Max. width24&#…

Vowel sound represented by ⟨ɵ⟩ in IPA Not to be confused with Voiceless dental fricative, represented by ⟨θ⟩ in the IPA. Close-mid central rounded vowelɵIPA Number323Audio sample source · helpEncodingEntity (decimal)ɵUnicode (hex)U+0275X-SAMPA8Braille Image IPA: Vowels Front Central Back Close i y ɨ ʉ ɯ u Near-close ɪ ʏ ʊ Close-mid e ø ɘ ɵ ɤ o Mid e̞ ø̞ ə ɤ̞ o̞ Open-mid ɛ œ ɜ ɞ ʌ ɔ Near-open æ ɐ Open a ɶ ä ɑ ɒ IPA help  audio fu…

此條目没有列出任何参考或来源。 (2013年10月29日)維基百科所有的內容都應該可供查證。请协助補充可靠来源以改善这篇条目。无法查证的內容可能會因為異議提出而被移除。 帕帕加尤斯Papagaios市镇帕帕加尤斯在巴西的位置坐标:19°26′56″S 44°44′52″W / 19.4489°S 44.7478°W / -19.4489; -44.7478国家巴西州米纳斯吉拉斯州面积 • 总计552.776 平方公里(213.42…

Giardini Majorelle UbicazioneStato Marocco LocalitàMarrakech IndirizzoRue Yves Saint Laurent CaratteristicheTipoGiardino Superficie8000 m² Aperturatutto l'anno RealizzazioneArchitettoPaul Sinoir ProprietarioFondation Pierre Bergé - Yves Saint Laurent Mappa di localizzazione Sito web Modifica dati su Wikidata · Manuale I giardini Majorelle (AFI: /maʒɔ'ʁɛl/; in arabo حديقة ماجوريل‎?; in francese: Jardin Majorelle), sono un complesso di giardini botanici e p…

Karta över Yeonpyeongdo (3) och andra öar längs Sydkoreas nordvästra kust Yeonpyeongdo (hangul: 연평도, hanja: 延坪島; IPA: [jʌnpʰjʌŋdo]) är en grupp öar längs Sydkoreas kust mot Gula havet. Ögruppen är en socken, Yeonpyeong-myeon inom Ongjin-gun, vilket är en landskommun som tillhör storstaden Incheon på det sydkoreanska fastlandet. Den totala folkmängden uppgick år 2024 till ca 2 000 invånare.[1] Ögruppen ligger bara 12 km från Nordkoreas kust, och sedan 1990-ta…

Questa voce o sezione sull'argomento ponti non cita le fonti necessarie o quelle presenti sono insufficienti. Puoi migliorare questa voce aggiungendo citazioni da fonti attendibili secondo le linee guida sull'uso delle fonti. Ponte di AugustoLocalizzazioneStato Italia CittàNarni AttraversaNera Dati tecniciTipoponte romano Materialetravertino Lunghezza160 m Larghezza8 m Altezza30 m RealizzazioneProgettistaignoto Costruzioneetà augustea-... Mappa di localizzazione Modifica dati su Wiki…

Province of Italy Province in Emilia-Romagna, ItalyProvince of FerraraProvinceEstense Castle, the provincial seat FlagCoat of armsMap highlighting the location of the province of Ferrara in ItalyCountry ItalyRegionEmilia-RomagnaCapital(s)FerraraComuni23Government • PresidentGianni Michele PadovaniArea • Total2,632 km2 (1,016 sq mi)Population (28 February 2023) • Total338 143GDP[1] • Total€9.016 billion (2015) …

此條目需要精通或熟悉相关主题的编者参与及协助编辑。 (2018年11月16日)請邀請適合的人士改善本条目。更多的細節與詳情請參见討論頁。 此條目没有列出任何参考或来源。 (2018年11月16日)維基百科所有的內容都應該可供查證。请协助補充可靠来源以改善这篇条目。无法查证的內容可能會因為異議提出而被移除。 數碼音頻無線電衛星(英文:Digital Audio Radio Satellite,簡稱:DARS…

Upiak IsilLahirSilvia Nanda24 Desember 1986 (umur 37)Bukittinggi, Sumatera Barat, IndonesiaNama lainUpiak IsilPekerjaanPenyanyiaktrisKarier musikInstrumenVokalTahun aktif2017—sekarangLabelElta Record Silvia Nanda[1], dikenal sebagai Upiak Isil (lahir 24 Desember 1986) adalah penyanyi dan aktris Indonesia. Ia mempopulerkan singel Tak Tun Tuang[2] yang diunggah dan dirilis di media sosial pada tahun 2017. Singel ini populer di Asia Tenggara, terutama Thailand[3]…