
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















The purpose of this lab is to show how firewalls work. It consists of two parts. The first part gives an overview of basic firewall concepts with exercises and examples. In the second part you will implement all the rules in the iptables.firewall file available from the lab cd. The effects of these rules are to be examined.
Lab Setup
The following network has already been set up for you in the lab. There are two machines labeled âProtected Machinesâ and âFirewallâ. The âProtected Machinesâ drive contains the virtual machines while the âFirewallâ machine is where you enable ipchains. The two virtual machines are considered protected from the outside by the firewall in the middle. You will access the firewall from your machine.
System Setup
VMware Linux â protected Normal Linux workstation installation with IP 192.168.0.5, the netmask 255.255.255.0, and the gateway 192.168.0.1.
VMware XP â protected Virtual Windows XP installation with the IP 192.168.0.7, the netmask 255.255.255.0, and the gateway 192.168.0.1.
Linux Firewall Normal Linux server installation with eth1 having an IP of 192.168.0.1 and a netmask of 255.255.255.0. eth0 is IP is 57.35.5.10, netmask is 255.255.255.0, and gateway is 57.35.5.1.
Your Machine Your normal Linux installation with the IP depending on your machine.
The password on each of these machines is âpasswordâ.
Setting up routing and iptables Some of the information given in this section will be only be clear and useful later on when you actually use iptables.
The executable binary for the iptables application is the /sbin/iptables file. RedHat also has an executable script in the /etc/init.d/iptables file so that it can start its default firewall at startup. An easy way to reset the firewall rules is to use this script as /etc/rc.d/init.d/iptables stop which flushes all the rules in memory and gives you a clean start. The other way to do the same thing is to flush all the chains and then delete any chains that are not default. iptables âF flushes all chains iptables âX deletes chains
The ~/fresh_iptables directory contains a file called iptables.router. This is an executable script that enables the router functionality of the firewall computer. This will allow you to access the protected machines from your computer. So go ahead and execute this script at this time. The way we have the network is that the firewall machine also functions as a gateway for the internal network. In a real network, with multiple networks inside the internal network, the gateway allows access, while the firewall is used to restrict access to sensitive machines.
The other file in the same directory is the iptables.firewall file. This file contains all of the firewall rules we will use in this lab. The contents of this file are included in Appendix A so you may follow the lab discussion in that file. You can execute this file to enable all the rules at once by executing it. Donât execute it yet.
Now go to the root directory /~ and make a directory with your group name. Copy both the files from the fresh_iptables directory to your directory. Make sure that whenever you edit the files, you are doing it in your own group directory.
Later in the lab, every time you need to restart the firewall with your rules, you can use the following commands: /etc/rc.d/init.d/iptables stop ./iptables.firewall (in the directory with your edited iptables.firewall file)
Write down which ports are open:
1.2 - Firewall Configuration
Firewalls are customizable. This means that you can add or remove filters based on several conditions. Some of these are:
A software firewall, such as ZoneAlarm, can be installed on the computer in your home that has an Internet connection. This computer is considered a gateway because it provides the only point of access between your home network and the Internet.
With a hardware firewall, the firewall unit itself is normally the gateway. A good example is the Linksys Cable/DSL router. It has a built-in Ethernet card and hub. Computers in your home network connect to the router, which in turn is connected to either a cable or DSL modem. You configure the router via a Web-based interface that you reach through the browser on your computer. You can then set any filters or additional information.
Hardware firewalls are incredibly secure and not very expensive. Home versions that include a router, firewall, and Ethernet hub for broadband connections can be found for well under $100.
1.3 - What It Protects You From:
There are many creative ways that unscrupulous people use to access or abuse unprotected computers. The level of security you establish will determine how many of these threats can be stopped by your firewall. The highest level of security would be to simply block everything. Obviously that defeats the purpose of having an Internet connection. But a common rule of thumb is to block everything, and then begin to select what types of traffic you will allow. You can also restrict traffic that travels through the firewall so that only certain types of information, such as e-mail, can get through. This is a good rule for businesses that have an experienced network administrator that understands what the needs are and knows exactly what traffic to allow through. For most of us, it is probably better to work with the defaults provided by the firewall developer unless there is a specific reason to change it.
One of the best things about a firewall from a security standpoint is that it stops anyone on the outside from logging onto a computer in your private network. While this is a big deal for businesses, most home networks will probably not be threatened in this manner. Still, putting a firewall in place provides some peace of mind.
1.4 â Demilitarized Zone:
DMZ stands for Demilitarized Zone. A DMZ is your frontline when protecting valuables from direct exposure to an untrusted environment. SI Security defines a DMZ as, "A network added between a protected network and an external network in order to provide an additional layer of security." A DMZ is sometimes called a "Perimeter network" or a "Three-homed perimeter network."
A DMZ is a step towards defense in depth because it adds an extra layer of security beyond that of a single perimeter. A DMZ separates an external network from directly referencing an internal network. It does this by isolating the machine that is being directly accessed from all other machines. Most of the time the external network is the Internet and what is in the DMZ is the web server but this isnât the only possible configuration. A DMZ can be used to isolate a particular machine within a network from other machines. This might be done for a branch office that needs its own Internet access but also needs access to the corporate network. In DMZ terminology, an internal connection is generally thought of as having more secret or valuable information than an external network. An easy way to understand which one is the internal network is to ask yourself which network I am protecting.
Separation is important. Any system should have its important applications separated. This acts as system of checks and balances to make sure that if any one area goes bad that it cannot corrupt the whole. It is important to separate information so an attacker canât get to all the systems. It would be bad enough for the attacker to get to the web server but if that attacker can get through the web server to your database then thatâs even worse. This is the type of problem that a DMZ is designed to prevent.
A DMZâs separation will degrade performance. If configured correctly the degradation in performance is usually minimal and seldom noticeable. However, it does exist and you need to be aware of it. This effect on performance must be calculated in the total cost of implementing a DMZ. Usually the performance drop is nominal and the security increase is significant.
The three circles represent the three chains mentioned above. When a packet reaches a circle in the diagram, that chain is examined to decide the fate of the packet. If the chain says to DROP the packet, it is killed there, but if the chain says to ACCEPT the packet, it continues traversing the diagram.
A chain is a checklist of rules. Each rule says âif the packet header looks like this, then hereâs what to do with the packetâ. If the rule doesnât match the packet, then the next rule in the chain is consulted. Finally, if there are no more rules to consult, then the kernel looks at the chain policy to decide what to do. In a security-conscious system, this policy usually tells the kernel to DROP the packet.
3.2 - Creating your own rules
The iptables tool inserts and deletes rules form the kernelâs packet filtering table. Initially all chains are set to ACCEPT by default. A detailed description can be obtained from the man pages (man iptables).
Commands to change chains:
Commands to add/delete rules:
The sections
4.0 - Iptables Parameters
Parameters specify the type of packet that you are looking to match with your rule.
4.1 - Specifying jump
If a packet matches one of your rules, you can tell the packet to jump to another chain with the â-jâ option
iptables âA INPUT âj DROP
4.2 - Specifying protocol
The protocol can be specified with the ââpâ option. Protocols can either be the number in the IP header or âtcpâ, âudpâ, or âicmpâ (case insensitive).
iptables âA INPUT âp icmp
4.3 - Specifying inversion
To invert (negate) any of your rules use the â!â character
#drop all packets that are not tcp iptables âA INPUT âp! tcp
4.4 - Specifying interface
Interfaces can be specified with the â-iâ (input) and â-oâ (output) paramaters. Note, a rule in the INPUT chain checking with â-oâ will never match any packet and a rule in the OUTPUT chain checking with â-iâ will never match any packet.
--limit-burst
Followed by a number, indicating the maximum burst before the above limit kicks in.
This match can often be used with the LOG target to do rate-limited logging. To understand how it works, let's look at the following rule, which logs packets with the default limit parameters:
The first time this rule is reached, the packet will be logged; in fact, since the default burst is 5, the first five packets will be logged. After this, it will be twenty minutes before a packet will be logged from this rule, regardless of how many packets reach it (60 minutes / 3 packets per hour). This value of twenty minutes is because the default limit is 3/hour. Also, every twenty minutes which passes without matching a packet, one of the burst will be regained; if no packets hit the rule for 100 minutes, the burst will be fully recharged to 5 packets (100 minutes / 20mintes per packet); back where we started.
Note: you cannot currently create a rule with a recharge time greater than about 59 hours, so if you set an average rate of one per day, then your burst rate must be less than 3.
You can also use this module to avoid various denial of service attacks (DoS) with a faster rate to increase responsiveness.
Syn-flood protection:
Furtive port scanner:
-limit 1/s -j ACCEPT
Ping of death:
1/s -j ACCEPT
5.0 - Network Address Translation (NAT)
There are two types of NAT, source NAT and destination NAT.
Source NAT is when you alter the source address of the first packet: i.e. you are changing where the connection is coming from. Source NAT is always done post-routing, just before the packet goes out onto the wire. Masquerading is a specialized form of SNAT. A router might do masquerading for packets going from one of its internal machines to an outside connection. In this case it will change the source address of the machine to its own address. The external machine will see the packets coming from the router.
Destination NAT is when you alter the destination address of the first packet: i.e. you are changing where the connection is going to. Destination NAT is always done before routing, when the packet first comes off the wire. Port forwarding, load sharing, and transparent proxying are all forms of DNAT. In the router example, the incoming packets intended for the internal machine are routed to it by changing the destination address to the internal address of the machine.
5.1 - NAT in the kernel
You need to create NAT rules which tell the kernel what connections to change, and how to change them. To do this, we use the very versatile iptables tool, and tell it to alter the NAT table by specifying the `-t nat' option.
The table of NAT rules contains three lists called `chains': each rule is examined in order until one matches. The two chains are called PREROUTING (for Destination NAT, as packets first come in), and POSTROUTING (for Source NAT, as packets leave). The third (OUTPUT) will be ignored here.
At each of the points above, when a packet passes we look up what connection it is associated with. If it's a new connection, we look up the corresponding chain in the NAT table to see what to do with it. The answer it gives will apply to all future packets on that connection.
5.2 - Iptables and NAT
iptables -A PREROUTING -t nat -p tcp -d 1.2.3.4 --dport 80 -j DNAT --to 192.168.1.1:
NOTE: This only changes the destination of the packet, it does not automatically accept it in the forwarding chain. A rule must be made in the forwarding chain also.
5.4 - Masquerading
There is a specialized case of Source NAT called masquerading: it should only be used for dynamically- assigned IP addresses, such as standard dialups.
You don't need to put in the source address explicitly with masquerading: it will use the source address of the interface the packet is going out from. But more importantly, if the link goes down, the connections (which are now lost anyway) are forgotten, meaning fewer glitches when connection comes back up with a new IP address.
6.0 â iptables.firewall Script Explanation (See Appendix A)
These rules are already contained in our file iptables.firewall. We do not cover the rules in exactly the same order as they appear in your file. Go through these rules and understand what exactly is being done.
6.1 - Load the iptables modules and connection tracking for ftp and nat:
modprobe ip_tables modprobe iptable_nat modprobe ip_conntrack_ftp modprobe ip_nat_ftp
Configure default policies (-P), meaning default rule to apply if no more specific rule below is applicable. These rules apply if a more specific rule below is not applicable. Defaults are to DROP anything sent to firewall or internal network, permit anything going out.
iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT ACCEPT
6.2 - Flush (-F) all specific rules:
iptables -F INPUT iptables -F FORWARD iptables -F OUTPUT iptables -F -t nat
The rest of this file contains specific rules that are applied in the order listed. If none applies, then the above policy rules are used.
Forward all packets from eth1 (internal network) to eth0 (the internet).
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
Forward all packets that are part of existing and related connections from eth0 to eth1.
iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
Permit packets in to firewall itself that are part of existing and related connections.
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
Note, in the above two rules, a connection becomes ESTABLISHED in the iptables PREROUTING chain upon receipt of a SYNACK packet that is a response to a previously sent SYN packet. The SYNACK
6.5 â Defending against ICMP Ping Floods
ICMP ping floods are commonly used attacks, especially by âscript kiddies.â The attack is really simple, the attacker ping floods you and if he has more upstream than your downstream, you wonât be able to access anything. Iptables allows you to specify how many ICMP âechoâ packets you want to reply to. This can be done by adding the following:
iptables -A INPUT âp icmp â-icmp-type echo-request âm limit / -âlimit 30/minute â-limit-burst 1 âj ACCEPT
you, just to test the network connection. The burst is set to 1 packet, so this limit will immediately take effect.
Our Linux based firewall is already completely setup since the iptables.firewall file is provided for us, and all of the machines behind the firewall are protected from harmful traffic. We will now run some tests to show the results of the firewall installation.
Exercise 3
Turn on the firewall rules by typing ./iptables.firewall (in the directory where your iptables.firewall is placed)
If you have enabled the firewall before, you will need to flush the rules before executing the above command.
Now rerun nmap from outside the firewall on the Linux machine behind the firewall.
Run nmap with these options:
SCAN -> SYN Stealth DISCOVER -> Donât Ping OPTIONS -> Donât resolve Fast Scan TIMING -> Max RTT 40ms
The command is nmap âsS âP0 ân âF âmax_rtt_timeout 40
We must add this additional timing option because the firewall does not send a reset packet when nmap scans a closed port, it simply drops it. The RTT value specifies that nmap will not wait longer than 40ms for a response on a port.
Write down which ports are open after the firewalls installation:
Exercise 4
What happened differently in the results from exercise three as opposed to exercise one? Can you speculate what firewall rules caused this?
Exercise 5
From your Linux machine, we are going to ping the firewall to observe the rule which defends against icmp ping floods. The rule specified in this lab has the limit as 30/minute and a burst of 1. This means that every other packet will be denied and this rule will be enabled with the first packet.
From your Linux machine, ping the firewall with these options:
ping 57.35.5.10 ân 20 âw 4
Record this output in one window.
Now change the rule in the iptables.firewall file to 10/minute and a burst of 5. Restart the firewall with the command
/etc/rc.d/init.d/iptables stop ./iptables.firewall
In another window from your external machine ping the firewall with these options:
ping 57.35.5.10 ân 20 âw 4
Comment on the differences between the first rule:
Exercise 7
Restart ethereal on the firewall machine. Run with the options capture packets on âanyâ interface, update packets in real time, and automatic scrolling.
From your machine, ssh to 57.35.5.
Record these output in ethereal and comment on what you saw happen:
Exercise 8
Attempt to telnet from your machine to the firewall. Check /var/log/messages for these telnet attemps and record the output from the messages file. type tail /var/log/messages to see the end of the /var/log/messages file.
What did you see:
Exercise 9
Write down three rules that you think might be useful and explain what they do.
7.0 â Zone Alarm
7.1 Using Zone Alarm
Zone alarm is a firewall for the windows operating system. It is available for all versions of Microsoft Windows including Windows CE. You can read more about it at
www.zonelabs.com
It might be a very useful for protecting your home computer if you use Windows.
Acknowledgement: This lab was originally written by Terri Calderone, Varun Kanotra, Ed Paradise, and Edward Rowe Spring 2003.