S 5.166 Configuration of the Mac OS X Personal Firewall

Initiation responsibility: IT Security Officer, Head of IT

Implementation responsibility: Administrator

The security mechanisms offered by Mac OS X include a personal firewall. A personal firewall offers various security functions such as a packet filter function to prevent the network communication of incoming and outgoing connections of the local system.

Before using the personal firewall under Mac OS X, two facts need to be checked. The personal firewall can be used to filter incoming or outgoing connections or to restrict the access of programs and services to the Internet. Before disabling the network communication for individual programs, it should be examined whether it is possible to disable the network communication internally within the program. Furthermore, it should be checked that no undesirable side-effects occur with the relevant program or service after blocking the network communication. If an attempt is made to directly prevent the network communication of a program by means of a personal firewall, problems may arise, as a program may depend on the network communication and wait for a response from the network before the program continues to be executed.

The use of a personal firewall directly operated on the client computer to be protected by no means replaces an independent security gateway (firewall) which protects the institution's entire internal network. The use of a personal firewall can make sense in order to protect Mac OS X computers against attacks from the local network in case of higher protection requirements. During mobile use of Mac OS X computers, the use of a personal firewall is always recommended in order to protect the computer against attacks from the Internet.

Before using a personal firewall, it must be specified which programs are to be granted network access and which not. In general, all network communication should be blocked, and in a second step the required ports or applications enabled. When configuring the personal firewall the recommendations in safeguard S 4.238 Use of local packet filters should be followed.

Mac OS X offers two firewalls operating on different levels:

The IP firewall and the application firewall can be operated simultaneously and together allow comprehensive control of the network communication. The application firewall can be enabled and configured in the system settings under Security in the menu tab "Firewall".

ipfw allows you to define finer rules than with the application fire wall. The handling is slightly more complicated as ipfw is configured via the command line.

In order to use ipfw to block a TCP connection to different servers on port 80 the following command can be used:

ipfw add 500 deny tcp from any to any dst-port 80

Every firewall rule has a number and is processed by the system from the highest to the lowest number. It is therefore possible for a rule to be modified or invalidated by another rule. As ipfw operates very close to the system, administrator rights are required to execute commands. If comprehensive firewall rules are created the content should be stored in a configuration file. To automatically load the rules from this configuration file a shell script is required which could appear as follows:

#!/bin/sh

# remove previous FW rules

/sbin/ipfw -q flush

execute #IPFW and load rules from file

/sbin/ipfw -q /STORAGE LOCATION/firewall rules.conf

# Logging after enable /var/log/system.log

/usr/sbin/sysctl -w net.inet.ip.fw.verbose=1

Subsequently, corresponding rights must be assigned for the shell script to enable the execution of the commands:

sudo chown root:admin Shellscript.sh

sudo chmod 544 Shellscript.sh

After this step, the shell script must be executed every time the computer is started. Under Mac OS X, Apples recommends the use of "launchd" for this task. The "launchd" system service requires a specially formatted file (Plist) in the directory /Library/LaunchDaemons to launch programs. The content of this file is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>com.apple.firewall</string>

<key>ProgramArguments</key>

<array>

<string>/usr/local/bin/Shellscript.sh</string>

</array>

<key>RunAtLoad</key>

<true/>

</dict>

</plist>

In the final step, this Plist file must receive corresponding rights, for example, by means of the following command:

sudo chown root:admin NameOf.plist

The changes can be read in and activated directly without the need for a restart by means of the following command:

sudo launchctl load /Library/LaunchDaemons/NameOf.plist

The log file of the personal firewall, to be found under /private/var/log/ipfw.log, should be checked regularly for irregularities such as an increased number of failed remote access and login attempts. Firewall log files can grow rapidly and use a considerable amount of storage space. For this reason, it makes sense to clarify which rules have a high priority and should be logged and which not. A corresponding command can appear as follows:

ipfw allow log tcp from any to any dst-port 6112-6119

This command logs all connection attempts to a server on a TCP basis to port 6112 to 6119.

Review questions: