View | Details | Raw Unified | Return to bug 40313
Collapse All | Expand All

(-)chapter.sgml (-50 / +50 lines)
Lines 919-926 Link Here
919
	respect except that it forwards encryption keys by default.  What
919
	respect except that it forwards encryption keys by default.  What
920
	this means is that if you have a secure workstation holding keys
920
	this means is that if you have a secure workstation holding keys
921
	that give you access to the rest of the system, and you
921
	that give you access to the rest of the system, and you
922
	ssh to an insecure machine, your keys
922
	ssh to an insecure machine, your keys are usable by the
923
	becomes exposed.  The actual keys themselves are not exposed, but
923
	insecure system.  The actual keys themselves are not exposed, but
924
	ssh installs a forwarding port for the
924
	ssh installs a forwarding port for the
925
	duration of your login, and if an attacker has broken
925
	duration of your login, and if an attacker has broken
926
	<username>root</username> on the
926
	<username>root</username> on the
Lines 1921-1927 Link Here
1921
      
1921
      
1922
      <para>There are currently two distinct types of firewalls in common use
1922
      <para>There are currently two distinct types of firewalls in common use
1923
	on the Internet today.  The first type is more properly called a
1923
	on the Internet today.  The first type is more properly called a
1924
	<emphasis>packet filtering router</emphasis>, where the kernel on a
1924
	<emphasis>packet filtering router</emphasis>, where a
1925
	multi-homed machine chooses whether to forward or block packets based
1925
	multi-homed machine chooses whether to forward or block packets based
1926
	on a set of rules.  The second type, known as a <emphasis>proxy
1926
	on a set of rules.  The second type, known as a <emphasis>proxy
1927
	  server</emphasis>, relies on daemons to provide authentication and to
1927
	  server</emphasis>, relies on daemons to provide authentication and to
Lines 1946-1974 Link Here
1946
	<title>Packet Filtering Routers</title>
1946
	<title>Packet Filtering Routers</title>
1947
1947
1948
	<para>A router is a machine which forwards packets between two or more
1948
	<para>A router is a machine which forwards packets between two or more
1949
	  networks.  A packet filtering router has an extra piece of code in
1949
	  networks.  A packet filtering router has extra code to
1950
	  its kernel which compares each packet to a list of rules before
1950
	  compare each packet to a list of rules before
1951
	  deciding if it should be forwarded or not.  Most modern IP routing
1951
	  deciding if it should be forwarded or not.  Most modern IP routing
1952
	  software has packet filtering code within it that defaults to
1952
	  software has packet filtering code within it that defaults to
1953
	  forwarding all packets.  To enable the filters, you need to define a
1953
	  forwarding all packets.  To enable the filters, you need to define a
1954
	  set of rules for the filtering code so it can decide if the
1954
	  set of rules for the filtering code so it can decide if any given
1955
	  packet should be allowed to pass or not.</para>
1955
	  packet should be allowed to pass or not.</para>
1956
	    
1956
	    
1957
	<para>To decide whether a packet should be passed on, the code looks
1957
	<para>To decide whether a packet should be passed on, the firewall looks
1958
	  through its set of rules for a rule which matches the contents of
1958
	  through its set of rules for a rule which matches the contents of
1959
	  this packets headers.  Once a match is found, the rule action is
1959
	  the packet's headers.  Once a match is found, the rule action is
1960
	  obeyed.  The rule action could be to drop the packet, to forward the
1960
	  obeyed.  The rule action could be to drop the packet, to forward the
1961
	  packet, or even to send an ICMP message back to the originator.
1961
	  packet, or even to send an ICMP message back to the originator.
1962
	  Only the first match counts, as the rules are searched in order.
1962
	  Only the first match counts, and the rules are searched in order.
1963
	  Hence, the list of rules can be referred to as a <quote>rule
1963
	  Hence, the list of rules can be referred to as a <quote>rule
1964
	  chain</quote>.</para>
1964
	  chain</quote>.</para>
1965
	    
1965
	    
1966
	<para>The packet matching criteria varies depending on the software
1966
	<para>The packet-matching criteria varies depending on the software
1967
	  used, but typically you can specify rules which depend on the source
1967
	  used, but typically you can specify rules which depend on the source
1968
	  IP address of the packet, the destination IP address, the source
1968
	  IP address of the packet, the destination IP address, the source
1969
	  port number, the destination port number (for protocols which
1969
	  port number, the destination port number (for protocols which
1970
	  support ports), or even the packet type (UDP, TCP, ICMP,
1970
	  support ports), or even the packet type (UDP, TCP, ICMP,
1971
	  etc).</para>
1971
	  etc.).</para>
