home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack / sequence_attacks.txt < prev    next >
Encoding:
Text File  |  1998-11-21  |  22.4 KB  |  472 lines

  1.  
  2.      Sequence Number Attacks
  3.  
  4.      By Rik Farrow
  5.  
  6.      Kevin Mitnick's alleged attack on Tsutomu Shimomura's Computers
  7.      used a vulnerability in TCP/IP and mistaken trust.
  8.  
  9.      Questions regarding this article should be directed to the author
  10.      at rik@spirit.com.
  11.  
  12.      December 25, 1994 found Tsutomu Shimomura, a computational
  13.      physicist for the San Diego Supercomputer Center, on his way to
  14.      the Sierra Nevadas to go skiing. He had left his personal network
  15.      of computers running at his beach cottage in Del Mar, just north
  16.      of San Diego. Perhaps it is fortunate for us he did so.
  17.  
  18.      Just after two o'clock in the afternoon, Shimomura's home systems
  19.      were probed, then successfully attacked using something new in
  20.      Internet attacks, sequence number guessing. Shimomura also works
  21.      as a security expert, which made his systems both desirable
  22.      targets for attack, and allows us to understand in detail what
  23.      happened. Because, unlike most networks, Shimomura was using
  24.      tcpdump to monitor traffic incoming from his Internet connection,
  25.      and routinely sent his logs to an offsite location.
  26.  
  27.      Sequence number guessing is not really new. Steve Bellovin, a
  28.      researcher at Bell Labs, and co-author of the Firewalls and
  29.      Internet Security book (Addison-Wesley, 1994, ISBN 0-201-63357-4),
  30.      included details of an attack scenario in his 1989 paper entitled
  31.      ``Security Problems in the TCP/IP Protocol Suite''. But the
  32.      Christmas day attack is the first known use of the technique.
  33.  
  34.      To better understand what happened, it helps to understand a
  35.      little about how TCP (Transport Control Protocol) works. TCP is
  36.      used for establishing bidirectional streams, like those used for
  37.      remote terminal connections (established with telnet or rlogin
  38.      utilities). TCP is also used for transferring large amounts of
  39.      data, for example with FTP or connecting to a Web server.
  40.  
  41.      TCP provides a reliable connection. That is, unlike most other
  42.      parts of the Internet Protocol suite (such as ICMP, Internet
  43.      Control Message Protocol, or UDP, User Datagram Protocol), TCP
  44.      establishes a connection between the local and remote site. Once
  45.      the connection has been successfully established, groups of bytes
  46.      of data are acknowledged by sending a sequence number back to the
  47.      sending site. If the sending site does not receive an
  48.      acknowledgement quickly enough, it will resend the data. If the
  49.      sending site has resent the same data several times
  50.      unsuccessfully, it will send an error to the application saying
  51.      that the connection has been broken.
  52.  
  53.      The sequence number is used to acknowledge receipt of data. At the
  54.      beginning of a TCP connection, the client sends a TCP packet with
  55.      an initial sequence number, but no acknowledgement (there can't be
  56.      one yet). If there is a server application running at the other
  57.      end of the connection, the server sends back a TCP packet with its
  58.      own initial sequence number, and an acknowledgement: the initial
  59.      sequence number from the client's packet plus one. When the client
  60.      system receives this packet, it must send back its own
  61.      acknowledgement: the server's initial sequence number plus one.
  62.      Thus, it takes three packets to establish a TCP connection (see
  63.      Part A of Figure 1 which shows the time-line diagram.
  64.  
  65.      There's more to TCP, of course. You won't learn all about TCP in
  66.      this short article (try Doug Comer's book Internetworking with
  67.      TCP/IP, Volume 1, Principles, Protocols, and Architecture. Second
  68.      Edition (Prentice Hall, 1991 ISBN 0-13-468505-9) or W. Richard
  69.      Steven's TCP/IP Illustrated, Volume 1 (Addison-Wesley, 1993, ISBN
  70.      0-201-63346-9). For now, it's important to understand that TCP
  71.      packets include flag bits that get set to indicate conditions.
  72.      When you read Shimomura's account of the attack, he makes
  73.      reference to several flags.
  74.  
  75.      The SYN flag (shown as a capital ``S'' in tcpdump command output)
  76.      indicates the initiation of a connection, and that an initial
  77.      sequence number is included. When the first packet is sent from
  78.      the client, only the SYN flag is set. When the server responds,
  79.      both the SYN flag and the ACK flag, indicating that a valid
  80.      acknowledgement is included, are set. From then on, the ACK flag
  81.      will be set, showing that each packet includes an acknowledgement
  82.      of a received packet.
  83.  
  84.      The PUSH (shown as a capital ``P'') flag means that the data in
  85.      this packet should be pushed to the application, rathered than
  86.      queued until more data arrives. The RESET (``R'') flag tells TCP
  87.      to break (reset) the connection, and is sent when a client
  88.      attempts to connect to a server application that is not running.
  89.      In the attack, RESETs are used to close the half-open connections
  90.      used to keep the server busy.
  91.  
  92.      The FIN bit (``F'') is used to close a connection. Each end of the
  93.      connection sends a packet with the FIN flag, which must be
  94.      acknowledged, so four packets are used to close a TCP connection.
  95.      Of course in the attack you won't see two FIN packets, because the
  96.      attacker never sees the responses from the target system, the X
  97.      terminal.
  98.  
  99.      With this background, you are ready to read Shimomura's own
  100.      description, if you haven't already. Essentially, the attack
  101.      begins when several probes were launched from toad.com (a site
  102.      registered by Nebula Consulting). Although I don't know this for
  103.      sure, it is likely that toad.com had been broken into previously
  104.      using other techniques.
  105.  
  106.      The probes, using finger, showmount, and rpcinfo (similar to
  107.      probes from SATAN, but not automatic) apparently helped the
  108.      attacker to determine a trust relationship between Shimomura's X
  109.      terminal (actually another workstation used as an X terminal), and
  110.      a local server. This was the real weakness exploited in the
  111.      attack. Shimomura's systems trusted one another, using the trust
  112.      mechanism exploited in the ``r'' commands like rsh and rcp.
  113.      Although convenient, and safe behind a strong perimeter defense,
  114.      trust has been used to break into systems for many years. The
  115.      November 1988 Internet Worm exploited trust in its automated
  116.      attacks.
  117.  
  118.      In the next phase of the attack, thirty TCP SYN packets are sent
  119.      to the rlogin port of Shimomura's server. These packets come from
  120.      an unused Internet address, and their initial sequence numbers are
  121.      incremented by one instead of the more common 128,000. The purpose
  122.      of these packets are to fill the queue on the server with
  123.      half-open connections, so when the spoofing begins, the server
  124.      won't be able to respond to the packets being sent as
  125.      acknowledgements from the X terminal.
  126.  
  127.      Next, a system at Loyola University of Chicago (apollo.it.luc.edu)
  128.      was used to probe the X terminal. Once again, a synthetic series
  129.      of TCP packets (initial sequence numbers incremented by one) gets
  130.      sent, but this time responses get sent back to a real site. It is
  131.      the responses that the attacker is after, because each response
  132.      contains an initial sequence number from the X terminal. In
  133.      Shimomura's paper tcpdump labels the responses with
  134.      x-terminal.shell > apollo.it.luc.edu.1000 S, indicating a packet
  135.      with the SYN flag set. If we subtract the first initial sequence
  136.      number from the second, 2021952000-2021824000, we get 128,000, a
  137.      pattern that holds for all twenty probes. So now the attacker
  138.      knows that the next initial sequence number will be 128,000
  139.      greater than the previous one.
  140.  
  141.      The stage is now set for abusing the trust between the X terminal
  142.      and the server. The attacker generates packets that appear to come
  143.      from the server to open a TCP connection with the X terminal
  144.      rshell daemon. The X terminal sends an acknowledgement back to the
  145.      server, but this acknowledgement gets stuck in the queue. Next,
  146.      the attacker generates the acknowledgement the server might have
  147.      sent (if it had really been the server initiating the connection).
  148.      Now there is an open TCP connection from the X terminal to the
  149.      server, which is being spoofed by the server. Figure 1B shows how
  150.      the packets actually traveled.
  151.  
  152.      Because the X terminal trusts the server, the attacker,
  153.      masquerading as root, sends the command "echo + + >> /.rhosts" to
  154.      the X terminal, extending trust to ANY root user with access to
  155.      this system. Then the attacker closes the connection by sending a
  156.      packet with FIN set, and acknowledging the FIN packet never seen
  157.      from the X terminal. Finally, thirty RESETs are sent to the server
  158.      to clear its queue. At this point, the server would send a RESET
  159.      to the X terminal to close the rshell connection it never made
  160.      (the one spoofed by the attacker), but it is now too late. The
  161.      attacked can now log in as root on the X terminal using rlogin.
  162.  
  163.      There was more to the attack, but I'd like to save taking over TCP
  164.      connections for another day. There is also a CERT advisory about
  165.      this attack, which you can read.
  166.  
  167.      Copyright ⌐ 1995-1997 The McGraw-Hill Companies, Inc.
  168.      All Rights Reserved.
  169.      Edited by Becca Thomas / editor@unixworld.com
  170.  
  171.  
  172.  
  173.  
  174. -------------------------------------------------------------------------------
  175.  
  176.  
  177.  
  178. Network Working Group                                        S. Bellovin
  179. Request for Comments: 1948                                 AT&T Research
  180. Category: Informational                                         May 1996
  181.  
  182.                Defending Against Sequence Number Attacks
  183.  
  184. Status of This Memo
  185.  
  186.    This memo provides information for the Internet community.  This memo
  187.    does not specify an Internet standard of any kind.  Distribution of
  188.    this memo is unlimited.
  189.  
  190. Abstract
  191.  
  192.    IP spoofing attacks based on sequence number spoofing have become a
  193.    serious threat on the Internet (CERT Advisory CA-95:01).  While
  194.    ubiquitous crypgraphic authentication is the right answer, we propose
  195.    a simple modification to TCP implementations that should be a very
  196.    substantial block to the current wave of attacks.
  197.  
  198. Overview and Rational
  199.  
  200.    In 1985, Morris [1] described a form of attack based on guessing what
  201.    sequence numbers TCP [2] will use for new connections.  Briefly, the
  202.    attacker gags a host trusted by the target, impersonates the IP
  203.    address of the trusted host when talking to the target, and completes
  204.    the 3-way handshake based on its guess at the next initial sequence
  205.    number to be used.  An ordinary connection to the target is used to
  206.    gather sequence number state information.  This entire sequence,
  207.    coupled with address-based authentication, allows the attacker to
  208.    execute commands on the target host.
  209.  
  210.    Clearly, the proper solution is cryptographic authentication [3,4].
  211.    But it will quite a long time before that is deployed.  It has
  212.    therefore been necessary for many sites to restrict use of protocols
  213.    that rely on address-based authentication, such as rlogin and rsh.
  214.    Unfortunately, the prevalence of "sniffer attacks" -- network
  215.    eavesdropping (CERT Advisory CA-94:01) -- has rendered ordinary
  216.    TELNET [5] very dangerous as well.  The Internet is thus left without
  217.    a safe, secure mechanism for remote login.
  218.  
  219.    We propose a simple change to TCP implementations that will block
  220.    most sequence number guessing attacks.  More precisely, such attacks
  221.    will remain possible if and only if the Bad Guy already has the
  222.    ability to launch even more devastating attacks.
  223.  
  224. Bellovin                     Informational                      [Page 1]
  225. ----------------------------------------------------------------------------
  226.  
  227. RFC 1948                Sequence Number Attacks                 May 1996
  228.  
  229. Details of the Attack
  230.  
  231.    In order to understand the particular case of sequence number
  232.    guessing, one must look at the 3-way handshake used in the TCP open
  233.    sequence [2].  Suppose client machine A wants to talk to rsh server
  234.    B.  It sends the following message:
  235.  
  236.            A->B: SYN, ISNa
  237.  
  238.    That is, it sends a packet with the SYN ("synchronize sequence
  239.    number") bit set and an initial sequence number ISNa.
  240.  
  241.    B replies with
  242.  
  243.            B->A: SYN, ISNb, ACK(ISNa)
  244.  
  245.    In addition to sending its own initial sequence number, it
  246.    acknowledges A's.  Note that the actual numeric value ISNa must
  247.    appear in the message.
  248.  
  249.    A concludes the handshake by sending
  250.  
  251.            A->B: ACK(ISNb)
  252.  
  253.    The initial sequence numbers are intended to be more or less random.
  254.    More precisely, RFC 793 specifies that the 32-bit counter be
  255.    incremented by 1 in the low-order position about every 4
  256.    microseconds.  Instead, Berkeley-derived kernels increment it by a
  257.    constant every second, and by another constant for each new
  258.    connection.  Thus, if you open a connection to a machine, you know to
  259.    a very high degree of confidence what sequence number it will use for
  260.    its next connection.  And therein lies the attack.
  261.  
  262.    The attacker X first opens a real connection to its target B -- say,
  263.    to the mail port or the TCP echo port.  This gives ISNb.  It then
  264.    impersonates A and sends
  265.  
  266.         Ax->B: SYN, ISNx
  267.  
  268.    where "Ax" denotes a packet sent by X pretending to be A.
  269.  
  270.    B's response to X's original SYN (so to speak)
  271.  
  272.         B->A: SYN, ISNb', ACK(ISNx)
  273.  
  274. Bellovin                     Informational                      [Page 2]
  275. ----------------------------------------------------------------------------
  276.  
  277. RFC 1948                Sequence Number Attacks                 May 1996
  278.  
  279.    goes to the legitimate A, about which more anon.  X never sees that
  280.    message but can still send
  281.  
  282.         Ax->B: ACK(ISNb')
  283.  
  284.    using the predicted value for ISNb'.  If the guess is right -- and
  285.    usually it will be -- B's rsh server thinks it has a legitimate
  286.    connection with A, when in fact X is sending the packets.  X can't
  287.    see the output from this session, but it can execute commands as more
  288.    or less any user -- and in that case, the game is over and X has won.
  289.  
  290.    There is a minor difficulty here.  If A sees B's message, it will
  291.    realize that B is acknowledging something it never sent, and will
  292.    send a RST packet in response to tear down the connection.  There are
  293.    a variety of ways to prevent this; the easiest is to wait until the
  294.    real A is down (possibly as a result of enemy action, of course).  In
  295.    actual practice, X can gag A by exploiting a very common
  296.    implementation bug; this is described below.
  297.  
  298. The Fix
  299.  
  300.    The choice of initial sequence numbers for a connection is not
  301.    random.  Rather, it must be chosen so as to minimize the probability
  302.    of old stale packets being accepted by new incarnations of the same
  303.    connection [6, Appendix A].  Furthermore, implementations of TCP
  304.    derived from 4.2BSD contain special code to deal with such
  305.    reincarnations when the server end of the original connection is
  306.    still in TIMEWAIT state [7, pp. 945].  Accordingly, simple
  307.    randomization, as suggested in [8], will not work well.
  308.  
  309.    But duplicate packets, and hence the restrictions on the initial
  310.    sequence number for reincarnations, are peculiar to individual
  311.    connections.  That is, there is no connection, syntactic or semantic,
  312.    between the sequence numbers used for two different connections.  We
  313.    can prevent sequence number guessing attacks by giving each
  314.    connection -- that is, each 4-tuple of <localhost, localport,
  315.    remotehost, remoteport> -- a separate sequence number space.  Within
  316.    each space, the initial sequence number is incremented according to
  317.    [2]; however, there is no obvious relationship between the numbering
  318.    in different spaces.
  319.  
  320.    The obvious way to do this is to maintain state for dead connections,
  321.    and the easiest way to do that is to change the TCP state transition
  322.    diagram so that both ends of all connections go to TIMEWAIT state.
  323.    That would work, but it's inelegant and consumes storage space.
  324.    Instead, we use the current 4 microsecond timer M and set
  325.  
  326.            ISN = M + F(localhost, localport, remotehost, remoteport).
  327.  
  328. Bellovin                     Informational                      [Page 3]
  329. ----------------------------------------------------------------------------
  330.  
  331. RFC 1948                Sequence Number Attacks                 May 1996
  332.  
  333.    It is vital that F not be computable from the outside, or an attacker
  334.    could still guess at sequence numbers from the initial sequence
  335.    number used for some other connection.  We therefore suggest that F
  336.    be a cryptographic hash function of the connection-id and some secret
  337.    data.  MD5 [9] is a good choice, since the code is widely available.
  338.    The secret data can either be a true random number [10], or it can be
  339.    the combination of some per-host secret and the boot time of the
  340.    machine.  The boot time is included to ensure that the secret is
  341.    changed on occasion.  Other data, such as the host's IP address and
  342.    name, may be included in the hash as well; this eases administration
  343.    by permitting a network of workstations to share the same secret data
  344.    while still giving them separate sequence number spaces.  Our
  345.    recommendation, in fact, is to use all three of these items: as
  346.    random a number as the hardware can generate, an administratively-
  347.    installed pass phrase, and the machine's IP address.  This allows for
  348.    local choice on how secure the secret is.
  349.  
  350.    Note that the secret cannot easily be changed on a live machine.
  351.    Doing so would change the initial sequence numbers used for
  352.    reincarnated connections; to maintain safety, either dead connection
  353.    state must be kept or a quiet time observed for two maximum segment
  354.    lifetimes after such a change.
  355.  
  356. A Common TCP Bug
  357.  
  358.    As mentioned earlier, attackers using sequence number guessing have
  359.    to "gag" the trusted machine first.  While a number of strategies are
  360.    possible, most of the attacks detected thus far rely on an
  361.    implementation bug.
  362.  
  363.    When SYN packets are received for a connection, the receiving system
  364.    creates a new TCB in SYN-RCVD state.  To avoid overconsumption of
  365.    resources, 4.2BSD-derived systems permit only a limited number of
  366.    TCBs in this state per connection.  Once this limit is reached,
  367.    future SYN packets for new connections are discarded; it is assumed
  368.    that the client will retransmit them as needed.
  369.  
  370.    When a packet is received, the first thing that must be done is a
  371.    search for the TCB for that connection.  If no TCB is found, the
  372.    kernel searches for a "wild card" TCB used by servers to accept
  373.    connections from all clients.  Unfortunately, in many kernels this
  374.    code is invoked for any incoming packets, not just for initial SYN
  375.    packets.  If the SYN-RCVD queue is full for the wildcard TCB, any new
  376.    packets specifying just that host and port number will be discarded,
  377.    even if they aren't SYN packets.
  378.  
  379. Bellovin                     Informational                      [Page 4]
  380. ----------------------------------------------------------------------------
  381.  
  382. RFC 1948                Sequence Number Attacks                 May 1996
  383.  
  384.    To gag a host, then, the attacker sends a few dozen SYN packets to
  385.    the rlogin port from different port numbers on some non-existent
  386.    machine.  This fills up the SYN-RCVD queue, while the SYN+ACK packets
  387.    go off to the bit bucket.  The attack on the target machine then
  388.    appears to come from the rlogin port on the trusted machine.  The
  389.    replies -- the SYN+ACKs from the target -- will be perceived as
  390.    packets belonging to a full queue, and will be dropped silently.
  391.    This could be avoided if the full queue code checked for the ACK bit,
  392.    which cannot legally be on for legitimate open requests.  If it is
  393.    on, RST should be sent in reply.
  394.  
  395. Security Considerations
  396.  
  397.    Good sequence numbers are not a replacement for cryptographic
  398.    authentication.  At best, they're a palliative measure.
  399.  
  400.    An eavesdropper who can observe the initial messages for a connection
  401.    can determine its sequence number state, and may still be able to
  402.    launch sequence number guessing attacks by impersonating that
  403.    connection.  However, such an eavesdropper can also hijack existing
  404.    connections [11], so the incremental threat isn't that high.  Still,
  405.    since the offset between a fake connection and a given real
  406.    connection will be more or less constant for the lifetime of the
  407.    secret, it is important to ensure that attackers can never capture
  408.    such packets.  Typical attacks that could disclose them include both
  409.    eavesdropping and the variety of routing attacks discussed in [8].
  410.  
  411.    If random numbers are used as the sole source of the secret, they
  412.    MUST be chosen in accordance with the recommendations given in [10].
  413.  
  414. Acknowledgments
  415.  
  416.    Matt Blaze and Jim Ellis contributed some crucial ideas to this RFC.
  417.    Frank Kastenholz contributed constructive comments to this memo.
  418.  
  419. References
  420.  
  421.    [1]  R.T. Morris, "A Weakness in the 4.2BSD UNIX TCP/IP Software",
  422.         CSTR 117, 1985, AT&T Bell Laboratories, Murray Hill, NJ.
  423.  
  424.    [2]  Postel, J., "Transmission Control Protocol", STD 7, RFC 793,
  425.         September 1981.
  426.  
  427.    [3]  Kohl, J., and C. Neuman, "The Kerberos Network Authentication
  428.         Service (V5)", RFC 1510, September 1993.
  429.  
  430.    [4]  Atkinson, R., "Security Architecture for the Internet
  431.         Protocol", RFC 1825, August 1995.
  432.  
  433. Bellovin                     Informational                      [Page 5]
  434. ----------------------------------------------------------------------------
  435.  
  436. RFC 1948                Sequence Number Attacks                 May 1996
  437.  
  438.    [5]  Postel, J., and J. Reynolds, "Telnet Protocol Specification",
  439.         STD 8, RFC 854, May 1983.
  440.  
  441.    [6]  Jacobson, V., Braden, R., and L. Zhang, "TCP Extension for
  442.         High-Speed Paths", RFC 1885, October 1990.
  443.  
  444.    [7]  G.R. Wright, W. R. Stevens, "TCP/IP Illustrated, Volume 2",
  445.         1995.  Addison-Wesley.
  446.  
  447.    [8]  S. Bellovin, "Security Problems in the TCP/IP Protocol Suite",
  448.         April 1989, Computer Communications Review, vol. 19, no. 2, pp.
  449.         32-48.
  450.  
  451.    [9]  Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
  452.         April 1992.
  453.  
  454.    [10] Eastlake, D., Crocker, S., and J. Schiller, "Randomness
  455.         Recommendations for Security", RFC 1750, December 1994.
  456.  
  457.    [11] L. Joncheray, "A Simple Active Attack Against TCP, 1995, Proc.
  458.         Fifth Usenix UNIX Security Symposium.
  459.  
  460. Author's Address
  461.  
  462.    Steven M. Bellovin
  463.    AT&T Research
  464.    600 Mountain Avenue
  465.    Murray Hill, NJ  07974
  466.  
  467.    Phone: (908) 582-5886
  468.    EMail: smb@research.att.com
  469.  
  470. ----------------------------------------------------------------------------
  471.  
  472.