Re: [Ntp] Last Call: <draft-ietf-ntp-mac-05.txt> / full length-extension attack

Tim Ruffing <crypto@timruffing.de> Thu, 01 November 2018 20:07 UTC

Return-Path: <crypto@timruffing.de>
X-Original-To: ntp@ietfa.amsl.com
Delivered-To: ntp@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 9E27212777C; Thu, 1 Nov 2018 13:07:44 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.602
X-Spam-Level:
X-Spam-Status: No, score=-2.602 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AujntVl8lr-g; Thu, 1 Nov 2018 13:07:41 -0700 (PDT)
Received: from mx2.mailbox.org (mx2.mailbox.org [80.241.60.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2E94D12D4E8; Thu, 1 Nov 2018 13:07:41 -0700 (PDT)
Received: from smtp1.mailbox.org (unknown [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id D02AEA1106; Thu, 1 Nov 2018 21:07:38 +0100 (CET)
X-Virus-Scanned: amavisd-new at heinlein-support.de
Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id d7EyLYtC_-I7; Thu, 1 Nov 2018 21:07:37 +0100 (CET)
Message-ID: <eff28a1653e6c90be52cf2a4185495e763bfc24e.camel@timruffing.de>
From: Tim Ruffing <crypto@timruffing.de>
To: ietf@ietf.org
Cc: ietf-announce@ietf.org, ntp-chairs@ietf.org, ntp@ietf.org, draft-ietf-ntp-mac@ietf.org, suresh@kaloom.com
Date: Thu, 01 Nov 2018 21:07:35 +0100
Content-Type: text/plain; charset="UTF-8"
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/ntp/gvibuB6bTbDRBumfHNdJ84Kq4kA>
Subject: Re: [Ntp] Last Call: <draft-ietf-ntp-mac-05.txt> / full length-extension attack
X-BeenThere: ntp@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <ntp.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/ntp>, <mailto:ntp-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/ntp/>
List-Post: <mailto:ntp@ietf.org>
List-Help: <mailto:ntp-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/ntp>, <mailto:ntp-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 01 Nov 2018 20:18:56 -0000

Dear all,

I've recently looked into NTP security and developed a proof-of-concept
exploit for a length-extension attack. It turns out that
length-extension attacks are possible but only under certain exotic
conditions with MD5 and RIPEMD-160. Since we now know that a concrete
attack can be crafted for MD5 and RIPEMD-160, I suggest that draft-
ietf-ntp-mac does not only deprecate MD5 but also RIPEMD-160, which is
not required by RFC 5905 but implemented by ntpd for example. I know
I'm late to the party...

A while ago I reported this to Miroslav Lichvar first, who suggested
that it's okay to post it publicly because the issue looks rather
harmless to both of us. 

Miroslav wrote on the NTP WG list:
> My understanding is that the NTPv4 packet format (with or without
> RFC7822) prevents the length-extension attack as extension fields
> cannot have a length of zero, which would come from the padding
> (always starting with 0x80000000). Even if the length field could be
> zero, there is no EF type 0x8000 assigned yet and it could be avoided
> in future in case people are for some reason still using the old MAC.

The problem here is that this assumes that the length value in the
padding is big-endian, which is not always the case. Notable exceptions
are MD5 and RIPEMD-160, which use little-endian, see
https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks
 for a nice overview.

With little-endian it's actually possible to exploit this. If the
hashed data is for example 117 bytes = 936 bits, then the padding
starts with 0x800000a803 and 0x00a8 (interpreted as big-endian) will be
the length value of an extension field. By adding enough dummy bytes,
the attacker can thus insert a dummy extension field (with type 0x00
and response flag set due to the leading 0x80), which will be ignored
by the recipient. The attacker can then add arbitrary malicious
extension fields after the dummy extension field.

In theory, the same should work when 118 bytes = 944 bits are hashed,
then the padding starts with 0x8000b003, but then the length of the
extension field is already 45059 bytes, which will hopefully be
rejected by most implementations anyway.

Miroslav observed that 119 bytes = 952 bits works, too:
> If the padding started with 0x80b80300, the EF would have a length of
> 768 bytes and could be skipped as an unknown valid EF.

Also, the same attack works for 117 + 64n or 119 + 64n bytes of hashed
data for any integer n due to the blocksize of MD5 and RIPEMD-160. For
packets without extension fields, this happens pretty rarely: It turns
out that we need a MAC key size of 5 + 64n or 7 + 64n bytes. I don't
except these key size to be common. (Some people probably use small
keys/passwords of size 5 or 7 but these can be broken by brute force
search anyway). However, if the original packet intercepted by the
attacker already contains extension fields, then the required key
lengths will be different. Miroslav told me that ntpd probably only
supports keys up to 32 bytes.

I have a working proof-of-concept exploit. It assumes MD5 with a 69
byte key, and chronyd will happily accept the forged packet. An exploit
for RIPEMD-160 should work the same way essentially. I can provide it
if anybody is interested.

Anyway, I think that all of this is not a big issue because I
don't see how the currently defined extension fields could do any harm.
As far as I understand autokey (and I'm sure I don't understand it
fully), the autokey protocol itself relies on signatures because
obviously the goal is to establish a symmetric key -- so if the
peers had already one, they wouldn't need autokey. Also, forging
RFC 7821 extension fields seems pretty harmless to me. Still, MD5 and
RIPEMD-160 should not be used.

Best,
Tim Ruffing