1 page 1 of 16 IP Firewalls an overview of the principles 0. Foreword WHY: These notes were born out of some discussions and lectures with technical security personnel. The main topics which we discussed were not subtle aspects of configuring some particular firewall of some vendor, but the general aspects and the overall strategy to adopt when creating a firewall configuration. Thus it was more on understanding the principles behind the technology than the technology itself. Needless to say, not always the firewalls do what they should if they would follow these principles, but having clear the principles makes it much easier to understand the exceptions (or the violations). WHAT: My aim in these notes is to give an overall description of what happens when one introduces a firewall in between a data flow, and to deduce from this some hopefully useful guidelines on how to plan and prepare the configuration of a firewall. HOW: I will describe a simple firewall which filters some IP traffic using the most relevant features (in my personal opinion) of TCP/IP. The important point for me is not to enter in the complicated details of the protocols, but to give the overall picture of what one should expect to happen. At the end I will give a very preliminary example on how to proceed to create a configuration using a Linux box with iptables. NOTICE: the terms TCP connection, datagram, segment and packet are used in a somewhat loose way to make the discussion more informal and easier to follow. Most of what I have written comes directly from my notes of the lectures that I gave, where it was more important to deliver the message than to be technically perfectly precise. In a future version I hope to be able to add a few diagrams to make the reading even more intuitive. Copyright 2003 Andrea Pasquinucci. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found at address or These notes are distributed in the hope that they can be useful, but WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2 page 2 of 16 Table of Contents 0. Foreword TCP/IP Background Types of Firewalls Packet Filtering Firewalls Stateful Inspection Firewalls UDP ICMP TCP Weaknesses Application Layer Gateways Proxy Firewalls Examples The Strategy A simple example with Linux iptables Firewalls and other Security Devices...13
3 page 3 of TCP/IP Background Sadly to say (write), this is basic stuff that one can find in many books, but sooner or later I'll add here a very short summary: encapsulation, OSI pile, TCP/IP stack, headers, TCP connections. In these notes I will introduce a term which generally is not used and someone will say at least quite improper if not completely wrong. I will talk about IP connections. Obviously IP is a connectionless protocol which doesn't have any means to insure the establishing and control of a connection, it does not even guarantee that a single packet/datagram is delivered to the intended recipient! So what do I mean by IP connection? The concept is very simple: when a sender sends a packet/datagram to a destination, most of the time the receiver will send something back, it can be an answer, an error message or just an acknowledgement. Thus by IP connection what I mean is the fact that very often sending a packet generates a reply. Someone (the firewall) in between the two ends of the connection, having seen the first packet passing by, will expect a reply to come back, and will be able to associate the reply, if it comes, to the first packet. Since this is not a precise protocol, the way of associating a reply with a first packet is mainly based on time, that is if within some time from the passing of the first packet there is a reply, this reply is associated with the original packet. If instead a timeout passes, then the connection is closed and if a packet goes back this is not considered to be a reply to the first. Only for TCP (and other connection-oriented protocols) it is possible to be more precise about which packets belong to a connection and which do not, but for all other connectionless protocols the definition of IP connection is based only on the time of the optional reply. 2. Types of Firewalls In these notes a firewall is a network device which should be able to filter the data stream and allow to pass through it only traffic which is deemed to be not harmful. There can be other kinds of firewalls, for example you can have a firewall on an host to directly protect the host from external traffic, and you should do this too on all your hosts which can receive outside traffic (directly or indirectly). Anyway, all firewalls work with the same idea, there is a data stream and the firewall is put in the middle of it to check what passes and to allow only the good data through. In this notes I will concentrate only on what happens in the firewall, and the setup is the following. There is an host A which communicates (sends some packets) to the host B, which in case can reply to A. In between them there is the firewall F which filters all the traffic between A and B. Depending on the principle on which it works, I can roughly organize the existing IP firewalls in 4 groups: 1. Packet Filtering: each and all packets passing through the firewall are tested against a
4 page 4 of 16 single list of rules, and depending on the rule which a packet matches, a different action, usually accept, drop or reject, is taken; 2. Stateful Inspection: the first packet of an IP connection is treated as for the previous firewall, but once an IP connection is established, all subsequent packets belonging to that connection are automatically accepted, or examined in a different, and faster, way; 3. Application Layer Gateway: these firewalls are also capable of understanding the payload of each packet at the application level, and thus to see if the payload contains harmful data; 4. Proxy: these firewalls for each application layer protocol of interest, behave like a server to the original client, and a client to the final server, in this way there are no direct connections between the original client and final server, but both are connected directly only to the Proxy in between. Of course, today many commercial firewalls have features from all four groups. In the next section I will describe these 4 groups, focusing mainly on the Stateful Inspection Firewalls. 2.1 Packet Filtering Firewalls I will consider only IP firewall, that is firewalls which filter IP traffic. I will consider mostly the Network (i.e. IP) and Transport (i.e. TCP, UDP) layers. The following are the data which I will consider out of all fields of the two headers: 1. Transport Protocol 2. Source IP address 3. Destination IP address 4. Source Port number (or equivalent data) 5. Destination Port number (or equivalent data) 6. Transport Flags (if any) 7. Timestamp The first 3 are part of the IP headers, 4 to 6 of the Transport protocol headers whereas the Timestamp is added by the firewall and marks the moment at which the packet is received by it. The points 1 to 5 of the previous list uniquely characterize a TCP/IP (public) connection, no two connections with the same first 5 numbers can exist. A Packet Filtering Firewall works as follows: there is a list of rules which select a packet based on the numbers 1 to 5 of the previous list. So each rule says that if a packet carries data for a particular Transport Protocol, from a certain Source to a Destination IP address and ports, then apply to this packet this action. The first rule which matches a packet is applied, and the packet breaks out of the matching of the rules. Usually the possible actions are to Accept a packet, by which a packet is allowed to pass through the firewall, to Deny or Drop the packet, by which the packet is silently discarded, or to Reject a packet, by which the packet is discarded but an error message is sent back to the sender. In most firewalls of this kind, it is the user who chooses the order of the rules, some firewalls instead create themselves the order based on various criteria.
5 page 5 of 16 It is important to notice that all packets go through the same list of rules (the only exception can be for firewalls that allow to specify different set of rules for different interfaces, for which the statement is true interface by interface). In particular, if A sends a packet to B and B replies with a packet, there must be a rule for accepting the packet which goes from A to B and another rule to accept the packet from B to A since the two packets have exchanged the Source and Destination addresses. Very often this situation leads system administrators to allow all packets originating from B to go to A, which can lead to security problems. Finally it should be noted that the Source Port number for A is very often a not registered and currently not used port with number between 1024 and 65535, in practice more or less a random number in this range. This guarantees that not two connections have the same numbers, but at the same time it makes it often impossible to filter on the Source Port of the original sender. Thus when A sends a packet, it is often not possible to filter on the Source Port number, and when B sends back a reply, it is often not possible to filter on the Destination Port number. 2.2 Stateful Inspection Firewalls A Stateful Inspection firewall builds on top of a Packet Filtering firewall, by recognizing that once a packet has been accepted, most times one has to expect a packet as a reply. Thus if A sends a packet to B, then the firewall has to expect that B will reply to A, and if the firewall has allowed the first packet, it should allow also the reply. In this case we treat in a very different way the first packet of an IP connection, from all the other packets belonging to that connection: 1. The first packet of an IP connection goes through a list of Filtering Rules which can be made specific only for first-packets, notice that these rules will apply in our example only to packets from A to B, and that there will be no rules of this kind for the packets from B to A; 2. Once a first-packet is Accepted, the firewall writes in the Connections Table all the 7 numbers (see previous section) which characterize the IP connection; 3. When a packet arrives at the firewall, the first thing it does is to check if the packet belongs to a known IP connection as recorded in the Connections Table: if it does it can apply some special rules or just Accept the packet; notice that both the packets from A to B and the replies of B to A belong to the same connection, so that a packet is tested in the Connections Table with respected to the Source and Destination addresses direct and inverted. If there is no match, then this is a first-packet and rule 1 above applies. To enter in more details in what the firewall does (or should do), I will consider the three most common Protocols: UDP, ICMP and TCP.
6 page 6 of UDP Assume that A sends a UDP packet to B. F is in the middle and receives this packet, it is a first-packet and, by looking at the rules, F can do 3 things with it: 1. Drop the packet; 2. Reject the packet: in this case the packet is discarded and an ICMP error message, usually of the type Port Unreachable, is sent back to the sender (in the next section I will say more on ICMP packets); 3. Accept the packet and forward it to B: in this case the 7 numbers which characterize the IP connection started by this packet are written in the Connections Table. Only in case 3. B will receive a packet. From the point of view of F, now B can do the following things: 1. B can send back an UDP reply to A: in this case F receives this packets, checks if it belongs to a known connection and since it does, it forwards the packet to A; 2. B can send back an ICMP error message to A: in this case F receives this packet, checks if it belongs to a known connection and since it does in the sense that it is a packet Related to a known connection, it forwards the packet to A and deletes the entry from the table; 3. B can send back nothing: in this case F waits some time and then deletes the connection from the Connections Table (it is here that the Timestamp in the Connections Table plays its role). When should F delete the entry in the Connections Table for point 1? Since UDP is not a connection oriented protocol, a firewall which does not understand the payload of UDP packets cannot know if more UDP packets belonging to this connection are going to be exchanged or not. Thus most firewalls update the timestamp every time a packet of a UDP connection passes, and then just wait for the timeout to expire, in case that another packet of this connection is sent to or from A, from or to B. Finally, how can F know that in case 2. an ICMP error message belongs to a particular UDP connection? It is very simple, since in the data portion of the ICMP error message there are the headers (or part of the headers) of the original packet which generated the error. By looking at the data portion of the ICMP message, the firewall can deduce to which connection the ICMP packet belongs to ICMP
7 page 7 of 16 There are two kinds of ICMP packets. The first are used to test the network and the most famous are the echo-request/echo-reply couple. In practice from the point of view of the firewall they behave as UDP packets, just that for one request packet from A to B there is at most one reply packet from B to A. B can reply to A only with one echo-reply ICMP packet, or with nothing. To avoid loops, it is indeed forbidden to send ICMP error messages if the packet which generates the error is an ICMP packet. Thus for ICMP echo-request/reply packets a Stateful Inspection firewall can allow the echo-request, put its data in the Connections Table, and allow the echo-reply packet back or close the connection after the timeout. After the echo-reply has passed, the connection can be removed from the Connections Table since for each echo-request B can send only one echo-reply. The other kind of ICMP packets are error messages. These packets are generated by the TCP/IP stack (or the firewall code itself) in response to a packet which tries to do something not allowed. For example if a packet tries to connect to a service, that is a port, to which no daemon (program) is listening, the TCP/IP stack can reply to the sender with a ICMP portunreachable message. This is to prevent the sender to keep trying if in case the first packet has gone lost, or something temporary has happened. As already said, in the data portion of the ICMP error message there are the headers (or part of the headers) of the original packet which generated the error. By looking at the data portion of the ICMP message, the original sender A can deduce which program has generated the original packet and report to it the error, and the firewall can deduce to which connection the ICMP packet belongs to TCP TCP is a connection oriented protocol, that is... is very complicated. Thus I are going to consider only the basic features which are of interest from the point of view of the firewall F. TCP connections are divided in 3 phases: the establishment of the connection in both directions, the exchange of the data, and the closing of the connection on both sides. To keep track of the status of the TCP connection, TCP uses some flag bits. The flag bits which will be important for us are: 1. SYN: this bit is used to start the connection, notice that a TCP connection must be established on both sides, so that first A sends a packet with the SYN bit up, and to this B replies with a packet also with the SYN bit up to request the connection in the opposite direction (SYN means synchronize); 2. ACK: this bit acknowledges the receipt of one or more packets, which ones are acknowledged has to do with the window scaling of TCP in which I do not want to go here, the important point is to know what this bit means; 3. FIN: if this bit is up, the side which has sent this packet is requesting to close the connection in this direction, that is the one which has sent this packet does not have anything else to send; 4. RST: this bit requests the reset or truncation of the connection, in other words the connection must stop immediately in both directions.
8 page 8 of 16 Lets follow what happens in a simple 1 TCP connection between A, which requests first the connection, and B. 1. A sends a packet with only the SYN flag up among the 4 flags just mentioned; 2. F can do 3 things as usual: 1. Drop the packet; 2. Reject the packet with a TCP reset packet, in this case the firewall sends back a packet with the RST flag up as if it was B telling A that the service requested is not running on B; 3. Accept the packet, forward it to B and add an entry in the Connections Table; notice that at this moment for F the IP connection is established, whereas for A and B the TCP connection is not yet established since the 3- way handshake is not finished; in the first two cases no packet arrives to B and thus nothing else passes, otherwise the communication can continue; 3. B receives the SYN packet and it too can do 3 things: 1. Drop the packet; 2. Reject the packet with a TCP reset (i.e. with the RST flag up) packet, in this case B tells A that the service requested is not running on B; 3. Reply to A sending a packet with the SYN and ACK flags up: the ACK flag is up to acknowledge the receipt of the first SYN packet and the SYN flag is up to request the opening of the connection in the opposite direction (no other flags are up); in the last two cases a packet is sent back and F will receive something; 4. if F receives a packet with the RST flag up for a TCP connection which exists in the Connections Table, it must forward it to the other host and cancel the connection from the Connections Table; otherwise F now receives from B a packet with the SYN and ACK flags up corresponding to a IP connection which exists in the Connections Table, and it allows it to pass; 5. A receives the SYN-ACK packet from B and sends back a packet with only an ACK to acknowledge the receipt and opening of the connection in the other direction. From now on, A and B exchange packets only with the ACK flag up among the 4 flags mentioned before, and the firewall let the packets pass. To gracefully end the connection, let say that B, which has finished first, sends a packet with the ACK-FIN flags up, to which A, replies with a packet with the ACK flag up. Then when A has finished too, it too sends a packet with ACK-FIN flags up. Finally B sends the last packet with the ACK flag up. When the firewall F sees the two packets in opposite directions with the FIN flag up, and the last packet with only the ACK flag, it can delete the connection from the Connections Table. A fundamental observation is that all packets of a TCP connection, except the first one, have the ACK flag up. Moreover, various combination of flags are not allowed, some never, other in some moment of the connection. I can list the following important combinations of flags: 1 There are more complicated scenarios.
9 page 9 of The SYN flag is up only in the first two packets, one in each direction, of a TCP connection; 2. The first packet of a TCP connection must have the SYN flag up and the ACK and RST flags down; it can have the FIN flag up, but this is used very rarely and for most application the FIN flag is down in the first packet of a TCP connection; 3. the ACK flag must be up in each packet after the first. Since a Stateful Inspection firewall treats differently the first packet of a IP connection from all the other, I can summarize the rules for the firewall as follows: 1. F should allow TCP packets with specified source and destination addresses and ports with only the SYN flag up out of the SYN,ACK,RST (and almost always also FIN) flags, as first packet establishing an IP connection (of course only if we want to allow this TCP connection through the firewall); 2. F should then allow all packets of the established IP connection in both direction; a good firewall should check if the TCP flags which are up are allowed; moreover when it sees that the RST or FIN flags are up, it should close the connection, that is delete it from the Connections Table; Moreover F should manage the timestamp and the timeouts in a manner consistent with the timeouts of the TCP protocol (which is not a completely trivial task). Thus it is quite easy to identify the first packet of a TCP connection, and to allow it to pass through the firewall. After that, it should be the firewall which follows the connection and allows or denies the packets. Following what TCP does is not an easy task: packets can arrive out of order, or be retransmitted, various flags in various combination can mean different things depending when they are set during a connection, and so on. Sometimes it is not only a technical difficulty of implementing an algorithm which follows the TCP connection, but also that security decisions must be taken. For example, one could decide to have a firewall to drop packets which arrive out of order because this could be a sign of someone who is trying to inject packets in a connection. What would happen is that slowly, very slowly, packets will be retransmitted, hopefully in the correct order (but SACK, FACK, DSACK etc. would actually make this more difficult to happen). In practice by dropping packets which arrive out of order we could end up to reduce tremendously the speed of the connection or to block it completely. On the other side, illegal or not correct TCP flags combinations are often used by attackers to scan (map) the internal network and hosts, and thus are the preliminary step of a true attack. A firewall should then drop these packets Weaknesses A Stateful Inspection firewall has, among others, two basic weaknesses which are worth mentioning here:
10 page 10 of the firewall makes most of its decisions based on the Source IP address and Source port, thus it must trust that these data are correct; it is practically impossible to understand if the source addresses and port written in the headers of a packet are fake, that is the host which sent the packet is not the one which has that IP address. There are cases when this is fine, for example when a host is NATted by a firewall or a router: in this case the source address and port which the firewall F receives are not the ones of the original host, but the one of the device which does the NAT/PAT translation. The security problems arise when a malicious host sends a packet writing in the headers of the packet the address of another legitimate host (this is called Spoofing). Thus the firewall thinks that the packet comes from the legitimate host, whereas instead it comes from another. Of course the malicious host will not receive the reply packets back, which are sent to the legitimate host, but this could be enough to pass through the firewall and do damage. 2 Routing can help a little to minimize this problem, since it tells us which classes of IP addresses are behind each interface, so that if a packet arrives on an interface with a source IP address which belongs to a class which is behind another interface, something is wrong and most probably (if our routing is set up correctly!!!) this source IP address is spoofed. For TCP connections the strict checking of the TCP flags of each packet can also help to prevent the injection in an active connection of forged packets by a malicious host. 2. The firewall does not look in the data portion of the packets, but only in the headers, thus it cannot know if the data contains some malicious code. The simplest example is the viruses: if a Stateful Inspection firewall allows the transit of s, it can not know if in an there is or not a virus. Another problem is with application protocols like ftp in which after the first connection is made on predefined ports, new connections are opened always between the same hosts on ports which are agreed upon in the first connection. Thus if the firewall does not look in the contents of the data, it cannot know that the two hosts want to start a new connection, related to the original ftp connection, using different ports, and this new connection should be allowed too if the first has been allowed. The first problem is very difficult to solve with today technologies. In practice one would like to identify with certainty the source of each packet which arrives at the firewall. This can be, and in same cases is, done for the internal network by using authentication schemes for users or machines, it is in general practically impossible for the Internet. One case in which this identification is done with some or partial success, is in E-commerce where Secure Web Servers are identified with their SSL Certificates which are issued by a Certificate Authority. Other encrypted communications, as in the case of IPSEC VPN, permit (depending on the configuration) to exactly identify the remote host. 2.3 Application Layer Gateways We can keep building on top of the previous kind of firewall, by adding to the Stateful Inspection features also the ability to look into the data portion of the packets. It must be noted that at this point the firewall gets a completely different structure. Up to now, all rules are valid for all IP packets, with some minor modifications due to the difference bewteen the 2 This technique is also used to attack the legitimate host but making it look like the attack comes from our B host behind the firewall, for example for Denial of Service attacks.
11 page 11 of 16 various Transport protocols (TCP, UDP etc.). There are not too many Transport protocols and they are all reasonably similar in their fundamental structure. Instead Application Protocols, like ftp, http, dns, smtp etc., even if usually adopt TCP or/and UDP as Transport protocol, can be really very different. For this reason most of the ALGs (Application Layer Gateways) are built in a modular form, to allow the possibility of adding a new module which understands a particular new protocol, or to activate just the modules for the protocols of interest. Thus we can have modules for ftp (active, passive, behind NAT or PAT), http, dns, H323 etc. and even modules for private protocols which are not public standards. The porpuse of these modules can be different: 1. the simplest modules are those for the protocols which require more dynamical connections to be opened, like ftp or H323, after the first one is allowed on the well known ports. These modules can just restrict themselves to look at some particular data in the packets (for example the PORT command in ftp) and from these learn the details of the new connection that is going to be opened. Once this happens they will insert in the Connections Table a new entry for this related connection, even if no rule exists which specifies these ports, and they will then allow the new connection to pass through the firewall. In this way, ports are opened and closed just when they are needed, and only after a first allowed connection has been established. This allows for example to have a firewall with all connections from outside denied by default, but if a H323 connection from the inside to the outside is allowed, then automatically all needed ports are opened also for the incoming connections from the outside related to this one. 2. A little more complicated are modules which look at some particular dangerous commands or data for a protocol. The prime example is the http module which filters out (delete or just comment out) Java applets inserted web pages. The module just looks for the command which starts a Java applet, and ignores everything else in the payload of an http packet. 3. In the future there will be modules which will check that the contents of a packet strictly adhere to the Application protocol to which they belong. This would prevent attacker to insert illegal data, from the point of view of the Application protocol, in the packets. The problem with this is that not always all applications adhere strictly to the protocols, there can be vendor extensions or just bad implementations, and such a module would just prevent these connections even if they are not malicious. One can imagine to have more advanced modules to do a real check of the contents of each packet, or even reassembling packets to understand exactly the possible consequences of the data on the destination host. Unfortunately one must keep in mind that for a firewall it is very expensive in terms or resources (RAM, CPU etc.) to analyse the payload of each or most packets. Thus the more complicated and sophisticated these modules are, the more powerful the hardware of the firewall must be. Moreover, the more checks the firewall must do, the longer delay it adds in the communication, even more if packets must be reassembled in files and so on. At this point we should strike a balance between what these modules can do, and what the hardware allows to do in such a way to introduce delays not noticeable in real time communications. Thus we could divide the Application protocols in 2 classes: 1. the ones which have timing constraints of the order of the (hundred of) milliseconds; 2. the ones for which delays of seconds or even minutes are not so important.
12 page 12 of 16 To the first class belong some interactive protocols like teleconferencing (H323), remote logins etc., whereas to the second class belong protocols from web surfing (which requires delays introduced by a firewall not more than a few seconds) to , where delays even of a few minutes do not really matter. The first class is usually addressed with ALG modules, whereas for the second class one can adopt Proxies. 2.4 Proxy Firewalls For Application protocols which are not too sensitive to delays, the more secure solution is to introduce an external host, parallel to the firewall which would fully filter all communications between the internal and external hosts. Thus F will send all packets of a certain kind, for example to or from port 80 TCP (i.e. http), to an host G which is directly connected to it. 3 Lets look at how this works in a simple example: 1. A sends a http request (first packet) to B on TCP port 80 of B from port 2345 of A. 2. F receives this packet and from the rules for first-packets knows that the packet is allowed and that it should be redirected to G on TCP port (Alternatively the user on A could have defined G as a http-proxy, and then A would send the first packet directly to G; a rule for this kind of first-packets should also be present in F.) 3. G receives the packet and behaves as if it was B, that is the final host to which the packet was addressed; thus G establishes a TCP connection with A posing as the final web server; this implies that the program running on G and listening on port TCP 8080 must emulate a full Web (httpd) server. 4. G sends a http request (first-packet) to B on TCP port 80 of B from port 5345 of G. What G is doing is to behave now as a Web client (a Web browser) and it forwards the request just arrived from A to B, but this time the request is coming from G as source address. 5. F receives this new first-packet, and has a rule which allows G to connect to B on port TCP 80, thus a new connection is established from G to B. 6. B sends the requested Web page to G thinking that G is a Web browser; G then sends the Web page to A, which thinks that G is a final Web server. This complicated setup accomplishes the following things: 1. A can connect only with G and believes that G is a Web server. 2. G receives all requests of Web pages from A and can decide which to honour and which to deny. 3. G asks all Web pages for A to the final Web Servers (B in this example) and receives all pages; G can reassemble and examine all pages before sending them to A; With respect to B, G behaves as a Web browser (a client). 4. A and B can never establish a direct TCP connection, they connect directly only with G. 3 On some firewalls the Proxy program could run on the same hardware device as the firewall itself, the physical division in two hosts is for a more clear understanding of the data flow and it is also the suggested implementation for security and reliability reasons.
13 page 13 of 16 Since G implements both a http client and a server, it is able to address all possible issues of the http protocol and it is then able to apply all possible kinds of filters and security checks on the Web pages which are requested by A. Moreover, B never even knows that A exists. Finally G can also cache the most requested pages from A, and serve them to A without getting them again from B. Besides http Proxy, the other very well known one is the electronic mail (smtp protocol) antivirus proxies. In this case the firewall will forward to a smtp proxy all s, and the smtp proxy checks every message for the presence of viruses. In the case of smtp it is very easy to implement a proxy, since for how the protocol is defined, any smtp server can be considered to be a proxy in the sense I are using here. Moreover the firewall does not even need to do any packet redirection if the DNS records are configured appropriately. 2.5 Examples After these general notes I am going to give an example just to end with something practical. I do not want to give another set of the infinite collection of the My favourite firewalls rules, but I should give you something anyway. I will give rules for a Stateful Inspection firewall with some simple Application Layer modules The Strategy To write some rules one has to start from some point of view. Here is a simple starting point: 1. Classify the traffic which is allowed to pass through the firewall, do it interface by interface considering all incoming traffic to the firewall and only for the first packet of each connection. 2. Adopt the point of view that all traffic which is not explicitly allowed is denied. 3. Write rules which start by accepting all established connections 4. then filter all incoming traffic (first packets) depending on the incoming interface (if the firewall has different rules for different interfaces, do this independently interface by interface) 5. if needed, filter also the traffic depending on the outgoing interface (this could be needed in complicated firewalls with many interfaces, simple firewalls with 3 interfaces rarely need this); in any case specify as much as possible all rules, restricting them to the most. Adopting this approach it is usually possible to write rules for a firewall in a compact and understandable way. Moreover, the lower the number of rules and the simpler their organization, the easiest it will be to have efficient and correct policies, and the easier will be to understand what is happening to the traffic through the firewall.
14 page 14 of A simple example with Linux iptables Consider a Linux firewall with iptables and 2 interfaces, eth0 towards the inside and eth1 towards the Internet. A part of the configuration of the FORWARD chain could be like the following (comments are after each group of instructions): iptables -P FORWARD DROP This sets the default policy of the chain to DROP. modprobe ip_conntrack_ftp modprobe ip_nat_ftp These start the (ALG) modules which allows the automatic opening of ftp ports. iptables -N logdrop iptables -A logdrop -m limit --limit 10/s --limit-burst 60 -j LOG --log-ip-options --log-tcp-options --log-prefix IPTlogdrop iptables -A logdrop -m limit --limit 10/s --limit-burst 60 -p tcp -j REJECT --reject-with tcp-reset iptables -A logdrop -m limit --limit 10/s --limit-burst 60 -p! icmp -j REJECT --reject-with icmp-port-unreachable iptables -A logdrop -j DROP These create an auxiliary chain which sends to syslog all packets to which it is denied to pass through the firewall. Then for TCP packets a tcp reset is sent back, for all other not icmp packet a icmp port unreachable is sent back. All packets are anyway discarded. All reject and log rules are rate limited to prevent to fill up the logs of the log server, and to act as a indirect Deny of Service agent. (If you fear that your firewall could be used for an indirect DoS, do not use the two Reject rules in this list.) iptables -A FORWARD -m state --state INVALID -j logdrop This rules drops (or rejects) all packets which are classified as INVALID by iptables. Among them there are also some illegal TCP flags combinations, or packets with impossible IP addresses. If you have also the tcp-window-tracking patch from patch-o-matic, all packets with illegal combination of TCP flags, or out of the tcp window, are marked as INVALID and dropped by this rule. iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT This rule accepts all established IP connections as listed in the Connections Table, the icmp error messages related to the allowed connections, and also all related ftp connections with the help of the modules we have previously loaded. Most of the traffic of the firewall will be accepted by this rule. From now on only first packets are examined. iptables -A FORWARD -i eth0 -o eth1 -s /24 -p tcp -m multiport --destination-port 21,22,53,80,443,993 --tcp-flags SYN,ACK,FIN,RST SYN -j ACCEPT iptables -A FORWARD -i eth0 -o eth1 -s /24
15 page 15 of 16 -p udp -m multiport --destination-port 53,123 -j ACCEPT iptables -A FORWARD -i eth0 -o eth1 -s /24 -p icmp --icmp-type echo-request -j ACCEPT These 3 rules accept all first packets for the allowed connection which are going out from our network to the Internet. Notice that ftp (TCP port 21) is allowed, the other ports used by ftp will be opened automatically by the modules. Our security policy allows the internal users to connect to the listed services to any external server, so no filter on the destination IP addresses is set. iptables -A FORWARD -j logdrop This rule simply says that all other packets are to be dropped (or rejected). iptables -t nat -A POSTROUTING -s /24 -o eth1 -j SNAT --to-source This rule says to PAT all internal IP addresses in the private class /24 to the external internet address These rules are only a first attempt to build a firewall, many issues have not been considered like the INPUT and OUTPUT chain of the Linux firewall, or a more detailed logging or accounting. For example it is suggested to filter all illegal source addresses, the rules for doing so could be the following: iptables -A FORWARD -s /8 -j logdrop iptables -A FORWARD -s /8 -j logdrop iptables -A FORWARD -s /8 -j logdrop iptables -A FORWARD -s /12 -j logdrop iptables -A FORWARD -i! eth0 -s /16 -j logdrop iptables -A FORWARD -s /3 -j logdrop iptables -A FORWARD -s /32 -j logdrop iptables -A FORWARD -s /32 -j logdrop which should be inserted just after the Accept ESTABLISHED,RELATED rule. A similar rule should be added also to filter the outgoing packets for illegal destination addresses, since a destination of would be routed to the Internet, but it is obviously not a valid address. 3. Firewalls and other Security Devices Firewalls do not live alone and do not solve alone all security problems of an ICT deployment. Actually quite the contrary, they are a very little, but important, tool in the full security system. To make a firewall more effective, other tools should be used together with it. In particular Intrusion Detection/Prevention Systems and cryptography/encrypted connections should be adopted. Whereas a firewall is very good in filtering the traffic, an IDS/IPS should recognize patterns in the traffic which can indicate that an attack is starting or under way. An Intrusion D/P System can analyse off-line the traffic which is reaching the firewall, and in almost real time correlate patterns or discover harmful payloads in the packets. This analysis requires often quite some hardware resources and some time on the scale of the millisecond delays that at most a
16 page 16 of 16 firewall can introduce, which makes it impossible to be done by the firewall. What instead an I[D/P]S can do is to alert an operator or to automatically change the rules of the firewall when it realizes that an attack is under way. Encrypted connections can help the firewall, but at the same time introduce other problems. Establishing an encrypted connection between two remote networks secures the communications between them, and also adds a strong authentication since the establishment of the encrypted tunnel requires it. Thus an encrypted tunnel is good traffic, from the point of view of the firewall, because at least the two endpoints are who they claim to be (man-in-the-middle attacks notwithstanding). On the other side the firewall must trust ultimately both endpoints, since being the traffic encrypted the firewall has no way to look at the contents of the packets, and doesn't have even a vague idea of which kind of application protocols are passing in the tunnel, or of the original payload. So if one of the two is cheating, the firewall cannot do anything about it. To minimize the security risks, one has to plan a reasonable complete system, taking in consideration not only the role of the firewall, but also that of all other components of the network.
Computer Fraud & Security, May 2007 page 1/10 From Network Security To Content Filtering Network security has evolved dramatically in the last few years not only for what concerns the tools at our disposals
Protecting and controlling Virtual LANs by Linux router-firewall Tihomir Katić Mile Šikić Krešimir Šikić Faculty of Electrical Engineering and Computing University of Zagreb Unska 3, HR 10000 Zagreb, Croatia
Firewalls Chien-Chung Shen email@example.com The Need for Firewalls Internet connectivity is essential however it creates a threat vs. host-based security services (e.g., intrusion detection), not cost-effective
Internet Firewall CSIS 3230 A combination of hardware and software that isolates an organization s internal network from the Internet at large Ch 8.8: Packet filtering, firewalls, intrusion detection Ch
Chapter 8 Security Pt 2 IC322 Fall 2014 Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012 All material copyright 1996-2012 J.F Kurose and K.W. Ross,
Security principles Firewalls and NAT These materials are licensed under the Creative Commons Attribution-Noncommercial 3.0 Unported license (http://creativecommons.org/licenses/by-nc/3.0/) Host vs Network
+ iptables packet filtering && firewall + what is iptables? iptables is the userspace command line program used to configure the linux packet filtering ruleset + a.k.a. firewall + iptable flow chart what?
Firewalls, NAT and Intrusion Detection and Prevention Systems (IDS) Internet (In)Security Exposed Prof. Dr. Bernhard Plattner With some contributions by Stephan Neuhaus Thanks to Thomas Dübendorfer, Stefan
Virtual private network Network security protocols COMP347 2006 Len Hamey Instead of a dedicated data link Packets securely sent over a shared network Internet VPN Public internet Security protocol encrypts
Firewall implementation and testing Patrik Ragnarsson, Niclas Gustafsson E-mail: firstname.lastname@example.org, email@example.com Supervisor: David Byers, firstname.lastname@example.org Project Report for Information
Firewalls (IPTABLES) Objectives Understand the technical essentials of firewalls. Realize the limitations and capabilities of firewalls. To be familiar with iptables firewall. Introduction: In the context
ΕΠΛ 674: Εργαστήριο 5 Firewalls Παύλος Αντωνίου Εαρινό Εξάμηνο 2011 Department of Computer Science Firewalls A firewall is hardware, software, or a combination of both that is used to prevent unauthorized
Main functions of Linux Netfilter Filter Nat Packet filtering (rejecting, dropping or accepting packets) Network Address Translation including DNAT, SNAT and Masquerading Mangle General packet header modification
Network Defense Tools Prepared by Vanjara Ravikant Thakkarbhai Engineering College, Godhra-Tuwa +91-94291-77234 www.cebirds.in, www.facebook.com/cebirds email@example.com What is Firewall? A firewall
Introduction Prior to iptables, the predominant software packages for creating Linux firewalls were 'IPChains' in Linux 2.2 and ipfwadm in Linux 2.0, which in turn was based on BSD's ipfw. Both ipchains
Firewalls, Tunnels, and Network Intrusion Detection 1 Part 1: Firewall as a Technique to create a virtual security wall separating your organization from the wild west of the public internet 2 1 Firewalls
Firewall Tutorial KAIST Dept. of EECS NC Lab. Contents What is Firewalls? Why Firewalls? Types of Firewalls Limitations of firewalls and gateways Firewalls in Linux What is Firewalls? firewall isolates
FIREWALLS FIREWALLS Firewall: isolates organization s internal net from larger Internet, allowing some packets to pass, blocking others FIREWALLS: WHY Prevent denial of service attacks: SYN flooding: attacker
ΕΠΛ 475: Εργαστήριο 9 Firewalls Τοίχοι πυρασφάλειας Department of Computer Science Firewalls A firewall is hardware, software, or a combination of both that is used to prevent unauthorized Internet users
CSE331: Introduction to Networks and Security Lecture 12 Fall 2006 Announcements Midterm I will be held Friday, Oct. 6th. True/False Multiple Choice Calculation Short answer Short essay Project 2 is on
Network Security Chapter 3 Cornelius Diekmann Lehrstuhl für Netzarchitekturen und Netzdienste Institut für Informatik Version: October 21, 2015 IN2101, WS 15/16, Network Security 1 Security Policies and
Summer Course at Mekelle Institute of Technology. July, 2015. Linux Routers and Community Networks Llorenç Cerdà-Alabern http://personals.ac.upc.edu/llorenc firstname.lastname@example.org Universitat Politènica de
Final exam review, Fall 2005 FSU (CIS-5357) Network Security Instructor: Breno de Medeiros 1. What is an insertion attack against a NIDS? Answer: An insertion attack against a network intrusion detection
system so that an unauthorized individual can take over an authorized session, or to disrupt service to authorized users. From a high-level standpoint, attacks on computer systems and networks can be grouped
CMPT 471 Networking II Firewalls Janice Regan, 2006-2013 1 Security When is a computer secure When the data and software on the computer are available on demand only to those people who should have access
1:1 NAT in ZeroShell Requirements The version of ZeroShell used for writing this document is Release 1.0.beta11. This document does not describe installing ZeroShell, it is assumed that the user already
UNDERSTANDING FIREWALLS TECHNICAL NOTE 10/04 REVISED 23 FEBRUARY 2005 This paper was previously published by the National Infrastructure Security Co-ordination Centre (NISCC) a predecessor organisation
Internet Firewall CSIS 4222 A combination of hardware and software that isolates an organization s internal network from the Internet at large Ch 27: Internet Routing Ch 30: Packet filtering & firewalls
Linux firewall Need of firewall Single connection between network Allows restricted traffic between networks Denies un authorized users Linux firewall Linux is a open source operating system and any firewall
INTRODUCTION TO FIREWALL SECURITY SESSION 1 Agenda Introduction to Firewalls Types of Firewalls Modes and Deployments Key Features in a Firewall Emerging Trends 2 Printed in USA. What Is a Firewall DMZ
Project4 EDoS Instructions 1 Project 4: (E)DoS Attacks Secure Systems and Applications 2009 Ben Smeets (C) Dept. of Electrical and Information Technology, Lund University, Sweden Introduction A particular
FIREWALL AND NAT Lecture 7a COMPSCI 726 Network Defence and Countermeasures Muhammad Rizwan Asghar August 3, 2015 Source of most of slides: University of Twente FIREWALL An integrated collection of security
Firewalls, Tunnels, and Network Intrusion Detection 1 Firewalls A firewall is an integrated collection of security measures designed to prevent unauthorized electronic access to a networked computer system.
CSCI 7000-001 Firewalls and Packet Filtering November 1, 2001 Firewalls are the wrong approach. They don t solve the general problem, and they make it very difficult or impossible to do many things. On
Transport Layer Protocols Version. Transport layer performs two main tasks for the application layer by using the network layer. It provides end to end communication between two applications, and implements
Lecture 23: Firewalls Introduce several types of firewalls Discuss their advantages and disadvantages Compare their performances Demonstrate their applications C. Ding -- COMP581 -- L23 What is a Digital
Internet Protocol: IP packet headers 1 IPv4 header V L TOS Total Length Identification F Frag TTL Proto Checksum Options Source address Destination address Data (payload) Padding V: Version (IPv4 ; IPv6)
The SpeedTouch and Firewalling Peter Huyge Date: April 2002 Edition: 01 Abstract: This application note provides technical Firewall information and how this relates to the DSL SpeedTouch 610Series product.
s (March 4, 2015) Abdou Illia Spring 2015 Test your knowledge Which of the following is true about firewalls? a) A firewall is a hardware device b) A firewall is a software program c) s could be hardware
Chapter 10 Firewall Firewalls are devices used to protect a local network from network based security threats while at the same time affording access to the wide area network and the internet. Basically,
http://technet.microsoft.com/en-us/library/cc757501(ws.10).aspx Appendix A: Configuring Firewalls for a VPN Server Running Windows Server 2003 Updated: October 7, 2005 Applies To: Windows Server 2003 with
Overview Security Type of attacks Firewalls Protocols Packet filter Computer Net Lab/Praktikum Datenverarbeitung 2 1 Security Security means, protect information (during and after processing) against impairment
Mikrotik Security IP -> Services Disable unused services Set Available From for appropriate hosts Secure protocols are preferred (Winbox/SSH) IP -> Neighbors Disable Discovery Interfaces where not necessary.
Classification of Firewalls and Proxies By Dhiraj Bhagchandka Advisor: Mohamed G. Gouda (email@example.com) Department of Computer Sciences The University of Texas at Austin Computer Science Research
Firewalls Pehr Söderman KTH-CSC Pehrs@kth.se 1 Definition A firewall is a network device that separates two parts of a network, enforcing a policy for all traversing traffic. 2 Fundamental requirements
Firewalls slide 1 configuring a sophisticated GNU/Linux firewall involves understanding iptables iptables is a package which interfaces to the Linux kernel and configures various rules for allowing packets
Linux Network Security Course ID SEC220 Course Description This extremely popular class focuses on network security, and makes an excellent companion class to the GL550: Host Security course. Protocols
Stateful Firewalls Hank and Foo 1 Types of firewalls Packet filter (stateless) Proxy firewalls Stateful inspection Deep packet inspection 2 Packet filter (Access Control Lists) Treats each packet in isolation
Chapter 4 Firewall Protection and Content Filtering This chapter describes how to use the content filtering features of the ProSafe Dual WAN Gigabit Firewall with SSL & IPsec VPN to protect your network.
N-CAP Users Guide Everything You Need to Know About Using the Internet! How Firewalls Work How Firewalls Work By: Jeff Tyson If you have been using the internet for any length of time, and especially if
co Characterizing and Tracing Packet Floods Using Cisco R Table of Contents Characterizing and Tracing Packet Floods Using Cisco Routers...1 Introduction...1 Before You Begin...1 Conventions...1 Prerequisites...1
Introduction of Intrusion Detection Systems Why IDS? Inspects all inbound and outbound network activity and identifies a network or system attack from someone attempting to compromise a system. Detection:
Session Hijacking Exploiting TCP, UDP and HTTP Sessions Shray Kapoor firstname.lastname@example.org Preface With the emerging fields in e-commerce, financial and identity information are at a higher risk of being
Chapter 4 Firewall Protection and Content Filtering The ProSafe VPN Firewall 50 provides you with Web content filtering options such as Block Sites and Keyword Blocking. Parents and network administrators
Introduction TELE 301 Lecture 21: s Zhiyi Huang Computer Science University of Otago Discernment of Routers, s, Gateways Placement of such devices Elementary firewalls Stateful firewalls and connection
83-10-41 Types of Firewalls E. Eugene Schultz Payoff Firewalls are an excellent security mechanism to protect networks from intruders, and they can establish a relatively secure barrier between a system
Pascal Muetschard John Nagle COEN 150, Spring 03 Prof. JoAnne Holliday Computer Firewalls Introduction The term firewall was originally used with forest fires, as a means to describe the barriers implemented
Laboratory for Computer Security Education 1 Attack Lab: Attacks on TCP/IP Protocols Copyright c 2006-2010 Wenliang Du, Syracuse University. The development of this document is funded by the National Science
Firewalls What is a Firewall? A choke point of control and monitoring Interconnects networks with differing trust Imposes restrictions on network services only authorized traffic is allowed Auditing and
Network Security ICMP, TCP, DNS, Scanning Marcus Bendtsen Institutionen för Datavetenskap (IDA) Avdelningen för Databas- och Informationsteknik (ADIT) Agenda A couple of examples of network protocols that
Port Scanning and Vulnerability Assessment ECE4893 Internetwork Security Georgia Institute of Technology Agenda Reconnaissance Scanning Network Mapping OS detection Vulnerability assessment Reconnaissance
Firewalls Carlo U. Nicola, SGI FHNW With extracts from slides/publications of : John Mitchell, Stanford U.; Marc Rennhard, ZHAW; E.H. Spafford, Purdue University. CINS/F1-01 Topics 1. Purpose of firewalls
Firewalls P+S Linux Router & Firewall 2013 Firewall Techniques What is a firewall? A firewall is a hardware or software device which is configured to permit, deny, or proxy data through a computer network
Evading Infrastructure Security Mohamed Bedewi Penetration Testing Consultant What infrastructure security really means? Infrastructure Security is Making sure that your system services are always running
IMPLEMENTATION OF INTELLIGENT FIREWALL TO CHECK INTERNET HACKERS THREAT Roopa K. Panduranga Rao MV Dept of CS and Engg., Dept of IS and Engg., J.N.N College of Engineering, J.N.N College of Engineering,
1. Firewall Configuration A firewall is a method of implementing common as well as user defined security policies in an effort to keep intruders out. Firewalls work by analyzing and filtering out IP packets
Red Hat Docs > Manuals > Red Hat Enterprise Linux Manuals > Red Hat Enterprise Linux 4: Security Guide Chapter 7. Firewalls http://www.redhat.com/docs/manuals/enterprise/rhel-4-manual/security-guide/ch-fw.html
How to protect your home/office network? Using IPTables and Building a Firewall - Background, Motivation and Concepts Adir Abraham email@example.com Do you think that you are alone, connected from
Networking for Caribbean Development BELIZE NOV 2 NOV 6, 2015 w w w. c a r i b n o g. o r g N E T W O R K I N G F O R C A R I B B E A N D E V E L O P M E N T BELIZE NOV 2 NOV 6, 2015 w w w. c a r i b n
Firewalls and VPNs Principles of Information Security, 5th Edition 1 Learning Objectives Upon completion of this material, you should be able to: Understand firewall technology and the various approaches
CSC574 - Computer and Network Security Module: Firewalls Prof. William Enck Spring 2013 1 Firewalls A firewall... is a physical barrier inside a building or vehicle, designed to limit the spread of fire,