Friday, June 19, 2009

Firewalling Tiger (VI)

A little note or postscript to the ipfw firewall script I'm using on Os X, this one is just a reminder of howto get all the different scripts up and running.

sudo mkdir /Library/StartupItems/Firewall/
sudo cp Firewall /Library/StartupItems/Firewall/
sudo chmod +x /Library/StartupItems/Firewall/Firewall
sudo cp StartupParameters.plist /Library/StartupItems/Firewall/
sudo cp rc.firewall /etc/rc.firewall
sudo chmod +x /etc/rc.firewall

Labels: , , , ,

Wednesday, August 20, 2008

Firewalling Tiger (V)

With the rules to access the SNMP server on Tiger.


#!/bin/sh
# To list the current rules
# sudo /sbin/ipfw list

## The startup of this script is controlled by the files on:
## /Library/StartupItems/Firewall/

# Variables to simplify maintenance

ipf="/sbin/ipfw"

# LAN Arenales
LAN="10.120.10.0/29"

# Judith
judith="10.120.10.2"

# You can add more servers, these are comma delimited
DNS_SERVERS="10.120.10.0/29"
NTPD_SERVERS="10.120.10.2, clock.via.net, 0.south-america.pool.ntp.org"

# Enable firewall logging
#/usr/sbin/sysctl -w net.inet.ip.fw.verbose=1
# Disable firewall logging
/usr/sbin/sysctl -w net.inet.ip.fw.verbose=0

# Flush existing rules
${ipf} -f flush

# If the rule was added to the dynamic rule table, let it in
${ipf} add check-state

# Allow traffic to flow on the loopback interface
${ipf} add allow all from any to any via lo0

# Allow established connections
${ipf} add allow tcp from any to any established


## ------------------------------------
## Incoming connections
## ------------------------------------

# Allow ICMP traffic
${ipf} add allow icmp from ${LAN} to me icmptype 0,8

# Allow SSH connections
${ipf} add allow tcp from ${LAN} to me 22 keep-state

# Allow DHCP
${ipf} add allow udp from ${LAN} 67-68 to me 67-68

# Allow snmp
${ipf} add allow udp from ${judith} to me 161-162

# Allow Synergy connections
${ipf} add allow tcp from ${LAN} to me 24800 keep-state


## ------------------------------------
## Outgoing connections
## ------------------------------------

# Allow SSH connections
${ipf} add allow tcp from me to any 22 keep-state

# Allow non-secure web traffic
${ipf} add allow tcp from me to any 80 keep-state

# Allow ntpd traffic
${ipf} add allow tcp from me to ${NTPD_SERVERS} 123 keep-state
${ipf} add allow udp from me to ${NTPD_SERVERS} 123 keep-state

# Allowed so SNMPD connections can return to Judith
${ipf} add allow udp from me to ${judith}

# Allow secure web traffic
${ipf} add allow tcp from me to any 443 keep-state

# Allow IMAPS
${ipf} add allow tcp from me to any 993 keep-state

# Allow Messenger
${ipf} add allow tcp from me to any 1863 keep-state

# Allow RDP traffic
${ipf} add allow tcp from me to any 3389 keep-state

# Allow HTTP alternative access
${ipf} add allow tcp from me to any 8080 keep-state

# Allow Webmin
${ipf} add allow tcp from me to any 10000 keep-state

# Allow Synergy connections to the server on Tango
${ipf} add allow tcp from me to ${LAN} 24800 keep-state

# Allow me to get to my DNS servers
${ipf} add allow udp from me to ${DNS_SERVERS} 53 keep-state

# Allow ICMP traffic out
${ipf} add allow icmp from me to any out keep-state

## ------------------------------------
## Close down

${ipf} add deny log ip from any to any

# EoF #

Labels: , , , , ,

Wednesday, January 23, 2008

Firewalling Tiger (IV)

A new update on the firewall script, added new rules to allow NTPD sync with the servers defined on the 'NTPD_SERVERS' variable; it does work with NTPD servers that have a "static" FQDN or if you use an IP address, but, for instance, unless you reload this script periodically, it will fail to sync with the server '0.south-america.pool.ntp.org' since the IP address of this server changes.
That's a special server used specifically to provide NTPD sync to as many clients as it can.


#!/bin/sh

# Variables to simplify maintenance
ipf="/sbin/ipfw"

LAN="192.168.2.0/24"

# You can add more servers, these are comma delimited
DNS_SERVERS="192.168.2.2"
NTPD_SERVERS="192.168.2.2, clock.via.net, 0.south-america.pool.ntp.org"

## ------------------------------------

# Enable firewall logging
#/usr/sbin/sysctl -w net.inet.ip.fw.verbose=1

# Disable firewall logging
/usr/sbin/sysctl -w net.inet.ip.fw.verbose=0

# Flush existing rules
${ipf} -f flush

# If the rule was added to the dynamic rule table, let it in
${ipf} add check-state

# Allow traffic to flow on the loopback interface
${ipf} add allow all from any to any via lo0

# Allow established connections
${ipf} add allow tcp from any to any established

## ------------------------------------
## Incoming connections
## ------------------------------------

# Allow ICMP traffic
${ipf} add allow icmp from ${LAN} to me icmptype 0,8

# Allow SSH connections
${ipf} add allow tcp from ${LAN} to me 22 keep-state

# Allow DHCP
${ipf} add allow udp from ${LAN} 67-68 to me 67-68

## ------------------------------------
## Outgoing connections
## ------------------------------------

# Allow SSH connections
${ipf} add allow tcp from me to any 22 keep-state

# Allow non-secure web traffic
${ipf} add allow tcp from me to any 80 keep-state