1972
      </sect3>
1972
      </sect3>
1973
	  
1973
	  
1974
      <sect3 id="firewalls-proxy-servers">
1974
      <sect3 id="firewalls-proxy-servers">
Lines 1976-2004 Link Here
1976
	    
1976
	    
1977
	<para>Proxy servers are machines which have had the normal system
1977
	<para>Proxy servers are machines which have had the normal system
1978
	  daemons (<application>telnetd</application>, 
1978
	  daemons (<application>telnetd</application>, 
1979
	  <application>ftpd</application>, etc) replaced with special servers.
1979
	  <application>ftpd</application>, etc.) replaced with special servers.
1980
	  These
1980
	  These
1981
	  servers are called <emphasis>proxy servers</emphasis> as they
1981
	  servers are called <emphasis>proxy servers</emphasis>, as they
1982
	  normally only allow onward connections to be made.  This enables you
1982
	  normally only allow onward connections to be made.  This enables you
1983
	  to run (for example) a proxy telnet server on your firewall host,
1983
	  to run (for example) a proxy <application>telnet</application> server on your firewall host,
1984
	  and people can telnet in to your firewall from the outside, go
1984
	  so people can <application>telnet</application> in to your firewall from the outside, go
1985
	  through some authentication mechanism, and then gain access to the
1985
	  through some authentication mechanism, and then gain access to the
1986
	  internal network (alternatively, proxy servers can be used for
1986
	  internal network (alternatively, proxy servers can be used for
1987
	  signals coming from the internal network and heading out).</para>
1987
	  signals coming from the internal network and heading out).</para>
1988
	    
1988
	    
1989
	<para>Proxy servers are normally more secure than normal servers, and
1989
	<para>Proxy servers are normally more secure than normal servers, and
1990
	  often have a wider variety of authentication mechanisms available,
1990
	  often have a wider variety of authentication mechanisms available,
1991
	  including <quote>one-shot</quote> password systems so that even if
1991
	  including <quote>one-shot</quote> password systems, so that even if
1992
	  someone manages to discover what password you used, they will not be
1992
	  someone manages to record a password being used, they will not be
1993
	  able to use it to gain access to your systems as the password
1993
	  able to use it, as the password
1994
	  instantly expires.  As they do not actually give users access to the
1994
	  instantly expires on first use.  As they do not actually give users direct access to the
1995
	  host machine, it becomes a lot more difficult for someone to install
1995
	  host machine, it becomes a lot more difficult for someone to install
1996
	  backdoors around your security system.</para>
1996
	  backdoors around your security system.</para>
1997
	    
1997
	    
1998
	<para>Proxy servers often have ways of restricting access further, so
1998
	<para>Proxy servers often have ways of restricting access further, so
1999
	  that only certain hosts can gain access to the servers, and often
1999
	  that only certain hosts can gain access to the servers, and often
2000
	  they can be set up so that you can limit which users can talk to
2000
	  they can be set up to limit which users can talk to
2001
	  which destination machine.  Again, what facilities are available
2001
	  which destination machines.  Again, what facilities are available
2002
	  depends largely on what proxy software you choose.</para>
2002
	  depends largely on what proxy software you choose.</para>
2003
      </sect3>
2003
      </sect3>
2004
    </sect2>
2004
    </sect2>
Lines 2011-2022 Link Here
2011
	FreeBSD, is a packet filtering and accounting system which resides in
2011
	FreeBSD, is a packet filtering and accounting system which resides in
2012
	the kernel, and has a user-land control utility,
2012
	the kernel, and has a user-land control utility,
2013
	    &man.ipfw.8;.  Together, they allow you to define and query the
2013
	    &man.ipfw.8;.  Together, they allow you to define and query the
2014
	rules currently used by the kernel in its routing decisions.</para>
2014
	rules used by the kernel for its routing decisions.</para>
2015
	  
2015
	  
2016
      <para>There are two related parts to IPFW.
2016
      <para>There are two related parts to IPFW.
2017
	The firewall section allows you to perform packet filtering.  There is
2017
	The firewall section performs packet filtering.  There is
2018
	also an IP accounting section which allows you to track usage of your
2018
	also an IP accounting section which tracks usage of your
2019
	router, based on similar rules to the firewall section.  This allows
2019
	router, based on similar rules.  This allows
2020
	you to see (for example) how much traffic your router is getting from
2020
	you to see (for example) how much traffic your router is getting from
2021
	a certain machine, or how much WWW (World Wide Web) traffic it is
2021
	a certain machine, or how much WWW (World Wide Web) traffic it is
2022
	forwarding.</para>
