Series: Security
Author: James Blackmore.
This was a graduate project, supervised by Bob Eager
Homepage: http://www.tavi.co.uk/os2pages/
 

Firewalling with TCPIP


Introduction

The OS/2 Warp Server TCP/IP V4.21 stack includes Virtual Private Network (VPN) capability.

The actual implementation is based on the IP Security Architecture (IPSec) framework, which provides security at the network layer.

While most of the VPN functionality of IPSec is not of particular interest here, its packet filtering capabilities are, as these allow it to be used as a firewall on a multi-homed host.

IPSec consists of four device drivers (only two of which are essential here) and a number of configuration utilities, which will be looked at in the next section.


Basic Configuration

The author has provided the Firestarter utility - an OS/2 REXX program - that will take the user through basic configuration of the firewall.

Please read the disclaimer first

Download Firestarter here

To run Firestarter, open an OS/2 window and type firestarter at the command prompt.

Alternatively, to manually configure the firewall, complete the 5 steps outlined below:

  1. Check your CONFIG.SYS file for the following lines and add them if they are not present (the drive letter will be whichever drive you are running OS/2 on):

    DEVICE=C:\MPTN\PROTOCOL\FWIP.SYS

    DEVICE=C:\MPTN\PROTOCOL\IPSEC.SYS

    (Note: FWIP.SYS is the filter driver device from IPSec. IPSEC.SYS provides the framework for IPSec, and in this context is only needed to implement packet logging.)

    [Editor:- if you have mislaid the necessary files, get them here - these are from an Aurora beta installation]

  2. Create the following configuration file:

    \MPTN\ETC\FWSECAD.CNF

    List the IP addresses (in dotted decimal form) of any interfaces you want to be secure in this file, one per line. Any interfaces not listed will be non-secure.

  3. Create the following configuration file (you will probably need to create the SECURITY sub-directory first):

    \MPTN\ETC\SECURITY\FWFILTRS.CNF

    This file is the firewall filter rules list.
    It is not necessary to enter any rules at this stage, as they will be explained later.

  4. Reboot your computer, to allow the changes to update. You must do this, otherwise the next step will not work.

  5. Open an OS/2 window and, at the command prompt, type the following command:

    cfgfilt -u -i

    This activates the filter support code. It also switches the firewall on, by automatically issuing the inetcfg -s firewall 1 command.

    To find out more about cfgfilt go here
    To find out more about inetcfg go here

blustar image Basic configuration is now complete.
The firewall should be up and running and blocking all traffic.


Filter Rule Definition

There are 2 freely available utilities that can be used to define and administer the firewall's filter rules.

They are both GUI-based applications that run on the desktop, and provide a good way to keep track of the firewall's configuration.

It is of course possible to manually configure the firewall rules.

To do so, complete the following 3 steps:


  1. Open \MPTN\ETC\SECURITY\FWFILTRS.CNF in an editor.

    For the format of the rules go here

    Rules are entered one per line, with a single space between each field.


  2. When you have finished entering rules and have saved the configuration, open an OS/2 window and type the following command:

    cfgfilt -u

    This will update the filter rules. If any of your rules use logging, you will need to include the -d flag on the above command.


  3. To check that your rules are correct, run cfgfilt with no parameters. The rules should now all be listed and numbered.

blustar image Notice that the last rule in the list is always the firewall's default 'deny all packets' rule.
To find out more about how FWIP.SYS operates go here


Example Rules

The information on this page shows how to configure rules for Telnet on the firewall.

Scenario: Telnet
Description: Allows remote login across a network
Port Number:23
Actions Required: Permit Telnet from secure hosts to non-secure hosts
Deny Telnet from non-secure hosts to secure hosts


