<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" docName="draft-ietf-ntp-port-randomization-08" number="9109" submissionType="IETF" category="std" consensus="true" updates="5905" ipr="trust200902" obsoletes="" xml:lang="en" symRefs="true" sortRefs="true" tocInclude="true" version="3">

  <front>

    <title abbrev="NTP Port Randomization">Network Time Protocol Version 4: Port Randomization</title>
    <seriesInfo name="RFC" value="9109"/>
    <author initials="F." surname="Gont" fullname="Fernando Gont">
      <organization>SI6 Networks</organization>
      <address>
        <postal>
          <street>Evaristo Carriego 2644</street>
          <city>Haedo, Provincia de Buenos Aires</city>
          <code>1706</code>
          <country>Argentina</country>
        </postal>
        <phone>+54 11 4650 8472</phone>
        <email>fgont@si6networks.com</email>
        <uri>https://www.si6networks.com</uri>
      </address>
    </author>
    <author initials="G." surname="Gont" fullname="Guillermo Gont">
      <organization>SI6 Networks</organization>
      <address>
        <postal>
          <street>Evaristo Carriego 2644</street>
          <city>Haedo, Provincia de Buenos Aires</city>
          <code>1706</code>
          <country>Argentina</country>
        </postal>
        <phone>+54 11 4650 8472</phone>
        <email>ggont@si6networks.com</email>
        <uri>https://www.si6networks.com</uri>
      </address>
    </author>
    <author initials="M." surname="Lichvar" fullname="Miroslav Lichvar">
      <organization>Red Hat</organization>
      <address>
        <postal>
          <street>Purkynova 115</street>
          <city>Brno</city>
          <code>612 00</code>
          <country>Czech Republic</country>
        </postal>
        <email>mlichvar@redhat.com</email>
      </address>
    </author>
    <date year="2021" month="August"/>
    <workgroup>Network Time Protocol (ntp) Working Group</workgroup>
 <keyword>security</keyword>
 <keyword>transport protocols</keyword>

    <abstract>
      <t>
   The Network Time Protocol (NTP) can operate in several modes.  Some of these
   modes are based on the receipt of unsolicited packets and therefore
   require the use of a well-known port as the local port.  However, in
   the case of NTP modes where the use of a well-known port is not required,
   employing such a well-known port unnecessarily facilitates the ability of
   attackers to perform blind/off-path attacks. This document formally
   updates RFC 5905, recommending the use of transport-protocol ephemeral port
   randomization for those modes where use of the NTP well-known port is not
   required.</t>
    </abstract>
  </front>
  <middle>
    <section anchor="sect-1" numbered="true" toc="default">
      <name>Introduction</name>
      <t>
   The Network Time Protocol (NTP) is one of the oldest Internet
   protocols and is currently specified in <xref target="RFC5905" format="default"/>.  Since its original
   implementation, standardization, and deployment, a number of
   vulnerabilities have been found both in the NTP specification and in
   some of its implementations <xref target="NTP-VULN" format="default"/>.  Some of these
   vulnerabilities allow for blind/off-path attacks, where an attacker
   can send forged packets to one or both NTP peers to achieve Denial
   of Service (DoS), time shifts, or other undesirable outcomes.  Many
   of these attacks require the attacker to guess or know at least a
   target NTP association, typically identified by the tuple {srcaddr,
   srcport, dstaddr, dstport, keyid} (see <xref target="RFC5905" sectionFormat="of" section="9.1"/>).
   Some of these parameters may be known or easily guessed.</t>
      <t>
   NTP can operate in several modes.  Some of these modes rely on the
   ability of nodes to receive unsolicited packets and therefore
   require the use of the NTP well-known port (123).  However, for modes
   where the use of a well-known port is not required, employing the
   NTP well-known port unnecessarily facilitates the ability of attackers
   to perform blind/off-path attacks (since knowledge of the port
   numbers is typically required for such attacks).  A recent study
   <xref target="NIST-NTP" format="default"/> that analyzes the port numbers employed by NTP clients
   suggests that numerous NTP clients employ the NTP well-known port as their local port, or select predictable ephemeral
   port numbers, thus unnecessarily facilitating the ability of
   attackers to perform blind/off-path attacks against NTP.</t>
      <t>
   BCP 156 <xref target="RFC6056" format="default"/> already recommends the randomization of transport-protocol ephemeral ports.  This document aligns NTP with the
   recommendation in BCP 156 <xref target="RFC6056" format="default"/> by formally updating <xref target="RFC5905" format="default"/>
   such that port randomization is employed for those NTP modes for
   which the use of the NTP well-known port is not needed.</t>
    </section>
    <section anchor="sect-2" numbered="true" toc="default">
      <name>Terminology</name>
      <t>
   The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>",
   "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>", "<bcp14>MAY</bcp14>", and
   "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as described in BCP
   14 <xref target="RFC2119" format="default"/> <xref target="RFC8174" format="default"/> when, and only when, they appear in all
   capitals, as shown here.</t>
    </section>
    <section anchor="sect-3" numbered="true" toc="default">
      <name>Considerations about Port Randomization in NTP</name>
      <t>
   The following subsections analyze a number of considerations about
   transport-protocol ephemeral port randomization when applied to NTP.</t>
      <section anchor="sect-3.1" numbered="true" toc="default">
        <name>Mitigation against Off-Path Attacks</name>
        <t>
   There has been a fair share of work in the area of blind/off-path
   attacks against transport protocols and upper-layer protocols, such
   as <xref target="RFC4953" format="default"/> and <xref target="RFC5927" format="default"/>.  Whether the target of the attack is a
   transport-protocol instance (e.g., TCP connection) or an upper-layer
   protocol instance (e.g., an application-protocol instance), the
   attacker is required to know or guess the five-tuple {Protocol, IP
   Source Address, IP Destination Address, Source Port, Destination
   Port} that identifies the target transport-protocol instance or the
   transport-protocol instance employed by the target upper-layer
   protocol instance.  Therefore, increasing the difficulty of guessing
   this five-tuple helps mitigate blind/off-path attacks.</t>
        <t>
   As a result of these considerations, transport-protocol ephemeral
   port randomization is a best current practice (BCP 156) that helps
   mitigate off-path attacks at the transport layer.  This document
   aligns the NTP specification <xref target="RFC5905" format="default"/> with the existing best current
   practice on transport-protocol ephemeral port selection, irrespective of other
   techniques that may (and should) be implemented for mitigating off-path attacks.</t>
        <t>
   We note that transport-protocol ephemeral port randomization is a
   transport-layer mitigation against blind/off-path attacks and does
   not preclude (nor is it precluded by) other possible mitigations for
   off-path attacks that might be implemented at other layers (e.g.,
   <xref target="I-D.ietf-ntp-data-minimization" format="default"/>).  For instance, some of the
   aforementioned mitigations may be ineffective against some off-path
   attacks <xref target="NTP-FRAG" format="default"/> or may benefit from the additional entropy
   provided by port randomization <xref target="NTP-security" format="default"/>.</t>
      </section>
      <section anchor="sect-3.2" numbered="true" toc="default">
        <name>Effects on Path Selection</name>
        <t>
   Intermediate systems implementing the Equal-Cost Multipath (ECMP)
   algorithm may select the outgoing link by computing a hash over a
   number of values, including the transport-protocol source port.
   Thus, as discussed in <xref target="NTP-CHLNG" format="default"/>, the selected client port may have
   an influence on the measured offset and delay.</t>
        <t>
   If the source port is changed with each request, packets in different
   exchanges will be more likely to take different paths, which could
   cause the measurements to be less stable and have a negative impact
   on the stability of the clock.</t>
        <t>

   Network paths to/from a given server are less likely to change between
   requests if port randomization is applied on a per-association basis. This 
   approach minimizes the impact on the stability of NTP measurements, 
   but it may cause different clients in the same network synchronized to the 
   same NTP server to have a significant stable offset between their clocks. 
   This is due to their NTP exchanges consistently taking different paths with 
   different asymmetry in the network delay.</t>
        <t>
   <xref target="sect-4" format="default"/> recommends that NTP implementations randomize the ephemeral
   port number of client/server associations.  The choice of whether to
   randomize the port number on a per-association or a per-request basis
   is left to the implementation.</t>
      </section>
      <section anchor="sect-3.3" numbered="true" toc="default">
        <name>Filtering of NTP Traffic</name>
        <t>
   In a number of scenarios (such as when mitigating DDoS attacks), a
   network operator may want to differentiate between NTP requests sent
   by clients and NTP responses sent by NTP servers.  If an
   implementation employs the NTP well-known port for the client port, requests/responses cannot be readily differentiated by
   inspecting the source and destination port numbers.  


   Implementation of port randomization for nonsymmetrical modes allows for   
   simple differentiation of NTP requests and responses and for the
   enforcement of security policies that may be valuable for the mitigation of 
   DDoS attacks, when all NTP clients in a given network employ port randomization.</t>
      </section>
      <section anchor="sect-3.4" numbered="true" toc="default">
        <name>Effect on NAPT Devices</name>
        <t>
   Some NAPT devices will reportedly not translate the source port of a
   packet when a system port number (i.e., a port number in the range
   0-1023) <xref target="RFC6335" format="default"/> is employed.  In networks where such NAPT devices
   are employed, use of the NTP well-known port for the client port may
   limit the number of hosts that may successfully employ NTP client
	implementations at any given time.</t>