2022
	forwarding.</para>
Lines 2078-2090 Link Here
2078
	      firewall activity, but do not want to be open to a denial of
2078
	      firewall activity, but do not want to be open to a denial of
2079
	      service attack via syslog flooding.</para>
2079
	      service attack via syslog flooding.</para>
2080
2080
2081
	    <para>When a chain entry reaches the packet limit specified,
2081
	    <para>When a chain entry (rule) reaches the packet limit specified,
2082
	      logging is turned off for that particular entry.  To resume
2082
	      logging is turned off for that particular entry.  To resume
2083
	      logging, you will need to reset the associated counter using the
2083
	      logging, you will need to reset the associated counter using the
2084
		&man.ipfw.8; utility:</para>
2084
		&man.ipfw.8; utility:</para>
2085
	    
2085
	    
2086
	    <screen>&prompt.root; <userinput>ipfw zero 4500</userinput></screen>
2086
	    <screen>&prompt.root; <userinput>ipfw zero 4500</userinput></screen>
2087
	    <para>Where 4500 is the chain entry you wish to continue
2087
	    <para>Where 4500 is the chain entry you wish to resume
2088
	      logging.</para>
2088
	      logging.</para>
2089
	  </listitem>
2089
	  </listitem>
2090
	</varlistentry>
2090
	</varlistentry>
Lines 2200-2208 Link Here
2200
	    <term>allow</term>
2200
	    <term>allow</term>
2201
	    
2201
	    
2202
	    <listitem>
2202
	    <listitem>
2203
	      <para>Pass the packet on as normal.  (aliases:
2203
	      <para>Pass the packet on as normal (aliases:
2204
		<literal>pass</literal> and
2204
		<literal>pass</literal>, <literal>permit</literal>, and
2205
		<literal>accept</literal>)</para>
2205
		<literal>accept</literal>).</para>
2206
	    </listitem>
2206
	    </listitem>
2207
	  </varlistentry>
2207
	  </varlistentry>
2208
	  
2208
	  
Lines 2212-2218 Link Here
2212
	    <listitem>
2212
	    <listitem>
2213
	      <para>Drop the packet.  The source is not notified via an
2213
	      <para>Drop the packet.  The source is not notified via an
2214
		ICMP message (thus it appears that the packet never
2214
		ICMP message (thus it appears that the packet never
2215
		arrived at the destination).</para>
2215
		arrived at the destination).  Alias: <literal>drop</literal>.</para>
2216
	    </listitem>
2216
	    </listitem>
2217
	  </varlistentry>
2217
	  </varlistentry>
2218
	  
2218
	  
Lines 2362-2372 Link Here
2362
	    <listitem>
2362
	    <listitem>
2363
	      <para>Matches if the IP header contains the comma separated list
2363
	      <para>Matches if the IP header contains the comma separated list
2364
		of options specified in <replaceable>spec</replaceable>.  The
2364
		of options specified in <replaceable>spec</replaceable>.  The
2365
		supported list of IP options are: <literal>ssrr</literal>
2365
		supported list of IP options is: <literal>ssrr</literal>
2366
		(strict source route), <literal>lsrr</literal> (loose source
2366
		(strict source route), <literal>lsrr</literal> (loose source
2367
		route), <literal>rr</literal> (record packet route), and
2367
		route), <literal>rr</literal> (record packet route), and
2368
		<literal>ts</literal> (time stamp).  The absence of a
2368
		<literal>ts</literal> (time stamp).  The absence of a
2369
		particular option may be denoted with a leading
2369
		particular option may be specified with a leading
2370
		<literal>!</literal>.</para>
2370
		<literal>!</literal>.</para>
2371
	    </listitem>
2371
	    </listitem>
2372
	  </varlistentry>
2372
	  </varlistentry>
Lines 2434-2443 Link Here
2434
	    <arg>-a</arg>
2434
	    <arg>-a</arg>
2435
	    <arg>-t</arg>
2435
	    <arg>-t</arg>
2436
	    <arg>-N</arg>
2436
	    <arg>-N</arg>
2437
	    <arg choice="plain">l</arg>
2437
	    <arg choice="plain">list</arg>
2438
	  </cmdsynopsis></para>
2438
	  </cmdsynopsis></para>
2439
2439
2440
	<para>There are three valid flags when using this form of the
2440
	<para>The list command may be abbreviated. There are three valid flags when using this form of the
2441
	  command:</para>
2441
	  command:</para>
2442
	    
2442
	    
2443
	<variablelist>
2443
	<variablelist>
Lines 2482-2488 Link Here
2482
2482
2483
	<para>This causes all entries in the firewall chain to be removed
