home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Enter 1999 June / enter_06_1999.iso / doc / HOWTO / mini / Term-Firewall < prev    next >
Text File  |  1998-10-14  |  11KB  |  331 lines

  1.   Using Term to Pierce an Internet Firewall
  2.   Barak Pearlmutter, bap@cs.unm.edu
  3.   v, 15 July 1996
  4.  
  5.   Directions for using ``term'' to do network stuff through a TCP fire¡
  6.   wall that you're not supposed to be able to.
  7.   ______________________________________________________________________
  8.  
  9.   Table of Contents
  10.  
  11.  
  12.   1. Disclaimer
  13.  
  14.   2. Copyright
  15.  
  16.   3. Introduction
  17.  
  18.   4. The basic procedure
  19.  
  20.   5. Detailed directions
  21.  
  22.   6. Multiple term sockets
  23.  
  24.   7. The
  25.  
  26.   8. Direction
  27.  
  28.   9. Security
  29.  
  30.   10. Telnet mode
  31.  
  32.   11. Bugs and term wish list
  33.  
  34.   12. Tricks that don't seem to work
  35.  
  36.   13. Related resources
  37.  
  38.   14. Acknowledgments
  39.  
  40.  
  41.  
  42.   ______________________________________________________________________
  43.  
  44.   1.  Disclaimer
  45.  
  46.   !!! READ THIS IMPORTANT SECTION !!!
  47.  
  48.   I hereby disclaim all responsibility for this hack.  If it backfires
  49.   on you in any way whatsoever, that's the breaks.  Not my fault.  If
  50.   you don't understand the risks inherent in doing this, don't do it.
  51.   If you use this hack and it allows vicious hackers to break into your
  52.   company's computers and costs you your job and your company millions
  53.   of dollars, well that's just tough nuggies.  Don't come crying to me.
  54.  
  55.   2.  Copyright
  56.  
  57.   Unless otherwise stated, Linux HOWTO documents are copyrighted by
  58.   their respective authors. Linux HOWTO documents may be reproduced and
  59.   distributed in whole or in part, in any medium physical or electronic,
  60.   as long as this copyright notice is retained on all copies. Commercial
  61.   redistribution is allowed and encouraged; however, the author would
  62.   like to be notified of any such distributions.
  63.  
  64.   All translations, derivative works, or aggregate works incorporating
  65.   any Linux HOWTO documents must be covered under this copyright notice.
  66.   That is, you may not produce a derivative work from a HOWTO and impose
  67.   additional restrictions on its distribution. Exceptions to these rules
  68.   may be granted under certain conditions; please contact the Linux
  69.   HOWTO coordinator at the address given below.
  70.  
  71.   In short, we wish to promote dissemination of this information through
  72.   as many channels as possible. However, we do wish to retain copyright
  73.   on the HOWTO documents, and would like to be notified of any plans to
  74.   redistribute the HOWTOs.
  75.  
  76.   If you have questions, please contact Tim Bynum, the Linux HOWTO
  77.   coordinator, at linux-howto@sunsite.unc.edu via email.
  78.  
  79.   3.  Introduction
  80.  
  81.   The "term" program is normally used over a modem or serial line, to
  82.   allow various host-to-host services to flow along this simple serial
  83.   connection.  However, sometimes it is useful to establish a term
  84.   connection between two machines that communicate via telnet.  The most
  85.   interesting instance of this is for connecting two hosts which are
  86.   separated by ethernet firewalls or SOCKS servers.  Such firewalls
  87.   provides facilities for establishing a telnet connection through the
  88.   firewall, typically by using the SOCKS protocol to allow inside
  89.   machines to get connections out, and requiring outside users to telnet
  90.   first to a gateway machine which requires a one-time password.  These
  91.   firewalls make it impossible to, for instance, have X clients on an
  92.   inside machine communicate with an X server on an outside machine.
  93.   But, by setting up a term connection, these restrictions can all be
  94.   bypassed quite conveniently, at the user level.
  95.  
  96.   4.  The basic procedure
  97.  
  98.   Setting up a term connection over a telnet substrate is a two-phase
  99.   process.  First your usual telnet client is used to set up a telnet
  100.   connection and log in.  Next, the telnet client is paused and control
  101.   of the established telnet connection is given to term.
  102.  
  103.   5.  Detailed directions
  104.  
  105.   In detail, the process goes like this.
  106.  
  107.   First, from a machine inside the firewall, telnet to a target machine
  108.   outside the firewall and log in.
  109.  
  110.   Unless you are under linux and will be using the proc filesystem (see
  111.   below) make sure your shell is an sh style shell.  Ie if your default
  112.   shell is a csh variant, invoke telnet by
  113.  
  114.  
  115.        (setenv SHELL /bin/sh; telnet machine.outside)
  116.  
  117.  
  118.  
  119.  
  120.   After logging in, on the remote (outside) machine invoke the command
  121.  
  122.  
  123.        term -r -n off telnet
  124.  
  125.  
  126.  
  127.  
  128.   Now break back to the telnet prompt on the local (inside) machine,
  129.   using ^] or whatever, and use the telnet shell escape command ! to
  130.   invoke term,
  131.  
  132.  
  133.   telnet> ! term -n on telnet >&3 <&3
  134.  
  135.  
  136.  
  137.  
  138.   Et voila!!!
  139.  
  140.   (If you have a variant telnet, you might have to use some other file
  141.   descriptor than 3; easy to check using strace.  But three seems to
  142.   work on all bsd descendent telnet clients I've tried, under both SunOS
  143.   4.x and the usual linux distributions.)
  144.  
  145.   Some telnet clients do not have the ! shell escape command.  Eg the
  146.   telnet client distributed with Slackware 3.0 is one such client.  The
  147.   sources that the Slackware telnet client is supposedly built from,
  148.  
  149.  
  150.        ftp://ftp.cdrom.com:/pub/linux/slackware-3.0/source/n/tcpip/NetKit-B-0.05.tar.gz
  151.  
  152.  
  153.  
  154.  
  155.   have the shell escape command.  A simple solution is therefore to
  156.   obtain these sources and recompile them.  This unfortunately is a task
  157.   I have had no luck with.  Plus, if you are running from inside a SOCKS
  158.   firewall, you will need a SOCKSified telnet client anyway.  To that
  159.   end, I was able to compile a SOCKSified telnet client from
  160.  
  161.  
  162.        ftp://ftp.nec.com/pub/security/socks.cstc/socks.cstc.4.2.tar.gz
  163.  
  164.  
  165.  
  166.  
  167.   or if you're outside the USA,
  168.  
  169.  
  170.        ftp://ftp.nec.com/pub/security/socks.cstc/export.socks.cstc.4.2.tar.gz
  171.  
  172.  
  173.  
  174.  
  175.   Alternatively, under linux kernels up to 1.2.13, you can pause the
  176.   telnet with ^]^z, figure out its pid, and invoke
  177.  
  178.  
  179.        term -n on -v /proc/<telnetpid>/fd/3 telnet
  180.  
  181.  
  182.  
  183.  
  184.   This doesn't work with newer 1.3.x kernels, which closed some mysteri¡
  185.   ous security hole by preventing access to these fd's by processes
  186.   other than the owner process and its children.
  187.  
  188.   6.  Multiple term sockets
  189.  
  190.   It is a good idea to give the term socket an explicit name.  This is
  191.   the "telnet" argument in the invocations of term above.  Unless you
  192.   have the TERMSERVER environment variable set to telnet as appropriate,
  193.   you invoke term clients with the -t switch, e.g. "trsh -t telnet".
  194.  
  195.   7.  The ~/.term/termrc.telnet  init file
  196.  
  197.   I have checked line clarity using linecheck over this medium.  I
  198.   expected it to be completely transparent, but it is not.  However, the
  199.   only bad character seems to be 255.  The ~/.term/termrc.telnet I use
  200.   (the .telnet is the name of the term connection, see above) contains:
  201.  
  202.  
  203.        baudrate off
  204.        escape 255
  205.        ignore 255
  206.        timeout 600
  207.  
  208.  
  209.  
  210.  
  211.   Perhaps it could be improved by diddling, I am getting a throughput of
  212.   only about 30k cps over a long-haul connection through a slow
  213.   firewall.  Ftp can move about 100k cps over the same route.  A
  214.   realistic baudrate might avoid some timeouts.
  215.  
  216.   8.  Direction
  217.  
  218.   Obviously, if you are starting from outside the firewall and zitching
  219.   in using a SecureID card or something, you will want to reverse the
  220.   roles of the remote vs local servers given above.  (If you don't
  221.   understand what this means, perhaps you are not familiar enough with
  222.   term to use the trick described in this file responsibly.)
  223.  
  224.   9.  Security
  225.  
  226.   This is not much more of a vulnerability than the current possibility
  227.   of having a telnet connection hijacked on an unsecured outside
  228.   machine.  The primary additional risk comes from people being able to
  229.   use the term socket you set up without you even being aware of it.  So
  230.   be careful out there.  (Personally, I do this with an outside machine
  231.   I know to be pretty secure, namely a linux laptop I maintain myself
  232.   that does not accept any incoming connections.)
  233.  
  234.   Another possibility is to add "socket off" to the remote
  235.   ~/.term/termrc.telnet, or add "-u off" to invocation of term.  This
  236.   prevents the socket from being hijacked from the remote end, with only
  237.   a minor loss of functionality.
  238.  
  239.   10.  Telnet mode
  240.  
  241.   Be sure the remote telnetd is not in some nasty seven-bit mode.  Or if
  242.   it is, you have to tell term about it when you invoke term, by adding
  243.   the -a switch at both ends.  (I sometimes use "^] telnet> set outbin"
  244.   or "set bin" or invoke telnet with a -8 switch to put the connection
  245.   into eight-bit mode.)
  246.  
  247.   11.  Bugs and term wish list
  248.  
  249.   The linecheck program has some problems checking telnet connections
  250.   sometimes.  This is sometimes because it doesn't check the return code
  251.   of the read() call it makes.  For network connections, this call to
  252.   read() can return -1 with an EINTR (interrupted) or EAGAIN (try again)
  253.   error code.  Obviously this should be checked for.
  254.  
  255.   There are a number of features that could ease the use of term over
  256.   telnet.  These primarily relate to an assumption that influenced the
  257.   design of term, namely that the connection is low bandwidth, low
  258.   latency, and somewhat noisy.
  259.  
  260.   A telnet connection is in general high bandwidth, high latency, and
  261.   error free.  This means that the connection could be better utilized
  262.   if (a) the maximum window size was raised, well above the limit
  263.   imposed by term's N_PACKETS/2=16, (b) there was an option to turn off
  264.   sending and checking packet checksums, and (c) larger packets were
  265.   permitted when appropriate.
  266.  
  267.   Also, to enhance security, it would be nice to have a term option to
  268.   log all connections through the socket it monitors to a log file, or
  269.   to stderr, or both.  This would allow one to see if one's term
  270.   connection is being subverted by nasty hackers on the outside insecure
  271.   machine.
  272.  
  273.   12.  Tricks that don't seem to work
  274.  
  275.   Some telnet clients and servers agree to encrypt their communications,
  276.   to prevent evesdropping on the connection.  Unfortunately, the hack
  277.   used above (using the network connection that the telnet client has
  278.   set up while the telnet client is idle) won't work in that case.
  279.   Instead, one really must go through the telnet client itself, so it
  280.   can do its encryption.  It seems like that requires a simple hack to
  281.   the telnet client itself, to add a command that runs a process with
  282.   its stdin and stdout are connected to the live telnet connection.
  283.   This would also be useful for various 'bots, so perhaps someone has
  284.   already hacked it up.
  285.  
  286.   13.  Related resources
  287.  
  288.   A vaguely related trick is to SOCKSify one's Term library.  Details,
  289.   including patches to SOCKS, are available from Steven Danz
  290.   <danz@wv.mentorg.com>.
  291.  
  292.   14.  Acknowledgments
  293.  
  294.   Thanks for valuable suggestions from:
  295.  
  296.   ╖  Gary Flake   <flake@scr.siemens.com>
  297.  
  298.   ╖  Bill Riemers <bcr@physics.purdue.edu>
  299.  
  300.   ╖  Greg Louis   <glouis@dynamicro.on.ca>
  301.  
  302.  
  303.        Extra copy of IMPORTANT DISCLAIMER --- BELIEVE IT!!!
  304.  
  305.  
  306.  
  307.        I hereby disclaim all responsibility for this hack.  If it
  308.        backfires on you in any way whatsoever, that's the breaks.
  309.        Not my fault.  If you don't understand the risks inherent in
  310.        doing this, don't do it.  If you use this hack and it allows
  311.        vicious hackers to break into your company's computers and
  312.        costs you your job and your company millions of dollars,
  313.        well that's just tough nuggies.  Don't come crying to me.
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.