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

  1.   Firewall Piercing mini-HOWTO
  2.   Franτois-RenΘ Rideau, fare@tunes.org
  3.   v0.3, 22 August 1998
  4.  
  5.   Directions for using ppp over telnet to do network stuff transparently
  6.   through an Internet firewall.
  7.   ______________________________________________________________________
  8.  
  9.   Table of Contents
  10.  
  11.  
  12.   1. Stuff
  13.  
  14.      1.1 DISCLAIMER
  15.      1.2 Legal Blurp
  16.      1.3 Credits
  17.  
  18.   2. Introduction
  19.  
  20.      2.1 Foreword
  21.      2.2 Security problems
  22.      2.3 Other requirements
  23.      2.4 Downloading software
  24.  
  25.   3. Understanding the problem
  26.  
  27.      3.1 Giving names to things
  28.      3.2 The problem
  29.      3.3 Additional difficulty
  30.  
  31.   4. The solution
  32.  
  33.      4.1 Principle
  34.      4.2 fwprc
  35.      4.3 .fwprcrc
  36.  
  37.   5. Reverse piercing
  38.  
  39.      5.1 Rationale
  40.      5.2 Getting the triggering mail
  41.  
  42.   6. Final notes
  43.  
  44.      6.1 Other settings
  45.      6.2 HOWTO maintenance
  46.      6.3 Extra copy of IMPORTANT DISCLAIMER --- BELIEVE IT!!!
  47.  
  48.  
  49.   ______________________________________________________________________
  50.  
  51.   1.  Stuff
  52.  
  53.  
  54.  
  55.   1.1.  DISCLAIMER
  56.  
  57.   READ THIS IMPORTANT SECTION !!!
  58.  
  59.   I hereby disclaim all responsibility for this hack.  If it backfires
  60.   on you in any way whatsoever, that's the breaks. Not my fault.  If you
  61.   don't understand the risks inherent in doing this, don't do it.  If
  62.   you use this hack and it allows vicious vandals to break into your
  63.   company's computers and costs you your job and your company millions
  64.   of dollars, well that's just tough nuggies.  Don't come crying to me.
  65.  
  66.  
  67.   1.2.  Legal Blurp
  68.  
  69.   Copyright ⌐ 1998 by Franτois-RenΘ Rideau.  This document may be
  70.   distributed only subject to the terms and conditions set forth in the
  71.   LDP license at <http://sunsite.unc.edu/LDP/LICENSE.html>.
  72.  
  73.  
  74.  
  75.   1.3.  Credits
  76.  
  77.   Even though I rewrote most everything but the disclaimers, I'm
  78.   indebted to Barak Pearlmutter  <mailto:bap@cs.unm.edu> for his Term-
  79.   Firewall mini-HOWTO: I think there was a necessity for a mini-HOWTO
  80.   about piercing firewalls, and despite its shortcomings, his mini-HOWTO
  81.   was a model and an encouragement.
  82.  
  83.  
  84.  
  85.   2.  Introduction
  86.  
  87.  
  88.  
  89.   2.1.  Foreword
  90.  
  91.   Because system administrators and users have different constraints and
  92.   proficiencies, it so happens that a user may find himself behind a
  93.   firewall, that he may cross, but only in awkward ways.  This mini-
  94.   HOWTO explains a generic and portable way to use standard internet
  95.   tools seamlessly across such firewalls, by the use of an IP emulator
  96.   over a telnet session.
  97.  
  98.   It is freely inspired by the Term-Firewall mini-HOWTO by Barak
  99.   Pearlmutter  <mailto:bap@cs.unm.edu>, which relies on an ancient and
  100.   no-more-supported program named Term (yet a great program at its
  101.   time), as well as on peculiarities of a not-so-standard telnet
  102.   implementation, that is, many obsolete and non-portable facts.
  103.  
  104.  
  105.  
  106.   2.2.  Security problems
  107.  
  108.   Of course, if your sysadm has setup a firewall, s/he might have a good
  109.   reason, and you may have signed an agreement to not circumvent it.  On
  110.   the other hand, the fact that you can telnet outside (which is a
  111.   requisite for the presented hacks to work) means that you are allowed
  112.   to access external systems, and the fact that you can log into a
  113.   particular external system somehow means you're allowed to do it, too.
  114.  
  115.   So this is all a matter of conveniently using legal holes in a
  116.   firewall, and allow generic programs to work from there with generic
  117.   protocols, as opposed to requiring special or modified (and
  118.   recompiled) programs going through lots of special-purpose proxies
  119.   that be misconfigured by an uncaring or incompetent sysadm, or to
  120.   installing lots of special-purpose converters to access each of your
  121.   usual services (like e-mail) through ways supported by the firewall
  122.   (like the web).
  123.  
  124.   Moreover, the use of a user-level IP emulator such as SLiRP should
  125.   still prevent external attackers from piercing the firewall back in
  126.   the other way, unless explicitly permitted by you (or they are clever
  127.   and wicked, and root or otherwise able to spy you on the remote host).
  128.  
  129.   All in all, the presented hack should be relatively safe.  However, it
  130.   all depends on the particular circumstances in which you set things
  131.   up, and I can give no guarantee about this hack.  Lots of things are
  132.   intrinsically unsafe about any internet connection, be it with this
  133.   hack or not, so don't you assume anything is safe unless you have good
  134.   reasons, and/or use some kind of encryption all the way.
  135.  
  136.   To sum it up, don't use this hack unless you know what you're doing.
  137.   Re-read the disclaimer above.
  138.  
  139.  
  140.  
  141.   2.3.  Other requirements
  142.  
  143.   It is assumed that you know what you're doing; that you know about
  144.   setting up a network connection; that you have shell accounts on both
  145.   sides of the firewall; that you can somehow telnet (or ssh, or
  146.   equivalent) from one account to the other; that you can run an IP
  147.   emulator on both shell accounts; that you have programs able to use
  148.   the IP connection emulated on their side.  Note that any program can
  149.   use the connection, in case the local emulator is pppd talking to the
  150.   Linux kernel; other emulators, like Term, need recompilation and
  151.   linking to a special library.
  152.  
  153.   Talking about IP emulators, pppd can be found in any good Linux
  154.   distribution or ftp site; so can SLiRP.  If your remote shell account
  155.   is user-level only, you can use SLiRP to connect.
  156.  
  157.  
  158.  
  159.   2.4.  Downloading software
  160.  
  161.   Most described software should be available from your standard
  162.   distribution, possibly among contrib's; at least all but the two small
  163.   last ones are available in as rpm packages.  In case you want to fetch
  164.   the latest sources or binaries (after all, one of the ends of the
  165.   connection may not be running linux), use the addresses below:
  166.  
  167.   ╖  SLiRP can be found at <http://blitzen.canberra.edu.au/slirp> and/or
  168.      <ftp://www.ibc.wustl.edu/pub/slirp_bin/>.
  169.  
  170.   ╖  zsh can be found at <http://www.peak.org/zsh/>.
  171.  
  172.   ╖  ppp can be found at <ftp://cs.anu.edu.au/pub/software/ppp/>.
  173.  
  174.   ╖  fwprc and cotty can be found at
  175.      <http://www.tunes.org/~fare/files/>.
  176.  
  177.  
  178.  
  179.   3.  Understanding the problem
  180.  
  181.   Understanding a problem is the first half of the path to solving it.
  182.  
  183.  
  184.   3.1.  Giving names to things
  185.  
  186.   If you want this hack to work for you, you'll have to get an idea of
  187.   how it works, so that in case anything breaks, you know where to look
  188.   for.
  189.  
  190.   The first step toward understanding the problem is to give a name to
  191.   relevant concepts.
  192.  
  193.   So we'll herein call "local" the machine that initiates the
  194.   connection, as well as programs and files on that machine; conversely,
  195.   we'll call "remote" what's on the other side of the connection.
  196.  
  197.  
  198.  
  199.   3.2.  The problem
  200.  
  201.   The goal is to connect the input and output of a local IP emulator to
  202.   the output and input respectively of a remote IP emulator.
  203.  
  204.   Only the communication channels with which IP emulators interact are
  205.   either direct devices (in the usual case of pppd), or the "current
  206.   tty".  The previous case obviously does not happen with telnet
  207.   sessions.  The latter is tricky, because when you launch the local
  208.   emulator from the command line, the "current tty" is linked to the
  209.   command-line user, not to a remote session; also, should we open a new
  210.   session (local or remote) on a new terminal, we must synchronize the
  211.   launching and connection of IP emulators on both sides, least one
  212.   session's garbage output is going to be executed as commands on the
  213.   other session, which would recursively produce more garbage.
  214.  
  215.  
  216.   3.3.  Additional difficulty
  217.  
  218.   To get the best ease of use, the local IP emulator has to provide IP
  219.   to kernel networking, hence be pppd.  However, pppd is dumb enough to
  220.   only accept having data through /dev or thru the current tty; it must
  221.   be a tty, not a pair of pipe (which would be the obvious design).
  222.   This is fine for the remote pppd if any, as it can use the telnet
  223.   session's tty; but for the local pppd, it sucks, as it can't launch
  224.   the telnet session to connect to; hence, there must some kind of
  225.   wrapper around it.
  226.  
  227.   Telnet behaves almost correctly with a pair of pipe, except that it
  228.   will still insist on doing ioctl's to the current tty, with which it
  229.   will interfere; using telnet without a tty also causes race
  230.   conditions, so that the whole connection will fail on "slow" computers
  231.   (fwprc 0.1 worked perfectly on a P/MMX 233, one time out of 6 on a
  232.   6x86-P200+, and never on a 486dx2/66).
  233.  
  234.   [Note: if I find the sucker (probably a MULTICS guy, though there must
  235.   have been UNIX people stupid enough to copy the idea) who invented the
  236.   principle of "tty" devices by which you read and write from a "same"
  237.   pseudo-file, instead of having clean pairs of pipes, I strangle him!]
  238.  
  239.  
  240.  
  241.   4.  The solution
  242.  
  243.  
  244.  
  245.   4.1.  Principle
  246.  
  247.   The firewall-piercing program, fwprc, will use a "tty proxy", cotty,
  248.   that opens two pseudo-tty devices, launches some command on each of
  249.   those devices' slaves, and stubbornly copies every character that one
  250.   outputs to the tty that serves as input of the other command.  One
  251.   command will be telnet connection to remote site, and the other will
  252.   be the local pppd.  pppd can then open and control the telnet session
  253.   with a chat script as usual.
  254.  
  255.  
  256.   4.2.  fwprc
  257.  
  258.   I wrote a very well self-documented script to pierce firewalls, fwprc,
  259.   available from my site  <http://www.tunes.org/~fare/files/>, together
  260.   with cotty (which is required by fwprc 0.2 and later).  At the time of
  261.   my writing these lines, latest versions are fwprc 0.2a and cotty 0.3.
  262.  
  263.   The name "fwprc" is voluntarily made unreadable and unpronounceable,
  264.   so that it will confuse the incompetent paranoid sysadm who might be
  265.   the cause of the firewall that annoys you (of course, there can be
  266.   legitimate firewalls, too).  If you must read it aloud, choose the
  267.   worst way you can imagine.
  268.  
  269.   CONTEST! CONTEST! Send me a .au audio file with a digital audio
  270.   recording of how you pronounce "fwprc".  The worst entry will win a
  271.   free upgrade and his name on the fwprc 0.3 page!
  272.  
  273.   I tested the program in several settings, by configuring it through
  274.   resource files.  But of course, by Murphy's law, it will break for
  275.   you.  Feel free to contribute enhancements that will make life easier
  276.   to other people who'll configure it after you.
  277.  
  278.  
  279.  
  280.   4.3.  .fwprcrc
  281.  
  282.   fwprc can be customized through a file .fwprcrc meant to be the same
  283.   on both sides of the firewall.  Having several alternate
  284.   configurations to choose from is sure possible (for instance, I do
  285.   it), and is left as an exercise to the reader.
  286.  
  287.   To begin with, copy the appropriate section of fwprc (the previous to
  288.   last) into a file named .fwprcrc in your home directory.  Then replace
  289.   variable values with stuff that fits your configuration.  Finally,
  290.   copy to the other host, and test.
  291.  
  292.   Default behavior is to use pppd locally, and slirp remotely.  To
  293.   modify that, you can redefine the appropriate function in your
  294.   .fwprcrc with such a line as:
  295.  
  296.        remote_IP_emu () { remote_pppd }
  297.  
  298.  
  299.   Note that SLiRP is safer than pppd, and easier to have access to,
  300.   since it does not require being root on the remote machine.  Anoter
  301.   safe feature is that it will drop packets not directly coming from the
  302.   connected machine (which feature becomes a misfeature if you attempt
  303.   to route a subnetwork onto it with masquerading).  The basic
  304.   functionality in SLiRP works quite well, but I've found advertised
  305.   pluses (like run-time controllability) to be deficient; of course,
  306.   since it is free software, feel free to hack the source so as to
  307.   actually implement whichever feature you need.
  308.  
  309.  
  310.  
  311.  
  312.   5.  Reverse piercing
  313.  
  314.  
  315.  
  316.   5.1.  Rationale
  317.  
  318.   Sometimes, only one side of the firewall can launch telnet sessions
  319.   into the other side; however, some means of communication is possible
  320.   (typically, through e-mail).  Piercing the firewall is still possible,
  321.   by triggering with whatever messaging capability is available a telnet
  322.   connection from the ``right'' side of the firewall to the other.
  323.  
  324.   fwprc includes code to trigger such connections from a PGP-
  325.   authentified e-mail message; all you need is add fwprc as a
  326.   procmail(1) filter to messages using the protocol, (instructions
  327.   included in fwprc itself).  Note however, that if you are to launch
  328.   pppd with appropriate priviledges, you might need create your own suid
  329.   wrapper to become root.  Instructions enclosed in fwprc.
  330.  
  331.   Also, authentified trigger does not remotely mean secure connection.
  332.   You should really use ssh (perhaps over telnet) for secure
  333.   connections.  And then, beware of what happens between the triggering
  334.   of a telnet connection, and ssh taking over that connection.
  335.   Contribution in that direction welcome.
  336.  
  337.  
  338.   5.2.  Getting the triggering mail
  339.  
  340.   If you are firewalled, your mail may as well be in a central server
  341.   that doesn't do procmail filtering or allow telnet sessions.  No
  342.   problem! You can use fetchmail(1) to run in daemon mode to poll and
  343.   get mail to your client linux system, and/or add a cron-job to
  344.   automatically poll for mail every 1-5 minutes.  fetchmail will forward
  345.   mail to a local address through sendmail(8), which itself will have
  346.   been configured to use procmail(1) for delivery.  Note that if you run
  347.   fetchmail(1) as a background daemon, it will lock away any other
  348.   fetchmail that you'd like to run only at other times, like when you
  349.   open a fwprc; of course, if you can also run a fetchmail daemon as a
  350.   fake user.  Too frequent a poll won't be nice to either the server or
  351.   your host.  Too unfrequent a poll means you'll have to wait before the
  352.   message gets read and the reverse connection gets established.  I use
  353.   two-minute poll frequency.
  354.  
  355.  
  356.  
  357.   6.  Final notes
  358.  
  359.  
  360.  
  361.   6.1.  Other settings
  362.  
  363.   There are other kinds of firewalls than those that allow for telnet
  364.   connections.  As long as a continuous flow of packets may go through a
  365.   firewall, and transmit information both ways, it is possible to pierce
  366.   it; only the price of writing the piercer may be higher or lower.
  367.  
  368.   In a very easy case, you can just launch ssh over a pty, and do some
  369.   pppd in the slave tty.  cotty 0.3 should be able to do it, but
  370.   nobody's modified fwprc to take it into account yet.  May be tonight's
  371.   exercise for you.  You may even want to do it without an adverse
  372.   firewall, just so as to build a secure ``VPN'' (Virtual Private
  373.   Network).
  374.  
  375.   If you need cross a 7-bit line, you'll want to use SLIP instead of
  376.   PPP.  I never tried, because lines are more or less 8-bit clean these
  377.   days, but it shouldn't be difficult.
  378.  
  379.   Now, if the only way through the firewall is a WWW proxy (usually, a
  380.   minimum for an internet-connected network), you might want to write a
  381.   daemon that buffers data in and out, and sends it during in HTTP
  382.   connections, achieving some telnet-over-HTTP over which to run fwprc.
  383.   It might be slow and not very responsive, but still good enough to use
  384.   fetchmail(1), suck(1), and other non-interactive programs.
  385.  
  386.   If you want more performance, or if the only thing that goes through
  387.   unfiltered is some wierder thing even (DNS queries, ICMP packets,
  388.   whatever), then you're in the very hard case where you'll have to re-
  389.   hack a wierd IP stack, using (for instance) the Fox project's packet-
  390.   protocol functors.  You'll then achieve some direct IP-over-HTTP, IP-
  391.   over-DNS, IP-over-ICMP, or such, which requires not only a complex
  392.   protocol, but also an interface to an OS kernel, both of which are
  393.   costly to implement.
  394.  
  395.   By the way, if you use some Firewall-piercing HTTP daemon, don't
  396.   forget to have it serve fake pages, so as to mislead suspicious
  397.   adverse firewall administrators.
  398.  
  399.  
  400.  
  401.   6.2.  HOWTO maintenance
  402.  
  403.   I felt it was necessary to write it, but I don't have that much time
  404.   for that, so this mini-HOWTO is very rough.  So will it stay, until I
  405.   get enough feedback so as to know what sections to enhance.  Feedback
  406.   welcome. Help welcome. mini-HOWTO maintenance take-over welcome.
  407.  
  408.   In any case, the above sections have shown many problems whose
  409.   solution is just a matter of someone (you?)  spending some time (or
  410.   money, by hiring someone else) to sit down and write it: nothing
  411.   conceptually complicated, though the details might be burdensome or
  412.   tricky.
  413.  
  414.   Do not hesitate to contribute more problems, and hopefully more
  415.   solutions, to this mini-HOWTO.
  416.  
  417.  
  418.  
  419.   6.3.  Extra copy of IMPORTANT DISCLAIMER --- BELIEVE IT!!!
  420.  
  421.  
  422.        I hereby disclaim all responsibility for this hack.  If it
  423.        backfires on you in any way whatsoever, that's the breaks.
  424.        Not my fault.  If you don't understand the risks inherent in
  425.        doing this, don't do it.  If you use this hack and it allows
  426.        vicious vandals to break into your company's computers and
  427.        costs you your job and your company millions of dollars,
  428.        well that's just tough nuggies.  Don't come crying to me.
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.