# Allow ntpd traffic
${ipf} add allow tcp from me to ${NTPD_SERVERS} 123 keep-state
${ipf} add allow udp from me to ${NTPD_SERVERS} 123 keep-state

# Allow secure web traffic
${ipf} add allow tcp from me to any 443 keep-state

# Allow IMAPS
${ipf} add allow tcp from me to any 993 keep-state

# Allow Messenger
${ipf} add allow tcp from me to any 1863 keep-state

# Allow Webmin
${ipf} add allow tcp from me to any 10000 keep-state

# Allow me to get to my DNS servers
${ipf} add allow udp from me to ${DNS_SERVERS} 53 keep-state

# Allow ICMP traffic out
${ipf} add allow icmp from me to any out keep-state

## ------------------------------------
## Close down

${ipf} add deny log ip from any to any

# EoF #

Labels: , , , ,

Tuesday, January 08, 2008

Firewalling Tiger (III)

I have found some missing (and need to be open!) ports, while using Safari today, to access some special websites at work, which are redirected thru alternative ports, and reverse proxies... I got an error on Safari, with this message:

“POSIX error: Permission denied” (NSPOSIXErrorDomain:13)

Of course, as usual, the first thing that comes to your head is that the 'other' part is working incorrectly... After double checking IP addresses, ports, running Apache processes, firewall settings on the remote server, on the remote router, and banging my head a few times, I decided too Google it! After a couple of minutes, find out that it was/ is a common problem, on the first link; and then a probable cause on the second one.

POSIX error
NSPOSIXErrorDomain:13 error in Safari

What I have to do to get past the Safari error was to add the ports I need to connect to the firewall script, of course on the 'Outgoing connections' section, with the same syntax, but using the ports I need to connect to; and then re-run the script.

Happy, happy, joy, joy.

Labels: , , , ,

Sunday, January 06, 2008

Firewalling Tiger (II)

Here is the script I'm running right now, it assumes that your DNS server is on the IP 192.168.2.2, and that you are not running any service on your Os x box, except for an sshd server (Remote Login) and Samba, if you want to share files with a Windows box, the '# Allow SMB/CIFS' line, if you aren't you might delete those.
Anyway, the services are only opened for the network (private, hopefully) that you define on the 'LAN' variable, the other open bit are DHCP, to get an IP address from the server, as well as ping, so you can make basic connectivity tests to the Os X box.

On the outgoing rules, you might want to add either a POP3 or IMAP (or the secure version of POP3) if that is what you are using for email.
I have used the firewall script here: Locking down the Os X firewall, as the template to write this one, which is an excellent resource, but it doesn't allow anything coming to the Os X box.

To use the script, copy it, save it, say as 'rc.firewall', on your Desktop, and then:


sudo cp ~/Desktop/rc.firewall /etc/rc.firewall
sudo chmod +x /etc/rc.firewall


To begin using it:

sudo sh /etc/rc.firewall


If you want to to stop and clear the rules, allowing everything once again:

sudo ipfw -f flush


If you want to see the rules in use, type:

sudo ipfw list



#!/bin/sh

# Variables to simplify maintenance
ipf="/sbin/ipfw"

# LAN MyLAN
LAN="192.168.2.0/24"

# You can add more servers, these are comma delimited
DNS_SERVERS="192.168.2.2"

## ------------------------------------

# Enable firewall logging
/usr/sbin/sysctl -w net.inet.ip.fw.verbose=1

# Flush existing rules
${ipf} -f flush

# If the rule was added to the dynamic rule table, let it in
${ipf} add check-state

# Allow traffic to flow on the loopback interface
${ipf} add allow all from any to any via lo0

# Allow established connections
${ipf} add allow tcp from any to any established

## ------------------------------------
## Incoming connections
## ------------------------------------

# Allow ICMP traffic
${ipf} add allow icmp from ${LAN} to me icmptype 0,8

# Allow SSH connections
${ipf} add allow tcp from ${LAN} to me 22 keep-state

# Allow DHCP
${ipf} add allow udp from ${LAN} 67-68 to me 67-68

# Allow SMB/CIFS
${ipf} add allow tcp from ${LAN} to me 139 keep-state

## ------------------------------------
## Outgoing connections
## ------------------------------------

# Allow SSH connections
${ipf} add allow tcp from me to any 22 keep-state

# Allow SMTP connections
${ipf} add allow tcp from me to any 25 keep-state

# Allow non-secure web traffic
${ipf} add allow tcp from me to any 80 keep-state

# Allow secure web traffic
${ipf} add allow tcp from me to any 443 keep-state

# Allow IMAPS traffic
${ipf} add allow tcp from me to any 993 keep-state

# Allow Messenger traffic
${ipf} add allow tcp from me to any 1863 keep-state

# Allow query to DNS servers
${ipf} add allow udp from me to ${DNS_SERVERS} 53 keep-state

# Allow ICMP traffic out (Ping anything on the internet)
${ipf} add allow icmp from me to any out keep-state

## ------------------------------------
## Close down

${ipf} add deny log ip from any to any


# EoF #

Labels: , , , ,

Saturday, January 05, 2008

Firewalling Tiger (I)

I have spent a few hours testing an increased security version of the built-in's firewall. Tiger's firewall is the famous ipfw, a free and very, very secure and stable firewall, built inside of the operating system kernel.
I'm very pleased with the results of the the firewall script, it is a very tight one, limiting not only what is allowed to connect to the Os X box, but also, what is actually allowed to go to the outside.
I'll keep testing it a little more, and then post it here.

I was a bit afraid, since I was doing exactly the same thing, editing the internal firewall, when my old & beloved iBook died on me.

Labels: , , , ,