home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / phrack33.008 < prev    next >
Encoding:
Text File  |  2003-06-11  |  24.0 KB  |  526 lines

  1.                                 ==Phrack Inc.==
  2.  
  3.                 Volume Three, Issue Thirty-Three, File 8 of 13
  4.  
  5.                     A TCP/IP Tutorial : Behind The Internet
  6.                                 Part One of Two
  7.  
  8.                               September 12, 1991
  9.  
  10.                                   by The Not
  11.  
  12.  
  13. Table of Contents
  14.  
  15.     1.  Introduction
  16.     2.  TCP/IP Overview
  17.     3.  Ethernet
  18.     4.  ARP
  19.  
  20. 1.  Introduction
  21.  
  22.    This tutorial contains only one view of the salient points of TCP/IP,
  23.    and therefore it is the "bare bones" of TCP/IP technology.  It omits
  24.    the history of development and funding, the business case for its
  25.    use, and its future as compared to ISO OSI.  Indeed, a great deal of
  26.    technical information is also omitted.  What remains is a minimum of
  27.    information that must be understood by the professional working in a
  28.    TCP/IP environment.  These professionals include the systems
  29.    administrator, the systems programmer, and the network manager.
  30.  
  31.    This tutorial uses examples from the UNIX TCP/IP environment, however
  32.    the main points apply across all implementations of TCP/IP.
  33.  
  34.    Note that the purpose of this memo is explanation, not definition.
  35.    If any question arises about the correct specification of a protocol,
  36.    please refer to the actual standards defining RFC.
  37.    The next section is an overview of TCP/IP, followed by detailed
  38.    descriptions of individual components.
  39.  
  40. 2.  TCP/IP Overview
  41.  
  42.    The generic term "TCP/IP" usually means anything and everything
  43.    related to the specific protocols of TCP and IP.  It can include
  44.    other protocols, applications, and even the network medium.  A sample
  45.    of these protocols are: UDP, ARP, and ICMP.  A sample of these
  46.    applications are: TELNET, FTP, and rcp.  A more accurate term is
  47.    "internet technology".  A network that uses internet technology is
  48.    called an "internet".
  49.  
  50. 2.1  Basic Structure
  51.  
  52.    To understand this technology you must first understand the following
  53.    logical structure:
  54.  
  55.                      ----------------------------
  56.                      |    network applications  |
  57.                      |                          |
  58.                      |...  \ | /  ..  \ | /  ...|
  59.                      |     -----      -----     |
  60.                      |     |TCP|      |UDP|     |
  61.                      |     -----      -----     |
  62.                      |         \      /         |
  63.                      |         --------         |
  64.                      |         |  IP  |         |
  65.                      |  -----  -*------         |
  66.                      |  |ARP|   |               |
  67.                      |  -----   |               |
  68.                      |      \   |               |
  69.                      |      ------              |
  70.                      |      |ENET|              |
  71.                      |      ---@--              |
  72.                      ----------|-----------------
  73.                                |
  74.          ----------------------o---------
  75.              Ethernet Cable
  76.  
  77.                   Figure 1.  Basic TCP/IP Network Node
  78.  
  79.    This is the logical structure of the layered protocols inside a
  80.    computer on an internet.  Each computer that can communicate using
  81.    internet technology has such a logical structure.  It is this logical
  82.    structure that determines the behavior of the computer on the
  83.    internet.  The boxes represent processing of the data as it passes
  84.    through the computer, and the lines connecting boxes show the path of
  85.    data.  The horizontal line at the bottom represents the Ethernet
  86.    cable; the "o" is the transceiver.  The "*" is the IP address and the
  87.    "@" is the Ethernet address.  Understanding this logical structure is
  88.    essential to understanding internet technology; it is referred to
  89.    throughout this tutorial.
  90.  
  91. 2.2  Terminology
  92.  
  93.    The name of a unit of data that flows through an internet is
  94.    dependent upon where it exists in the protocol stack.  In summary: if
  95.    it is on an Ethernet it is called an Ethernet frame; if it is between
  96.    the Ethernet driver and the IP module it is called a IP packet; if it
  97.    is between the IP module and the UDP module it is called a UDP
  98.    datagram; if it is between the IP module and the TCP module it is
  99.    called a TCP segment (more generally, a transport message); and if it
  100.    is in a network application it is called a application message.
  101.  
  102.    These definitions are imperfect.  Actual definitions vary from one
  103.    publication to the next.  More specific definitions can be found in
  104.    RFC 1122, section 1.3.3.
  105.  
  106.    A driver is software that communicates directly with the network
  107.    interface hardware.  A module is software that communicates with a
  108.    driver, with network applications, or with another module.
  109.  
  110.    The terms driver, module, Ethernet frame, IP packet, UDP datagram,
  111.    TCP message, and application message are used where appropriate
  112.    throughout this tutorial.
  113.  
  114. 2.3  Flow of Data
  115.  
  116.    Let's follow the data as it flows down through the protocol stack
  117.    shown in Figure 1.  For an application that uses TCP (Transmission
  118.    Control Protocol), data passes between the application and the TCP
  119.    module.  For applications that use UDP (User Datagram Protocol), data
  120.    passes between the application and the UDP module.  FTP (File
  121.    Transfer Protocol) is a typical application that uses TCP.  Its
  122.    protocol stack in this example is FTP/TCP/IP/ENET.  SNMP (Simple
  123.    Network Management Protocol) is an application that uses UDP.  Its
  124.    protocol stack in this example is SNMP/UDP/IP/ENET.
  125.  
  126.    The TCP module, UDP module, and the Ethernet driver are n-to-1
  127.    multiplexers.  As multiplexers they switch many inputs to one output.
  128.    They are also 1-to-n de-multiplexers.  As de-multiplexers they switch
  129.    one input to many outputs according to the type field in the protocol
  130.    header.
  131.  
  132.  
  133.          1   2 3 ...   n                   1   2 3 ...   n
  134.           \  |      /      |               \  | |      /       ^
  135.            \ | |   /       |                \ | |     /        |
  136.          -------------   flow              ----------------   flow
  137.          |multiplexer|    of               |de-multiplexer|    of
  138.          -------------   data              ----------------   data
  139.               |            |                     |              |
  140.               |            v                     |              |
  141.               1                                  1
  142.  
  143.         Figure 2.  n-to-1 multiplexer and 1-to-n de-multiplexer
  144.  
  145.    If an Ethernet frame comes up into the Ethernet driver off the
  146.    network, the packet can be passed upwards to either the ARP (Address
  147.    Resolution Protocol) module or to the IP (Internet Protocol) module.
  148.    The value of the type field in the Ethernet frame determines whether
  149.    the Ethernet frame is passed to the ARP or the IP module.
  150.  
  151.    If an IP packet comes up into IP, the unit of data is passed upwards
  152.    to either TCP or UDP, as determined by the value of the protocol
  153.    field in the IP header.
  154.  
  155.    If the UDP datagram comes up into UDP, the application message is
  156.    passed upwards to the network application based on the value of the
  157.    port field in the UDP header.  If the TCP message comes up into TCP,
  158.    the application message is passed upwards to the network application
  159.    based on the value of the port field in the TCP header.
  160.  
  161.    The downwards multiplexing is simple to perform because from each
  162.    starting point there is only the one downward path; each protocol
  163.    module adds its header information so the packet can be de-
  164.    multiplexed at the destination computer.
  165.  
  166.    Data passing out from the applications through either TCP or UDP
  167.    converges on the IP module and is sent downwards through the lower
  168.    network interface driver.
  169.  
  170.    Although internet technology supports many different network media,
  171.    Ethernet is used for all examples in this tutorial because it is the
  172.    most common physical network used under IP.  The computer in Figure 1
  173.    has a single Ethernet connection.  The 6-byte Ethernet address is
  174.    unique for each interface on an Ethernet and is located at the lower
  175.    interface of the Ethernet driver.
  176.  
  177.    The computer also has a 4-byte IP address.  This address is located
  178.    at the lower interface to the IP module.  The IP address must be
  179.    unique for an internet.
  180.  
  181.    A running computer always knows its own IP address and Ethernet
  182.    address.
  183.  
  184. 2.4  Two Network Interfaces
  185.  
  186.    If a computer is connected to 2 separate Ethernets it is as in Figure
  187.    3.
  188.  
  189.                 ----------------------------
  190.                 |    network applications  |
  191.                 |                          |
  192.                 |...  \ | /  ..  \ | /  ...|
  193.                 |     -----      -----     |
  194.                 |     |TCP|      |UDP|     |
  195.                 |     -----      -----     |
  196.                 |         \      /         |
  197.                 |         --------         |
  198.                 |         |  IP  |         |
  199.                 |  -----  -*----*-  -----  |
  200.                 |  |ARP|   |    |   |ARP|  |
  201.                 |  -----   |    |   -----  |
  202.                 |      \   |    |   /      |
  203.                 |      ------  ------      |
  204.                 |      |ENET|  |ENET|      |
  205.                 |      ---@--  ---@--      |
  206.                 ----------|-------|---------
  207.                           |       |
  208.                           |    ---o---------------------------
  209.                           |             Ethernet Cable 2
  210.            ---------------o----------
  211.              Ethernet Cable 1
  212.  
  213.              Figure 3.  TCP/IP Network Node on 2 Ethernets
  214.  
  215.    Please note that this computer has 2 Ethernet addresses and 2 IP
  216.    addresses.
  217.  
  218.    It is seen from this structure that for computers with more than one
  219.    physical network interface, the IP module is both a n-to-m
  220.    multiplexer and an m-to-n de-multiplexer.
  221.  
  222.          1   2 3 ...   n                   1   2 3 ...   n
  223.           \  | |      /    |                \  | |      /       ^
  224.            \ | |     /     |                 \ | |     /        |
  225.          -------------   flow              ----------------   flow
  226.          |multiplexer|    of               |de-multiplexer|    of
  227.          -------------   data              ----------------   data
  228.            / | |     \     |                 / | |     \        |
  229.           /  | |      \    v                /  | |      \       |
  230.          1   2 3 ...   m                   1   2 3 ...   m
  231.  
  232.         Figure 4.  n-to-m multiplexer and m-to-n de-multiplexer
  233.  
  234.    It performs this multiplexing in either direction to accommodate
  235.    incoming and outgoing data.  An IP module with more than 1 network
  236.    interface is more complex than our original example in that it can
  237.    forward data onto the next network.  Data can arrive on any network
  238.    interface and be sent out on any other.
  239.  
  240.                            TCP      UDP
  241.                              \      /
  242.                               \    /
  243.                           --------------
  244.                           |     IP     |
  245.                           |            |
  246.                           |    ---     |
  247.                           |   /   \    |
  248.                           |  /     v   |
  249.                           --------------
  250.                            /         \
  251.                           /           \
  252.                        data           data
  253.                       comes in         goes out
  254.                      here               here
  255.  
  256.             Figure 5.  Example of IP Forwarding a IP Packet
  257.  
  258.    The process of sending an IP packet out onto another network is
  259.    called "forwarding" an IP packet.  A computer that has been dedicated
  260.    to the task of forwarding IP packets is called an "IP-router".
  261.  
  262.    As you can see from the figure, the forwarded IP packet never touches
  263.    the TCP and UDP modules on the IP-router.  Some IP-router
  264.    implementations do not have a TCP or UDP module.
  265.  
  266. 2.5  IP Creates a Single Logical Network
  267.  
  268.    The IP module is central to the success of internet technology.  Each
  269.    module or driver adds its header to the message as the message passes
  270.    down through the protocol stack.  Each module or driver strips the
  271.    corresponding header from the message as the message climbs the
  272.    protocol stack up towards the application.  The IP header contains
  273.    the IP address, which builds a single logical network from multiple
  274.    physical networks.  This interconnection of physical networks is the
  275.    source of the name: internet.  A set of interconnected physical
  276.    networks that limit the range of an IP packet is called an
  277.    "internet".
  278.  
  279. 2.6  Physical Network Independence
  280.  
  281.    IP hides the underlying network hardware from the network
  282.    applications.  If you invent a new physical network, you can put it
  283.    into service by implementing a new driver that connects to the
  284.    internet underneath IP.  Thus, the network applications remain intact
  285.    and are not vulnerable to changes in hardware technology.
  286.  
  287. 2.7  Interoperability
  288.  
  289.    If two computers on an internet can communicate, they are said to
  290.    "interoperate"; if an implementation of internet technology is good,
  291.    it is said to have "interoperability".  Users of general-purpose
  292.    computers benefit from the installation of an internet because of the
  293.    interoperability in computers on the market.  Generally, when you buy
  294.    a computer, it will interoperate.  If the computer does not have
  295.    interoperability, and interoperability can not be added, it occupies
  296.    a rare and special niche in the market.
  297.  
  298. 2.8  After the Overview
  299.  
  300.    With the background set, we will answer the following questions:
  301.  
  302.    When sending out an IP packet, how is the destination Ethernet
  303.    address determined?
  304.  
  305.    How does IP know which of multiple lower network interfaces to use
  306.    when sending out an IP packet?
  307.  
  308.    How does a client on one computer reach the server on another?
  309.  
  310.    Why do both TCP and UDP exist, instead of just one or the other?
  311.  
  312.    What network applications are available?
  313.  
  314.    These will be explained, in turn, after an Ethernet refresher.
  315.  
  316. 3.  Ethernet
  317.  
  318.    This section is a short review of Ethernet technology.
  319.  
  320.    An Ethernet frame contains the destination address, source address,
  321.    type field, and data.
  322.  
  323.    An Ethernet address is 6 bytes.  Every device has its own Ethernet
  324.    address and listens for Ethernet frames with that destination
  325.    address.  All devices also listen for Ethernet frames with a wild-
  326.    card destination address of "FF-FF-FF-FF-FF-FF" (in hexadecimal),
  327.    called a "broadcast" address.
  328.  
  329.    Ethernet uses CSMA/CD (Carrier Sense and Multiple Access with
  330.    Collision Detection).  CSMA/CD means that all devices communicate on
  331.    a single medium, that only one can transmit at a time, and that they
  332.    can all receive simultaneously.  If 2 devices try to transmit at the
  333.    same instant, the transmit collision is detected, and both devices
  334.    wait a random (but short) period before trying to transmit again.
  335.  
  336. 3.1  A Human Analogy
  337.  
  338.    A good analogy of Ethernet technology is a group of people talking in
  339.    a small, completely dark room.  In this analogy, the physical network
  340.    medium is sound waves on air in the room instead of electrical
  341.    signals on a coaxial cable.
  342.  
  343.    Each person can hear the words when another is talking (Carrier
  344.    Sense).  Everyone in the room has equal capability to talk (Multiple
  345.    Access), but none of them give lengthy speeches because they are
  346.    polite.  If a person is impolite, he is asked to leave the room
  347.    (i.e., thrown off the net).
  348.  
  349.    No one talks while another is speaking.  But if two people start
  350.    speaking at the same instant, each of them know this because each
  351.    hears something they haven't said (Collision Detection).  When these
  352.    two people notice this condition, they wait for a moment, then one
  353.    begins talking.  The other hears the talking and waits for the first
  354.    to finish before beginning his own speech.
  355.  
  356.    Each person has an unique name (unique Ethernet address) to avoid
  357.    confusion.  Every time one of them talks, he prefaces the message
  358.    with the name of the person he is talking to and with his own name
  359.    (Ethernet destination and source address, respectively), i.e., "Hello
  360.    Jane, this is Jack, ..blah blah blah...".  If the sender wants to
  361.    talk to everyone he might say "everyone" (broadcast address), i.e.,
  362.    "Hello Everyone, this is Jack, ..blah blah blah...".
  363.  
  364. 4.  ARP
  365.  
  366.    When sending out an IP packet, how is the destination Ethernet
  367.    address determined?
  368.  
  369.    ARP (Address Resolution Protocol) is used to translate IP addresses
  370.    to Ethernet addresses.  The translation is done only for outgoing IP
  371.    packets, because this is when the IP header and the Ethernet header
  372.    are created.
  373.  
  374. 4.1  ARP Table for Address Translation
  375.  
  376.    The translation is performed with a table look-up.  The table, called
  377.    the ARP table, is stored in memory and contains a row for each
  378.    computer.  There is a column for IP address and a column for Ethernet
  379.    address.  When translating an IP address to an Ethernet address, the
  380.    table is searched for a matching IP address.  The following is a
  381.    simplified ARP table:
  382.  
  383.                   ------------------------------------
  384.                   |IP address       Ethernet address |
  385.                   ------------------------------------
  386.                   |223.1.2.1        08-00-39-00-2F-C3|
  387.                   |223.1.2.3        08-00-5A-21-A7-22|
  388.                   |223.1.2.4        08-00-10-99-AC-54|
  389.                   ------------------------------------
  390.                       TABLE 1.  Example ARP Table
  391.  
  392.    The human convention when writing out the 4-byte IP address is each
  393.    byte in decimal and separating bytes with a period.  When writing out
  394.    the 6-byte Ethernet address, the conventions are each byte in
  395.    hexadecimal and separating bytes with either a minus sign or a colon.
  396.  
  397.    The ARP table is necessary because the IP address and Ethernet
  398.    address are selected independently; you can not use an algorithm to
  399.    translate IP address to Ethernet address.  The IP address is selected
  400.    by the network manager based on the location of the computer on the
  401.    internet.  When the computer is moved to a different part of an
  402.    internet, its IP address must be changed.  The Ethernet address is
  403.    selected by the manufacturer based on the Ethernet address space
  404.    licensed by the manufacturer.  When the Ethernet hardware interface
  405.    board changes, the Ethernet address changes.
  406.  
  407. 4.2  Typical Translation Scenario
  408.  
  409.    During normal operation a network application, such as TELNET, sends
  410.    an application message to TCP, then TCP sends the corresponding TCP
  411.    message to the IP module.  The destination IP address is known by the
  412.    application, the TCP module, and the IP module.  At this point the IP
  413.    packet has been constructed and is ready to be given to the Ethernet
  414.    driver, but first the destination Ethernet address must be
  415.    determined.
  416.  
  417.    The ARP table is used to look-up the destination Ethernet address.
  418.  
  419.    4.3  ARP Request/Response Pair
  420.  
  421.    But how does the ARP table get filled in the first place?  The answer
  422.    is that it is filled automatically by ARP on an "as-needed" basis.
  423.  
  424.    Two things happen when the ARP table can not be used to translate an
  425.    address:
  426.  
  427.      1. An ARP request packet with a broadcast Ethernet address is sent
  428.         out on the network to every computer.
  429.  
  430.      2. The outgoing IP packet is queued.
  431.  
  432.    Every computer's Ethernet interface receives the broadcast Ethernet
  433.    frame.  Each Ethernet driver examines the Type field in the Ethernet
  434.    frame and passes the ARP packet to the ARP module.  The ARP request
  435.    packet says "If your IP address matches this target IP address, then
  436.    please tell me your Ethernet address".  An ARP request packet looks
  437.    something like this:
  438.  
  439.                 ---------------------------------------
  440.                 |Sender IP Address   223.1.2.1        |
  441.                 |Sender Enet Address 08-00-39-00-2F-C3|
  442.                 ---------------------------------------
  443.                 |Target IP Address   223.1.2.2        |
  444.                 |Target Enet Address <blank>          |
  445.                 ---------------------------------------
  446.                      TABLE 2.  Example ARP Request
  447.  
  448.    Each ARP module examines the IP address and if the Target IP address
  449.    matches its own IP address, it sends a response directly to the
  450.    source Ethernet address.  The ARP response packet says "Yes, that
  451.    target IP address is mine, let me give you my Ethernet address".  An
  452.    ARP response packet has the sender/target field contents swapped as
  453.    compared to the request.  It looks something like this:
  454.  
  455.                 ---------------------------------------
  456.                 |Sender IP Address   223.1.2.2        |
  457.                 |Sender Enet Address 08-00-28-00-38-A9|
  458.                 ---------------------------------------
  459.                 |Target IP Address   223.1.2.1        |
  460.                 |Target Enet Address 08-00-39-00-2F-C3|
  461.                 ---------------------------------------
  462.                      TABLE 3.  Example ARP Response
  463.  
  464.    The response is received by the original sender computer.  The
  465.    Ethernet driver looks at the Type field in the Ethernet frame then
  466.    passes the ARP packet to the ARP module.  The ARP module examines the
  467.    ARP packet and adds the sender's IP and Ethernet addresses to its ARP
  468.    table.
  469.  
  470.    The updated table now looks like this:
  471.  
  472.                    ----------------------------------
  473.                    |IP address     Ethernet address |
  474.                    ----------------------------------
  475.                    |223.1.2.1      08-00-39-00-2F-C3|
  476.                    |223.1.2.2      08-00-28-00-38-A9|
  477.                    |223.1.2.3      08-00-5A-21-A7-22|
  478.                    |223.1.2.4      08-00-10-99-AC-54|
  479.                    ----------------------------------
  480.                    TA
  481. BLE 4.  ARP Table after Response
  482.  
  483. 4.4  Scenario Continued
  484.  
  485.    The new translation has now been installed automatically in the
  486.    table, just milli-seconds after it was needed.  As you remember from
  487.    step 2 above, the outgoing IP packet was queued.  Next, the IP
  488.    address to Ethernet address translation is performed by look-up in
  489.    the ARP table then the Ethernet frame is transmitted on the Ethernet.
  490.    Therefore, with the new steps 3, 4, and 5, the scenario for the
  491.    sender computer is:
  492.  
  493.      1. An ARP request packet with a broadcast Ethernet address is sent
  494.         out on the network to every computer.
  495.  
  496.      2. The outgoing IP packet is queued.
  497.  
  498.      3. The ARP response arrives with the IP-to-Ethernet address
  499.         translation for the ARP table.
  500.  
  501.      4. For the queued IP packet, the ARP table is used to translate the
  502.         IP address to the Ethernet address.
  503.  
  504.      5. The Ethernet frame is transmitted on the Ethernet.
  505.  
  506.    In summary, when the translation is missing from the ARP table, one
  507.    IP packet is queued.  The translation data is quickly filled in with
  508.    ARP request/response and the queued IP packet is transmitted.
  509.  
  510.    Each computer has a separate ARP table for each of its Ethernet
  511.    interfaces.  If the target computer does not exist, there will be no
  512.    ARP response and no entry in the ARP table.  IP will discard outgoing
  513.    IP packets sent to that address.  The upper layer protocols can't
  514.    tell the difference between a broken Ethernet and the absence of a
  515.    computer with the target IP address.
  516.  
  517.    Some implementations of IP and ARP don't queue the IP packet while
  518.    waiting for the ARP response.  Instead the IP packet is discarded and
  519.    the recovery from the IP packet loss is left to the TCP module or the
  520.    UDP network application.  This recovery is performed by time-out and
  521.    retransmission.  The retransmitted message is successfully sent out
  522.    onto the network because the first copy of the message has already
  523.    caused the ARP table to be filled.
  524. _______________________________________________________________________________
  525.                                                                         
  526.