<aside>	
        <t>NOTES:</t>
        <t indent="3">NAPT devices are defined in <xref target="RFC2663" sectionFormat="of" section="4.1.2"/>.</t>
        <t indent="3">The reported behavior is similar to the special treatment of UDP
      port 500, which has been documented in <xref target="RFC3715" sectionFormat="of" section="2.3"/>.</t>
</aside>
        <t>
   In the case of NAPT devices that will translate the source port even
   when a system port is employed, packets reaching the external realm
   of the NAPT will not employ the NTP well-known port as the source
   port, as a result of the port translation function being performed by the
   NAPT device.</t>
      </section>
    </section>
    <section anchor="sect-4" numbered="true" toc="default">
      <name>Update to RFC 5905</name>
      <t>
   The following text from Section                                       
      <xref target="RFC5905" section="9.1" sectionFormat="bare">Peer     
Process Variables</xref> of <xref target="RFC5905"/>:</t>
<blockquote>
      <dl newline="false" spacing="normal" indent="3">
        <dt>dstport:</dt>
        <dd> UDP port number of the client, ordinarily the NTP port
      number PORT (123) assigned by the IANA.  This becomes the source
      port number in packets sent from this association.</dd>
      </dl>
</blockquote>
      <t>is replaced with:</t>
      