Rules: permit sh.sh.sh.sh. m.m.m.m sf.sf.sf.sf. m.m.m.m tcp gt 1023 eq 23 secure local inbound
(permits any secure host to Telnet the firewall's secure interface)
permit sf.sf.sf.sf m.m.m.m sh.sh.sh.sh. m.m.m.m tcp/ack eq 23 gt 1023 secure local outbound
(permits the firewall's secure interface to Telnet ACK any secure host)
permit nf.nf.nf.nf m.m.m.m nh.nh.nh.nh m.m.m.m tcp gt 1023 eq 23 non-secure local outbound
(permits the firewall's non-secure interface to Telnet any non-secure host)
permit nh.nh.nh.nh m.m.m.m nf.nf.nf.nf m.m.m.m tcp/ack eq 23 gt 1023 non-secure local inbound
(permits any non-secure host to Telnet ACK the firewall's non-secure interface)
deny nh.nh.nh.nh m.m.m.m nf.nf.nf.nf m.m.m.m tcp gt 1023 eq 23 non-secure local inbound
(denies Telnet from any non-secure host to the firewall's non-secure interface)


sh.sh.sh.sh = any secure host IP address
sf.sf.sf.sf = firewall's secure interface IP address
nf.nf.nf.nf = firewall's non-secure interface IP address
nh.nh.nh.nh = any non-secure host IP address
m.m.m.m = address mask
(Note: All IP addresses must be specified in dotted decimal format, e.g. 192.168.42.50)


Packet Logging

IPSec on OS/2 Warp Server supports packet logging.

To configure packet logging, complete the following 5 steps.


  1. Create the following file:

    \MPTN\ETC\FWLOG.CNF

    This is the firewall log configuration file, where the level of packet logging is defined.
    The file contains a single line, of the form:

    level=(value)

    where the value parameter can be one of the following:

    10(Debug -All messages are logged)
    20(Informational -Information, warning, error and alert messages are logged)
    30(Warning -Warning, error and alert messages are logged)
    40(Errors -Error and alert messages are logged)
    50(Alert -Only alert messages are logged)

    so to log all packets, enter the line:

    level=10

  2. Open an OS/2 window and type the following command:

    fssd

    This runs the packet filter syslog daemon. A log file with today's date will be created in \MPTN\ETC. For example:

    fw0824

    would be the name of the file created on the 24th of August. The file will now be open.

  3. Open \MPTN\ETC\SECURITY\FWFILTRS.CNF in an editor and add:

    l=y

    to the end of any rules that need to be logged.

  4. Open another OS/2 window (you will need to, as fssd will still be running) and type:

    cfgfilt -u -d

    This updates the filter rules and enables packet logging. You should notice this being added to the log file in the other window.

  5. To view the log file, change to the \MPTN\ETC directory and type:

    fwlslog file=(filename)

    where the filename parameter is the name of the log file. This is the only way to access the log file while it is still running.

    So to continue the example from above, type:

    fwlslog file=fw0824


blustar image Any packets that match the rules with logging enabled will now be logged.
(Default = denied packets are logged, permitted packets are not logged)


Appendices


cfgfilt

Typing cfgfilt, without any parameters, runs the Packet Filter Rules Dump Facility.

This provides a summary of the firewall's current configuration.

To see an example of what should appear on your screen, go here

After basic configuration, any secure interfaces should now be listed and the status of the filter support code should be 'active'.

Rule 1 is the firewall's default rule (it is always present as the last rule in the list). It blocks all traffic through the firewall. Having this as default (and setting individual 'permit' rules to allow specific services) is the safest possible configuration.

The following table summarises the possible parameters for cfgfilt:

-u update filter rules
-i initialise filter device (must use with -u)
-f (file) check a set of rules (default is \MPTN\ETC\SECURITY\FWFILTRS.CNF)
-c deactivate filters and use default rules
-d (start|stop) start | stop packet logging

There are other parameters, but they are used by IPSec in its tunnelling capacity, and are not relevant here.

Back


inetcfg

Typing this command, without any parameters, runs the Interactive TCP/IP Stack Parameters' Configuration Utility.

To see an example of what should appear on your screen, go here

The only relevant usage here, involves the firewall parameter:

-s firewall (1|0) set the status (on | off) of the firewall
-g firewall get the current status of the firewall

Back



Filter Rule Format

Filter rules contain the following fields (each separated by a single space):

  1. Rule Action
  2. Source IP Address
  3. Source Address Mask
  4. Destination IP Address
  5. Destination Address Mask
  6. Protocol
  7. Source Port
  8. Destination Port
  9. Interface
  10. Routing
  11. Direction
  12. Log Control (optional)
  13. Fragmentation Control (optional)
  14. Tunnel ID (optional)

Click the links to see the possible values for each field.

Rule action

Value

Description

permit

Packets matching the rest of the fields in the rule definition will be allowed through the firewall

deny

Packets matching the rest of the fields in the rule definition will be blocked by the firewall

Back to top of Ruleform appendix

 

Source / Destination IP address

Value

Description

x.x.x.x

A valid IP address in dotted decimal format, e.g. 192.168.42.50

Back to top of Ruleform appendix

 

Source / Destination address mask

Value

Description

x.x.x.x

Applied as bitwise AND to match address, e.g. 255.255.255.0

Back to top of Ruleform appendix

 

Protocol

Value

Description

all

Matches all protocols

icmp

Matches ICMP packets

udp

Matches UDP packets

tcp

Matches TCP packets

tcp/ack

Matches TCP packets with acknowledgement bit set

ipsp

Matches IPSP packets

Back to top of Ruleform appendix

 

Source / Destination port

Value

Description

any 0

Matches any port number

eq (port no.)

Matches specified port number, e.g. eq 301

neq (port no.)

Matches any port number other than that specified

lt (port no.)

Matches any port number less than that specified

gt (port no.)

Matches any port number greater than that specified

le (port no.)

Matches any port number less than or equal to that specified

ge (port no.)

Matches any port number greater than or equal to that specifed

Back to top of Ruleform appendix

 

Interface

Value

Description

secure

Matches packets flowing through a secure interface

non-secure

Matches packets flowing through a non-secure interface

both

Matches all packets

Back to top of Ruleform appendix

 

Routing

Value

Description

local

Matches packets flowing to or from the firewall

route

Matches packets flowing through the firewall

both

Matches all packets

Back to top of Ruleform appendix

 

Direction

Value

Description

inbound

Matches packets flowing to the specified interface

outbound

Matches packets flowing from the specified interface

both

Matches all packets

Back to top of Ruleform appendix

 

Log control (optional)

Value

Description

l=yes

Logs packets if set (default for denied packets)

l=no

Does not log packets if set (default for permitted packets)

Back to top of Ruleform appendix

 

Fragmentation control (optional)

Value

Description

f=yes

Matches headers, fragments and non-fragmented packets if set

f=no

Matches only non-fragmented packets if set

f=only

Matches only headers and fragments if set

Back to top of Ruleform appendix

 

Tunnel ID (optional)

Value

Description

t=(tunnel id)

Identifies tunnel through which packet must be sent if set

Back to top of Ruleform appendix

Back


FWIP.SYS

FWIP.SYS works in the following manner:

  • FWIP.SYS is called by the IP layer of the TCP/IP stack for each packet that arrives at the firewall
  • The packet is compared to a list of filter rules, starting from the top and working down the list until a match is found
  • If a match is found, the rule action (permit or deny) is carried out
  • If no match is found, the packet is denied by default

While, strictly speaking, it is not necessary to define specific rules to deny packets (as the firewall's default rule will catch them) it is advisable to do so, as a precaution against mis-configured 'permit' rules later in the list.

Because FWIP.SYS stops searching through the list when it finds a match, a specific deny rule will catch a prohibited packet before it has a chance to be matched against any mis-configured rules in the rest the list.

Back