1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
|
---|
4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
5 | %general-entities;
|
---|
6 | ]>
|
---|
7 |
|
---|
8 | <sect1 id="postlfs-security-fw-firewall" xreflabel="Firewalling">
|
---|
9 | <sect1info>
|
---|
10 | <othername>$LastChangedBy$</othername>
|
---|
11 | <date>$Date$</date>
|
---|
12 | </sect1info>
|
---|
13 | <?dbhtml filename="firewall.html"?>
|
---|
14 | <title>Setting up a network firewall</title>
|
---|
15 |
|
---|
16 | <para>Before you read this part of the chapter, note that we assume that you
|
---|
17 | have already installed iptables as described in the previous section.</para>
|
---|
18 |
|
---|
19 |
|
---|
20 | <sect2 id="postlfs-security-fw-intro" xreflabel="Firewalling Introduction">
|
---|
21 | <title>Introduction to Firewall Creation</title>
|
---|
22 |
|
---|
23 | <para>The general purpose of a firewall is to protect a network
|
---|
24 | against malicious access by using a single machine as a firewall.
|
---|
25 | This does imply that the firewall is to be considered a single point
|
---|
26 | of failure, but it can make the administrator's life a lot easier.</para>
|
---|
27 |
|
---|
28 | <para>In a perfect world where you knew that every daemon or service
|
---|
29 | on every machine was perfectly configured and was immune to, e.g.,
|
---|
30 | buffer-overflows and any other imaginable problem regarding its
|
---|
31 | security, and where you trusted every user accessing your services
|
---|
32 | to aim no harm, you wouldn't need to have a firewall!
|
---|
33 | In the real world however, daemons may be misconfigured,
|
---|
34 | exploits against essential services are freely available, you
|
---|
35 | may wish to choose which services are accessible by certain machines,
|
---|
36 | you may wish to limit which machines or applications are allowed
|
---|
37 | to have Internet access, or you may simply not trust some of your
|
---|
38 | apps or users.
|
---|
39 | In these situations you might benefit by using a firewall.</para>
|
---|
40 |
|
---|
41 | <para>Don't assume however, that having a firewall makes careful
|
---|
42 | configuration redundant, or that it makes any negligent
|
---|
43 | misconfiguration harmless. It also doesn't prevent anyone from exploiting a
|
---|
44 | service you intentionally offer but haven't recently updated or patched
|
---|
45 | after an exploit went public. Despite having a firewall, you need to
|
---|
46 | keep applications and daemons on your system well-configured and
|
---|
47 | up-to-date; a firewall is not a cure-all!</para>
|
---|
48 |
|
---|
49 | </sect2>
|
---|
50 |
|
---|
51 | <sect2>
|
---|
52 | <title>Meaning of the word firewall.</title>
|
---|
53 |
|
---|
54 | <para>The word firewall can have several different meanings.</para>
|
---|
55 |
|
---|
56 | <sect3><title><xref linkend="postlfs-security-fw-persFw"/></title>
|
---|
57 |
|
---|
58 | <para>This is a setup or program, for Windows commercially sold by
|
---|
59 | companies such as Symantec, of which they claim or pretend that it
|
---|
60 | secures a home or desktop-pc with Internet access. This topic is
|
---|
61 | highly relevant for users who do not know the methods their computers
|
---|
62 | might be accessed via the Internet or how to disable them,
|
---|
63 | especially if they are always online and connected via
|
---|
64 | broadband links.</para></sect3>
|
---|
65 |
|
---|
66 | <sect3><title><xref linkend="postlfs-security-fw-masqRouter"/></title>
|
---|
67 | <para>This is a box placed between the Internet and an intranet.
|
---|
68 | To minimize the risk of compromising the firewall itself it
|
---|
69 | should generally have only one role, that of protecting the intranet.
|
---|
70 | Although not completely risk free, the tasks of doing the routing
|
---|
71 | and eventually IP masquerading (rewriting IP-headers
|
---|
72 | of the packets it routes from clients with private IP-addresses onto
|
---|
73 | the Internet so that they seem to come from the firewall
|
---|
74 | itself) are commonly considered harmless.</para></sect3>
|
---|
75 |
|
---|
76 | <sect3><title><xref linkend="postlfs-security-fw-busybox"/></title>
|
---|
77 | <para>This is often an old box you may have retired and nearly forgotten,
|
---|
78 | performing masquerading or routing functions, but offering a bunch of
|
---|
79 | services, e.g., web-cache, mail, etc. This may be very commonly used
|
---|
80 | for home networks, but can definitely not be considered as secure
|
---|
81 | anymore because the combining of server and router on one machine raises
|
---|
82 | the complexity of the setup.</para></sect3>
|
---|
83 |
|
---|
84 | <sect3><title>Firewall with a demilitarized zone [not further described
|
---|
85 | here]</title>
|
---|
86 | <para>This box performs masquerading or routing, but grants public access to
|
---|
87 | some branch of your network which, because of public IP's and a physically
|
---|
88 | separated structure, is neither considered to be part of the inter- nor
|
---|
89 | intranet. These servers are those which must be easily accessible
|
---|
90 | from both the inter- and intranet. The firewall protects
|
---|
91 | them all.</para></sect3>
|
---|
92 |
|
---|
93 | <sect3><title>Packetfilter / partly accessible net [partly described
|
---|
94 | here, see <xref linkend="postlfs-security-fw-busybox"/>]</title>
|
---|
95 | <para>Doing routing or masquerading, but permitting only selected
|
---|
96 | services to be accessible, sometimes only by selected internal users or boxes;
|
---|
97 | mostly used in highly secure business contexts, sometimes by distrusting
|
---|
98 | employers. This was the common configuration of a firewall at the time of
|
---|
99 | the Linux 2.2 kernel. It's still possible to configure a firewall this way,
|
---|
100 | but it makes the rules quite complex and lengthy.</para></sect3>
|
---|
101 |
|
---|
102 | </sect2>
|
---|
103 |
|
---|
104 | <sect2 id="postlfs-security-fw-disclaimer" xreflabel="Disclaimer">
|
---|
105 | <title>Disclaimer</title>
|
---|
106 |
|
---|
107 | <!-- <para><emphasis>NEITHER THE AUTHOR NOR ANY OF THE LINUXFROMSCRATCH TEAM
|
---|
108 | ARE RESPONSIBLE FOR ANY DAMAGES INCURRED DUE TO ACTIONS TAKEN BASED ON THIS
|
---|
109 | DOCUMENT.</emphasis></para> -->
|
---|
110 |
|
---|
111 | <para>This document is meant as an introduction to how to setup a firewall. It
|
---|
112 | is not a complete guide to securing systems. Firewalling is a complex issue
|
---|
113 | that requires careful configuration. The scripts quoted here are simply
|
---|
114 | intended to give examples as to how a firewall works, they are not intended to
|
---|
115 | fit into any imaginable configuration and may not prevent any imaginable
|
---|
116 | attack.</para>
|
---|
117 |
|
---|
118 | <para>The purpose of this text is simply to give you a hint on how to get
|
---|
119 | started with a firewall.</para>
|
---|
120 |
|
---|
121 | <para>Customization of these scripts for your specific situation will
|
---|
122 | be necessary for an optimal configuration, but you should make a serious
|
---|
123 | study of the iptables documentation and creating firewalls in general before hacking
|
---|
124 | away. Have a look at the list of <xref linkend="postlfs-security-fw-library"/> at the end
|
---|
125 | of this section for more details. Here you will find a list of URLs that
|
---|
126 | contain quite comprehensive information about building your own firewall.</para>
|
---|
127 |
|
---|
128 | </sect2>
|
---|
129 |
|
---|
130 |
|
---|
131 | <sect2 id="postlfs-security-fw-kernel" xreflabel="getting a firewalling-enabled Kernel">
|
---|
132 | <title>Getting a firewall enabled Kernel</title>
|
---|
133 |
|
---|
134 | <para>If you want your Linux-Box to have a firewall, you must first ensure
|
---|
135 | that your kernel has been compiled with the relevant options turned on.
|
---|
136 | <!-- <footnote><para>If you needed assistance how to configure, compile and install
|
---|
137 | a new kernel, refer back to chapter VIII of the LinuxFromScratch book,
|
---|
138 | <ulink url="http://www.linuxfromscratch.org/view/3.1/chapter08/kernel.html">Installing a kernel</ulink>
|
---|
139 | and eventually
|
---|
140 | <ulink url="http://www.linuxfromscratch.org/view/3.1/chapter08/lilo.html">Making the LFS system bootable</ulink>
|
---|
141 | ; note, that you'll need to reboot
|
---|
142 | to actually run your new kernel.</para></footnote>-->
|
---|
143 | </para>
|
---|
144 |
|
---|
145 | <para>How to configure your kernel, with enabling the options to be
|
---|
146 | either compiled into the kernel or as modules, depends on your personal
|
---|
147 | preferences and experience. Note, that for the quoted scripts it is assumed
|
---|
148 | that the modules need to be loaded at first.</para>
|
---|
149 |
|
---|
150 | <screen>Network options menu
|
---|
151 | Network packet filtering: Y
|
---|
152 | Unix domain sockets: Y or M
|
---|
153 | TCP/IP networking: Y
|
---|
154 | IP: advanced router: Y
|
---|
155 | IP: verbose route monitoring: Y
|
---|
156 | IP: TCP Explicit Congestion Notification support: Y
|
---|
157 | IP: TCP syncookie support: Y
|
---|
158 | IP: Netfilter Configuration menu
|
---|
159 | Every option except: Y or M
|
---|
160 | ipchains (2.2-style) support N
|
---|
161 | ipfwadm (2.0-style) support N
|
---|
162 | Fast switching: N</screen>
|
---|
163 |
|
---|
164 | <!--
|
---|
165 | <table frame='none'>
|
---|
166 | <title>Essential config-options for a firewall enabled Kernel</title>
|
---|
167 |
|
---|
168 | <tgroup cols='5'>
|
---|
169 | <colspec colnum='1' colwidth='8*' align='center'/>
|
---|
170 | <colspec colnum='2' colwidth='19*' align='left'/>
|
---|
171 | <colspec colnum='3' colwidth='11*' align='center'/>
|
---|
172 | <colspec colnum='4' colwidth='1*' align='center'/>
|
---|
173 | <colspec colnum='5' colwidth='14*' align='left'/>
|
---|
174 |
|
---|
175 | <tbody>
|
---|
176 |
|
---|
177 | <row>
|
---|
178 | <entry><emphasis><userinput>Networking options:</userinput></emphasis></entry>
|
---|
179 | <entry><userinput>Network packet filtering</userinput></entry>
|
---|
180 | <entry></entry>
|
---|
181 | <entry>=</entry>
|
---|
182 | <entry>CONFIG_NETFILTER</entry>
|
---|
183 | </row>
|
---|
184 |
|
---|
185 | <row>
|
---|
186 | <entry></entry>
|
---|
187 | <entry><userinput>Unix domain sockets</userinput></entry>
|
---|
188 | <entry></entry>
|
---|
189 | <entry>=</entry>
|
---|
190 | <entry>CONFIG_UNIX</entry>
|
---|
191 | </row>
|
---|
192 |
|
---|
193 | <row>
|
---|
194 | <entry></entry>
|
---|
195 | <entry><userinput>IP: TCP/IP networking</userinput></entry>
|
---|
196 | <entry></entry>
|
---|
197 | <entry>=</entry>
|
---|
198 | <entry>CONFIG_INET</entry>
|
---|
199 | </row>
|
---|
200 |
|
---|
201 | <row>
|
---|
202 | <entry></entry>
|
---|
203 | <entry><userinput>IP: advanced router</userinput></entry>
|
---|
204 | <entry></entry>
|
---|
205 | <entry>=</entry>
|
---|
206 | <entry>CONFIG_IP_ADVANCED_ROUTER</entry>
|
---|
207 | </row>
|
---|
208 |
|
---|
209 | <row>
|
---|
210 | <entry></entry>
|
---|
211 | <entry><userinput>IP: verbose route monitoring</userinput></entry>
|
---|
212 | <entry></entry>
|
---|
213 | <entry>=</entry>
|
---|
214 | <entry>CONFIG_IP_ROUTE_VERBOSE</entry>
|
---|
215 | </row>
|
---|
216 |
|
---|
217 | <row>
|
---|
218 | <entry></entry>
|
---|
219 | <entry><userinput>IP: TCP Explicit Congestion Notification support</userinput></entry>
|
---|
220 | <entry></entry>
|
---|
221 | <entry>=</entry>
|
---|
222 | <entry>CONFIG_INET_ECN</entry>
|
---|
223 | </row>
|
---|
224 |
|
---|
225 | <row>
|
---|
226 | <entry></entry>
|
---|
227 | <entry><userinput>IP: TCP syncookie support</userinput></entry>
|
---|
228 | <entry></entry>
|
---|
229 | <entry>=</entry>
|
---|
230 | <entry>CONFIG_SYN_COOKIES</entry>
|
---|
231 | </row>
|
---|
232 |
|
---|
233 | <row>
|
---|
234 | <entry></entry>
|
---|
235 | <entry align='center'>
|
---|
236 | <emphasis><userinput>IP: Netfilter Configuration:</userinput></emphasis></entry>
|
---|
237 | <entry align='left'><userinput>every option</userinput></entry>
|
---|
238 | <entry>=</entry>
|
---|
239 | <entry>CONFIG_IP_NF_*</entry>
|
---|
240 | </row>
|
---|
241 |
|
---|
242 | <row>
|
---|
243 | <entry></entry>
|
---|
244 | <entry align='right'><emphasis>WITHOUT:</emphasis></entry>
|
---|
245 | <entry align='left'><literallayout><userinput>ipchains (2.2-style) support
|
---|
246 | ipfw-adm (2.0-style) support</userinput></literallayout></entry>
|
---|
247 | <entry>w\</entry>
|
---|
248 | <entry>CONFIG_IP_NF_COMPAT_*</entry>
|
---|
249 | </row>
|
---|
250 |
|
---|
251 | <row>
|
---|
252 | <entry></entry>
|
---|
253 | <entry><userinput>Fast switching</userinput></entry>
|
---|
254 | <entry>Make sure to disable it because it would setup a bypass around
|
---|
255 | your firewall rules.</entry>
|
---|
256 | <entry>w\</entry>
|
---|
257 | <entry>CONFIG_NET_FASTROUTE</entry>
|
---|
258 | </row>
|
---|
259 |
|
---|
260 | </tbody>
|
---|
261 |
|
---|
262 | </tgroup>
|
---|
263 |
|
---|
264 | </table> -->
|
---|
265 |
|
---|
266 | </sect2>
|
---|
267 |
|
---|
268 |
|
---|
269 | <sect2 id="postlfs-security-fw-writing" xreflabel="writing the firewalling-setup-scripts">
|
---|
270 | <title>Now you can start to build your Firewall</title>
|
---|
271 |
|
---|
272 |
|
---|
273 | <sect3 id="postlfs-security-fw-persFw" xreflabel="Personal Firewall">
|
---|
274 | <title>Personal Firewall</title>
|
---|
275 |
|
---|
276 | <para>A Personal Firewall is supposed to let you access all the services
|
---|
277 | offered on the Internet, but keep your box secure and your data private.</para>
|
---|
278 |
|
---|
279 | <para>Below is a slightly modified version of Rusty Russell's recommendation
|
---|
280 | from the <ulink
|
---|
281 | url="http://www.netfilter.org/documentation/HOWTO/packet-filtering-HOWTO.html">Linux
|
---|
282 | 2.4 Packet Filtering HOWTO</ulink>:</para>
|
---|
283 |
|
---|
284 | <screen><userinput><command>cat > /etc/rc.d/init.d/firewall << "EOF"</command>
|
---|
285 | #!/bin/sh
|
---|
286 |
|
---|
287 | # Begin $rc_base/init.d/firewall
|
---|
288 |
|
---|
289 | # Insert connection-tracking modules (not needed if built into the kernel).
|
---|
290 | modprobe ip_tables
|
---|
291 | modprobe iptable_filter
|
---|
292 | modprobe ip_conntrack
|
---|
293 | modprobe ip_conntrack_ftp
|
---|
294 | modprobe ipt_state
|
---|
295 | modprobe ipt_LOG
|
---|
296 |
|
---|
297 | # allow local-only connections
|
---|
298 | iptables -A INPUT -i lo -j ACCEPT
|
---|
299 | # free output on any interface to any ip for any service (equal to -P ACCEPT)
|
---|
300 | iptables -A OUTPUT -j ACCEPT
|
---|
301 |
|
---|
302 | # permit answers on already established connections
|
---|
303 | # and permit new connections related to established ones (eg active-ftp)
|
---|
304 | iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
---|
305 |
|
---|
306 | # Log everything else: What's Windows' latest exploitable vulnerability?
|
---|
307 | iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
|
---|
308 |
|
---|
309 | # set a sane policy: everything not accepted > /dev/null
|
---|
310 | iptables -P INPUT DROP
|
---|
311 | iptables -P FORWARD DROP
|
---|
312 | iptables -P OUTPUT DROP
|
---|
313 |
|
---|
314 | # be verbose on dynamic ip-addresses (not needed in case of static IP)
|
---|
315 | echo 2 > /proc/sys/net/ipv4/ip_dynaddr
|
---|
316 |
|
---|
317 | # disable ExplicitCongestionNotification - too many routers are still ignorant
|
---|
318 | echo 0 > /proc/sys/net/ipv4/tcp_ecn
|
---|
319 |
|
---|
320 | # End $rc_base/init.d/firewall
|
---|
321 | <command>EOF</command></userinput></screen>
|
---|
322 |
|
---|
323 | <para>His script is quite simple, it drops all traffic coming in into your
|
---|
324 | computer that wasn't initiated from your box, but as long as you are simply
|
---|
325 | surfing the Internet you are unlikely to exceed its limits.</para>
|
---|
326 |
|
---|
327 | <para>If you frequently encounter certain delays at accessing ftp-servers,
|
---|
328 | please have a look at <xref linkend="postlfs-security-fw-busybox"/> -
|
---|
329 | <xref linkend="postlfs-security-fw-BB-4"/>.</para>
|
---|
330 |
|
---|
331 | <para>Even if you have daemons or services running on your box, these
|
---|
332 | should be inaccessible everywhere but from your box itself.
|
---|
333 | If you want to allow access to services on your machine, such as ssh or pinging,
|
---|
334 | take a look at <xref linkend="postlfs-security-fw-busybox"/>.</para>
|
---|
335 |
|
---|
336 | </sect3>
|
---|
337 |
|
---|
338 |
|
---|
339 | <sect3 id="postlfs-security-fw-masqRouter" xreflabel="Masquerading Router">
|
---|
340 | <title>Masquerading Router</title>
|
---|
341 |
|
---|
342 | <para>A true Firewall has two interfaces, one connected to an intranet,
|
---|
343 | in this example, <emphasis role="strong">eth0</emphasis>, and one
|
---|
344 | connected to the Internet, here, <emphasis role="strong">ppp0</emphasis>.
|
---|
345 | To provide the maximum security against the box itself being broken into,
|
---|
346 | make sure that there are no servers running on it, especially not
|
---|
347 | <application>X11</application> et
|
---|
348 | al. And, as a general principle, the box itself should not access any untrusted
|
---|
349 | service (Think of a name server giving answers that make your
|
---|
350 | bind crash, or, even worse, that implement a worm via a
|
---|
351 | buffer-overflow).</para>
|
---|
352 |
|
---|
353 | <screen><userinput><command>cat > /etc/rc.d/init.d/firewall << "EOF"</command>
|
---|
354 | #!/bin/sh
|
---|
355 |
|
---|
356 | # Begin $rc_base/init.d/firewall
|
---|
357 |
|
---|
358 | echo
|
---|
359 | echo "You're using the example-config for a setup of a firewall"
|
---|
360 | echo "from the firewalling-hint written for LinuxFromScratch."
|
---|
361 | echo "This example is far from being complete, it is only meant"
|
---|
362 | echo "to be a reference."
|
---|
363 | echo "Firewall security is a complex issue, that exceeds the scope"
|
---|
364 | echo "of the quoted configuration rules."
|
---|
365 | echo "You can find some quite comprehensive information"
|
---|
366 | echo "about firewalls in Chapter 4 of the BLFS book."
|
---|
367 | echo "http://www.linuxfromscratch.org/blfs"
|
---|
368 | echo
|
---|
369 |
|
---|
370 | # Insert iptables modules (not needed if built into the kernel).
|
---|
371 |
|
---|
372 | modprobe ip_tables
|
---|
373 | modprobe iptable_filter
|
---|
374 | modprobe ip_conntrack
|
---|
375 | modprobe ip_conntrack_ftp
|
---|
376 | modprobe ipt_state
|
---|
377 | modprobe iptable_nat
|
---|
378 | modprobe ip_nat_ftp
|
---|
379 | modprobe ipt_MASQUERADE
|
---|
380 | modprobe ipt_LOG
|
---|
381 | modprobe ipt_REJECT
|
---|
382 |
|
---|
383 | # allow local-only connections
|
---|
384 | iptables -A INPUT -i lo -j ACCEPT
|
---|
385 | iptables -A OUTPUT -o lo -j ACCEPT
|
---|
386 |
|
---|
387 | # allow forwarding
|
---|
388 | iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
|
---|
389 | iptables -A FORWARD -m state --state NEW -i ! ppp+ -j ACCEPT
|
---|
390 |
|
---|
391 | # do masquerading (not needed if intranet is not using private ip-addresses)
|
---|
392 | iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE
|
---|
393 |
|
---|
394 | # Log everything for debugging (last of all rules, but before DROP/REJECT)
|
---|
395 | iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
|
---|
396 | iptables -A FORWARD -j LOG --log-prefix "FIREWALL:FORWARD"
|
---|
397 | iptables -A OUTPUT -j LOG --log-prefix "FIREWALL:OUTPUT "
|
---|
398 |
|
---|
399 | # set a sane policy
|
---|
400 | iptables -P INPUT DROP
|
---|
401 | iptables -P FORWARD DROP
|
---|
402 | iptables -P OUTPUT DROP
|
---|
403 |
|
---|
404 | # be verbose on dynamic ip-addresses (not needed in case of static IP)
|
---|
405 | echo 2 > /proc/sys/net/ipv4/ip_dynaddr
|
---|
406 |
|
---|
407 | # disable ExplicitCongestionNotification
|
---|
408 | echo 0 > /proc/sys/net/ipv4/tcp_ecn
|
---|
409 |
|
---|
410 | # activate TCPsyncookies
|
---|
411 | echo 1 > /proc/sys/net/ipv4/tcp_syncookies
|
---|
412 |
|
---|
413 | # activate Route-Verification = IP-Spoofing_protection
|
---|
414 | for f in /proc/sys/net/ipv4/conf/*/rp_filter; do
|
---|
415 | echo 1 > $f
|
---|
416 | done
|
---|
417 |
|
---|
418 | # activate IP-Forwarding
|
---|
419 | echo 1 > /proc/sys/net/ipv4/ip_forward
|
---|
420 | <command>EOF</command></userinput></screen>
|
---|
421 |
|
---|
422 | <para>With this script your intranet should be sufficiently secure against
|
---|
423 | external attacks. No one should be able to setup a new connection to any
|
---|
424 | internal service and, if it's masqueraded, it's even invisible. Furthermore,
|
---|
425 | your firewall should be nearly immune because there are no services running
|
---|
426 | that a cracker could attack.</para>
|
---|
427 |
|
---|
428 | <para>Note: if the interface you're connecting to the Internet
|
---|
429 | doesn't connect via ppp, you will need to change
|
---|
430 | <replaceable>ppp+</replaceable> to the name of the interface which you are
|
---|
431 | using. If you are using the same interface type to connect to both your
|
---|
432 | intranet and the Internet, you need to use the actual name of the
|
---|
433 | interface such as <emphasis role="strong">eth0</emphasis>,
|
---|
434 | on both interfaces.</para>
|
---|
435 |
|
---|
436 | <para>If you need stronger security (e.g., against DOS, connection
|
---|
437 | highjacking, spoofing, etc.), have a look at the list of
|
---|
438 | <xref linkend="postlfs-security-fw-library"/> at the end of this section.</para>
|
---|
439 |
|
---|
440 | </sect3>
|
---|
441 |
|
---|
442 | <sect3 id="postlfs-security-fw-busybox" xreflabel="BusyBox">
|
---|
443 | <title>BusyBox</title>
|
---|
444 |
|
---|
445 | <para>This scenario isn't too different from (<xref linkend="postlfs-security-fw-masqRouter"/>),
|
---|
446 | but in this case you want to offer some services to your intranet.
|
---|
447 | Examples of this can be when you want to admin your box from another host
|
---|
448 | on your intranet or use it as a proxy or a name server. Note: Outlining a true
|
---|
449 | concept of how to protect a server that offers services on the Internet
|
---|
450 | goes far beyond the scope of this document,
|
---|
451 | see <xref linkend="postlfs-security-fw-disclaimer"/>.</para>
|
---|
452 |
|
---|
453 | <para>Be cautious. Every service you offer and have enabled makes your
|
---|
454 | setup more complex and your box less secure. You induce the risks of
|
---|
455 | misconfigured services or running a service with an exploitable bug. A firewall
|
---|
456 | should generally not run any extra services. See the introduction to
|
---|
457 | <xref linkend="postlfs-security-fw-masqRouter"/> for some more details.</para>
|
---|
458 |
|
---|
459 | <para>If the services you'd like to offer do not need to access the Internet
|
---|
460 | themselves, like internal-only samba- or name-servers, it's quite
|
---|
461 | simple and should still be acceptable from a security standpoint.
|
---|
462 | Just add the following lines <emphasis>before</emphasis> the logging-rules
|
---|
463 | into the script.</para>
|
---|
464 |
|
---|
465 | <screen>iptables -A INPUT -i ! ppp+ -j ACCEPT
|
---|
466 | iptables -A OUTPUT -o ! ppp+ -j ACCEPT</screen>
|
---|
467 |
|
---|
468 | <para>If your daemons have to access the web themselves, like squid would need
|
---|
469 | to, you could open OUTPUT generally and restrict INPUT.</para>
|
---|
470 |
|
---|
471 | <screen>iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
---|
472 | iptables -A OUTPUT -j ACCEPT</screen>
|
---|
473 |
|
---|
474 | <para>However, it is generally not advisable to leave OUTPUT unrestricted. You lose
|
---|
475 | any control over trojans who'd like to "call home", and a bit of redundancy in case
|
---|
476 | you've (mis-)configured a service so that it does broadcast its existence to the
|
---|
477 | world.</para>
|
---|
478 |
|
---|
479 | <para>If you prefer to have this protection, you may restrict INPUT and OUTPUT
|
---|
480 | on all ports except those that it's absolutely necessary to have open.
|
---|
481 | Which ports you have to open depends on your needs: mostly you will find them
|
---|
482 | by looking for failed accesses in your log-files.</para>
|
---|
483 | <itemizedlist spacing="compact">
|
---|
484 | <!-- <orderedlist numeration="arabic" spacing="compact"> -->
|
---|
485 | <title>Have a look at the following examples:</title>
|
---|
486 |
|
---|
487 | <listitem><para>Squid is caching the web:</para>
|
---|
488 | <screen>iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
|
---|
489 | iptables -A INPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT</screen></listitem>
|
---|
490 |
|
---|
491 | <listitem><para>Your caching name server (e.g., dnscache) does its
|
---|
492 | lookups via udp:</para>
|
---|
493 | <screen>iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
|
---|
494 | iptables -A INPUT -p udp --sport 53 -m state --state ESTABLISHED -j ACCEPT</screen></listitem>
|
---|
495 |
|
---|
496 | <listitem><para>Alternatively, if you want to be able to ping your box to ensure
|
---|
497 | it's still alive:</para>
|
---|
498 | <screen>iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -j ACCEPT
|
---|
499 | iptables -A OUTPUT -p icmp -m icmp --icmp-type echo-reply -j ACCEPT</screen></listitem>
|
---|
500 |
|
---|
501 | <listitem><para><anchor id='postlfs-security-fw-BB-4' xreflabel="example no. 4"/>If you are
|
---|
502 | frequently accessing ftp-servers or enjoy chatting, you might notice certain
|
---|
503 | delays because some implementations of these daemons have the feature of
|
---|
504 | querying an identd on your box for logging usernames.
|
---|
505 | Although there's really no harm in this, having an identd running is not
|
---|
506 | recommended because some implementations are known to be vulnerable.</para>
|
---|
507 |
|
---|
508 | <para>To avoid these delays you could reject the requests
|
---|
509 | with a 'tcp-reset':</para>
|
---|
510 |
|
---|
511 | <screen>iptables -A INPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset
|
---|
512 | iptables -A OUTPUT -p tcp --sport 113 -m state --state RELATED -j ACCEPT</screen></listitem>
|
---|
513 |
|
---|
514 | <listitem><para>To log and drop invalid packets (harmless packets
|
---|
515 | that came in after netfilter's timeout or some types of network scans):</para>
|
---|
516 |
|
---|
517 | <screen>iptables -I INPUT 1 -p tcp -m state --state INVALID -j LOG --log-prefix \
|
---|
518 | "FIREWALL:INVALID"
|
---|
519 | iptables -I INPUT 2 -p tcp -m state --state INVALID -j DROP</screen></listitem>
|
---|
520 |
|
---|
521 | <listitem><para>Anything coming from the outside should not have a
|
---|
522 | private address, this is a common attack called IP-spoofing:</para>
|
---|
523 |
|
---|
524 | <screen>iptables -t nat -A PREROUTING -i ppp+ -s 10.0.0.0/8 -j DROP
|
---|
525 | iptables -t nat -A PREROUTING -i ppp+ -s 172.16.0.0/12 -j DROP
|
---|
526 | iptables -t nat -A PREROUTING -i ppp+ -s 192.168.0.0/16 -j DROP</screen></listitem>
|
---|
527 |
|
---|
528 | <listitem><para>To simplify debugging and be fair to anyone who'd like to
|
---|
529 | access a service you have disabled, purposely or by mistake, you should REJECT
|
---|
530 | those packets that are dropped.</para>
|
---|
531 |
|
---|
532 | <para>Obviously this must be done directly after logging as the very
|
---|
533 | last lines before the packets are dropped by policy:</para>
|
---|
534 |
|
---|
535 | <screen>iptables -A INPUT -j REJECT
|
---|
536 | iptables -A OUTPUT -p icmp --icmp-type 3 -j ACCEPT</screen></listitem>
|
---|
537 | </itemizedlist>
|
---|
538 | <!--</orderedlist>-->
|
---|
539 |
|
---|
540 | <para>These are only examples to show you some of the capabilities of the new
|
---|
541 | firewall code in Linux-Kernel 2.4. Have a look at the man page of
|
---|
542 | iptables.
|
---|
543 | There you will find more of them. The port-numbers you'll need for this
|
---|
544 | can be found in <filename>/etc/services</filename>, in case you didn't
|
---|
545 | find them by trial and error in your log file.</para>
|
---|
546 |
|
---|
547 | <para>If you add any of your offered or accessed services such as the above,
|
---|
548 | maybe even in FORWARD and for intranet-communication, and delete the
|
---|
549 | general clauses, you get an old fashioned packet filter.</para>
|
---|
550 |
|
---|
551 |
|
---|
552 | </sect3>
|
---|
553 |
|
---|
554 | </sect2>
|
---|
555 |
|
---|
556 |
|
---|
557 | <sect2 id="postlfs-security-fw-finale" xreflabel="Conclusion">
|
---|
558 | <title>Conclusion</title>
|
---|
559 |
|
---|
560 | <para>Finally, I'd like to remind you of one fact we must not forget:
|
---|
561 | The effort spent attacking a system corresponds to the value the cracker
|
---|
562 | expects to gain from it.
|
---|
563 | If you are responsible for such valuable assets that you expect great
|
---|
564 | effort to be made by potential crackers, you hopefully won't be in the
|
---|
565 | need of this hint!</para>
|
---|
566 |
|
---|
567 | <!-- <para><literallayout>Be cautious!
|
---|
568 |
|
---|
569 | Henning Rohde
|
---|
570 | <email>Henning.Rohde@uni-bayreuth.de</email></literallayout></para>
|
---|
571 |
|
---|
572 | <para>PS: And always do remember:
|
---|
573 | SecureIT is not a matter of a status-quo but one of never stopping
|
---|
574 | to take care!</para>
|
---|
575 |
|
---|
576 | <para>PPS: If any of these scripts fail, please tell me. I will try to trace
|
---|
577 | any faults.</para> -->
|
---|
578 |
|
---|
579 | </sect2>
|
---|
580 |
|
---|
581 |
|
---|
582 | <sect2 id="postlfs-security-fw-extra" xreflabel="Extra Information">
|
---|
583 | <title>Extra Information</title>
|
---|
584 |
|
---|
585 | <sect3 id="postlfs-security-fw-library" xreflabel="Links for further reading">
|
---|
586 | <title>Where to start with further reading on firewalls.</title>
|
---|
587 |
|
---|
588 | <para><blockquote><literallayout>
|
---|
589 | <ulink url="http://www.netfilter.org/">www.netfilter.org - Homepage of the netfilter/iptables project</ulink>
|
---|
590 | <ulink url="http://www.netfilter.org/documentation/FAQ/netfilter-faq.html">Netfilter related FAQ</ulink>
|
---|
591 | <ulink url="http://www.netfilter.org/documentation/index.html#HOWTO">Netfilter related HOWTO's</ulink>
|
---|
592 | <ulink url="http://en.tldp.org/LDP/nag2/x-087-2-firewall.html">en.tldp.org/LDP/nag2/x-087-2-firewall.html</ulink>
|
---|
593 | <ulink url="http://en.tldp.org/HOWTO/Security-HOWTO.html">en.tldp.org/HOWTO/Security-HOWTO.html</ulink>
|
---|
594 | <ulink url="http://en.tldp.org/HOWTO/Firewall-HOWTO.html">en.tldp.org/HOWTO/Firewall-HOWTO.html</ulink>
|
---|
595 | <ulink url="http://www-106.ibm.com/developerworks/security/library/s-fire.html">www.ibm.com/developerworks/security/library/s-fire.html</ulink>
|
---|
596 | <ulink url="http://www-106.ibm.com/developerworks/security/library/s-fire2.html">www.ibm.com/developerworks/security/library/s-fire2.html</ulink>
|
---|
597 | <ulink url="http://www.interhack.net/pubs/fw-faq/">www.interhack.net/pubs/fw-faq/</ulink>
|
---|
598 | <ulink url="http://www.linuxsecurity.com/docs/">www.linuxsecurity.com/docs/</ulink>
|
---|
599 | <ulink url="http://www.little-idiot.de/firewall">www.little-idiot.de/firewall (German & outdated, but very comprehensive)</ulink>
|
---|
600 | <ulink url="http://www.linuxgazette.com/issue65/stumpel.html">www.linuxgazette.com/issue65/stumpel.html</ulink>
|
---|
601 | <ulink url="http://linux.oreillynet.com/pub/a/linux/2000/03/10/netadmin/ddos.html">linux.oreillynet.com/pub/a/linux/2000/03/10/netadmin/ddos.html</ulink>
|
---|
602 | <ulink url="http://staff.washington.edu/dittrich/misc/ddos">staff.washington.edu/dittrich/misc/ddos</ulink>
|
---|
603 | <ulink url="http://www.e-infomax.com/ipmasq">www.e-infomax.com/ipmasq</ulink>
|
---|
604 | <ulink url="http://www.circlemud.org/~jelson/writings/security/index.htm">www.circlemud.org/~jelson/writings/security/index.htm</ulink>
|
---|
605 | <ulink url="http://www.securityfocus.com">www.securityfocus.com</ulink>
|
---|
606 | <ulink url="http://www.cert.org/tech_tips/">www.cert.org - tech_tips</ulink>
|
---|
607 | <ulink url="http://security.ittoolbox.com/">security.ittoolbox.com</ulink>
|
---|
608 | <ulink url="http://www.linux-firewall-tools.com/linux/">www.linux-firewall-tools.com/linux/</ulink>
|
---|
609 | <ulink url="http://logi.cc/linux/athome-firewall.php3">logi.cc/linux/athome-firewall.php3</ulink>
|
---|
610 | <ulink url="http://www.insecure.org/reading.html">www.insecure.org/reading.html</ulink>
|
---|
611 | <ulink url="http://www.robertgraham.com/pubs/firewall-seen.html">www.robertgraham.com/pubs/firewall-seen.html</ulink>
|
---|
612 | </literallayout></blockquote></para>
|
---|
613 |
|
---|
614 | <!-- <para>If a link proves to be dead or if you think I missed one,
|
---|
615 | please mail!</para> -->
|
---|
616 |
|
---|
617 | </sect3>
|
---|
618 |
|
---|
619 | <sect3 id="postlfs-security-fw-status" xreflabel="/etc/rc.d/init.d/firewall.status">
|
---|
620 | <title>firewall.status</title>
|
---|
621 |
|
---|
622 | <para>If you'd like to have a look at the chains your firewall consists of and
|
---|
623 | the order in which the rules take effect:</para>
|
---|
624 |
|
---|
625 | <screen><userinput><command>cat > /etc/rc.d/init.d/firewall.status << "EOF"</command>
|
---|
626 | #!/bin/sh
|
---|
627 |
|
---|
628 | # Begin $rc_base/init.d/firewall.status
|
---|
629 |
|
---|
630 | echo "iptables.mangling:"
|
---|
631 | iptables -t mangle -v -L -n --line-numbers
|
---|
632 |
|
---|
633 | echo
|
---|
634 | echo "iptables.nat:"
|
---|
635 | iptables -t nat -v -L -n --line-numbers
|
---|
636 |
|
---|
637 | echo
|
---|
638 | echo "iptables.filter:"
|
---|
639 | iptables -v -L -n --line-numbers
|
---|
640 | <command>EOF</command></userinput></screen>
|
---|
641 | </sect3>
|
---|
642 |
|
---|
643 | <sect3 id="postlfs-security-fw-stop" xreflabel="/etc/rc.d/init.d/firewall.stop">
|
---|
644 | <title>firewall.stop</title>
|
---|
645 |
|
---|
646 | <para>If you need to turn the firewall off, this script will do it:</para>
|
---|
647 |
|
---|
648 | <screen><userinput><command>cat > /etc/rc.d/init.d/firewall.stop << "EOF"</command>
|
---|
649 | #!/bin/sh
|
---|
650 |
|
---|
651 | # Being $rc_base/init.d/firewall.stop
|
---|
652 |
|
---|
653 | # deactivate IP-Forwarding
|
---|
654 | echo 0 > /proc/sys/net/ipv4/ip_forward
|
---|
655 |
|
---|
656 | iptables -Z
|
---|
657 | iptables -F
|
---|
658 | iptables -t nat -F PREROUTING
|
---|
659 | iptables -t nat -F OUTPUT
|
---|
660 | iptables -t nat -F POSTROUTING
|
---|
661 | iptables -t mangle -F PREROUTING
|
---|
662 | iptables -t mangle -F OUTPUT
|
---|
663 | iptables -X
|
---|
664 | iptables -P INPUT ACCEPT
|
---|
665 | iptables -P FORWARD ACCEPT
|
---|
666 | iptables -P OUTPUT ACCEPT
|
---|
667 | <command>EOF</command></userinput></screen>
|
---|
668 |
|
---|
669 | </sect3>
|
---|
670 |
|
---|
671 | </sect2>
|
---|
672 | </sect1>
|
---|
673 |
|
---|