<blockquote>
      <dl newline="false" spacing="normal" indent="3">
        <dt>dstport:</dt>
        <dd> UDP port number of the client.  In the case of broadcast
      server mode (5) and symmetric modes (1 and 2), it <bcp14>SHOULD</bcp14> contain
      the NTP port number PORT (123) assigned by IANA.  In the
      client mode (3), it <bcp14>SHOULD</bcp14> contain a randomized port number, as
      specified in <xref target="RFC6056" format="default"/>.  The value in this variable becomes the
      source port number of packets sent from this association.  The
      randomized port number <bcp14>SHOULD NOT</bcp14> be shared with other
      associations, to avoid revealing the randomized port to other
      associations.</dd>
        <dt/>
        <dd>If a client implementation performs transport-protocol ephemeral port randomization
        on a per-request basis, it <bcp14>SHOULD</bcp14> close the corresponding socket/port
        after each request/response exchange.  In order to prevent duplicate
        or delayed server packets from eliciting ICMP port unreachable error
        messages <xref target="RFC0792"/> <xref target="RFC4443"/> at the client, the client <bcp14>MAY</bcp14> wait for more responses from
        the server for a specific period of time (e.g., 3 seconds) before
        closing the UDP socket/port.</dd>
<dt/>
<dd/>
      </dl>
      <dl newline="false" spacing="normal" indent="6">
        <dt/><dd><t>NOTES:</t>
        <t>Randomizing the ephemeral port number on a per-request basis
         will better mitigate blind/off-path attacks, particularly if
         the socket/port is closed after each request/response exchange,
         as recommended above.  The choice of whether to randomize the
         ephemeral port number on a per-request or a per-association
         basis is left to the implementation, and it should consider the
         possible effects on path selection along with its possible
         impact on time measurement.</t></dd>
        <dt/>
         <dd>On most current operating systems, which implement ephemeral
         port randomization <xref target="RFC6056" format="default"/>, an NTP client may normally rely
         on the operating system to perform ephemeral port
         randomization.  For example, NTP implementations using POSIX
         sockets may achieve ephemeral port randomization by <em>not</em>
         binding the socket with the bind() function or binding it to
         port 0, which has a special meaning of "any port". Using the connect() function for the socket will make the port inaccessible 
   by other systems (that is, only packets from the specified remote socket will be
         received by the application).</dd>
         </dl>
        </blockquote>
         
    </section>
    <section anchor="sect-6" numbered="true" toc="default">
      <name>IANA Considerations</name>
      <t>
