home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / rfc / rfc1948 < prev    next >
Text File  |  1996-05-17  |  13KB  |  340 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                        S. Bellovin
  8. Request for Comments: 1948                                 AT&T Research
  9. Category: Informational                                         May 1996
  10.  
  11.  
  12.                Defending Against Sequence Number Attacks
  13.  
  14. Status of This Memo
  15.  
  16.    This memo provides information for the Internet community.  This memo
  17.    does not specify an Internet standard of any kind.  Distribution of
  18.    this memo is unlimited.
  19.  
  20. Abstract
  21.  
  22.    IP spoofing attacks based on sequence number spoofing have become a
  23.    serious threat on the Internet (CERT Advisory CA-95:01).  While
  24.    ubiquitous crypgraphic authentication is the right answer, we propose
  25.    a simple modification to TCP implementations that should be a very
  26.    substantial block to the current wave of attacks.
  27.  
  28. Overview and Rational
  29.  
  30.    In 1985, Morris [1] described a form of attack based on guessing what
  31.    sequence numbers TCP [2] will use for new connections.  Briefly, the
  32.    attacker gags a host trusted by the target, impersonates the IP
  33.    address of the trusted host when talking to the target, and completes
  34.    the 3-way handshake based on its guess at the next initial sequence
  35.    number to be used.  An ordinary connection to the target is used to
  36.    gather sequence number state information.  This entire sequence,
  37.    coupled with address-based authentication, allows the attacker to
  38.    execute commands on the target host.
  39.  
  40.    Clearly, the proper solution is cryptographic authentication [3,4].
  41.    But it will quite a long time before that is deployed.  It has
  42.    therefore been necessary for many sites to restrict use of protocols
  43.    that rely on address-based authentication, such as rlogin and rsh.
  44.    Unfortunately, the prevalence of "sniffer attacks" -- network
  45.    eavesdropping (CERT Advisory CA-94:01) -- has rendered ordinary
  46.    TELNET [5] very dangerous as well.  The Internet is thus left without
  47.    a safe, secure mechanism for remote login.
  48.  
  49.    We propose a simple change to TCP implementations that will block
  50.    most sequence number guessing attacks.  More precisely, such attacks
  51.    will remain possible if and only if the Bad Guy already has the
  52.    ability to launch even more devastating attacks.
  53.  
  54.  
  55.  
  56.  
  57.  
  58. Bellovin                     Informational                      [Page 1]
  59.  
  60. RFC 1948                Sequence Number Attacks                 May 1996
  61.  
  62.  
  63. Details of the Attack
  64.  
  65.    In order to understand the particular case of sequence number
  66.    guessing, one must look at the 3-way handshake used in the TCP open
  67.    sequence [2].  Suppose client machine A wants to talk to rsh server
  68.    B.  It sends the following message:
  69.  
  70.            A->B: SYN, ISNa
  71.  
  72.    That is, it sends a packet with the SYN ("synchronize sequence
  73.    number") bit set and an initial sequence number ISNa.
  74.  
  75.    B replies with
  76.  
  77.            B->A: SYN, ISNb, ACK(ISNa)
  78.  
  79.    In addition to sending its own initial sequence number, it
  80.    acknowledges A's.  Note that the actual numeric value ISNa must
  81.    appear in the message.
  82.  
  83.    A concludes the handshake by sending
  84.  
  85.            A->B: ACK(ISNb)
  86.  
  87.    The initial sequence numbers are intended to be more or less random.
  88.    More precisely, RFC 793 specifies that the 32-bit counter be
  89.    incremented by 1 in the low-order position about every 4
  90.    microseconds.  Instead, Berkeley-derived kernels increment it by a
  91.    constant every second, and by another constant for each new
  92.    connection.  Thus, if you open a connection to a machine, you know to
  93.    a very high degree of confidence what sequence number it will use for
  94.    its next connection.  And therein lies the attack.
  95.  
  96.    The attacker X first opens a real connection to its target B -- say,
  97.    to the mail port or the TCP echo port.  This gives ISNb.  It then
  98.    impersonates A and sends
  99.  
  100.         Ax->B: SYN, ISNx
  101.  
  102.    where "Ax" denotes a packet sent by X pretending to be A.
  103.  
  104.    B's response to X's original SYN (so to speak)
  105.  
  106.         B->A: SYN, ISNb', ACK(ISNx)
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. Bellovin                     Informational                      [Page 2]
  115.  
  116. RFC 1948                Sequence Number Attacks                 May 1996
  117.  
  118.  
  119.    goes to the legitimate A, about which more anon.  X never sees that
  120.    message but can still send
  121.  
  122.         Ax->B: ACK(ISNb')
  123.  
  124.    using the predicted value for ISNb'.  If the guess is right -- and
  125.    usually it will be -- B's rsh server thinks it has a legitimate
  126.    connection with A, when in fact X is sending the packets.  X can't
  127.    see the output from this session, but it can execute commands as more
  128.    or less any user -- and in that case, the game is over and X has won.
  129.  
  130.    There is a minor difficulty here.  If A sees B's message, it will
  131.    realize that B is acknowledging something it never sent, and will
  132.    send a RST packet in response to tear down the connection.  There are
  133.    a variety of ways to prevent this; the easiest is to wait until the
  134.    real A is down (possibly as a result of enemy action, of course).  In
  135.    actual practice, X can gag A by exploiting a very common
  136.    implementation bug; this is described below.
  137.  
  138. The Fix
  139.  
  140.    The choice of initial sequence numbers for a connection is not
  141.    random.  Rather, it must be chosen so as to minimize the probability
  142.    of old stale packets being accepted by new incarnations of the same
  143.    connection [6, Appendix A].  Furthermore, implementations of TCP
  144.    derived from 4.2BSD contain special code to deal with such
  145.    reincarnations when the server end of the original connection is
  146.    still in TIMEWAIT state [7, pp. 945].  Accordingly, simple
  147.    randomization, as suggested in [8], will not work well.
  148.  
  149.    But duplicate packets, and hence the restrictions on the initial
  150.    sequence number for reincarnations, are peculiar to individual
  151.    connections.  That is, there is no connection, syntactic or semantic,
  152.    between the sequence numbers used for two different connections.  We
  153.    can prevent sequence number guessing attacks by giving each
  154.    connection -- that is, each 4-tuple of <localhost, localport,
  155.    remotehost, remoteport> -- a separate sequence number space.  Within
  156.    each space, the initial sequence number is incremented according to
  157.    [2]; however, there is no obvious relationship between the numbering
  158.    in different spaces.
  159.  
  160.    The obvious way to do this is to maintain state for dead connections,
  161.    and the easiest way to do that is to change the TCP state transition
  162.    diagram so that both ends of all connections go to TIMEWAIT state.
  163.    That would work, but it's inelegant and consumes storage space.
  164.    Instead, we use the current 4 microsecond timer M and set
  165.  
  166.            ISN = M + F(localhost, localport, remotehost, remoteport).
  167.  
  168.  
  169.  
  170. Bellovin                     Informational                      [Page 3]
  171.  
  172. RFC 1948                Sequence Number Attacks                 May 1996
  173.  
  174.  
  175.    It is vital that F not be computable from the outside, or an attacker
  176.    could still guess at sequence numbers from the initial sequence
  177.    number used for some other connection.  We therefore suggest that F
  178.    be a cryptographic hash function of the connection-id and some secret
  179.    data.  MD5 [9] is a good choice, since the code is widely available.
  180.    The secret data can either be a true random number [10], or it can be
  181.    the combination of some per-host secret and the boot time of the
  182.    machine.  The boot time is included to ensure that the secret is
  183.    changed on occasion.  Other data, such as the host's IP address and
  184.    name, may be included in the hash as well; this eases administration
  185.    by permitting a network of workstations to share the same secret data
  186.    while still giving them separate sequence number spaces.  Our
  187.    recommendation, in fact, is to use all three of these items: as
  188.    random a number as the hardware can generate, an administratively-
  189.    installed pass phrase, and the machine's IP address.  This allows for
  190.    local choice on how secure the secret is.
  191.  
  192.    Note that the secret cannot easily be changed on a live machine.
  193.    Doing so would change the initial sequence numbers used for
  194.    reincarnated connections; to maintain safety, either dead connection
  195.    state must be kept or a quiet time observed for two maximum segment
  196.    lifetimes after such a change.
  197.  
  198. A Common TCP Bug
  199.  
  200.    As mentioned earlier, attackers using sequence number guessing have
  201.    to "gag" the trusted machine first.  While a number of strategies are
  202.    possible, most of the attacks detected thus far rely on an
  203.    implementation bug.
  204.  
  205.    When SYN packets are received for a connection, the receiving system
  206.    creates a new TCB in SYN-RCVD state.  To avoid overconsumption of
  207.    resources, 4.2BSD-derived systems permit only a limited number of
  208.    TCBs in this state per connection.  Once this limit is reached,
  209.    future SYN packets for new connections are discarded; it is assumed
  210.    that the client will retransmit them as needed.
  211.  
  212.    When a packet is received, the first thing that must be done is a
  213.    search for the TCB for that connection.  If no TCB is found, the
  214.    kernel searches for a "wild card" TCB used by servers to accept
  215.    connections from all clients.  Unfortunately, in many kernels this
  216.    code is invoked for any incoming packets, not just for initial SYN
  217.    packets.  If the SYN-RCVD queue is full for the wildcard TCB, any new
  218.    packets specifying just that host and port number will be discarded,
  219.    even if they aren't SYN packets.
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. Bellovin                     Informational                      [Page 4]
  227.  
  228. RFC 1948                Sequence Number Attacks                 May 1996
  229.  
  230.  
  231.    To gag a host, then, the attacker sends a few dozen SYN packets to
  232.    the rlogin port from different port numbers on some non-existent
  233.    machine.  This fills up the SYN-RCVD queue, while the SYN+ACK packets
  234.    go off to the bit bucket.  The attack on the target machine then
  235.    appears to come from the rlogin port on the trusted machine.  The
  236.    replies -- the SYN+ACKs from the target -- will be perceived as
  237.    packets belonging to a full queue, and will be dropped silently.
  238.    This could be avoided if the full queue code checked for the ACK bit,
  239.    which cannot legally be on for legitimate open requests.  If it is
  240.    on, RST should be sent in reply.
  241.  
  242. Security Considerations
  243.  
  244.    Good sequence numbers are not a replacement for cryptographic
  245.    authentication.  At best, they're a palliative measure.
  246.  
  247.    An eavesdropper who can observe the initial messages for a connection
  248.    can determine its sequence number state, and may still be able to
  249.    launch sequence number guessing attacks by impersonating that
  250.    connection.  However, such an eavesdropper can also hijack existing
  251.    connections [11], so the incremental threat isn't that high.  Still,
  252.    since the offset between a fake connection and a given real
  253.    connection will be more or less constant for the lifetime of the
  254.    secret, it is important to ensure that attackers can never capture
  255.    such packets.  Typical attacks that could disclose them include both
  256.    eavesdropping and the variety of routing attacks discussed in [8].
  257.  
  258.    If random numbers are used as the sole source of the secret, they
  259.    MUST be chosen in accordance with the recommendations given in [10].
  260.  
  261. Acknowledgments
  262.  
  263.    Matt Blaze and Jim Ellis contributed some crucial ideas to this RFC.
  264.    Frank Kastenholz contributed constructive comments to this memo.
  265.  
  266. References
  267.  
  268.    [1]  R.T. Morris, "A Weakness in the 4.2BSD UNIX TCP/IP Software",
  269.         CSTR 117, 1985, AT&T Bell Laboratories, Murray Hill, NJ.
  270.  
  271.    [2]  Postel, J., "Transmission Control Protocol", STD 7, RFC 793,
  272.         September 1981.
  273.  
  274.    [3]  Kohl, J., and C. Neuman, "The Kerberos Network Authentication
  275.         Service (V5)", RFC 1510, September 1993.
  276.  
  277.    [4]  Atkinson, R., "Security Architecture for the Internet
  278.         Protocol", RFC 1825, August 1995.
  279.  
  280.  
  281.  
  282. Bellovin                     Informational                      [Page 5]
  283.  
  284. RFC 1948                Sequence Number Attacks                 May 1996
  285.  
  286.  
  287.    [5]  Postel, J., and J. Reynolds, "Telnet Protocol Specification",
  288.         STD 8, RFC 854, May 1983.
  289.  
  290.    [6]  Jacobson, V., Braden, R., and L. Zhang, "TCP Extension for
  291.         High-Speed Paths", RFC 1885, October 1990.
  292.  
  293.    [7]  G.R. Wright, W. R. Stevens, "TCP/IP Illustrated, Volume 2",
  294.         1995.  Addison-Wesley.
  295.  
  296.    [8]  S. Bellovin, "Security Problems in the TCP/IP Protocol Suite",
  297.         April 1989, Computer Communications Review, vol. 19, no. 2, pp.
  298.         32-48.
  299.  
  300.    [9]  Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
  301.         April 1992.
  302.  
  303.    [10] Eastlake, D., Crocker, S., and J. Schiller, "Randomness
  304.         Recommendations for Security", RFC 1750, December 1994.
  305.  
  306.    [11] L. Joncheray, "A Simple Active Attack Against TCP, 1995, Proc.
  307.         Fifth Usenix UNIX Security Symposium.
  308.  
  309. Author's Address
  310.  
  311.    Steven M. Bellovin
  312.    AT&T Research
  313.    600 Mountain Avenue
  314.    Murray Hill, NJ  07974
  315.  
  316.    Phone: (908) 582-5886
  317.    EMail: smb@research.att.com
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. Bellovin                     Informational                      [Page 6]
  339.  
  340.