2483
	<para>This causes all entries in the firewall chain to be removed
2484
	  except the fixed default policy enforced by the kernel (index
2484
	  except the fixed default policy enforced by the kernel (index
2485
	  65535).  Use caution when flushing rules, the default deny policy
2485
	  65535).  Use caution when flushing rules; the default deny policy
2486
	  will leave your system cut off from the network until allow entries
2486
	  will leave your system cut off from the network until allow entries
2487
	  are added to the chain.</para>
2487
	  are added to the chain.</para>
2488
      </sect3>
2488
      </sect3>
Lines 2499-2505 Link Here
2499
2499
2500
	<para>When used without an <replaceable>index</replaceable> argument,
2500
	<para>When used without an <replaceable>index</replaceable> argument,
2501
	  all packet counters are cleared.  If an
2501
	  all packet counters are cleared.  If an
2502
	  <replaceable>index</replaceable> is supplied, the clearing operation
2502
	  <replaceable>index</replaceable> is supplied, the clear operation
2503
	  only affects a specific chain entry.</para>
2503
	  only affects a specific chain entry.</para>
2504
      </sect3>
2504
      </sect3>
2505
    </sect2>
2505
    </sect2>
Lines 2546-2570 Link Here
2546
      
2546
      
2547
      <note>
2547
      <note>
2548
	<para>The following suggestions are just that: suggestions.  The
2548
	<para>The following suggestions are just that: suggestions.  The
2549
	  requirements of each firewall are different and we cannot tell you
2549
	  requirements for each firewall are different and we cannot tell you
2550
	  how to build a firewall to meet your particular requirements.</para>
2550
	  how to build a firewall to meet your particular requirements.</para>
2551
      </note>
2551
      </note>
2552
	  
2552
	  
2553
      <para>When initially setting up your firewall, unless you have a test
2553
      <para>When initially setting up your firewall, unless you have a test
2554
	bench setup where you can configure your firewall host in a controlled
2554
	bench setup where you can configure your firewall host in a controlled
2555
	environment, it is strongly recommend you use the logging version of the
2555
	environment, it is strongly recommend you use the logging versions of the
2556
	commands and enable logging in the kernel.  This will allow you to
2556
	commands and enable logging in the kernel.  This will allow you to
2557
	quickly identify problem areas and cure them without too much
2557
	quickly identify problem areas and cure them without too much
2558
	disruption.  Even after the initial setup phase is complete, I
2558
	disruption.  Even after the initial setup phase is complete, I
2559
	recommend using the logging for `deny' as it allows tracing of
2559
	recommend using the logging for `deny' rule, as it allows tracing of
2560
	possible attacks and also modification of the firewall rules if your
2560
	possible attacks and also modification of the firewall rules if your
2561
	requirements alter.</para>
2561
	requirements change.</para>
2562
	  
2562
	  
2563
      <note>
2563
      <note>
2564
	<para>If you use the logging versions of the <command>accept</command>
2564
	<para>If you use the logging versions of the <command>accept</command>
2565
	  command, it can generate <emphasis>large</emphasis> amounts of log
2565
	  command, it can generate <emphasis>large</emphasis> amounts of log
2566
	  data as one log line will be generated for every packet that passes
2566
	  data, as one log line will be generated for every packet that passes
2567
	  through the firewall, so large FTP/http transfers, etc, will really
2567
	  through the firewall; this means large FTP/http transfers, etc., will really
2568
	  slow the system down.  It also increases the latencies on those
2568
	  slow the system down.  It also increases the latencies on those
2569
	  packets as it requires more work to be done by the kernel before the
2569
	  packets as it requires more work to be done by the kernel before the
2570
	  packet can be passed on.  <application>syslogd</application> will 
2570
	  packet can be passed on.  <application>syslogd</application> will 
Lines 2576-2582 Link Here
2576
	  
2576
	  
2577
      <para>You should enable your firewall from
2577
      <para>You should enable your firewall from
2578
	<filename>/etc/rc.conf.local</filename> or
2578
	<filename>/etc/rc.conf.local</filename> or
2579
	<filename>/etc/rc.conf</filename>.  The associated manual page explains
2579
	<filename>/etc/rc.conf</filename>.  The <filename>/etc/rc.conf</filename> manual page explains
2580
	which knobs to fiddle and lists some preset firewall configurations.
2580
	which knobs to fiddle and lists some preset firewall configurations.
2581
	If you do not use a preset configuration, <command>ipfw list</command>
2581
	If you do not use a preset configuration, <command>ipfw list</command>
2582
	will output the current ruleset into a file that you can