This document has no IANA actions.</t>
    </section>
    <section anchor="sect-7" numbered="true" toc="default">
      <name>Security Considerations</name>
      <t>
   The security implications of predictable numeric identifiers
   <xref target="I-D.irtf-pearg-numeric-ids-generation" format="default"/> (and of predictable
   transport-protocol port numbers <xref target="RFC6056" format="default"/> in particular) have been
   known for a long time now.  However, the NTP specification has
   traditionally followed a pattern of employing common settings even
   when not strictly necessary, which at times has resulted in negative
   security and privacy implications (see, e.g.,
   <xref target="I-D.ietf-ntp-data-minimization" format="default"/>).  The use of the NTP well-known
   port (123) for the srcport and dstport variables is not required for
   all operating modes.  Such unnecessary usage comes at the expense of
   reducing the amount of work required for an attacker to successfully
   perform blind/off-path attacks against NTP.  Therefore, this document
   formally updates <xref target="RFC5905" format="default"/>, recommending the use of transport-protocol port randomization when use of the NTP well-known port is
   not required.</t>
      <t>
   This issue has been assigned CVE-2019-11331 <xref target="VULN-REPORT" format="default"/> in the U.S.
   National Vulnerability Database (NVD).</t>
    </section>
  </middle>
  <back>

<displayreference target="I-D.ietf-ntp-data-minimization" to="NTP-DATA-MINIMIZATION"/>
<displayreference target="I-D.irtf-pearg-numeric-ids-generation" to="PEARG-NUMERIC-IDS"/>

    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5905.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6056.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>

      </references>
      <references>
        <name>Informative References</name>

<reference anchor='I-D.ietf-ntp-data-minimization'>
<front>
<title>NTP Client Data Minimization</title>
<author initials='D' surname='Franke' fullname='Daniel Franke'>
    <organization />
</author>
<author initials='A' surname='Malhotra' fullname='Aanchal Malhotra'>
    <organization />
</author>
<date month='March' day='25' year='2019' />
</front>
<seriesInfo name='Internet-Draft' value='draft-ietf-ntp-data-minimization-04' />
</reference>

        <xi:include href="https://datatracker.ietf.org/doc/bibxml3/reference.I-D.irtf-pearg-numeric-ids-generation.xml"/>


        <reference anchor="NIST-NTP" target="https://tf.nist.gov/general/pdf/2818.pdf">
          <front>
            <title>Usage Analysis of the NIST Internet Time Service</title>
            <author initials="J." surname="Sherman" fullname="Jeffrey Sherman">
	</author>
            <author initials="J." surname="Levine" fullname="Judah Levine">
	</author>
            <date month="March" year="2016"/>
          </front>
	  <seriesInfo name="DOI" value="10.6028/jres.121.003"/>
          <refcontent>Journal of Research of the National Institute of Standards and Technology, Volume 121</refcontent>
        </reference>

        <reference anchor="NTP-CHLNG" target="http://leapsecond.com/ntp/NTP_Paper_Sommars_PTTI2017.pdf">
          <front>
            <title>Challenges in Time Transfer using the Network Time Protocol (NTP)</title>
            <author initials="S." surname="Sommars" fullname="Steven Sommars">
	</author>
            <date month="January" year="2017"/>
          </front>
<seriesInfo name="DOI" value="10.33012/2017.14978"/>
          <refcontent>Proceedings of the 48th Annual Precise Time and Time Interval Systems and Applications Meeting, pp. 271-290</refcontent>
        </reference>

        <reference anchor="NTP-FRAG" target="https://www.cs.bu.edu/~goldbe/papers/NTPattack.pdf">
          <front>
            <title>Attacking the Network Time Protocol</title>
            <author initials="A." surname="Malhotra" fullname="Aanchal Malhotra">
	</author>
            <author initials="I." surname="Cohen" fullname="Isaac Cohen">
	</author>
            <author initials="E." surname="Brakke" fullname="Erik Brakke">
	</author>
            <author initials="S." surname="Goldberg" fullname="Sharon Goldberg">
	</author>
            <date month="February" year="2016"/>
          </front>
