Linux Firewall Builder - XML to IPtables Converter
Converts firewall definitions written in XML to an iptables based shell script suitable for Linux based firewall boxes.
Linux firewalls with large numbers of chains can quickly become unwieldly to maintain, especially if there are multiple firewalls containing common rulesets, which can lead to errors being introduced into the firewall's configuration.By writing the firewall definitions in XML these rules become much simpler to maintain and hopefully eliminate dangerous configuration errors.
This program reads an XML firewall definition file, parses it and then creates a Bourne shell script which is suitable for use as an init.d script, suitable for loading the filewall at system boot time.
The program MakeFW.pl requires XML::Parser,
it also uses these Perl modules:
These modules need to be accessible to MakeFW.pl so it usually enough to drop them in the same directory as the main program.
Refer to the DTD for details on the XML structure.
The firewall definition starts with a firewall element this has two
attributes host and file. The host attribute should be set to the
name of the machine on which the firewall is to be run. This ensures that the
wrong firewall file can not be loaded on to the wrong machine. The file
attribute defines the filename in which to store the generated firewall.
The include element can be used anywhere to include additional XML files,
for example, allowing common host and service definitions to be used in
several firewalls. Eg. <include file="hosts.xml">
The remainder of the file is made up of four sections:
hostgrp element allows IP addresses, hostnames and
network/netmask pairs to be grouped together for ease of use.
Eg.
<hostgrp name="myhosts"> myhost.mydomain.com 10.0.1.1 10.0.2.0/24 </hostgrp>
name: defines a human friendly name for the interface. The
name is also used in the generated rule chain names
in/out: defines whether rules on this interface are
associated with incoming or outgoing packets
tag: defines a name that can be used in the rule chain
definitions. Multiple interfaces can use the same tag
allowing the same rulesets to be applied quickly to
multiple interfaces.
broadcasts: setting this attribute to "deny" drops broadcast
packets immediately without passing them through the
rule chains. Setting this to "allow" permits broadcast
packets to enter the rule chains, for example in the
case of a DHCP server.
For example,
<interface name="dirty" in="eth0" tag="dirty" broadcasts="deny">
Port is a comma separated list of ports numbers or service names. A port range
is defined as lowport:highport where either lowport or highport may be
omitted to use the default lowest or highest ports.
For example,
<service name="web" port="http,https" proto="tcp"> <dst>wwwServers</dst> </service>
Group definitions are a flexible way to define complex service definitions, and can consist of a mixture of service definitions (without the name attribute), source and destination address definitions.
For example,
<group name="bootp"> <service proto="tcp" port="bootp"/> <service proto="udp" port="bootp"/> </group>
input and forward. These take
one attribute which is the tag of the interface to which the rules should be
applied. These elements should contain a services element which
lists the service or group names that are to be included in the chain.
For example,
<forward interface="public">
<services>
web
smtp
imap
</services>
</forward>
Class A (10.0.0.0/8)
Class B (172.16.0.0/12)
Class C (192.168.0.0/16)
Class D Multicast (224.0.0.0/4)
Class E Reserved (240.0.0.0/5)
Link Local (169.254.0.0/16)
However, if sites use these addresses for internal servers the enable
element can be used to prevent the specified address class being loaded into
the src-addr-check chain. For example, to prevent class_a addresses being
dropped use:
<enable>class_a</enable>
fastdrop attribute can be added to a firewall, service or
group element. When set to true this attribute causes packets to bypass
the firewall logging rule. This is achieved by dropping packets in the rule
chain rather than letting them fall through to the default policy.
ipforward attribute can be added
to a firewall element to disable IP forwarding. For example:
<firewall host="mymachine" file="example.fw" ipforward="disable"> ... </firewall>
The order attribute can be added to service definitions to optimise a
rules. For example:
<service name="example" proto="tcp" port="http" order="dst,src,svc"> <dst>host1</dst> <src>host2</src> </service>
physdev-in and physdev-out can be added to service
definitions to allow the use physical device matching. This is useful if the
firewall is to be used in conjunction with bridging where you need to know
where a packet came from.
For example:
<service name="example" proto="udp" port="67" physdev-in="eth0"/>
policy attribute can be
added to service definitions to specify the required policy options are
ACCEPT, DROP or REJECT.
MakeFW.pl [-n][-d] <file.xml>
-n : Resolves hostnames and port names to their numeric values.
-d : Dumps the internal data structure once file.xml has been
parsed without creating a shell script.
First time rule installation requires the script to be copied into the init.d directory and activating via chkconfig as outlined below:
cp firewall.fw /etc/rc.d/init.d/firewall
/sbin/chkconfig --add firewall
/etc/rc.d/init.d/firewall start
Subsequent rule installations only require the modified script to be copied into place an reloaded as outlines below:
cp firewall.fw /etc/rc.d/init.d/firewall
/etc/rc.d/init.d/firewall restart
The generated Bourne shell script has a number of Enablefeature definitions which can be used during troubleshooting. These can be used to prevent various features of the firewall being loaded at runtime.
The SilentDrop feature drops a number of packets before they get to the log
section. This was designed to prevent the firewall log being filled up with
broadcast traffic from NetBios, bootp/DHCP etc. This can be turned off by
EnableSilentDrop=0
Stephen Pillinger <S.M.Pillinger@cs.bham.ac.uk>
School of Computer Science,
The University of Birmingham, UK.
http://www.cs.bham.ac.uk/~smp
I've modulised the package so in theory the iptables module could be replaced with an ipfilter or ipfw module if necessary. Although I've not had (nor am I likely to get) the time to test this. I'm probably not going to get time to fix any major bugs or add any extra features.