2582
	will output the current ruleset into a file that you can
Lines 2590-2596 Link Here
2590
	<emphasis>do</emphasis>! This is largely dependent on what access to
2590
	<emphasis>do</emphasis>! This is largely dependent on what access to
2591
	your network you want to allow from the outside, and how much access
2591
	your network you want to allow from the outside, and how much access
2592
	to the outside world you want to allow from the inside. Some general
2592
	to the outside world you want to allow from the inside. Some general
2593
	rules are:</para>
2593
	rules to start with are:</para>
2594
      
2594
      
2595
      <itemizedlist>
2595
      <itemizedlist>
2596
	<listitem>
2596
	<listitem>
Lines 2603-2609 Link Here
2603
	  <para>Block <emphasis>all</emphasis> incoming UDP traffic.  There
2603
	  <para>Block <emphasis>all</emphasis> incoming UDP traffic.  There
2604
	    are very few useful services that travel over UDP, and what useful
2604
	    are very few useful services that travel over UDP, and what useful
2605
	    traffic there is, is normally a security threat (e.g. Suns RPC and
2605
	    traffic there is, is normally a security threat (e.g. Suns RPC and
2606
	    NFS protocols).  This has its disadvantages also, since UDP is a
2606
	    NFS protocols).  This has its disadvantages also; since UDP is a
2607
	    connectionless protocol, denying incoming UDP traffic also blocks
2607
	    connectionless protocol, denying incoming UDP traffic also blocks
2608
	    the replies to outgoing UDP traffic.  This can cause a problem for
2608
	    the replies to outgoing UDP traffic.  This can cause a problem for
2609
	    people (on the inside) using external archie (prospero) servers.
2609
	    people (on the inside) using external archie (prospero) servers.
Lines 2626-2632 Link Here
2626
	      
2626
	      
2627
	<listitem>
2627
	<listitem>
2628
	  <para>Check what ports any internal servers use (e.g. SQL servers,
2628
	  <para>Check what ports any internal servers use (e.g. SQL servers,
2629
	    etc).  It is probably a good idea to block those as well, as they
2629
	    etc.).  It is probably a good idea to block those as well, as they
2630
	    normally fall outside the 1-1024 range specified above.</para>
2630
	    normally fall outside the 1-1024 range specified above.</para>
2631
	</listitem>
2631
	</listitem>
2632
      </itemizedlist>
2632
      </itemizedlist>
Lines 2659-2671 Link Here
2659
	<literal>ip_fw_chk</literal> routine, displaying the results
2659
	<literal>ip_fw_chk</literal> routine, displaying the results
2660
	to the console every 1000 packets.</para>
2660
	to the console every 1000 packets.</para>
2661
2661
2662
      <para>Two rule sets, each with 1000 rules were tested.  The
2662
      <para>Two rule sets, each with 1000 rules, were tested.  The
2663
	first set was designed to demonstrate a worst case scenario by
2663
	first set was designed to demonstrate a worst case scenario by
2664
	repeating the rule:</para>
2664
	repeating the rule:</para>
2665
2665
2666
      <screen>&prompt.root; <userinput>ipfw add deny tcp from any to any 55555</userinput></screen>
2666
      <screen>&prompt.root; <userinput>ipfw add deny tcp from any to any 55555</userinput></screen>
2667
2667
2668
      <para>This demonstrates worst case by causing most of IPFW's
2668
      <para>This demonstrates a worst case by causing most of IPFW's
2669
	packet check routine to be executed before finally deciding
2669
	packet check routine to be executed before finally deciding
2670
	that the packet does not match the rule (by virtue of the port
2670
	that the packet does not match the rule (by virtue of the port
2671
	number). Following the 999th iteration of this rule was an
2671
	number). Following the 999th iteration of this rule was an
Lines 2686-2692 Link Here
2686
	rule. Thus the theoretical packet processing limit with these
2686
	rule. Thus the theoretical packet processing limit with these
2687
	rules is around 370 packets per second. Assuming 10Mbps
2687
	rules is around 370 packets per second. Assuming 10Mbps
2688
	Ethernet and a ~1500 byte packet size, we would only be able
2688
	Ethernet and a ~1500 byte packet size, we would only be able
2689
	to achieve a 55.5% bandwidth utilization.</para>
2689
	to achieve 55.5% bandwidth utilization.</para>
2690
2690
2691
      <para>For the latter case each packet was processed in
2691
      <para>For the latter case each packet was processed in
2692
	approximately 1.172ms, or roughly 1.2 microseconds per rule.
2692
	approximately 1.172ms, or roughly 1.2 microseconds per rule.

Return to bug 40313