<seriesInfo name="DOI" value="10.14722/ndss.2016.23090"/>
<refcontent>NDSS '16</refcontent>
        </reference>

        <reference anchor="NTP-security" target="https://eprint.iacr.org/2016/1006.pdf">
          <front>
            <title>The Security of NTP's Datagram Protocol</title>
            <author initials="A." surname="Malhotra" fullname="Aanchal Malhotra">
	</author>
            <author initials="M." surname="Van Gundy" fullname="Matthew Van Gundy">
	</author>
            <author initials="M." surname="Varia" fullname="Mayank Varia">
	</author>
            <author initials="H." surname="Kennedy" fullname="Haydn Kennedy">
	</author>
            <author initials="J." surname="Gardner" fullname="Jonathan Gardner">
	</author>
            <author initials="S." surname="Goldberg" fullname="Sharon Goldberg">
	</author>
            <date year="2017" month="February"/>
          </front>
          <seriesInfo name="DOI" value="10.1007/978-3-319-70972-7_23"/>
<refcontent>Cryptology ePrint Archive Report 2016/1006</refcontent>
        </reference>

        <reference anchor="NTP-VULN" target="http://support.ntp.org/bin/view/Main/SecurityNotice">
          <front>
            <title>Network Time Foundation</title>
            <author>
	</author>
            <date/>
          </front>
        </reference>

        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2663.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3715.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4953.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5927.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6335.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.0792.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4443.xml"/>
        <reference anchor="VULN-REPORT" target="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-11331">
          <front>
            <title>CVE-2019-1133</title>
            <author>
              <organization>The MITRE Corporation</organization>
            </author>
            <date month="August" year="2020"/>
          </front>
         <refcontent>National Vulnerability Database</refcontent>
        </reference>
     
 </references>
    </references>
    <section anchor="sect-8" numbered="false" toc="default">
      <name>Acknowledgments</name>
      <t>
   The authors would like to thank (in alphabetical order) <contact fullname="Ivan Arce"/>,
   <contact fullname="Roman Danyliw"/>, <contact fullname="Dhruv Dhody"/>, <contact fullname="Lars Eggert"/>, <contact fullname="Todd Glassey"/>, <contact fullname="Blake Hudson"/>,
   <contact fullname="Benjamin Kaduk"/>, <contact fullname="Erik Kline"/>, <contact fullname="Watson Ladd"/>, <contact fullname="Aanchal Malhotra"/>, <contact fullname="Danny
   Mayer"/>, <contact fullname="Gary E. Miller"/>, <contact fullname="Bjorn Mork"/>, <contact fullname="Hal Murray"/>, <contact fullname="Francesca Palombini"/>,
   <contact fullname="Tomoyuki Sahara"/>, <contact fullname="Zaheduzzaman Sarker"/>, <contact fullname="Dieter Sibold"/>, <contact fullname="Steven Sommars"/>,
   <contact fullname="Jean St-Laurent"/>, <contact fullname="Kristof Teichel"/>, <contact fullname="Brian Trammell"/>, <contact fullname="Éric Vyncke"/>, <contact fullname="Ulrich
   Windl"/>, and <contact fullname="Dan Wing"/> for providing valuable comments on earlier draft versions of this document.</t>
      <t>
   <contact fullname="Watson Ladd"/> raised the problem of DDoS mitigation when the NTP well-known
   port is employed as the client port (discussed in <xref target="sect-3.3"/> of this document).</t>
      <t>
   The authors would like to thank <contact fullname="Harlan Stenn"/> for answering questions
   about a popular NTP implementation (see <eref target="https://www.nwtime.org" brackets="angle"/>).</t>
      <t>
   <contact fullname="Fernando Gont"/> would like to thank <contact fullname="Nelida Garcia"/> and <contact fullname="Jorge Oscar Gont"/> for
   their love and support.</t>
    </section>
  </back>
</rfc>
