home *** CD-ROM | disk | FTP | other *** search
/ Cuteskunk BBS / cuteskunk.zip / cuteskunk / unsorted-zines / sequence_attacks.txt < prev    next >
Text File  |  2003-06-29  |  23KB  |  473 lines

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