Linux Server Security (2nd Edition( [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Linux Server Security (2nd Edition( [Electronic resources] - نسخه متنی

Michael D. Bauer

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








2.5. The Firewall



Naturally, you need to do more than create and populate a DMZ to
build a strong perimeter network. What ultimately distinguishes the
DMZ from your internal network is your firewall.


Your firewall
(or firewalls) provides the first and last word as to which traffic
may enter and leave each of your networks. Although
it's a mistake to mentally elevate firewalls to a
panacea, which can lead to complacency and thus to bad security,
it's imperative that your firewalls are carefully
configured, diligently maintained, and closely watched.


As I mentioned earlier, in-depth coverage of firewall architecture
and specific configuration procedures are beyond the scope of this
chapter. What we will discuss are some essential
firewall concepts and some general principles of good firewall
construction.



2.5.1. Types of Firewall



In increasing order of strength, the three primary types of firewall
are the
simple packet filter, the
so-called "stateful"
packet filter, and the
application-layer proxy. Most
packaged firewall products use some combination of these three
technologies.


2.5.1.1 Simple packet filters



Simple packet filters evaluate packets based solely on IP headers
(Figure 2-5). Accordingly, this is a relatively
fast way to regulate traffic, but it is also easy to subvert.
Source-IP
spoofing
attacks generally aren't blocked by packet
filters,[2] and since allowed
packets are literally passed through the firewall (without being
rewritten in any way), packets with
"legitimate" IP headers but
dangerous data payloads, as in
buffer-overflow attacks, can often be
sent intact to "protected" targets.


[2] Unless the packet filter uses
"interface rules" that filter
packets based on which network interface they arrive on, rather than
solely based on IP header.




Figure 2-5. Simple packet filtering

An example of an open source packet-filtering software package is
Linux 2.2's
ipchains
kernel modules (superseded by Linux 2.4's
netfilter/iptables, which
is a stateful packet filter). In both the commercial and open source
worlds, simple packet filters are increasingly rare: nowadays all
major firewall products and packages have some degree of
state-tracking ability.


2.5.1.2 Stateful packet filtering



Stateful packet filtering comes in two flavors: generic and
application-aware, notably Check Point.
Let's discuss the generic type first.


At its simplest, the term refers to the tracking of TCP connections,
beginning with the "three-way handshake"
(SYN, SYN/ACK, ACK), which occurs at the start of each TCP
transaction and ends with the session's last packet
(a FIN or RST). Most packet-filtering firewalls now support some
degree of low-level connection tracking.


Typically, after a stateful packet-filtering firewall verifies that a
given transaction is allowable (based on source/destination IP
addresses and ports), it monitors this initial
TCP handshake.
If the handshake completes within a reasonable period of time, the
TCP headers of all subsequent packets for that transaction are
checked against the firewall's
"state table" and passed until the
TCP session is closedthat is, until one side or the other
closes it with a FIN or RST. (See Figure 2-6.)
Specifically, each packet's source IP address,
source port, destination IP address, destination port, and TCP
sequence numbers are kept track of.



Figure 2-6. Stateful packet filtering



This has several important advantages over simple (stateless) packet
filtering. The first is bidirectionality: without some sort of
connection-state tracking, a packet filter isn't
really smart enough to know whether an incoming packet is part of an
existing connection (e.g., one initiated by an internal host) or the
first packet in a new (inbound) connection. Simple packet filters can
be told to assume that any TCP packet with the
ACK flag set is part of an established session, but this leaves the
door open for various attacks, especially IP
spoofing.


Another advantage of state tracking is protection against certain
kinds of port scanning and even some attacks. For example, the
powerful port scanner nmap supports advanced
"stealth scans" (FIN,
Xmas-Tree, and NULL scans) that, rather than simply attempting to
initiate legitimate TCP handshakes with target hosts, involve sending
out-of-sequence or otherwise nonstandard packets. When you filter
packets based not only on IP-header information but also on their
relationship to other packets (i.e., whether they're
part of established connections), you increase the odds of detecting
such a scan and blocking it.

2.5.1.3 Stateful Inspection



The second type of stateful packet filtering is that used by Check
Point technologies in its Firewall-1 and VPN-1 products:
Stateful
Inspection. Check Point's Stateful
Inspection technology combines generic TCP state tracking with a
certain amount of application-level intelligence.


For example, when a Check Point firewall examines packets from an
HTTP transaction, it looks not only at IP headers and TCP
handshaking; it also examines the data payloads to verify that the
transaction's initiator is in fact attempting a
legitimate HTTP session instead of, say, some sort of Denial of
Service attack on TCP port 80.


Check Point's application-layer intelligence is
dependent on the INSPECT code (Check
Point's proprietary packet-inspection language)
built into its various service filters. TCP services, particularly
common ones like FTP, Telnet, and HTTP, have fairly sophisticated
INSPECT code behind them. UDP services such as NTP and RTTP, on the
other hand, tend to have much less. Furthermore, Check Point users
who add custom services to their firewalls usually do so without
adding any INSPECT code at all and instead define the new services
strictly by port number.


Check Point technology is sort of a hybrid between packet filtering
and application-layer proxying. Due to the marked variance in
sophistication with which it handles different services, however, its
overall strength is probably much closer to that of
"generic" stateful packet filters
than it is to the better proxying firewalls (i.e.,
application-gateway firewalls).


Although Stateful Inspection is a Check Point trademark, other
stateful firewalls such as Cisco PIX and even Linux
iptables
have similar application-layer intelligence in tracking certain types
of applications' sessions.

2.5.1.4 Application-layer proxies


The third category of common firewall technologies is
application-layer proxying. Unlike simple and stateful packet
filters, which inspect but do not alter packets (except, in some
cases, readdressing or redirecting them), a proxying firewall acts as
an intermediary in all transactions that traverse it (see Figure 2-7).



Figure 2-7. Application-layer proxy

Proxying firewalls are often called
"application-layer" proxies
because, unlike other types of proxies that enhance performance but
not necessarily security, proxying firewalls usually have a large
amount of application-specific intelligence about the services they
broker.



This section is about proxying firewalls, like Sidewinder, that are
capable of proxying many different types of trafficnot
single-application proxies such as XML proxies.


For example, a proxying firewall's FTP proxy might
be configured to allow external clients of an internal FTP server to
issue USER, PASS, DIR, PORT, and GET commands, but not PUT commands.
Its SMTP proxy might be configured to allow external hosts to issue
HELO, FROM, MAILTO, and DATA commands to your SMTP gateway, but not
VRFY or EXPN. In short, an application-layer proxy not only
distinguishes between allowed and forbidden source-IP and
destination-IP addresses and ports, it also distinguishes between
allowable and forbidden application behavior.


As if that in itself weren't good enough, by
definition, proxying firewalls also afford a great deal of protection
against stack-based attacks on protected hosts. For example, suppose
your DMZed web server is, unbeknownst to you, vulnerable to Denial of
Service attacks in which deliberately malformed TCP
"SYN" packets can cause its TCP/IP
stack to crash, hanging the system. An application-layer proxy
won't forward those malformed packets; instead, it
will initiate a new SYN packet from itself (the firewall) to the
protected host and reply to the attacker itself.


The primary disadvantages of proxying firewalls are performance and
flexibility. Since a proxying firewall actively participates in,
rather than merely monitoring, the connections it brokers, it must
expend much more of its own resources for each transaction than a
packet filter doeseven a stateful one. Furthermore, whereas a
packet filter can very easily accommodate new services, since it
deals with them only at low levels (e.g., via low-level protocols
common to many applications), an application-layer proxy firewall can
usually provide full protection only to a relatively small variety of
known services, albeit probably the most popular and important ones.


However, both limitations can be mitigated to some degree. A proxying
firewall run on clustered server-class machines can easily manage
large (T3-sized) Internet connections. Most proxy suites now include
some sort of Generic Service Proxy (GSP), a proxy that
lacks application-specific intelligence but can still provide
protection against attacks on TCP/IP anomaliesby rewriting IP
and TCP/UDP headers, while passing data payloads as is. A GSP can be
configured to listen on any port (or multiple ports) for which the
firewall has no application-specific proxy.


As a last resort, most proxying firewalls also support packet
filtering. However, this is very seldom preferable to using GSPs.


Commercial application-layer
proxy firewalls include Secure Computing
Corp.'s
Sidewinder,
Symantec Enterprise Firewall (formerly
called Raptor), and
Watchguard Technologies'
Firebox.
(Actually, Firebox is a hybrid, with application proxies only for
HTTP, SMTP, DNS, and FTP, and stateful packet filtering for
everything else.) Free/open source application-layer proxy packages include
the TIS Firewall
Toolkit (now largely obsolete) and Balazs
Scheidler's firewall
suite, Zorp.



Don't confuse application-layer proxies
("application
gateways") with
circuit-relay
proxies. The former possess application-specific intelligence, but
the latter do not. While circuit-relay proxies such as SOCKS-based
products do reproduce application data from sender to receiver, they
don't actually parse or regulate it as application
gateways do.



2.5.2. Selecting a Firewall



Choosing which type of
firewall to use, which hardware platform
to run it on, and which commercial or free firewall package to build
it with depends on your particular needs, financial and technical
resources, and to some extent, subjective considerations. For
example, a business or government entity that must protect its data
integrity to the highest possible degree (because customer data,
state secrets, etc. are at stake) is probably best served by an
application-gateway (proxy) firewall. If 24/7 support is important, a
commercial product might be a good choice.


A public school system, on the other hand, may lack the technical
resources (i.e., full-time professional network engineers) to support
a proxying firewall, and very likely lacks the financial resources to
purchase and maintain an enterprise-class commercial product. Such an
organization may find an inexpensive stateful packet-filtering
firewall "appliance" or even a
Linux or FreeBSD firewall (if they have some
engineering talent) to be more than adequate.


Application-gateway firewalls are generally the strongest, but they
are the most complex to administer and have the highest hardware
speed and capacity requirements. Stateful packet-filtering firewalls
move packets faster and are simpler to administer, but tend to
provide much better protection for some services than for others.
Simple packet filters are fastest of all and generally the cheapest
as well, but they are also the easiest to subvert. (Simple packet
filters are increasingly rare, thanks to the rapid adoption of
stateful packet filtering in even entry-level firewall products.) Free/open source firewall packages are obviously much cheaper than
commercial products, but since technical support is somewhat harder
to obtain for them, they require more in-house expertise than
commercial packages. This is mitigated somewhat by the ease with
which one can find and exchange information with other users over the
Internet: most major open source initiatives have enthusiastic and
helpful communities of users and developers.


In addition, free firewall products may or may not benefit from the
public scrutiny of their source code for security vulnerabilities.
Such scrutiny is often assumed but seldom assured (except for systems
like OpenBSD, in which security audits of source code are an explicit
and essential part of the development process).


On the other hand, most open source security project development
teams have excellent track records in responding to and fixing
reported security bugs. When open source systems or applications are
vulnerable to bugs that also affect commercial operating systems,
patches and fixes to the open source products are often released much
more quickly than for the affected commercial systems.


It's also important to note that many of
today's commercial firewall appliances, including
consumer devices such as DSL modems with firewall functionality, are
in fact based on free technologies such as Linux and FreeBSD. With
such products, the primary advantages over
"home-rolled" solutions are
optimized hardware, professional support, and proprietary
configuration/administration GUIs.


Another consideration is the firewall's feature set.
Most but not all commercial firewalls support
Virtual Private
Networking (VPN), which allows you to connect remote networks and
even remote users to your firewall through an encrypted
"tunnel." (Linux firewalls support
VPNs via the separately maintained FreeS/Wan package.) Centralized administration is less common, but desirable: pushing
firewall policies to multiple firewalls from a single management
platform makes it easier to manage complex networks with numerous
entry points or "compartmentalized"
(firewalled) internal networks. In the Linux firewall world, one of
the best tools for centralized iptables management is Firewall
Builder (http://www.fwbuilder.com).


Ultimately, the firewall you select should reflect the needs of your
perimeter network design. These needs are almost always predicated on
the assets, threats, and risks you've previously
identified, but are also subject to the political, financial, and
technical limitations of your environment.



2.5.3. General Firewall Configuration Guidelines



Precisely how you configure your
firewall will naturally depend on
what type you've chosen and on your specific
environment. However, some general principles should be observed.


2.5.3.1 Harden your firewall's OS


First, before installing firewall software, you should harden the
firewall's underlying
operating environment to at least as high a degree as you would
harden, for example, a web server. Unnecessary software should be
removed; unnecessary startup scripts should be disabled; important
daemons should be run without root privileges and chrooted if
possible; and all OS and application software should be kept patched
and current. As soon as possible after OS installation (and before
the system is connected to the Internet), an integrity checker such
as tripwire or AIDE should be installed and initialized.


In addition, you'll need to decide who receives
administrative access to the firewall, with particular attention to
who will edit or create firewall policies. No administrators should
be given a higher level of access privileges than they actually need.


For example, the Operations Technician who backs up the system
periodically should have an account and group membership that give
him read access to all filesystems that he needs to back up, but not
write access. Furthermore, his account should not belong to the
groups wheel or root (i.e.,
he shouldn't be able to su to
root).


If you're running your firewall on Linux, see Chapter 3 for detailed system-hardening instructions.


2.5.3.2 Configure anti-IP-spoofing rules



If your firewall supports
anti-IP-spoofing features,
configure and use them. Many network attacks involved
spoofed packets, i.e., packets with
forged source-IP addresses. This technique is used most commonly in
Denial of Service (DoS) attacks to
mask the attack's origin, as well as in attempts to
make packets appear to originate from trusted (internal) networks.
The ability to detect spoofed packets is so important that if your
firewall doesn't support it, I strongly recommend
you consider upgrading to a firewall that does.


For example, suppose your firewall has three Ethernet interfaces:
eth0, with the IP 208.98.98.1, faces the
outside; eth1, with the IP address
192.168.111.2, faces your DMZ network; and eth2,
with the IP address 10.23.23.2, faces your internal network. No
packets arriving at eth0 should have source IPs
beginning "192.168." or
"10.": only packets originating in
your DMZ or internal network are expected to have such source
addresses. Furthermore, eth0 faces an
Internet-routable address space, and 10.0.0.0/8 and 192.168.0.0/16
are both non-Internet-routable networks.[3] [3] The range
of addresses from 172.16.0.0 to 172.31.255.255 (or, in
"CIDR" shorthand,
"172.16.0.0/12") is also
non-Internet-routable and therefore should also be included in your
anti-spoofing rules, though for brevity's sake, I
left it out of Example 2-1. These ranges of IPs are
specified by RFC 1918.



Therefore, in this example, your firewall would contain rules along
these lines:


"Drop packets arriving at eth0
whose source IP is within 192.168.0.0/16 or
10.0.0.0/8".


"Drop packets arriving on eth1
whose source IP isn't within
192.168.111/24".


"Drop packets arriving on eth2
whose source IP isn't within
10.0.0.0/8".



(The last rule is unnecessary if you're not worried
about IP spoofing attacks originating from your
internal network.) Anti-IP-spoofing rules should be at or near the
top of the applicable firewall policy.


Example 2-1 shows the iptables commands equivalent
to the three previous rules.


Example 2-1. iptables commands to block spoofed IP addresses



iptables -I INPUT 1 -i eth0 -s 192.168.0.0/16 -j DROP
iptables -I INPUT 2 -i eth0 -s 10.0.0.0/8 -j DROP
iptables -I INPUT 3 -i eth1 -s ! 192.168.111.0/24 -j DROP
iptables -I INPUT 4 -i eth2 -s ! 10.0.0.0/8 -j DROP
iptables -I FORWARD 1 -i eth0 -s 192.168.0.0/16 -j DROP
iptables -I FORWARD 2 -i eth0 -s 10.0.0.0/8 -j DROP
iptables -I FORWARD 3 -i eth1 -s ! 192.168.111.0/24 -j DROP
iptables -I FORWARD 4 -i eth2 -s ! 10.0.0.0/8 -j DROP For complete
iptables
documentation, see http://netfilter.samba.org and the
iptables(8) manpage.


2.5.3.3 Deny by default



In the words of Marcus Ranum, "That which is
not explicitly permitted is prohibited." A firewall
should be configured to drop any connection it
doesn't know what to do with. Therefore, set all
default policies to deny requests that aren't
explicitly allowed elsewhere. Although this is the default behavior
of netfilter, Example 2-2 lists the iptables
commands to set the default policy of all three built-in chains to
DROP.


Example 2-2. (Re)setting the default policies of netfilter's built-in policies



iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP Note that most firewalls, including Linux 2.4's
iptables, can be configured to reject packets two
different ways. The first method, usually called
dropping, is to discard denied packets
"silently"i.e., with no
notificationto the packet's sender. The
second method, usually called rejecting,
involves returning a TCP RST (reset) packet if the denied request was
via the TCP protocol, or an ICMP "Port
Unreachable" message if the request was via UDP.


In most cases, you'll probably prefer to use the
Drop method, since this adds significant delay to port scans. Note,
however, that it runs contrary to relevant RFCs, which instead
specify the TCP-RST and ICMP-Port-Unreachable behavior used in the
Reject method. The Drop method is therefore used only by firewalls,
which means that while a port-scanning attacker will experience
delay, he'll know precisely why.


Most firewalls that support the Drop method can be configured to log
the dropped packet if desired.


2.5.3.4 Strictly limit incoming traffic



The most
obvious job of a firewall is to block incoming attacks from external
hosts. Therefore, allow incoming connections only to specific
(hopefully DMZed) servers. Furthermore, limit those connections to
the absolute minimum services/ports necessarye.g., to TCP 80
on your public web server, TCP 25 on your SMTP gateway, etc.


2.5.3.5 Strictly limit all traffic out of the DMZ



A central assumption with DMZs is that its hosts are at significant
risk of being compromised. So to contain this risk, you should
restrict traffic out of the DMZ to known-necessary services/ports. A
DMZed web server, for example, needs to receive HTTP sessions on TCP
80 but does not need to
initiate sessions on TCP 80, so it should not be
allowed to. If that web server is somehow infected with, say, the
Code Red virus, Code Red's attempts to identify and
infect other systems from your server will be blocked.


Give particular consideration to traffic from the DMZ to your
internal network, and design your environments to minimize the need
for such traffic. For example, if a DMZed host needs to make DNS
queries, configure it to use the DNS server in the DMZ (if you have
one) rather than your internal DNS server. A compromised DMZ server
with poorly controlled access to the Internet is a legal liability
due to the threat it poses to other networks; one with poorly
controlled access into your internal network is an egregious threat
to your own network's security.


2.5.3.6 Don't give internal systems unrestricted outbound access



It's common practice to configure firewalls with the
philosophy that "inbound transactions are mostly
forbidden, but all outbound transactions are
permitted."[4] This is usually the result not only of politics
("surely we trust our own users!"),
but also of expedience, since a large set of outbound services may
legitimately be required, resulting in a long list of firewall rules.


[4] Firewall rules
concerning outbound transactions are commonly called
"egress rules." Inbound rules are
called "ingress rules."

However, many "necessary" outbound
services are, on closer examination, merely
"desirable" services (e.g.,
stock-ticker applets, Internet radio, etc.). Furthermore, once the
large list of allowed services is in place, it's in
place: requests for additional services can be reviewed as needed.


There are several reasons to restrict
outbound access from the internal network. First, it helps conserve
bandwidth on your Internet connection. Certainly,
it's often possible for users to pull audio streams
in over TCP 80 to get around firewall restrictions, but the
ramifications of doing so will be different from when outbound access
is uncontrolled.


Second, as with the DMZ, restricting outbound access from the inside
helps mitigate the risk of compromised internal systems being used to
attack hosts on other networks, especially where viruses and other
hostile code is the culprit.


Third, the fact is that in most organizations, not all internal users
and systems are equally trustworthy. For example,
it's no better to allow mischievous or malicious
insiders to be able to attack the SSH process on your DMZed web
server than it is to allow mischievous or malicious outsiders to do
so; the firewall should restrict such connections both from the
Internet and from the internal network.


2.5.3.7 If you have the means, use an application-gateway firewall


By now, there should be no mistaking my stance on proxying firewalls:
if you have the technical wherewithal and can devote sufficient
hardware resources, application-gateway firewalls provide superior
protection over even stateful packet-filtering firewalls. If you
must, use application proxies for some services and packet filtering
only part of the time. (Proxying firewalls nearly always let you use
some amount of filtering, if you so choose.) For example, SUSE's FTP proxy (misleadingly called
"proxy-suite") and the Squid
HTTP/HTTPS proxy are two single-application proxies that work well
with netfilter. Zorp provides an entire suite of
proxies that run on top of netfilter.


2.5.3.8 Don't be complacent about host security



My final piece of firewall advice is that you must avoid the trap of
ever considering your firewall to be a provider
of absolute security. The only absolute protection from network
attacks is a cut network cable. Do configure
your firewall as carefully and granularly as you possibly can;
don't skip hardening your DMZ
servers, for example, on the assumption that the firewall provides
all the protection they need.


In particular, you should harden publicly accessible servers, such as
those you might place in a DMZ, as though you have no
firewall at all. Remember, our operating assumption in the
DMZ is that any host in it may be compromised at any point and used
to attack other DMZed hosts. Therefore,
"defense in depth" is
extremely important: the more layers of protection you can construct
around your important data and systems, the more time-consuming a
target they'll represent to prospective attackers.



Not to belabor the point, but inadequate application security can
make all your firewalling efforts amount to
nothing. HTTP
"fuzzing" attacks against web
applications, for example, generally are not blocked by even the best
application-layer proxy firewalls; many attacks can only be defended
against by using, and properly configuring, good software on your
bastion servers. That's what the rest of this book
is about.



/ 94