Linux Firewall and Proxy Server - HOWTO (BitCity) (HOIM)
Linux Firewall and Proxy Server - HOWTO (BitCity) (HOIM)
Linux Firewall and Proxy Server - HOWTO (BitCity) (HOIM)
Table of Contents
Firewall and Proxy Server HOWTO................................................................................................................1 Mark Grennan, mark@grennan.com.......................................................................................................1 1.Introduction...........................................................................................................................................1 2.Understanding Firewalls.......................................................................................................................1 3.Firewall Architecture ...........................................................................................................................1 4.Setting up the Linux Filtering Firewall ................................................................................................1 5.Software requirements..........................................................................................................................2 6.Preparing the Linux system..................................................................................................................2 7.IP filtering setup (IPFWADM).............................................................................................................2 8.IP filtering setup (IPCHAINS).............................................................................................................2 . 9.Installing a Transparent SQUID proxy.................................................................................................2 10.Installing the TIS Proxy server...........................................................................................................2 11.The SOCKS Proxy Server..................................................................................................................2 12.Advanced Configurations...................................................................................................................3 13.Making Management Easy.................................................................................................................3 14.Defeating a Proxy Firewall.................................................................................................................3 15.APPENDEX A Example Scripts.....................................................................................................3 16.APPENDEX B An VPN RC Script for RedHat..............................................................................3 1.Introduction...........................................................................................................................................3 1.1 Feedback............................................................................................................................................3 1.2 Disclaimer .........................................................................................................................................4 1.3 Copyright...........................................................................................................................................4 1.4 My Reasons for Writing this..............................................................................................................4 1.5 Further Readings................................................................................................................................5 2.Understanding Firewalls.......................................................................................................................5 2.1 Firewall Politics.................................................................................................................................6 How it create a security policy...................................................................................................6 2.2 Types of Firewalls ..............................................................................................................................7 Packet Filtering Firewalls...........................................................................................................7 Proxy Servers..............................................................................................................................7 Application Proxy.......................................................................................................................8 SOCKS Proxy.............................................................................................................................8 3.Firewall Architecture ...........................................................................................................................8 3.1 Dialup Architecture.........................................................................................................................8 3.2 Single Router Architecture................................................................................................................9 3.3 Firewall with Proxy Server................................................................................................................9 3.4 Redundent Internet Configuration...................................................................................................10 4.Setting up the Linux Filtering Firewall ..............................................................................................10 4.1 Hardware requirements....................................................................................................................10 5.Software requirements........................................................................................................................11 5.1 Selecting a Kernel............................................................................................................................11 5.2 Selecting a proxy server...................................................................................................................11 6.Preparing the Linux system................................................................................................................12 6.1 Compiling the Kernel......................................................................................................................12 . 6.2 Configuring two network cards.......................................................................................................13 6.3 Configuring the Network Addresses ................................................................................................13 6.4 Testing your network.......................................................................................................................15 i
Table of Contents
6.5 Securing the Firewall.......................................................................................................................17 7.IP filtering setup (IPFWADM)...........................................................................................................17 8.IP filtering setup (IPCHAINS)...........................................................................................................19 . 9.Installing a Transparent SQUID proxy...............................................................................................21 10.Installing the TIS Proxy server.........................................................................................................21 10.1 Getting the software.......................................................................................................................21 10.2 Compiling the TIS FWTK.............................................................................................................22 10.3 Installing the TIS FWTK ..............................................................................................................22 10.4 Configuring the TIS FWTK...........................................................................................................22 The netpermtable file..............................................................................................................23 The /etc/services file.................................................................................................................26 11.The SOCKS Proxy Server................................................................................................................26 11.1 Setting up the Proxy Server...........................................................................................................26 11.2 Configuring the Proxy Server........................................................................................................27 The Access File .........................................................................................................................27 The Routing File.......................................................................................................................28 11.3 Working With a Proxy Server.......................................................................................................29 . Unix..........................................................................................................................................29 MS Windows with Trumpet Winsock......................................................................................29 Getting the Proxy Server to work with UDP Packets...............................................................29 11.4 Drawbacks with Proxy Servers......................................................................................................29 12.Advanced Configurations.................................................................................................................30 12.1 A large network with emphasis on security...................................................................................30 The Network Setup...................................................................................................................31 The Proxy Setup ........................................................................................................................31 13.Making Management Easy...............................................................................................................33 13.1 Firewall tools.................................................................................................................................33 13.2 General tools..................................................................................................................................33 ...............................................................................................................................................................34 15.APPENDEX A Example Scripts...................................................................................................34 15.1 RC Script useing GFCC.................................................................................................................34 15.2 GFCC script...................................................................................................................................36 15.3 RC Script without GFCC This is the firewall rules set built my hand. It does not use GFCC......37 16.APPENDEX B An VPN RC Script for RedHat............................................................................41
ii
This document is designed to describe the basics of firewall systems and give you some detail on setting up both a filtering and proxy firewall on a Linux based system. An HTML version of this document is available at http://www.grennan.com/FirewallHOWTO.html
1.Introduction
1.1 Feedback 1.2 Disclaimer 1.3 Copyright 1.4 My Reasons for Writing this 1.5 Further Readings
2.Understanding Firewalls
2.1 Firewall Politics 2.2 Types of Firewalls
3.Firewall Architecture
3.1 Dialup Architecture 3.2 Single Router Architecture 3.3 Firewall with Proxy Server 3.4 Redundent Internet Configuration
5.Software requirements
5.1 Selecting a Kernel 5.2 Selecting a proxy server
7.IP filtering setup (IPFWADM) 8.IP filtering setup (IPCHAINS) 9.Installing a Transparent SQUID proxy 10.Installing the TIS Proxy server
10.1 Getting the software 10.2 Compiling the TIS FWTK 10.3 Installing the TIS FWTK 10.4 Configuring the TIS FWTK
5.Software requirements
12.Advanced Configurations
12.1 A large network with emphasis on security
1.1 Feedback
Any feedback is very welcome. PLEASE REPORT ANY INACCURACIES IN THIS PAPER!!! I am human, and prone to making mistakes. If you find a fix for anything please send it to me. I will try to answer all email, but I am busy, so don't get insulted if I don't. 12.Advanced Configurations 3
1.2 Disclaimer
I AM NOT RESPONSIBLE FOR ANY DAMAGES INCURRED DUE TO ACTIONS TAKEN BASED ON THIS DOCUMENT. This document is meant as an introduction to how firewalls and proxy servers work. I am not, nor do I pretend to be, a security expert. ;) I am just some guy who has read too much and likes computers more than most people. Please, I am writing this to help people get acquainted with this subject, and I am not ready to stake my life on the accuracy of what is in here.
1.3 Copyright
Unless otherwise stated, Linux HOWTO documents are copyrighted by their respective authors. Linux HOWTO documents may be reproduced and distributed in whole or in part, in any medium physical or electronic, as long as this copyright notice is retained on all copies. Commercial redistribution is allowed and encouraged; however, the author would like to be notified of any such distributions. All translations, derivative works, or aggregate works incorporating any Linux HOWTO documents must be covered under this copyright notice. That is, you may not produce a derivative work from a HOWTO and impose additional restrictions on its distribution. Exceptions to these rules may be granted under certain conditions; please contact the Linux HOWTO coordinator. In short, we wish to promote dissemination of this information through as many channels as possible. However, we do wish to retain copyright on the HOWTO documents, and would like to be notified of any plans to redistribute the HOWTOs. If you have any questions, please email me. (See Above)
1.2 Disclaimer
2.Understanding Firewalls
A firewall is a structure intended to keep a fire from spreading. Building have firewalls made of brick walls completely dividing sections of the building. In a car a firewall is the metal wall separating the engine and passenger compartments. Internet firewalls are intended to keep the flames of Internet hell out of your private LAN. Or, to keep the members of your LAN pure and chaste by denying them access the all the evil Internet temptations. ;) The first computer firewall was a nonrouting Unix host with connections to two different networks. One network card connected to the Internet and the other to the private LAN. To reach the Internet from the private network, you had to logon to the firewall (Unix) server. You then used the resources of the system to access the Internet. For example, you could use Xwindows to run Netscape's browser on the firewall system and have the display on your work station. With the browser running on the firewall it has access to both networks. This sort of dual homed system (a system with two network connections) is great if you can TRUST ALL of your users. You can simple setup a Linux system and give an account accounts on it to everyone needing Internet access. With this setup, the only computer on your private network that knows anything about the outside world is the firewall. No one can download to their personal workstations. They must first download a file to the firewall and then download the file from the firewall to their workstation. BIG NOTE: 99% of all breakins start with gaining account level access on the system being attacked. Because of this I don't recommend this type of firewall. It is also very limiting.
1. to keep people (worms / crackers) out. 2. to keep people (employees / children) in. When I started working on firewalls I was surprised to learn the company I worked for were more interested in "spying" on their employees then keeping crackers out of their networks. At least in my state (Oklahoma) employers have the right to monitor phone calls and Internet activity as long as they inform the employees they are doing it. Big Brother is not government. Big Brother = Big Business. Don't get me wrong. People should work, not play at work. And I feel the work ethic has been eroding. However, I have also observed that management types are the biggest abusers of the rules they set. I have seen hourly workers reprimanded for using the Internet to looking for bus routesto get to work while the same manager used hours of work time looking for fine restaurants and nightclubs to take prospective customers. My fix for this type of abuse is to publish the firewall logs on a Web page for everyone to see. The security business can be scary. If you are the firewall manager, watch your back.
1. describe what you need to service 2. describe the group of people you need to service 3. describe which service each group needs access to 4. for each service group describe how the service should be keep secure 5. write a statment making all other forms of access a vialation Your policy will become more complicated with time but don't try to cover to much ground now. Make it simple and clear.
1. Filtering Firewalls that block selected network packets. 2. Proxy Servers (sometimes called firewalls) that make network connections for you.
Proxy Servers
Proxies are mostly used to control, or monitor, outbound traffic. Some application proxies cache the requested data. This lowers bandwidth requirements and decreases the access the same data for the next user. It also gives unquestionable evidence of what was transferred. There are two types of proxy servers. 1. Application Proxies that do the work for you. 2. SOCKS Proxies that cross wire ports.
Application Proxy
The best example is a person telneting to another computer and then telneting from there to the outside world. With a application proxy server the process is automated. As you telnet to the outside world the client send you to the proxy first. The proxy then connects to the server you requested (the outside world) and returns the data to you. Because proxy servers are handling all the communications, they can log everything they (you) do. For HTTP (web) proxies this includes very URL they you see. For FTP proxies this includes every file you download. They can even filter out "inappropriate" words from the sites you visit or scan for viruses. Application proxy servers can authenticate users. Before a connection to the outside is made, the server can ask the user to login first. To a web user this would make every site look like it required a login.
SOCKS Proxy
A SOCKS server is a lot like an old switch board. It simply cross wires your connection through the system to another outside connection. Most SOCKS server only work with TCP type connections. And like filtering firewalls they don't provide for user authentication. They can however record where each user connected to.
3.Firewall Architecture
There are lots of ways to structure your network to protect your systems using a firewall. If you have a dedicated connections to the Internet through a router, you could plug the router directly into your firewall system. Or, you could go through a hub to provide for full access servers outside your firewall.
Application Proxy
You can put the proxy server on your LAN as will. In this case the firewall should have rules to only allow the proxy server to connect to the Internet for the services it is providing. This way the users can get to the Internet only through the proxy.
__________ _/\__/\_ | | _______________ | | | Firewall | (LAN) | | / Internet \| System |(HUB)| Workstation/s | \_ _ _ _/ |__________| | |_______________| \/ \/ \/ | ______________ | | | +| Proxy Server | |______________|
It is easy to let your network get out of hand. Keep control of every connection. It only takes a user with a modem to compromise your LAN.
1. a 486DX66 with 32 meg of memory 2. a 250m hard disk (500 recommended) 3. network connections (LAN Cards, Serial Ports, Wireless?) 4. monitor and keyboard With some systems by using a serial port console, you can even eliminate the monitor and keyboard. If you need a proxy server that will handle lots of traffic, you should get the largest system you can afford. This is because for every user that connects to the system it will be creating another process. If you will have 3.4 Redundent Internet Configuration 10
Firewall and Proxy Server HOWTO 50 or more concurrent users I'm guessing you will need:
1. a Pentium II with 64meg of memory 2. a two gig hard disk to store all the logs 3. two network connections 4. monitor and keyboard The network connections can be any type (NIC cards, ISDN, even modems).
Squid is a great package and works with Linux's Transparent Proxy feature. I will be describing how to setup this server. AT the time of this writing, Network Associates and Trusted Information System's (TIS) , have merged. So keep watching their web sites for more information about changes. Mean while, the Tool Kit can still be had at. http://www.tis.com/research/software/ 5.Software requirements 11
Firewall and Proxy Server HOWTO Trusted Information System put out a collection of programs designed to facilitate firewalling. With this toolkit, you set up one daemon for each service (WWW, telnet ect.) you will be using.
12
The IPX protocol Appletalk DDP CCITT X.25 Packet Layer (EXPERIMENTAL) LAPB Data Link Driver (EXPERIMENTAL) Bridging (EXPERIMENTAL) 802.2 LLC (EXPERIMENTAL) Acorn Econet/AUN protocols (EXPERIMENTAL) WAN router Fast switching (read help!) Forwarding between high speed interfaces PU is too slow to handle full bandwidth and/or fair queueing >
After making all the setting you need you should recompile, reinstall the kernel and reboot. I use the command: make dep;make clean;make bzlilo;make modules;make modules_install;init 6 to accomplish all of this in one step.
append="ether=12,0x300,eth0 ether=15,0x340,eth1"
1. Will you use Real IP number or Make some up for your LAN. 6.2 Configuring two network cards 13
Firewall and Proxy Server HOWTO 2. Will your ISP assign the number or will you be using static IP numbers? Since you don't want the internet to have access to your private network, you don't need to use "real addresses". You could just makeup addresses for your private LAN. But this is not recommended. If data gets routed out of your LAN, it might end up at another systems port. There are a number of Internet address ranges set aside for private networks. Of these, 192.168.1.xxx, is set aside and we will use it in our examples. You will need to use IP masquerading to make this happen. With this process the firewall will forward packets and translate them into "REAL " " IP address to travel on the Internet. Using these nonroutable IP address makes your network is more secure. Internet routers will not pass packets with these addresses. You may want to read the IP Masquerading HOWTO at this point.
24.94.1.123 __________ 192.168.1.1 _/\__/\_ \ | | / _______________ | | \| Firewall |/ | | / Internet \| System || Workstation/s | \_ _ _ _/ |__________| |_______________| \/ \/ \/
You must have a "real" IP address to assign to your Internet network card. This address can be permanently assigned to you. (A static IP address) or it can be assigned at network connect time by the PPP process. You assign your inside IP numbers. Like 192.168.1.1 to the LAN card. This will be your gateway IP address. You can assign all the other machines in the protected network (LAN) a number in the 192.168.1.xxx range. (192.168.1.2 through 192.168.1.254) I use RedHat Linux. To configure the network at boot time I added a ifcfgeth1 file in the /etc/sysconfig/networkscripts directory. You may also find a ifcfgppp0 or ifcfgtr0 in this directory. These 'ifcfg' files are used by RedHat to configure and enable your network devices at boot time. The are named after the connection type. Here is the ifcfgeth1 (second ehternet card) for our example;
DEVICE=eth1 IPADDR=192.168.1.1 NETMASK=255.255.255.0 NETWORK=192.168.1.0 BROADCAST=192.168.1.255 GATEWAY=24.94.1.123 ONBOOT=yes
If you are going to use a dialup connection you will need to look at the ifcfgppp0 and the chatppp0 file. These control your PPP connection. This ifcfg file might look like;
14
eth1
15
Flags U U U UG
Note: 24.94.1.0 is the Internet side of this firewall and 192.168.1.0 is the private (LAN) side. You should start by making sure every computer on your LAN can ping the inside address of your firewall system. (192.168.1.1 in this example) If not, go over the NET2 HOWTO again and work on the network some more. Next, from the firewall, try to ping a Internet system. I use www.internic.net as my test point. If it doesn't work, try a server at your ISP. If this doesn't work some part of your Internet connection is wrong. You should be able to connect to the anywhere on the Internet from the firewall. Try looking at your default gateway setting. If you are using a dialup connection double check your user ID and Password. Reread the Net2 HOWTO, and try again. Now try to ping the outside address of the firewall (24.94.1.123) from a computer on your LAN. This shouldn't work. If it does, you have masquerading or IP Forwarding turned on, or you already have some packet filtering set. Turn them off and try again. You need to know the filtering is in place. For kernels newer then 2.1.102 you can issue the command;
echo "0" > /proc/sys/net/ipv4/ip_forward
If you are using an older kernel (WHY) you will need to recompile your kernel with forwarding turned off. (Just upgrade.) Try pinging the outside address of the firewall (24.94.1.123) again. It shouldn't work. Now turn on IP forwarding and/or masquerading. You should be able to ping the anywhere on the Internet from any system on your LAN.
echo "1" > /proc/sys/net/ipv4/ip_forward
BIG NOTE: If you are using "REAL" IP addresses on your LAN (not 192.168.1.*) and you can't ping the internet but you CAN ping the Internet side of your firewall, make sure your ISP is routing packets for your private network address. A test for this problem is to have someone else on the Internet (say a friend using a local provider) use traceroute to your network. If the trace stops at your providers router, then they are not forwarding your traffic. It works? Great. The hard part is done. :)
16
17
Now we have the ultimate firewall. Nothing can get through. Now create the file /etc/rc.d/rc.firewall. This script should allow email, Web and DNS traffic through. ;)
#! /bin/sh # # rc.firewall # # Source function library. . /etc/rc.d/init.d/functions # Get config. . /etc/sysconfig/network # Check that networking is up. if [ ${NETWORKING} = "no" ] then exit 0 fi case "$1" in start) echo n "Starting Firewall Services: " # Allow email to got to the server /sbin/ipfwadm F a accept b P tcp S 0.0.0.0/0 1024:65535 D 192.1.2.10 25 # Allow email connections to outside email servers /sbin/ipfwadm F a accept b P tcp S 192.1.2.10 25 D 0.0.0.0/0 1024:65535 # Allow Web connections to your Web Server /sbin/ipfwadm F a accept b P tcp S 0.0.0.0/0 1024:65535 D 192.1.2.11 80 # Allow Web connections to outside Web Server /sbin/ipfwadm F a accept b P tcp S 192.1.2.* 80 D 0.0.0.0/0 1024:65535 # Allow DNS traffic /sbin/ipfwadm F a accept b P udp S 0.0.0.0/0 53 D 192.1.2.0/24 ;; stop) echo n "Stooping Firewall Services: " ipfwadm F p deny ;; status) echo n "Now do you show firewall stats?" ;; restart|reload) $0 stop $0 start ;; *) echo "Usage: firewall {start|stop|status|restart|reload}" exit 1 esac
18
Firewall and Proxy Server HOWTO NOTE: In this example we have the email (smtp) server running at 192.1.2.10 that must be able to send and receive on port 25. The web server running at 192.1.2.11. We are allowing anyone on the LAN to get to outside web and DNS servers. This is not perfectly secure. Because port 80 doesn't have to used as a web port, a smart hacker might use this port to create a virtual private network (VPN) through the firewall. The way around this is to setup a web proxy. and only allow the proxy through the firewall. Users on the LAN will have to go through the proxy to get to outside web servers. You might also be interested in accounting for traffic going through your firewall. This script will count ever packet. You could add a line or two to account for packets going to just a single system.
# Flush the current accounting rules ipfwadm A f # Accounting /sbin/ipfwadm A f /sbin/ipfwadm A out i S 192.1.2.0/24 D 0.0.0.0/0 /sbin/ipfwadm A out i S 0.0.0.0/0 D 192.1.2.0/24 /sbin/ipfwadm A in i S 192.1.2.0/24 D 0.0.0.0/0 /sbin/ipfwadm A in i S 0.0.0.0/0 D 192.1.2.0/24
If all you need is a filtering firewall you can stop here. Test it and Enjoy.
Firewall and Proxy Server HOWTO 2. Delete an empty chain (X). 3. Change the policy for a builtin chain. (P). 4. List the rules in a chain (L). 5. Flush the rules out of a chain (F). 6. Zero the packet and byte counters on all rules in a chain (Z). There are several ways to manipulate rules inside a chain:
1. Append a new rule to a chain (A). 2. Insert a new rule at some position in a chain (I). 3. Replace a rule at some position in a chain (R). 4. Delete a rule at some position in a chain (D). 5. Delete the first rule that matches in a chain (D). There are a few operations for masquerading, which are in ipchains for want of a good place to put them:
1. List the currently masqueraded connections (M L). 2. Set masquerading timeout values (M S). There are some timing issues involved in altering firewall rules. If you are not careful, you can let packets through while you are halfway through your changes. A simplistic approach is to do the following:
# ipchains I input 1 j DENY # ipchains I output 1 j DENY # ipchains I forward 1 j DENY
This drops all packets for the duration of the changes. Here a duplicate of the above firewall rules in IPChains.
#!/bin/sh # # rc.firewall # ## Flush everything, start from scratch /sbin/ipchains F input /sbin/ipchains F output /sbin/ipchains F forward ## Redirect for HTTP Transparent Proxy #$IPCHAINS A input p tcp s 192.1.2.0/24 d 0.0.0.0/0 80 j REDIRECT 8080 ## Create your own chain
20
Don't stop here. This is not a great firewall and I'm sure you have other services you will be providing. Again, read the IPCHAINSHOWTO.
Firewall and Proxy Server HOWTO send email to [email protected] with only the word accepted in the body of the message to learn the name of this hidden directory. No subject is needed in the message. Their system will then mails you back the directory name (good for 12 hours) to download the source. As of this writing, the current version of FWTK is 2.1.
/etc/services Tells the system what ports a services is on. /etc/inetd.conf Tells inetd what program to call when someone knocks on a service port. /usr/local/etc/netpermtable
22
Firewall and Proxy Server HOWTO Tells the FWTK services who to allow and deny service to.
To get the FWTK functioning, you should edit these files from the bottom up. Editing the services file without the inetd.conf or netpermtable file set correctly could make your system inaccessible.
To initialize the database, su to root, and run ./authsrv in the /var/local/etc directory to create the administrative user record. Here is a sample session. Read the FWTK documentation to learn how to add users and groups.
# # authsrv authsrv# list authsrv# adduser admin "Auth DB admin" ok user added initially disabled authsrv# ena admin enabled authsrv# proto admin pass changed authsrv# pass admin "plugh" Password changed. authsrv# superwiz admin set wizard authsrv# list Report for users in database user group longname ok?
proto
last
23
The telnet gateway (tngw) controls are straight forward and the first you should set up. In my example, I permit host from inside the private network to pass through without authenticating themselves. (permithosts 19961.2.* passok) But, any other user must enter their user ID and password to use the proxy. (permithosts * auth) I also allow one other system (192.1.2.202) to access the firewall directly without going through the firewall at all. The two inetaclin.telnetd lines do this. I will explain how these lines are called latter. The Telnet timeout should be keep short.
# telnet gateway rules: tngw: denialmsg /usr/local/etc/tndeny.txt tngw: welcomemsg /usr/local/etc/tnwelcome.txt tngw: helpmsg /usr/local/etc/tnhelp.txt tngw: timeout 90 tngw: permithosts 192.1.2.* passok xok tngw: permithosts * auth # Only the Administrator can telnet directly to the Firewall via Port 24 netaclin.telnetd: permithosts 192.1.2.202 exec /usr/sbin/in.telnetd
You shouldn't have anyone accessing your firewall directly and that includes FTP so don't put an FTP, server on you firewall. Again, the permithosts line allows anyone in the protected network free access to the Internet and all others must authenticate themselves. I included logging of every file sent and received to my controls. (log { retr stor }) The ftp timeout controls how long it will take to drop a bad connections as well as how long a connection will stay open with out activity.
24
denialmsg /usr/local/etc/ftpdeny.txt welcomemsg /usr/local/etc/ftpwelcome.txt helpmsg /usr/local/etc/ftphelp.txt timeout 300 permithosts 192.1.2.* log { retr stor } permithosts * authall log { retr stor }
Web, gopher and browser based ftp are contorted by the httpgw. The first two lines create a directory to store ftp and web documents as they are passing through the firewall. I make these files owned by root and put the in a directory accessible only by root. The Web connection should be kept short. It controls how long the user will wait on a bad connections.
# www and gopher gateway rules: httpgw: userid root httpgw: directory /jail httpgw: timeout 90 httpgw: defaulthttpd www.afs.net httpgw: hosts 192.1.2.* log { read write ftp } httpgw: denyhosts *
The sslgw is really just a pass anything gateway. Be carefully with it. In this example I allow anyone inside the protected network to connect to any server outside the network except the addresses 127.0.0.* and 192.1.1.* and then only on ports 443 through 563. Ports 443 through 563 are known SSL ports.
# ssl gateway rules: sslgw: timeout 300 sslgw: hosts sslgw: denyhosts
Here is an example of how to use the pluggw to allow connections to a news server. In this example I allow anyone inside the protected network to connect to only one system and only to it's news port. The seconded line allows the news server to pass its data back to the protected network. Because most clients expect to stay connected while the user read news, the timeout for a news server should be long.
# NetNews Pluged gateway pluggw: timeout 3600 pluggw: port nntp 192.1.2.* plugto 24.94.1.22 port nntp pluggw: port nntp 24.94.1.22 plugto 192.1.2.* port nntp
The finger gateway is simple. Anyone inside the protected network must login first and then we allow them to use the finger program on the firewall. Anyone else just gets a message.
# Enable finger service netaclfingerd: permithosts 192.1.2.* exec /usr/libexec/fingerd netaclfingerd: permithosts * exec /bin/cat /usr/local/etc/finger.txt
25
Firewall and Proxy Server HOWTO I haven't setup the Mail and Xwindows services so I'm not including examples. If anyone has a working example, please send me email.
ident
26
it will permit only the IP address that matches every bit in 192.168.1.23, eg, only 192.168.1.3. The line:
permit 192.168.1.0 255.255.255.0
will permit every number within group 192.168.1.0 through 192.168.1.255, the whole C Class domain. One should not have the line:
permit 192.168.1.0 0.0.0.0
as this will permit every address, regardless. So, first permit every address you want to permit, and then deny the rest. To allow everyone in the domain 192.168.1.xxx, the lines:
permit 192.168.1.0 255.255.255.0 deny 0.0.0.0 0.0.0.0
will work nicely. Notice the first "0.0.0.0" in the deny line. With a modifier of 0.0.0.0, the IP address field does not matter. All 0's is the norm because it is easy to type. 11.2 Configuring the Proxy Server 27
Firewall and Proxy Server HOWTO More than one entry of each is allowed. Specific users can also be granted or denied access. This is done via ident authentication. Not all systems support ident, including Trumpet Winsock, so I will not go into it here. The documentation with socks is quite adequate on this subject.
deny direct sockd Deny tells SOCKS when to reject a request. This entry has the same three fields as in sockd.conf, identifier, address and modifier. Generally, since this is also handled by sockd.conf, the access file, the modifier field is set to 0.0.0.0. If you want to preclude yourself from calling any place, you can do it here. The direct entry tells which addresses to not use socks for. These are all the addresses that can be reached without the proxy server. Again we have the three fields, identifier, address and modifier. Our example would have
direct 192.168.1.0 255.255.255.0
Thus going direct for any on our protected network. The sockd entry tells the computer which host has the socks server daemon on it. The syntax is:
sockd @=<serverlist> <IP address> <modifier>
Notice the @= entry. This allows you to set the IP addresses of a list of proxy servers. In our example, we only use one proxy server. But, you can have many to allow a greater load and for redundancy in case of failure. The IP address and modifier fields work just like in the other examples. You specify which addresses go where through these. 6.2.3. DNS from behind a Firewall Setting up Domain Name service from behind a firewall is a relatively simple task. You need merely to set up the DNS on the firewalling machine. Then, set each machine behind the firewall to use this DNS.
28
29
Firewall and Proxy Server HOWTO Your daughter goes to college. You want to email her. You have some private things to talk about, and would rather have your mail sent directly to your machine. You trust your systems administrator completely, but still, this is private mail. The inability to use UDP packets represents a big drawback with the proxy servers. I imagine UDP capabilities will be coming shortly. FTP causes another problem with a proxy server. When getting or doing an ls, the FTP server opens a socket on the client machine and sends the information through it. A proxy server will not allow this, so FTP doesn't particularly work. And, proxy servers run slow. Because of the greater overhead, almost any other means of getting this access will be faster. Basically, if you have the IP addresses, and you are not worried about security, do not use a firewall and/or proxy servers. If you do not have the IP addresses, but you are also not worried about security, you might also want to look into using an IP emulator, like Term, Slirp or TIA. Term is available from ftp://sunsite.unc.edu, Slirp is available from ftp://blitzen.canberra.edu.au/pub/slirp, and TIA is available from marketplace.com. These packages will run faster, allow better connections, and provide a greater level of access to the inside network from the internet. Proxy servers are good for those networks which have a lot of hosts that will want to connect to the internet on the fly, with one setup and little work after that.
12.Advanced Configurations
There is one configuration I would like to go over before wrapping this document up. The one I have just outlined will probably suffice for most people. However, I think the next outline will show a more advanced configuration that can clear up some questions. If you have questions beyond what I have just covered, or are just interested in the versatility of proxy servers and firewalls, read on.
1. The external level. This is the level that gets shown to everybody. This is where you rant and rave to get new volunteers. 2. Troop This is the level of people who have gotten beyond the external level. Here is where you teach them about the evail government and how to make bombs. 3. Mercenary Here is where the real plans are keep. In this level is stored all the information on how the 3rd world government is going to take over the world, your plans involving Newt Gingrich, 12.Advanced Configurations 30
Firewall and Proxy Server HOWTO Oklahoma City, lown care products and what really is stored in that hangers at area 51.
1 number is 192.168.1.255, which is the broadcast address and is not usable. 23 of the 32 IP addresses are allocated to 23 machines that will be accessible to the internet. 1 extra IP goes to a Linux box on that network 1 extra goes to a different Linux box on that network. 2 IP #'s go to the router 4 are left over, but given domain names paul, ringo, john, and george, just to confuse things a bit. The protected networks both have the addresses 192.168.1.xxx Then, two separate networks are built, each in different rooms. They are routed via infrared Ethernet so that they are completely invisible to the outside room. Luckily, infrared ethernet works just like normal ethernet. These networks are each connected to one of the Linux boxes with an extra IP address. There is a file server connecting the two protected networks. This is because the plans for taking over the world involves some of the higher Troops. The file server holds the address 192.168.1.17 for the Troop network and 192.168.1.23 for the Mercenary network. It has to have different IP addresses because it has to have different Ethernet cards. IP Forwarding on it is turned off. IP Forwarding on both Linux boxes is also turned off. The router will not forward packets destined for 192.168.1.xxx unless explicitly told to do so, so the internet will not be able to get in. The reason for turning off IP Forwarding here is so that packets from the Troop's network will not be able to reach the Mercenary network, and vica versa. The NFS server can also be set to offer different files to the different networks. This can come in handy, and a little trickery with symbolic links can make it so that the common files can be shared with all. Using this setup and another ethernet card can offer this one file server for all three networks.
1. No one can use the file server for internet access. This exposes the file server to viruses and other nasty things, and it is rather important, so its off limits. The Network Setup 31
Firewall and Proxy Server HOWTO 2. We will not allow troop access to the World Wide Web. They are in training, and this kind of information retrieval power might prove to be damaging. So, the sockd.conf file on the Troop's Linux box will have this line:
deny 192.168.1.17 255.255.255.255
This says to deny access to all machines trying to access the port equal (eq) to 80, the http port. This will still allow all other services, just deny Web access. Then, both files will have:
permit 192.168.1.0 255.255.255.0
to allow all the computers on the 192.168.1.xxx network to use this proxy server except for those that have already been denied (ie. The file server and Web access from the Troop network).
This should configure everything correctly. Each network is isolated accordingly, with the proper amount of interaction. Everyone should be happy.
32
httptunnel. httptunnel creates a bidirectional virtual data path tunnelled in HTTP requests. The HTTP requests 13.Making Management Easy 33
Firewall and Proxy Server HOWTO can be sent via an HTTP proxy if so desired. Or, on their system they install a Virtual Private Network (vpn). See: http://sunsite.auc.dk/vpnd/ Or, Maybe this user simply puts a modem on their NT system and turns on routing. Finally, on the workstation, on the private LAN, change the default gateway to point to the new route to the Internet. Now, from this workstation, you can go anywhere. The only thing the firewall admin might see is one connect with nowill see is a really long DNS lookup. Now, take over the world!
34
35
localnet="192.168.1.0/24" firewallhost="192.168.1.1/32" localhost="172.0.0.0/8" DNS1="24.94.163.119/32" DNS2="24.94.163.124/32" Broadcast="255.255.255.255/32" Multicast="224.0.0.0/8" Any="0.0.0.0/0" mail_grennan_com="192.168.1.1/32" mark_grennan_com="192.168.1.3/32" $IPCHAINS P input DENY $IPCHAINS P forward ACCEPT $IPCHAINS P output ACCEPT $IPCHAINS F $IPCHAINS X # input rules $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input $IPCHAINS A input
s p p p p p p s s s s p p p p p p p p p p p s
$Any d $Broadcast j DENY udp s $Any d $Any netbiosns j DENY tcp s $Any d $Any netbiosns j DENY udp s $Any d $Any netbiosdgm j DENY tcp s $Any d $Any netbiosdgm j DENY udp s $Any d $Any bootps j DENY udp s $Any d $Any bootpc j DENY $Multicast d $Any j DENY $localhost d $Any i lo j ACCEPT $localnet d $Any i eth1 j ACCEPT $localnet d $Broadcast i eth1 j ACCEPT icmp s $Any d $Any j ACCEPT tcp s $Any d $Any j ACCEPT ! y udp s $DNS1 domain d $Any 1023:65535 j ACCEPT udp s $DNS2 domain d $Any 1023:65535 j ACCEPT tcp s $Any d $Any ssh j ACCEPT tcp s $Any d $Any telnet j ACCEPT tcp s $Any d $Any smtp j ACCEPT tcp s $Any d $Any pop3 j ACCEPT tcp s $Any d $Any auth j ACCEPT tcp s $Any d $Any www j ACCEPT tcp s $Any d $Any ftp j ACCEPT $Any d $Any j DENY l
36
15.3 RC Script without GFCC This is the firewall rules set built my hand. It does not use GFCC.
#!/bin/bash # # Firewall Script Version 0.9.0 # chkconfig: 2345 09 99 # description: firewall script for 2.2.x kernel # Set for testing # set x # # NOTES: # # This script is written for RedHat 6.0 or better. # # This firewall script should work for most routers, dialup or cable modem. # It was written for RedHat distributions. # # Be careful about offering public services like web or ftp servers. # # INSTALLATION: # 1. This file planned for a RedHat system. It would work # on other distro's with perhaps no modification, but again... # Who knows?!!? These instructions apply to RedHat systems. # # 2. place this file in /etc/rc.d/init.d (you'll have to be root..) # call it something like "firewall" :) # make it root owned > "chown root.root <filename>" # make it executable > "chmod 755 <filename>" # # 3. set the values for your network, internal interface, and DNS servers # uncomment lines further down to enable optional inbound services # make sure "eth0" is your internal NIC (or change the value below) # test it > "/etc/rc.d/init.d/<filename> start" # you can list the rules > "ipchains L n" # fix anything that broke... :) # # 4. add the firewall to the RH init structure > "chkconfig add <filename>" # next time the router boots, things should happen automagically! # sleep better at night knowing you are *LESS* vulnerable than before... # # RELEASE NOTES # 20 July, 1999 initial writing Anthony Ball <[email protected]> # 11 Dec, 1999 updated by Mark Grennan <[email protected]> # ################################################ # Fill in the values below to match your # local network. PRIVATENET=xxx.xxx.xxx.xxx/xx PUBLIC=ppp0 PRIVATE=eth0 # your dns servers
15.3 RC Script without GFCC This is the firewall rules set built my hand. It does not use GFCC.
37
15.3 RC Script without GFCC This is the firewall rules set built my hand. It does not use GFCC.
38
15.3 RC Script without GFCC This is the firewall rules set built my hand. It does not use GFCC.
39
# uncomment to allow HTTP in (only if you run a web server on the router) /sbin/ipchains A input p tcp d $ANY http j ACCEPT # uncomment to allow FTP in /sbin/ipchains A input p tcp d $ANY ftp j ACCEPT ## ## Masquerading stuff ## # masquerade packets forwarded from internal network /sbin/ipchains A forward s $PRIVATENET d $ANY j MASQ ## ## deny EVERYthing else and log them to /var/log/messages ## /sbin/ipchains A input l j DENY # Remove the Plug /sbin/ipchains D input 1 ;; stop) action "Stoping firewall: " /bin/true echo 0 > /proc/sys/net/ipv4/ip_forward /sbin/ipchains F input /sbin/ipchains F output /sbin/ipchains F forward echo ;; restart) action "Restarting firewall: " /bin/true $0 stop $0 start echo ;; status) # List out settings /sbin/ipchains L ;; test) ## ## This is about as simple as it gets ## (This is not secure AT ALL) action "WARNING Test Firewall: " /bin/true /sbin/ipchains F input /sbin/ipchains F output /sbin/ipchains F forward echo 1 > /proc/sys/net/ipv4/ip_forward /sbin/ipchains A input j ACCEPT /sbin/ipchains A output j ACCEPT /sbin/ipchains P forward DENY /sbin/ipchains A forward i $PUBLIC j MASQ echo ;;
15.3 RC Script without GFCC This is the firewall rules set built my hand. It does not use GFCC.
40
vpnd: "
&& rm f /var/lock/subsys/vpnd
41
42