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

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