diff --git a/en_US.ISO8859-1/books/handbook/Makefile b/en_US.ISO8859-1/books/handbook/Makefile
index 4c6fac6387..b0dca1956f 100644
--- a/en_US.ISO8859-1/books/handbook/Makefile
+++ b/en_US.ISO8859-1/books/handbook/Makefile
@@ -1,256 +1,257 @@
#
# $FreeBSD$
#
# Build the FreeBSD Handbook.
#
# ------------------------------------------------------------------------
#
# Handbook-specific variables
#
# WITH_PGPKEYS The print version of the handbook only prints PGP
# fingerprints by default. If you would like for the
# entire key to be displayed, then set this variable.
# This option has no affect on the HTML formats.
#
# Handbook-specific targets
#
# pgpkeyring This target will read the contents of
# pgpkeys/chapter.sgml and will extract all of
# the pgpkeys to standard out. This output can then
# be redirected into a file and distributed as a
# public keyring of FreeBSD developers that can
# easily be imported into PGP/GPG.
#
# ------------------------------------------------------------------------
.PATH: ${.CURDIR}/../../share/sgml/glossary
MAINTAINER= doc@FreeBSD.org
DOC?= book
FORMATS?= html-split
HAS_INDEX= true
INSTALL_COMPRESSED?= gz
INSTALL_ONLY_COMPRESSED?=
IMAGES_EN = advanced-networking/isdn-bus.eps
IMAGES_EN+= advanced-networking/isdn-twisted-pair.eps
IMAGES_EN+= advanced-networking/natd.eps
IMAGES_EN+= advanced-networking/net-routing.pic
IMAGES_EN+= advanced-networking/static-routes.pic
IMAGES_EN+= install/adduser1.scr
IMAGES_EN+= install/adduser2.scr
IMAGES_EN+= install/adduser3.scr
IMAGES_EN+= install/boot-mgr.scr
IMAGES_EN+= install/console-saver1.scr
IMAGES_EN+= install/console-saver2.scr
IMAGES_EN+= install/console-saver3.scr
IMAGES_EN+= install/console-saver4.scr
IMAGES_EN+= install/desktop.scr
IMAGES_EN+= install/disklabel-auto.scr
IMAGES_EN+= install/disklabel-ed1.scr
IMAGES_EN+= install/disklabel-ed2.scr
IMAGES_EN+= install/disklabel-fs.scr
IMAGES_EN+= install/disklabel-root1.scr
IMAGES_EN+= install/disklabel-root2.scr
IMAGES_EN+= install/disklabel-root3.scr
IMAGES_EN+= install/disk-layout.eps
IMAGES_EN+= install/dist-set.scr
IMAGES_EN+= install/dist-set2.scr
IMAGES_EN+= install/docmenu1.scr
IMAGES_EN+= install/ed0-conf.scr
IMAGES_EN+= install/ed0-conf2.scr
IMAGES_EN+= install/edit-inetd-conf.scr
IMAGES_EN+= install/fdisk-drive1.scr
IMAGES_EN+= install/fdisk-drive2.scr
IMAGES_EN+= install/fdisk-edit1.scr
IMAGES_EN+= install/fdisk-edit2.scr
IMAGES_EN+= install/ftp-anon1.scr
IMAGES_EN+= install/ftp-anon2.scr
IMAGES_EN+= install/hdwrconf.scr
IMAGES_EN+= install/keymap.scr
IMAGES_EN+= install/main1.scr
IMAGES_EN+= install/mainexit.scr
IMAGES_EN+= install/main-std.scr
IMAGES_EN+= install/main-options.scr
IMAGES_EN+= install/main-doc.scr
IMAGES_EN+= install/main-keymap.scr
IMAGES_EN+= install/media.scr
IMAGES_EN+= install/mouse1.scr
IMAGES_EN+= install/mouse2.scr
IMAGES_EN+= install/mouse3.scr
IMAGES_EN+= install/mouse4.scr
IMAGES_EN+= install/mouse5.scr
IMAGES_EN+= install/mouse6.scr
IMAGES_EN+= install/mta-main.scr
IMAGES_EN+= install/net-config-menu1.scr
IMAGES_EN+= install/net-config-menu2.scr
IMAGES_EN+= install/nfs-server-edit.scr
IMAGES_EN+= install/ntp-config.scr
IMAGES_EN+= install/options.scr
IMAGES_EN+= install/pkg-cat.scr
IMAGES_EN+= install/pkg-confirm.scr
IMAGES_EN+= install/pkg-install.scr
IMAGES_EN+= install/pkg-sel.scr
IMAGES_EN+= install/probstart.scr
IMAGES_EN+= install/routed.scr
IMAGES_EN+= install/security.scr
IMAGES_EN+= install/sysinstall-exit.scr
IMAGES_EN+= install/timezone1.scr
IMAGES_EN+= install/timezone2.scr
IMAGES_EN+= install/timezone3.scr
IMAGES_EN+= install/userconfig.scr
IMAGES_EN+= install/userconfig2.scr
IMAGES_EN+= install/xf86setup.scr
IMAGES_EN+= mail/mutt1.scr
IMAGES_EN+= mail/mutt2.scr
IMAGES_EN+= mail/mutt3.scr
IMAGES_EN+= mail/pine1.scr
IMAGES_EN+= mail/pine2.scr
IMAGES_EN+= mail/pine3.scr
IMAGES_EN+= mail/pine4.scr
IMAGES_EN+= mail/pine5.scr
IMAGES_EN+= install/example-dir1.eps
IMAGES_EN+= install/example-dir2.eps
IMAGES_EN+= install/example-dir3.eps
IMAGES_EN+= install/example-dir4.eps
IMAGES_EN+= install/example-dir5.eps
IMAGES_EN+= security/ipsec-network.pic
IMAGES_EN+= security/ipsec-crypt-pkt.pic
IMAGES_EN+= security/ipsec-encap-pkt.pic
IMAGES_EN+= security/ipsec-out-pkt.pic
IMAGES_EN+= vinum/vinum-concat.pic
IMAGES_EN+= vinum/vinum-mirrored-vol.pic
IMAGES_EN+= vinum/vinum-raid10-vol.pic
IMAGES_EN+= vinum/vinum-raid5-org.pic
IMAGES_EN+= vinum/vinum-simple-vol.pic
IMAGES_EN+= vinum/vinum-striped-vol.pic
IMAGES_EN+= vinum/vinum-striped.pic
# Images from the cross-document image library
IMAGES_LIB= callouts/1.png
IMAGES_LIB+= callouts/2.png
IMAGES_LIB+= callouts/3.png
IMAGES_LIB+= callouts/4.png
IMAGES_LIB+= callouts/5.png
IMAGES_LIB+= callouts/6.png
IMAGES_LIB+= callouts/7.png
IMAGES_LIB+= callouts/8.png
IMAGES_LIB+= callouts/9.png
IMAGES_LIB+= callouts/10.png
#
# SRCS lists the individual SGML files that make up the document. Changes
# to any of these files will force a rebuild
#
# SGML content
SRCS+= book.sgml
SRCS+= colophon.sgml
SRCS+= freebsd-glossary.sgml
SRCS+= advanced-networking/chapter.sgml
SRCS+= basics/chapter.sgml
SRCS+= bibliography/chapter.sgml
SRCS+= boot/chapter.sgml
SRCS+= config/chapter.sgml
SRCS+= cutting-edge/chapter.sgml
SRCS+= desktop/chapter.sgml
SRCS+= disks/chapter.sgml
SRCS+= eresources/chapter.sgml
+SRCS+= firewalls/chapter.sgml
SRCS+= install/chapter.sgml
SRCS+= introduction/chapter.sgml
SRCS+= kernelconfig/chapter.sgml
SRCS+= l10n/chapter.sgml
SRCS+= linuxemu/chapter.sgml
SRCS+= mac/chapter.sgml
SRCS+= mail/chapter.sgml
SRCS+= mirrors/chapter.sgml
SRCS+= multimedia/chapter.sgml
SRCS+= network-servers/chapter.sgml
SRCS+= pgpkeys/chapter.sgml
SRCS+= ports/chapter.sgml
SRCS+= ppp-and-slip/chapter.sgml
SRCS+= preface/preface.sgml
SRCS+= printing/chapter.sgml
SRCS+= security/chapter.sgml
SRCS+= serialcomms/chapter.sgml
SRCS+= users/chapter.sgml
SRCS+= vinum/chapter.sgml
SRCS+= x11/chapter.sgml
# Entities
SRCS+= chapters.ent
SYMLINKS= ${DESTDIR} index.html handbook.html
# Turn on all the chapters.
CHAPTERS?= ${SRCS:M*chapter.sgml}
SGMLFLAGS+= ${CHAPTERS:S/\/chapter.sgml//:S/^/-i chap./}
SGMLFLAGS+= -i chap.freebsd-glossary
# XXX The Handbook build currently overflows some internal, hardcoded
# limits in pdftex. Until we split the Handbook up, build the PDF
# version using ps2pdf instead of pdftex.
PS2PDF?= ${PREFIX}/bin/ps2pdf
book.tex-pdf:
${TOUCH} book.tex-pdf
book.pdf: book.ps
${PS2PDF} book.ps book.pdf
pgpkeyring: pgpkeys/chapter.sgml
@${JADE} -V nochunks ${OTHERFLAGS} ${JADEOPTS} -d ${DSLPGP} -t sgml ${MASTERDOC}
#
# Handbook-specific variables
#
.if defined(WITH_PGPKEYS)
JADEFLAGS+= -V withpgpkeys
.endif
.for p in ftp cvsup
SRCS+= mirrors.sgml.${p}.inc
CLEANFILES+= mirrors.sgml.${p}.inc
CLEANFILES+= mirrors.sgml.${p}.inc.tmp
.endfor
SRCS+= eresources.sgml.www.inc
CLEANFILES+= eresources.sgml.www.inc
CLEANFILES+= eresources.sgml.www.inc.tmp
URL_RELPREFIX?= ../../../..
DOC_PREFIX?= ${.CURDIR}/../../..
.include "${DOC_PREFIX}/share/mk/doc.project.mk"
.for p in ftp cvsup
mirrors.sgml.${p}.inc: ${XML_MIRRORS} ${XSL_MIRRORS}
${XSLTPROC} ${XSLTPROCOPTS} \
-o $@.tmp \
--param 'type' "'$p'" \
--param 'proto' "'$p'" \
--param 'target' "'handbook/mirrors/chapter.sgml'" \
${XSL_MIRRORS} ${XML_MIRRORS}
${SED} -e 's,<\([^ >]*\)\([^>]*\)/>,<\1\2>\1>,;s,,,'\
< $@.tmp > $@ || (${RM} -f $@ && false)
${RM} -f $@.tmp
.endfor
eresources.sgml.www.inc: ${XML_MIRRORS} ${XSL_MIRRORS}
${XSLTPROC} ${XSLTPROCOPTS} \
-o $@.tmp \
--param 'type' "'www'" \
--param 'proto' "'http'" \
--param 'target' "'handbook/eresources/chapter.sgml'" \
${XSL_MIRRORS} ${XML_MIRRORS}
${SED} -e 's,<\([^ >]*\)\([^>]*\)/>,<\1\2>\1>,;s,,,'\
< $@.tmp > $@ || (${RM} -f $@ && false)
${RM} -f $@.tmp
diff --git a/en_US.ISO8859-1/books/handbook/book.sgml b/en_US.ISO8859-1/books/handbook/book.sgml
index 485bea1fc4..cb7ffccec5 100644
--- a/en_US.ISO8859-1/books/handbook/book.sgml
+++ b/en_US.ISO8859-1/books/handbook/book.sgml
@@ -1,329 +1,334 @@
%books.ent;
%chapters;
%txtfiles;
%pgpkeys;
]>
FreeBSD HandbookThe FreeBSD Documentation ProjectFebruary 19991995199619971998199920002001200220032004The FreeBSD Documentation Project
&bookinfo.legalnotice;
&tm-attrib.freebsd;
&tm-attrib.3com;
&tm-attrib.3ware;
&tm-attrib.arm;
&tm-attrib.adaptec;
&tm-attrib.adobe;
&tm-attrib.apple;
&tm-attrib.corel;
&tm-attrib.creative;
&tm-attrib.cvsup;
&tm-attrib.heidelberger;
&tm-attrib.ibm;
&tm-attrib.ieee;
&tm-attrib.intel;
&tm-attrib.intuit;
&tm-attrib.linux;
&tm-attrib.lsilogic;
&tm-attrib.m-systems;
&tm-attrib.macromedia;
&tm-attrib.microsoft;
&tm-attrib.netscape;
&tm-attrib.nexthop;
&tm-attrib.opengroup;
&tm-attrib.oracle;
&tm-attrib.powerquest;
&tm-attrib.realnetworks;
&tm-attrib.redhat;
&tm-attrib.sap;
&tm-attrib.sun;
&tm-attrib.symantec;
&tm-attrib.themathworks;
&tm-attrib.thomson;
&tm-attrib.usrobotics;
&tm-attrib.vmware;
&tm-attrib.waterloomaple;
&tm-attrib.wolframresearch;
&tm-attrib.xfree86;
&tm-attrib.xiph;
&tm-attrib.general;
Welcome to FreeBSD! This handbook covers the installation and day
to day use of FreeBSD &rel2.current;-RELEASE
and FreeBSD &rel.current;-RELEASE.
This manual is a work in progress and is the work
of many individuals. Many sections do not yet exist and some of those
that do exist need to be updated. If you are interested in helping
with this project, send email to the &a.doc;. The latest version of
this document is always available from the FreeBSD web site.
It may also be downloaded in a variety of formats and compression
options from the FreeBSD FTP
server or one of the numerous mirror sites. If you would prefer
to have a hard copy of the handbook, you can purchase one at the
FreeBSD Mall. You
may also want to search the
handbook.
&chap.preface;
Getting StartedThis part of the FreeBSD Handbook is for users and
administrators who are new to FreeBSD. These chapters:Introduce you to FreeBSD.Guide you through the installation process.Teach you &unix; basics and fundamentals.Show you how to install the wealth of third party
applications available for FreeBSD.Introduce you to X, the &unix; windowing system, and
detail how to configure a desktop environment that makes you
more productive.We have tried to keep the number of forward references in
the text to a minimum so that you can read this section of the
Handbook from front to back with the minimum page flipping
required.Common TasksNow that the basics have been covered, this part of the
FreeBSD Handbook will discuss some frequently used features of
FreeBSD. These chapters:Introduce you to popular and useful desktop
applications: browsers, productivity tools, document
viewers, etc.Introduce you to a number of multimedia tools
available for FreeBSD.Explain the process of building a customized FreeBSD
kernel, to enable extra functionality on your system.Describe the print system in detail, both for desktop
and network-connected printer setups.Show you how to run Linux applications on your FreeBSD
system.Some of these chapters recommend that you do some prior
reading, and this is noted in the synopsis at the beginning of
each chapter.System AdministrationThe remaining chapters of the FreeBSD Handbook cover all
aspects of FreeBSD system administration. Each chapter
starts by describing what you will learn as a result of reading
the chapter, and also details what you are expected to know
before tackling the material.These chapters are designed to be read when
you need the information. You do not have to read them in any
particular order, nor do you need to read all of them before you
can begin using FreeBSD.Network CommunicationFreeBSD is one of the most widely deployed operating
systems for high performance network servers. The chapters in
this part cover:Serial communicationPPP and PPP over EthernetElectronic MailRunning Network Servers
+
+ Firewalls
+
+
Other Advanced Networking TopicsThese chapters are designed to be read when
you need the information. You do not have to read them in any
particular order, nor do you need to read all of them before you
can begin using FreeBSD in a network environment.
+
Appendices
&chap.colophon;
diff --git a/en_US.ISO8859-1/books/handbook/chapters.ent b/en_US.ISO8859-1/books/handbook/chapters.ent
index 558a081210..6585365fd0 100644
--- a/en_US.ISO8859-1/books/handbook/chapters.ent
+++ b/en_US.ISO8859-1/books/handbook/chapters.ent
@@ -1,56 +1,57 @@
+
diff --git a/en_US.ISO8859-1/books/handbook/firewalls/Makefile b/en_US.ISO8859-1/books/handbook/firewalls/Makefile
new file mode 100644
index 0000000000..331f5bf8ec
--- /dev/null
+++ b/en_US.ISO8859-1/books/handbook/firewalls/Makefile
@@ -0,0 +1,15 @@
+#
+# Build the Handbook with just the content from this chapter.
+#
+# $FreeBSD$
+#
+
+CHAPTERS= firewalls/chapter.sgml
+
+VPATH= ..
+
+MASTERDOC= ${.CURDIR}/../${DOC}.${DOCBOOKSUFFIX}
+
+DOC_PREFIX?= ${.CURDIR}/../../../..
+
+.include "../Makefile"
diff --git a/en_US.ISO8859-1/books/handbook/firewalls/chapter.sgml b/en_US.ISO8859-1/books/handbook/firewalls/chapter.sgml
new file mode 100644
index 0000000000..2b90e0a90b
--- /dev/null
+++ b/en_US.ISO8859-1/books/handbook/firewalls/chapter.sgml
@@ -0,0 +1,2868 @@
+
+
+
+
+
+
+ Joseph J.
+ Barbish
+ Contributed by
+
+
+
+
+ Brad
+ Davis
+ Converted to SGML and updated by
+
+
+
+ Firewalls
+
+ firewall
+
+ security
+ firewalls
+
+
+
+ Introduction
+
+ All software-based firewalls provide some way to filter
+ incoming and outgoing traffic that flows through your system.
+ The firewall uses one or more sets of rules to
+ inspect the network packets as they come in or go out of your
+ network connections and either allows the traffic through or
+ blocks it. The rules of the firewall can inspect one or more
+ characteristics of the packets, including but not limited to the
+ protocol type, the source or destination host address and the
+ source or destination port.
+
+ Firewalls greatly enhance the security of your network, your
+ applications and services. They can be used to do one of more of
+ the following things:
+
+
+
+ To protect and insulate the applications, services and
+ machines of your internal network from unwanted traffic
+ coming in from the public Internet.
+
+
+
+ To limit or disable access from hosts of the internal
+ network to services of the public Internet.
+
+
+
+ To support network address translation
+ (NAT), which allows your internal network
+ to use private IP addresses and share a
+ single connection to the public Internet (either with a
+ single IP address or by a shared pool of
+ automatically assigned public addresses).
+
+
+
+
+ After reading this chapter, you will know:
+
+
+
+ How to properly define packet filtering rules.
+
+
+
+ The differences between the firewall software products
+ built into &os;
+
+
+
+ How to use and configure the OpenBSD
+ PF firewall software.
+
+
+
+
+ How to use and configure the
+ IPFILTER software.
+
+
+
+ How to use and configure the
+ IPFW software.
+
+
+
+ Before reading this chapter, you should:
+
+
+
+ Understand basic &os; and Internet concepts.
+
+
+
+
+
+
+ Firewall Rule Set Types
+
+ Constructing a software application firewall rule set may
+ seem to be trivial, but most people get it wrong. The most
+ common mistake is to create an exclusive firewall
+ rather than an inclusive firewall.
+
+ An exclusive firewall allows all services through except for
+ those matching a set of rules that block certain
+ services.
+
+ An inclusive firewall does the reverse. It only allows
+ services matching the rules through and blocks everything else.
+ This way you can control what services can originate behind the
+ firewall destined for the public Internet and also control which
+ services originating from the public Internet may access your
+ network. Inclusive firewalls are much, much safer than exclusive
+ firewalls.
+
+ When you use your browser to access a web site there are
+ many internal functions that happen before your screen fills
+ with the data from the target web site. Your browser does not
+ receive one large file containing all the data and display
+ format instructions at one time. Each internal function accesses
+ the public Internet in multiple send/receive cycles of packets
+ of information. When all the packets containing the data finally
+ arrive, the data contained in the packets is combined together
+ to fill your screen. Each service (DNS,
+ HTTP, etc) has its own port number. The port
+ number 80 is for HTTP services. So you can
+ code your firewall to only allow web page session start requests
+ originating from your LAN to pass through the
+ firewall out to the public Internet.
+
+ Security can be tightened further by telling the firewall to
+ monitor the send/receive cycles of all the packets making up
+ that session until the session completes. These are called
+ stateful capabilities and provides the maximum level of
+ protection.
+
+ A firewall rule set that does not implement stateful
+ capabilities on all the services being authorized is an insecure
+ firewall that is still open to many of the most common methods
+ of attack.
+
+
+
+ Firewall Software Applications
+
+ &os; has two different firewall software products built into
+ the base system. They are IPFILTER (i.e. also known as IPF) and
+ IPFIREWALL (i.e. also known as IPFW). IPFIREWALL has the built
+ in DUMMYNET traffic shaper facilities for controlling bandwidth
+ usage. IPFILTER does not have a built in traffic shaper facility
+ for controlling bandwidth usage, but the ALTQ port application
+ can be used to accomplish the same function. The DUMMYNET
+ feature and ALTQ is generally useful only to
+ large ISPs or commercial users. Both IPF and IPFW use rules to
+ control the access of packets to and from your system, although
+ they go about it different ways and have different rule
+ syntaxes.
+
+ The IPFW sample rule set (found in
+ /etc/rc.firewall) delivered in the basic
+ install is outdated, complicated and does not use stateful rules
+ on the interface facing the public Internet. It exclusively uses
+ legacy stateless rules which only have the ability to open or
+ close the service ports. The IPFW example stateful rules sets
+ presented here supercede the
+ /etc/rc.firewall file distributed with the
+ system.
+
+ Stateful rules have technically advanced interrogation
+ abilities capable of defending against the flood of different
+ methods currently employed by attackers.
+
+ Both of these firewall software solutions IPF and IPFW still
+ maintain their legacy heritage of their original rule processing
+ order and reliance on non-stateful rules. These outdated
+ concepts are not covered here, only the new, modern stateful
+ rule construct and rule processing order is presented.
+
+ You should read about both of them and make your own
+ decision on which one best fits your needs.
+
+ The author prefers IPFILTER because its stateful rules are
+ much less complicated to use in a NAT
+ environment and it has a built in ftp proxy that simplifies the
+ rules to allow secure outbound FTP usage. If is also more
+ appropriate to the knowledge level of the inexperienced firewall
+ user.
+
+ Since all firewalls are based on interrogating the values of
+ selected packet control fields, the creator of the firewall
+ rules must have an understanding of how
+ TCP/IP works, what the different values in
+ the packet control fields are and how these values are used in a
+ normal session conversation. For a good explanation go to:
+ .
+
+
+
+ The Packet Filter Firewall
+
+ As of July 2003 the OpenBSD firewall software application
+ known as PF was ported to &os; 5.3.
+ PF is a complete, fully featured firewall
+ that contains ALTQ for bandwidth usage
+ management in a way similar to the dummynet provides in
+ IPFW. The OpenBSD project does an
+ outstanding job of maintaining the PF users' guide that it will
+ not be made part of this handbook firewall section as that would
+ just be duplicated effort.
+
+ For older 5.X version of &os; you can find
+ PF in the &os; ports collection here:
+ security/pf.
+
+ More info can be found at the PF for &os; web site: .
+
+ The OpenBSD PF user's guide is here: .
+
+
+ PF in &os; 5.X is at the level of OpenBSD version 3.5. The
+ port from the &os; ports collection at the level of OpenBSD
+ version 3.4. Keep that in mind when browsing the user's
+ guide.
+
+
+
+ Enabling PF
+ PF is included in the basic &os; install for versions newer than
+ 5.3 as a separate run time loadable module. PF will dynamically load
+ its kernel loadable module when the rc.conf statement
+ pf_enable="YES" is used. The
+ loadable module was created with &man.pflog.4; logging
+ enabled.
+
+
+
+ Kernel options
+ It is not a mandatory requirement that you enable PF by
+ compiling the following options into the &os; kernel. It is only
+ presented here as background information. Compiling PF into the
+ kernel causes the loadable module to never be used.
+
+ Sample kernel config PF option statements are in the
+ /usr/src/sys/conf/NOTES kernel source and are
+ reproduced here:
+
+ device pf
+device pflog
+device pfsync
+
+ device pf tells the compile to include
+ Packet Filter as part of its core kernel.
+
+ device pflog enables the optional
+ &man.pflog.4; pseudo network device which can be used to log traffic
+ to a &man.bpf.4; descriptor. The &man.pflogd.8; daemon can be used to
+ store the logging information to disk.
+
+ device pfsync enables the optional
+ &man.pfsync.4; pseudo network device that is used to monitor
+ state changes. As this is not part of the loadable
+ module one has to build a custom kernel to use it.
+
+ These settings will take affect only after you have built and
+ installed a kernel with them set.
+
+
+
+ Available rc.conf Options
+
+ You need the following statements in /etc/rc.conf
+ to activate PF at boot time:
+
+ pf_enable="YES" # Enable PF (load module if required)
+pf_rules="/etc/pf.conf" # rules definition file for pf
+pf_flags="" # additional flags for pfctl startup
+pflog_enable="YES" # start pflogd(8)
+pflog_logfile="/var/log/pflog" # where pflogd should store the logfile
+pflog_flags="" # additional flags for pflogd startup
+
+ If you have a LAN behind this firewall and have to forward
+ packets for the computers in the LAN or want to do NAT you have to
+ enable the following option as well:
+
+ gateway_enable="YES" # Enable as Lan gateway
+
+
+
+
+
+ The IPFILTER (IPF) Firewall
+
+ The author of IPFILTER is Darren Reed. IPFILTER is not
+ operating system dependent. IPFILTER is a open source
+ application and has been ported to &os;, NetBSD, OpenBSD, SunOS,
+ HP/UX, and Solaris operating systems. IPFILTER is actively being
+ supported and maintained, with updated versions being released
+ regularly.
+
+ IPFILTER is based on a kernel-side firewall and
+ NAT mechanism that can be controlled and
+ monitored by userland interface programs. The firewall rules can
+ be set or deleted with the &man.ipf.8; utility. The
+ NAT rules can be set or deleted with the
+ &man.ipnat.1; utility. The &man.ipfstat.8; utility can print
+ run-time statistics for the kernel parts of IPFILTER. The
+ &man.ipmon.8; program can log IPFILTER actions to the system log
+ files.
+
+ IPF was originally written using a rule processing logic of
+ the last matching rule wins and used only
+ stateless type of rules. Over time IPF has been enhanced to
+ include a quick option and a stateful keep
+ state option which drastically modernized the rules
+ processing logic. IPF's official documentation covers the legacy
+ rule coding parameters and the legacy rule file processing
+ logic. the modernized functions are only included as additional
+ options, completely understating their benefits in producing a
+ far superior secure firewall.
+
+ The instructions contained in this section are based on
+ using rules that contain the quick option and the
+ stateful keep state option. This is the basic
+ framework for coding an inclusive firewall rule set.
+
+ An inclusive firewall only allows packets matching the rules
+ to pass through. This way you can control what services can
+ originate behind the firewall destine for the public Internet
+ and also control the services which can originate from the
+ public Internet accessing your private network. Everything else
+ is blocked and logged by default design. Inclusive firewalls are
+ much, much more secure than exclusive firewall rule sets and is
+ the only rule set type covered here in.
+
+ For detailed explanation of the legacy rules processing
+ method see:
+ and
+ .
+
+ The IPF FAQ is at .
+
+
+ Enabling IPF
+ IPF is included in the basic &os; install as a separate
+ run time loadable module. IPF will dynamically load its kernel
+ loadable module when the rc.conf statement
+ ipfilter_enable="YES" is used. The loadable
+ module was created with logging enabled and the default
+ pass all options. You do not need to compile IPF into
+ the &os; kernel just to change the default to block all
+ , you can do that by just coding a block all rule at
+ the end of your rule set.
+
+
+
+ Kernel options
+ It is not a mandatory requirement that you enable IPF by
+ compiling the following options into the &os; kernel. It is
+ only presented here as background information. Compiling IPF
+ into the kernel causes the loadable module to never be used.
+
+
+ Sample kernel config IPF option statements are in the
+ /usr/src/sys/i386/conf/LINT kernel source
+ and are reproduced here.
+
+ options IPFILTER
+options IPFILTER_LOG
+options IPFILTER_DEFAULT_BLOCK
+
+ options IPFILTER tells the compile
+ to include IPFILTER as part of its core kernel.
+
+ options IPFILTER_LOG enables the
+ option to have IPF log traffic by writing to the ipl packet
+ logging pseudo—device for every rule that has the log
+ keyword.
+
+ options IPFILTER_DEFAULT_BLOCK
+ changes the default behavior so any packet not matching a
+ firewall pass rule gets blocked.
+
+ These settings will take affect only after you have built
+ and installed a kernel with them set.
+
+
+
+ Available rc.conf Options
+ You need the following statements in /etc/rc.conf
+ to activate IPF at boot time:
+
+ ipfilter_enable="YES" # Start ipf firewall
+ipfilter_rules="/etc/ipf.rules" # loads rules definition text file
+ipmon_enable="YES" # Start IP monitor log
+ipmon_flags="-Ds" # D = start as daemon
+ # s = log to syslog
+ # v = log tcp window, ack, seq
+ # n = map IP & port to names
+ If you have a LAN behind this firewall that uses the
+ reserved private IP address ranges, then you need to add the
+ following to enable NAT function.
+
+ gateway_enable="YES" # Enable as Lan gateway
+ipnat_enable="YES" # Start ipnat function
+ipnat_rules="/etc/ipnat.rules" # rules definition file for ipnat
+
+
+
+
+ IPF
+ The ipf command is used to load your rules file. Normally
+ you create a file containing your custom rules and use this
+ command to replace in mass the currently running firewall
+ internal rules.
+
+ ipf -Fa -f /etc/ipf.rules
+
+ -Fa means flush all internal rules tables.
+ -f means this is the file to read for the rules to load.
+
+ This gives you the ability to make changes to their custom
+ rules file, run the above IPF command thus updating the running
+ firewall with a fresh copy of all the rules without having to
+ reboot the system. This method is very convenient for testing new
+ rules as the procedure can be executed as many times as needed.
+
+
+ See the &man.ipf.8; manual page for details on the other flags
+ available with this command.
+
+ The &man.ipf.8; command expects the rules file to be a
+ standard text file. It will not accept a rules file written as a
+ script with symbolic substitution.
+
+ There is a way to build IPF rules that utilities the power of
+ script symbolic substitution. For more information, see .
+
+
+
+ IPFSTAT
+ The default behavior of &man.ipfstat.8; is to retrieve and
+ display the totals of the accumulated statistics gathered as a
+ result of applying the user coded rules against packets going
+ in and out of the firewall since it was last started, or since
+ the last time the accumulators were reset to zero by
+ ipf -Z command.
+
+ See the &man.ipfstat.8; manual page for details.
+
+ The default &man.ipfstat.8; command output will look
+ something like this:
+
+ input packets: blocked 99286 passed 1255609 nomatch 14686 counted 0
+ output packets: blocked 4200 passed 1284345 nomatch 14687 counted 0
+ input packets logged: blocked 99286 passed 0
+ output packets logged: blocked 0 passed 0
+ packets logged: input 0 output 0
+ log failures: input 3898 output 0
+ fragment state(in): kept 0 lost 0
+ fragment state(out): kept 0 lost 0
+ packet state(in): kept 169364 lost 0
+ packet state(out): kept 431395 lost 0
+ ICMP replies: 0 TCP RSTs sent: 0
+ Result cache hits(in): 1215208 (out): 1098963
+ IN Pullups succeeded: 2 failed: 0
+ OUT Pullups succeeded: 0 failed: 0
+ Fastroute successes: 0 failures: 0
+ TCP cksum fails(in): 0 (out): 0
+ Packet log flags set: (0)
+
+ When supplied with either -i for inbound or -o for outbound,
+ it will retrieve and display the appropriate list of filter
+ rules currently installed and in use by the kernel.
+
+ ipfstat -in displays the inbound internal
+ rules table with rule number.
+
+ ipfstat -on displays the outbound
+ internal rules table with the rule number.
+
+ The output will look something like this:
+
+ @1 pass out on xl0 from any to any
+@2 block out on dc0 from any to any
+@3 pass out quick on dc0 proto tcp/udp from any to any keep state
+
+ ipfstat -ih displays the inbound internal
+ rules table prefixed each rule with count of how many times the
+ rule was matched.
+
+ ipfstat -oh displays the outbound
+ internal rules table prefixed each rule with count of how many
+ times the rule was matched.
+
+ The output will look something like this:
+
+ 2451423 pass out on xl0 from any to any
+354727 block out on dc0 from any to any
+430918 pass out quick on dc0 proto tcp/udp from any to any keep state
+
+ One of the most important functions of the ipfstat command
+ is the -t flag which activates the display state table in a way
+ similar to the way &man.top.1; shows the &os; running process
+ table. When your firewall is under attack this function gives
+ you the ability to identify, drill down to, and see the
+ attacking packets. The optional sub-flags give the ability to
+ select destination or source IP, port, protocol, you want to
+ monitor in real time. See the &man.ipfstat.8; manual page for
+ details.
+
+
+
+
+ IPMON
+ In order for ipmon to properly work, the
+ kernel option IPFILTER_LOG must be turned on. This command has
+ 2 different modes it can be used in. Native mode is the default
+ mode when you type the command on the command line without the
+ -D flag.
+
+ Daemon mode is for when you want to have a continuous
+ system log file available so you can review logging of past
+ events. This is how &os; and IPFILTER are configured to work
+ together. &os; has a built in facility to automatically
+ rotate syslogs. That is why outputting the log information to
+ syslogd is better than the default of outputting to a regular
+ file. In rc.conf file you see the
+ ipmon_flags statement uses the "-Ds" flags
+
+ ipmon_flags="-Ds" # D = start as daemon
+ # s = log to syslog
+ # v = log tcp window, ack, seq
+ # n = map IP & port to names
+
+ The benefits of logging are obvious. It provides the
+ ability to review, after the fact, information like: what
+ packets had been dropped, what addresses they came from and
+ where they were going. These all give you a significant edge in
+ tracking down attackers.
+
+ Even with the logging facility enabled, IPF will not
+ generate any rule logging on its own. The firewall
+ administrator decides what rules in the rule set he wants to
+ log and adds the log keyword to those rules. Normally only
+ deny rules are logged.
+
+ Its very customary to include a default deny everything
+ rule with the log keyword included as your last rule in the
+ rule set. This way you get to see all the packets that did not
+ match any of the rules in the rule set.
+
+
+
+ IPMON Logging
+
+ Syslogd uses its own special method for segregation of log
+ data. It uses special grouping called facility
+ and level. IPMON in -Ds mode uses Local0 as the
+ facility name. All IPMON logged data goes to
+ Local0. The following levels can be used to further segregate
+ the logged data if desired.
+
+ LOG_INFO - packets logged using the "log" keyword as the action rather than pass or block.
+LOG_NOTICE - packets logged which are also passed
+LOG_WARNING - packets logged which are also blocked
+LOG_ERR - packets which have been logged and which can be considered short
+
+ To setup IPFILTER to log all data to
+ /var/log/ipfilter.log, you will need to create the
+ file. The following command will do that:
+
+ touch /var/log/ipfilter.log
+
+ The syslog function is controlled by definition statements
+ in the /etc/syslog.conf file. The syslog.conf file offers
+ considerable flexibility in how syslog will deal with system
+ messages issued by software applications like IPF.
+
+ Add the following statement to /etc/syslog.conf
+ :
+
+ Local0.* /var/log/ipfilter.log
+
+ The Local0.* means to write all the logged messages to the
+ coded file location.
+
+ To activate the changes to /etc/syslog.conf
+ you can reboot or bump the syslog task into
+ re-reading /etc/syslog.conf by
+ kill -HUP <pid>. You get the pid (i.e. process
+ number) by listing the tasks with the ps -ax
+ command. Find syslog in the display and the pid is the number
+ in the left column.
+
+ Do not forget to change /etc/newsyslog.conf
+ to rotate the new log you just created above.
+
+
+
+
+
+ The Format of Logged Messages
+
+ Messages generated by ipmon consist of data fields
+ separated by white space. Fields common to all messages are:
+
+
+
+
+ The date of packet receipt.
+
+
+
+ The time of packet receipt. This is in the form
+ HH:MM:SS.F, for hours, minutes, seconds, and fractions of a
+ second (which can be several digits long).
+
+
+
+ The name of the interface the packet was processed on,
+ e.g. dc0.
+
+
+
+ The group and rule number of the rule, e.g. @0:17.
+
+
+
+
+ These can be viewed with ipfstat -in.
+
+
+
+ The action: p for passed, b for blocked, S for a short
+ packet, n did not match any rules, L for a log rule. The
+ order of precedence in showing flags is: S, p, b, n, L. A
+ capital P or B means that the packet has been logged due to
+ a global logging setting, not a particular rule.
+
+
+
+ The addresses. This is actually three fields: the
+ source address and port (separated by a comma), the ->
+ symbol, and the destination address and port.
+ 209.53.17.22,80 -> 198.73.220.17,1722.
+
+
+
+ PR followed by the protocol name or number, e.g. PR
+ tcp.
+
+
+
+ len followed by the header length and total length of
+ the packet, e.g. len 20 40.
+
+
+
+ If the packet is a TCP packet, there will be an additional
+ field starting with a hyphen followed by letters corresponding
+ to any flags that were set. See the &man.ipmon.8; manual page
+ for a list of letters and their flags.
+
+ If the packet is an ICMP packet, there will be two fields
+ at the end, the first always being ICMP, and
+ the next being the ICMP message and sub-message type,
+ separated by a slash, e.g. ICMP 3/3 for a port unreachable
+ message.
+
+
+
+
+ Building the Rule Script
+
+ Some experienced IPF users create a file containing the
+ rules and code them in a manner compatible with running them
+ as a script with symbolic substitution. The major benefit of
+ doing this is you only have to change the value associated
+ with the symbolic name and when the script is run all the rules
+ containing the symbolic name will have the value substituted in
+ the rules. Being a script, you can use symbolic substitution to
+ code frequent used values and substitute them in multiple
+ rules. You will see this in the following example.
+
+ The script syntax used here is compatible with the sh, csh,
+ and tcsh shells.
+
+ Symbolic substitution fields are prefixed with a dollar
+ sign $.
+
+ Symbolic fields do not have the $ prefix
+
+ The value to populate the Symbolic field must be enclosed
+ with "double quotes".
+
+ Start your rule file with something like this:
+
+
+############# Start of IPF rules script ########################
+
+oif="dc0" # name of the outbound interface
+odns="192.0.2.11" # ISP's dns server IP address Symbolic>
+myip="192.0.2.7" # My Static IP address from ISP
+ks="keep state"
+fks="flags S keep state"
+
+# You can use this same to build the /etc/ipf.rules file
+#cat >> /etc/ipf.rules << EOF
+
+# exec ipf command and read inline data, stop reading
+# when word EOF is found. There has to be one line
+# after the EOF line to work correctly.
+/sbin/ipf -Fa -f - << EOF
+
+# Allow out access to my ISP's Domain name server.
+pass out quick on $oif proto tcp from any to $odns port = 53 $fks
+pass out quick on $oif proto udp from any to $odns port = 53 $ks
+
+# Allow out non-secure standard www function
+pass out quick on $oif proto tcp from $myip to any port = 80 $fks
+
+# Allow out secure www function https over TLS SSL
+pass out quick on $oif proto tcp from $myip to any port = 443 $fks
+EOF
+################## End of IPF rules script ########################
+
+ That is all there is to it. The rules are not important in
+ this example, how the Symbolic substitution field are populated
+ and used are. If the above example was in /etc/ipf.rules.script
+ file, you could reload these rules by entering on the command
+ line.
+
+ sh /etc/ipf.rules.script
+
+
+ There is one problem with using a rules file with embedded
+ symbolics. IPF has no problem with it, but the rc startup
+ scripts that read rc.conf will have
+ problems.
+
+ To get around this limitation with a rc scripts, remove
+ the following line:
+
+ ipfilter_rules=
+
+
+ Add a script like the following to your
+ /usr/local/etc/rc.d/ startup directory. The script
+ should have a obvious name like loadipfrules.sh
+ . The .sh extension is mandatory.
+
+ #!/bin/sh
+sh /etc/ipf.rules.script
+
+ The permission on this script file must be read, write,
+ exec for owner root.
+
+ chmod 700 /usr/local/etc/rc.d/ipf.loadrules.sh
+
+ Now when you system boots your IPF rules will be loaded
+ using the script.
+
+
+
+
+ IPF Rule Sets
+ A rule set is a group of ipf rules coded to pass or block
+ packets based on the values contained in the packet. The
+ bi-directional exchange of packets between hosts comprises a
+ session conversation. The firewall rule set processes the
+ packet 2 times, once on its arrival from the public Internet
+ host and again as it leaves for its return trip back to the
+ public Internet host. Each tcp/ip service (i.e. telnet, www,
+ mail, etc.) is predefined by its protocol, source and
+ destination IP address, or the source and destination port
+ number. This is the basic selection criteria used to create
+ rules which will pass or block services.
+
+ IPF was originally written using a rules processing logic
+ of 'the last matching rule wins' and used only stateless
+ rules. Over time IPF has been enhanced to include a 'quick'
+ option and a stateful 'keep state' option which drastically
+ modernized the rules processing logic.
+
+ The instructions contained in this section is based on
+ using rules that contain the 'quick' option. and the stateful
+ 'keep state' option. This is the basic framework for coding an
+ inclusive firewall rule set.
+
+ An inclusive firewall only allows services matching the
+ rules through. This way you can control what services can
+ originate behind the firewall destined for the public Internet
+ and also control the services which can originate from the
+ public Internet accessing your private network. Everything
+ else is blocked and logged by default design. Inclusive
+ firewalls are much, much securer than exclusive firewall rule
+ sets and is the only rule set type covered herein.
+
+
+ Warning, when working with the firewall rules, always,
+ always do it from the root console of the system running the
+ firewall or you can end up locking your self out.
+
+
+
+
+ Rule Syntax
+ The rule syntax presented here has been simplified to only
+ address the modern stateful rule context and first matching
+ rule wins logic. For the complete legacy rule syntax
+ description see the &man.ipf.8; manual page.
+
+ # is used to mark the start of a comment and may appear at
+ the end of a rule line or on its own lines. Blank lines are
+ ignored.
+
+ Rules contain keywords, These keywords have to be coded in
+ a specific order from left to right on the line. Keywords are
+ identified in bold type. Some keywords have sub-options which
+ may be keywords them selves and also include more sub-options.
+ Each of the headings in the below syntax has a bold section
+ header which expands on the content.
+
+
+
+ ACTION IN-OUT OPTIONS SELECTION STATEFUL
+ PROTO SRC_ADDR,DST_ADDR OBJECT PORT_NUM TCP_FLAG STATEFUL
+
+
+ ACTION = block | pass
+
+ IN-OUT = in | out
+
+ OPTIONS = log | quick | on
+ interface-name
+
+ SELECTION = proto value |
+ source/destination IP | port = number | flags flag-value
+
+ PROTO = tcp/udp | udp | tcp |
+ icmp
+
+ SRC_ADD,DST_ADDR = all | from
+ object to object
+
+ OBJECT = IP address | any
+
+ PORT_NUM = port number
+
+ TCP_FLAG = S
+
+ STATEFUL = keep state
+
+
+ ACTION
+
+ The action indicates what to do with the packet if it
+ matches the rest of the filter rule. Each rule must have a
+ action. The following actions are recognized:
+
+ block indicates that the packet should be dropped if
+ the selection parameters match the packet.
+
+ pass indicates that the packet should exit the firewall
+ if the selection parameters match the packet.
+
+
+
+ IN-OUT
+ This is a mandatory requirement that each filter rule
+ explicitly state which side of the I/O it is to be used on.
+ The next keyword must be either in or out and one or the
+ other has to be coded or the rule will not pass syntax
+ check.
+
+ in means this rule is being applied against an inbound
+ packet which has just been received on the interface
+ facing the public Internet.
+
+ out means this rule is being applied against an
+ outbound packet destined for the interface facing the public
+ Internet.
+
+
+
+ OPTIONS
+
+ These options must be used in the order shown here.
+
+
+
+ log indicates that the packet header will be written to
+ the ipl log (as described in the LOGGING section below) if
+ the selection parameters match the packet.
+
+ quick indicates that if the selection parameters match
+ the packet, this rule will be the last rule checked,
+ allowing a "short-circuit" path to avoid processing any
+ following rules for this packet. This option is a mandatory
+ requirement for the modernized rules processing logic.
+
+
+ on indicates the interface name to be incorporated into
+ the selection parameters. Interface names are as displayed
+ by ifconfig. Using this option, the rule will only match if
+ the packet is going through that interface in the specified
+ direction (in/out). This option is a mandatory requirement
+ for the modernized rules processing logic.
+
+ When a packet is logged, the headers of the packet are
+ written to the IPL packet logging pseudo-device.
+ Immediately following the log keyword, the following
+ qualifiers may be used (in this order):
+
+ body indicates that the first 128 bytes of the packet
+ contents will be logged after the headers.
+
+ first If the 'log' keyword is being used in conjunction
+ with a "keep state" option, it is recommended that this
+ option is also applied so that only the triggering packet
+ is logged and not every packet which there after matches
+ the 'keep state' information.
+
+
+
+ SELECTION
+ The keywords described in this section are used to
+ describe attributes of the packet to be interrogated when
+ determining whether rules match or don't match. There is a
+ keyword subject, and it has sub-option keywords, one of
+ which has to be selected. The following general-purpose
+ attributes are provided for matching, and must be used in
+ this order:
+
+
+
+ PROTO
+ Proto is the subject keyword, it must be coded along
+ with one of it.s corresponding keyword sub-option values.
+ The value allows a specific protocol to be matched against.
+ This option is a mandatory requirement for the modernized
+ rules processing logic.
+
+ tcp/udp | udp | tcp | icmp or any protocol names found
+ in /etc/protocols are recognized and may be used. The
+ special protocol keyword tcp/udp may be used to match
+ either a TCP or a UDP packet, and has been added as a
+ convenience to save duplication of otherwise identical
+ rules.
+
+
+
+ SRC_ADDR/DST_ADDR
+ The 'all' keyword is essentially a synonym for "from
+ any to any" with no other match parameters.
+
+ from src to dst The from and to keywords are used to
+ match against IP addresses. Rules must specify BOTH source
+ and destination parameters. .any. is a special keyword that
+ matches any IP address. As in 'from any to any' or 'from
+ 0.0.0.0/0 to any' or 'from any to 0.0.0.0/0' or 'from
+ 0.0.0.0 to any' or 'from any to 0.0.0.0'
+
+ IP addresses may be specified as a dotted IP address
+ numeric form/mask-length, or as single dotted IP address
+ numeric form.
+
+ There isn't a way to match ranges of IP addresses which
+ do not express themselves easily as mask-length. See this
+ link for help on writing mask-length:
+
+
+
+
+ PORT
+ If a port match is included, for either or both of
+ source and destination, then it is only applied to TCP and
+ UDP packets. When composing port comparisons, either the
+ service name from /etc/services or an integer port number
+ may be used. When the port appears as part of the from
+ object, it matches the source port number, when it appears
+ as part of the to object, it matches the destination port
+ number. The use of the port option with the .to. object is
+ a mandatory requirement for the modernized rules processing
+ logic. As in 'from any to any port = 80'
+
+ Port comparisons may be done in a number of forms, with
+ a number of comparison operators, or port ranges may be
+ specified.
+
+ port "=" | "!=" | "<" | ">" | "<=" | ">=" | "eq" | "ne"
+ | "lt" | "gt" | "le" | "ge".
+
+ To specify port ranges, port "<>" | "><"
+
+
+ Following the source and destination matching
+ parameters, the following two parameters are mandatory
+ requirements for the modernized rules processing logic.
+
+
+
+
+
+ TCP_FLAG
+ Flags are only effective for TCP filtering. The letters
+ represents one of the possible flags that can be
+ interrogated in the TCP packet header.
+
+ The modernized rules processing logic uses the 'flags
+ S' parameter to identify the tcp session start request.
+
+
+
+
+ STATEFUL
+ 'keep state' indicates that on a pass rule, any packets
+ that match the rules selection parameters is to activate
+ the stateful filtering facility.
+
+
+ This option is a mandatory requirement for the
+ modernized rules processing logic.
+
+
+
+
+
+ Stateful Filtering
+ Stateful filtering treats traffic as a bi-directional
+ exchange of packets comprising a session conversation. When
+ activated keep-state dynamically generates internal rules for
+ each anticipated packet being exchanged during the
+ bi-directional session conversation. It has the interrogation
+ abilities to determine if the session conversation between the
+ originating sender and the destination are following the valid
+ procedure of bi-directional packet exchange. Any packets that
+ do not properly fit the session conversation template are
+ automatically rejected as impostors.
+
+ Keep state will also allow ICMP packets related to a TCP
+ or UDP session through. So if you get ICMP type 3 code 4 in
+ response to some web surfing allowed out by a keep state rule,
+ they will be automatically allowed in. Any packet that IPF can
+ be certain is part of a active session, even if it is a
+ different protocol, will be let in.
+
+ What happens is:
+
+ Packets destined to go out the interface connected to the
+ public Internet are first checked against the dynamic state
+ table, if the packet matches the next expected packet
+ comprising in a active session conversation, then it exits
+ the firewall and the state of the session conversation flow
+ is updated in the dynamic state table, the remaining packets
+ get checked against the outbound rule set.
+
+ Packets coming in to the interface connected to the public
+ Internet are first checked against the dynamic state table, if
+ the packet matches the next expected packet comprising a
+ active session conversation, then it exits the firewall and
+ the state of the session conversation flow is updated in the
+ dynamic state table, the remaining packets get checked against
+ the inbound rule set.
+
+ When the conversation completes it is removed from the
+ dynamic state table.
+
+ Stateful filtering allows you to focus on blocking/passing
+ new sessions. If the new session is passed, all its subsequent
+ packets will be allowed through automatically and any
+ impostors automatically rejected. If a new session is blocked,
+ none of its subsequent packets will be allowed through.
+ Stateful filtering has technically advanced interrogation
+ abilities capable of defending against the flood of different
+ attack methods currently employed by attackers.
+
+
+
+ Inclusive Rule set Example
+
+ The following rule set is an example of how to code a very
+ secure inclusive type of firewall. An inclusive firewall only
+ allows services matching pass rules through and blocks all
+ other by default. All firewalls have at the minimum two
+ interfaces which have to have rules to allow the firewall to
+ function.
+
+ All Unix flavored systems including &os; are designed to
+ use interface l0 and IP address 127.0.0.1 for internal
+ communication with in the &os; operating system. The firewall
+ rules must contain rules to allow free unmolested movement of
+ these special internally used packets.
+
+ The interface which faces the public Internet, is the one
+ which you code your rules to authorize and control access out
+ to the public Internet and access requests arriving from the
+ public Internet. This can be your .user ppp. tun0 interface or
+ your NIC card that is cabled to your DSL or cable modem.
+
+ In cases where one or more than one NICs are cabled to
+ Private LANs (local area networks) behind the firewall, those
+ interfaces must have a rule coded to allow free unmolested
+ movement of packets originating from those LAN interfaces.
+
+ The rules should be first organized into three major
+ sections, all the free unmolested interfaces, public interface
+ outbound, and the public interface inbound.
+
+ The order of the rules in each of the public interface
+ sections should be in order of the most used rules being
+ placed before less often used rules with the last rule in the
+ section being a block log all packets on that interface and
+ direction.
+
+ The Outbound section in the following rule set only
+ contains 'pass' rules which contain selection values that
+ uniquely identify the service that is authorized for public
+ Internet access. All the rules have the 'quick', 'on',
+ 'proto', 'port', and 'keep state' option coded. The 'proto
+ tcp' rules have the 'flag' option included to identify the
+ session start request as the triggering packet to activate the
+ stateful facility.
+
+ The Inbound section has all the blocking of undesirable
+ packets first for two different reasons. First is these things
+ being blocked may be part of an otherwise valid packet which
+ may be allowed in by the later authorized service rules.
+ Second reason is that by having a rule that explicitly blocks
+ selected packets that I receive on an infrequent bases and
+ don't want to see in the log, this keeps them from being
+ caught by the last rule in the section which blocks and logs
+ all packets which have fallen through the rules. The last rule
+ in the section which blocks and logs all packets is how you
+ create the legal evidence needed to prosecute the people who
+ are attacking your system.
+
+ Another thing you should take note of, is there is no
+ response returned for any of the undesirable stuff, their
+ packets just get dropped and vanish. This way the attackers
+ has no knowledge if his packets have reached your system. The
+ less the attackers can learn about your system the more secure
+ it is. The inbound 'nmap OS fingerprint' attempts rule I log
+ the first occurrence because this is something a attacker
+ would do.
+
+ Any time you see log messages on a rule with .log first.
+ You should do an ipfstat -hio command to
+ see the number of times the rule has been matched so you know
+ if your are being flooded, i.e. under attack.
+
+ When you log packets with port numbers you do not
+ recognize, go to
+ and do a port number lookup to find what the purpose of that
+ port number is.
+
+ Check out this link for port numbers used by Trojans
+
+
+
+ The following rule set is a complete very secure
+ 'inclusive' type of firewall rule set that I have used on my
+ system. You can not go wrong using this rule set for your own.
+ Just comment out any pass rules for services to don.t want to
+ authorize.
+
+ If you see messages in your log that you want to stop
+ seeing just add a block rule in the inbound section.
+
+ You have to change the dc0
+ interface name in every rule to the interface name of the Nic
+ card that connects your system to the public Internet. For
+ user PPP it would be tun0.
+
+ Add the following statements to
+ /etc/ipf.rules:
+
+ #################################################################
+# No restrictions on Inside Lan Interface for private network
+# Not needed unless you have Lan
+#################################################################
+
+#pass out quick on xl0 all
+#pass in quick on xl0 all
+
+#################################################################
+# No restrictions on Loopback Interface
+#################################################################
+pass in quick on lo0 all
+pass out quick on lo0 all
+
+#################################################################
+# Interface facing Public Internet (Outbound Section)
+# Interrogate session start requests originating from behind the
+# firewall on the private network
+# or from this gateway server destine for the public Internet.
+#################################################################
+
+# Allow out access to my ISP's Domain name server.
+# xxx must be the IP address of your ISP.s DNS.
+# Dup these lines if your ISP has more than one DNS server
+# Get the IP addresses from /etc/resolv.conf file
+pass out quick on dc0 proto tcp from any to xxx port = 53 flags S keep state
+pass out quick on dc0 proto udp from any to xxx port = 53 keep state
+
+# Allow out access to my ISP's DHCP server for cable or DSL networks.
+# This rule is not needed for .user ppp. type connection to the
+# public Internet, so you can delete this whole group.
+# Use the following rule and check log for IP address.
+# Then put IP address in commented out rule & delete first rule
+pass out log quick on dc0 proto udp from any to any port = 67 keep state
+#pass out quick on dc0 proto udp from any to z.z.z.z port = 67 keep state
+
+
+# Allow out non-secure standard www function
+pass out quick on dc0 proto tcp from any to any port = 80 flags S keep state
+
+# Allow out secure www function https over TLS SSL
+pass out quick on dc0 proto tcp from any to any port = 443 flags S keep state
+
+# Allow out send & get email function
+pass out quick on dc0 proto tcp from any to any port = 110 flags S keep state
+pass out quick on dc0 proto tcp from any to any port = 25 flags S keep state
+
+# Allow out Time
+pass out quick on dc0 proto tcp from any to any port = 37 flags S keep state
+
+# Allow out nntp news
+pass out quick on dc0 proto tcp from any to any port = 119 flags S keep state
+
+# Allow out gateway & LAN users non-secure FTP ( both passive & active modes)
+# This function uses the IPNAT built in FTP proxy function coded in
+# the nat rules file to make this single rule function correctly.
+# If you want to use the pkg_add command to install application packages
+# on your gateway system you need this rule.
+pass out quick on dc0 proto tcp from any to any port = 21 flags S keep state
+
+# Allow out secure FTP, Telnet, and SCP
+# This function is using SSH (secure shell)
+pass out quick on dc0 proto tcp from any to any port = 22 flags S keep state
+
+# Allow out non-secure Telnet
+pass out quick on dc0 proto tcp from any to any port = 23 flags S keep state
+
+# Allow out FBSD CVSUP function
+pass out quick on dc0 proto tcp from any to any port = 5999 flags S keep state
+
+# Allow out ping to public Internet
+pass out quick on dc0 proto icmp from any to any icmp-type 8 keep state
+
+# Allow out whois for LAN PC to public Internet
+pass out quick on dc0 proto tcp from any to any port = 43 flags S keep state
+
+# Block and log only the first occurrence of everything
+# else that.s trying to get out.
+# This rule enforces the block all by default logic.
+block out log first quick on dc0 all
+
+#################################################################
+# Interface facing Public Internet (Inbound Section)
+# Interrogate packets originating from the public Internet
+# destine for this gateway server or the private network.
+#################################################################
+
+# Block all inbound traffic from non-routable or reserved address spaces
+block in quick on dc0 from 192.168.0.0/16 to any #RFC 1918 private IP
+block in quick on dc0 from 172.16.0.0/12 to any #RFC 1918 private IP
+block in quick on dc0 from 10.0.0.0/8 to any #RFC 1918 private IP
+block in quick on dc0 from 127.0.0.0/8 to any #loopback
+block in quick on dc0 from 0.0.0.0/8 to any #loopback
+block in quick on dc0 from 169.254.0.0/16 to any #DHCP auto-config
+block in quick on dc0 from 192.0.2.0/24 to any #reserved for docs
+block in quick on dc0 from 204.152.64.0/23 to any #Sun cluster interconnect
+block in quick on dc0 from 224.0.0.0/3 to any #Class D & E multicast
+
+##### Block a bunch of different nasty things. ############
+# That I don't want to see in the log
+
+# Block frags
+block in quick on dc0 all with frags
+
+# Block short tcp packets
+block in quick on dc0 proto tcp all with short
+
+# block source routed packets
+block in quick on dc0 all with opt lsrr
+block in quick on dc0 all with opt ssrr
+
+# Block nmap OS fingerprint attempts
+# Log first occurrence of these so I can get their IP address
+block in log first quick on dc0 proto tcp from any to any flags FUP
+
+# Block anything with special options
+block in quick on dc0 all with ipopts
+
+# Block public pings
+block in quick on dc0 proto icmp all icmp-type 8
+
+# Block ident
+block in quick on dc0 proto tcp from any to any port = 113
+
+# Block all Netbios service. 137=name, 138=datagram, 139=session
+# Netbios is MS/Windows sharing services.
+# Block MS/Windows hosts2 name server requests 81
+block in log first quick on dc0 proto tcp/udp from any to any port = 137
+block in log first quick on dc0 proto tcp/udp from any to any port = 138
+block in log first quick on dc0 proto tcp/udp from any to any port = 139
+block in log first quick on dc0 proto tcp/udp from any to any port = 81
+
+# Allow traffic in from ISP's DHCP server. This rule must contain
+# the IP address of your ISP.s DHCP server as it.s the only
+# authorized source to send this packet type. Only necessary for
+# cable or DSL configurations. This rule is not needed for
+# .user ppp. type connection to the public Internet.
+# This is the same IP address you captured and
+# used in the outbound section.
+pass in quick on dc0 proto udp from z.z.z.z to any port = 68 keep state
+
+# Allow in standard www function because I have apache server
+pass in quick on dc0 proto tcp from any to any port = 80 flags S keep state
+
+# Allow in non-secure Telnet session from public Internet
+# labeled non-secure because ID/PW passed over public Internet as clear text.
+# Delete this sample group if you do not have telnet server enabled.
+#pass in quick on dc0 proto tcp from any to any port = 23 flags S keep state
+
+# Allow in secure FTP, Telnet, and SCP from public Internet
+# This function is using SSH (secure shell)
+pass in quick on dc0 proto tcp from any to any port = 22 flags S keep state
+
+# Block and log only first occurrence of all remaining traffic
+# coming into the firewall. The logging of only the first
+# occurrence stops a .denial of service. attack targeted
+# at filling up your log file space.
+# This rule enforces the block all by default logic.
+block in log first quick on dc0 all
+################### End of rules file #####################################
+
+
+
+
+ NAT
+
+ NAT stands for Network Address
+ Translation. To those familiar with Linux, this concept is
+ called IP Masquerading, NAT and IP
+ Masquerading are the same thing. One of the many things the
+ IPF NAT function enables, is the ability to
+ have a private Local Area Network (LAN) behind the firewall
+ sharing a single ISP assigned IP address to the public
+ Internet.
+
+ You ask why would someone want to do this. ISPs normally
+ assign a dynamic IP address to their non-commercial users.
+ Dynamic means the IP address can be different each time you
+ dial in and logon to your ISP, or for cable and DSL modem
+ users when you power off and then power on your modems you can
+ get assigned a different IP address. This IP address is how
+ you are known to the public Internet.
+
+ Now lets say you have 5 PCs at home and each one needs
+ Internet access. You would have to pay your ISP for an
+ individual Internet account for each PC and have 5 phone
+ lines.
+
+ With NAT you only need a single account
+ with your ISP, then cable your other 4 PC.s to a switch and
+ the switch to the NIC in your &os; system which is going to
+ service your LAN as a gateway. NAT will
+ automatically translate the private LAN IP address for each
+ separate PC on the LAN to the single public IP address as it
+ exits the firewall bound for the public Internet. It also does
+ the reverse translation for returning packets.
+
+ NAT is most often accomplished without
+ the approval, or knowledge, of your ISP and in most cases is
+ grounds for your ISP terminating your account if found
+ out. Commercial users pay a lot more for their Internet
+ connection and usually get assigned a block of static IP
+ address which never change. The ISP also expects and consents
+ to their Commercial customers using NAT for
+ their internal private LANs.
+
+ There is a special range of IP addresses reserved for
+ NATed private LAN IP address. According to
+ RFC 1918, you can use the following IP ranges for private nets
+ which will never be routed directly to the public
+ Internet.
+
+
+
+
+
+
+
+
+ Start IP 10.0.0.0
+
+ -
+ Ending IP 10.255.255.255
+
+
+
+
+ Start IP 172.16.0.0
+
+ -
+ Ending IP 172.31.255.255
+
+
+
+
+ Start IP 192.168.0.0
+
+ -
+ Ending IP 192.168.255.255
+
+
+
+
+
+
+
+
+ IPNAT
+
+ NAT rules are loaded by using the ipnat
+ command. Typically the NAT rules are stored
+ in /etc/ipnat.rules . See &man.ipnat.1
+ for details.
+
+ When changing the NAT rules after
+ NAT has been started, Make your changes to
+ the file containing the nat rules, then run ipnat command with
+ the -CF flags to delete the internal in use
+ NAT rules and flush the contents of the
+ translation table of all active entries.
+
+ To reload the NAT rules issue a command
+ like this:
+
+ ipnat -CF -f /etc/ipnat.rules
+
+ To display some statistics about your
+ NAT, use this command:
+
+ ipnat -s
+
+ To list the NAT table's current
+ mappings, use this command:
+
+ ipnat -l
+
+ To turn verbose mode on, and display information relating
+ to rule processing and active rules/table entries:
+
+ ipnat -v
+
+
+
+ IPNAT Rules
+
+ NAT rules are very flexible and can
+ accomplish many different things to fit the needs of
+ commercial and home users.
+
+ The rule syntax presented here has been simplified to what
+ is most commonly used in a non-commercial environment. For a
+ complete rule syntax description see the &man.ipnat.5; manual
+ page.
+
+ The syntax for a NAT rule looks
+ something like this:
+
+ map IFLAN_IP_RANGE -> PUBLIC_ADDRESS
+
+ The keyword map starts the rule.
+
+ Replace IF with the external
+ interface.
+
+ The LAN_IP_RANGE is what your
+ internal clients use for IP Addressing, usually this is
+ something like 192.168.1.0/24.
+
+ The PUBLIC_ADDRESS can either
+ be the external IP address or the special keyword `0.32',
+ which means to use the IP address assigned to
+ IF.
+
+
+
+ How NAT works
+
+ A packet arrives at the firewall from the LAN with a
+ public destination. It passes through the outbound filter
+ rules, NAT gets his turn at the packet and
+ applies its rules top down, first matching rule
+ wins. NAT tests each of its rules against
+ the packets interface name and source IP address. When a
+ packets interface name matches a NAT rule
+ then the [source IP address, i.e. private Lan IP address] of
+ the packet is checked to see if it falls within the IP address
+ range specified to the left of the arrow symbol on the
+ NAT rule. On a match the packet has its
+ source IP address rewritten with the public IP address
+ obtained by the `0.32' keyword. NAT posts a
+ entry in its internal NAT table so when the
+ packet returns from the public Internet it can be mapped back
+ to its original private IP address and then passed to the
+ filter rules for processing.
+
+
+
+
+ Enabling IPNAT
+
+ To enable IPNAT add these statements to
+ /etc/rc.conf
+
+ To enable your machine to route traffic between
+ interfaces.
+
+ gateway_enable="YES"
+
+ To start IPNAT automatically each time:
+
+ ipnat_enable="YES"
+
+ To specify where to load the IPNAT
+ rules from
+
+ ipnat_rules="/etc/ipnat.rules"
+
+
+
+ NAT for a very large LAN
+
+ For networks that have large numbers of PC's on the Lan or
+ networks with more that a single LAN the process of funneling
+ all those private IP address into a single public IP address
+ becomes a resource problem that may cause problems with same
+ port numbers being used many times across many
+ NATed LAN PC's causing collisions. There
+ are 2 ways to relieve this resource problem.
+
+
+ Assigning Ports to Use
+
+ XXXBLAH
+
+ map dc0 192.168.1.0/24 -> 0.32
+
+ In the above rule the packet's source port is unchanged
+ as the packet passes through IPNAT. By
+ adding the portmap keyword you can tell
+ IPNAT to only use source ports in a
+ range. For example the following rule will tell
+ IPNAT to modify the source port to be
+ within that range.
+
+ map dc0 192.168.1.0/24 -> 0.32 portmap tcp/udp 20000:60000
+
+ Additionally we can make things even easier by using the
+ `auto' keyword to tell IPNAT to determine
+ by itself which ports are available to use:
+
+ map dc0 192.168.1.0/24 -> 0.32 portmap tcp/udp auto
+
+
+
+ Using a pool of public addresses
+
+ In very large LANs there comes a point where there are
+ just too many LAN addresses to fit into a single public
+ address. By changing the following rule:
+
+ map dc0 192.168.1.0/24 -> 204.134.75.1
+
+ Currently this rule maps all connections through 204.134.75.1. This can be changed to
+ specify a range:
+
+ map dc0 192.168.1.0/24 -> 204.134.75.1-10
+
+ Or a subnet using CIDR notation such as:
+
+ map dc0 192.168.1.0/24 -> 204.134.75.0/24
+
+
+
+
+ Port Redirection
+
+ An very common practice is to have a web server, email
+ server, database server and DNS server each segregated to a
+ different PC on the LAN. In this case the traffic from these
+ servers still have to be NATed, but there
+ has to be some way to direct the inbound traffic to the
+ correct LAN PC's. IPNAT has the redirection
+ facilities of NAT to solve this problem.
+ Lets say you have your web server on LAN address 10.0.10.25 and your single public IP
+ address is 20.20.20.5 you would
+ code the rule like this:
+
+ map dc0 20.20.20.5/32 port 80 -> 10.0.10.25 port 80
+
+ or
+
+ map dc0 0/32 port 80 -> 10.0.10.25 port 80
+
+ or for a LAN DNS Server on LAN address of 10.0.10.33 that needs to receive
+ public DNS requests
+
+ map dc0 20.20.20.5/32 port 53 -> 10.0.10.33 port 53 udp
+
+
+
+ FTP and NAT
+
+ FTP is a dinosaur left over from the time before the
+ Internet as it is known today, when research universities were
+ leased lined together and FTP was used to share files among
+ research Scientists. This was a time when data security was
+ not even an idea yet. Over the years the FTP protocol became
+ buried into the backbone of the emerging Internet and its
+ username and password being sent in clear text was never
+ changed to address new security concerns. FTP has two flavors,
+ it can run in active mode or passive mode. The difference is
+ in how the data channel is acquired. Passive mode is more
+ secure as the data channel is acquired be the ordinal ftp
+ session requester. For a real good explanation of FTP and the
+ different modes see .
+
+
+ IPNAT Rules
+
+ IPNAT has a special built in FTP
+ proxy option which can be specified on the
+ NAT map rule. It can monitor all outbound
+ packet traffic for FTP active or passive start session
+ requests and dynamically create temporary filter rules
+ containing only the port number really in use for the data
+ channel. This eliminates the security risk FTP normally
+ exposes the firewall to from having large ranges of high
+ order port numbers open.
+
+ This rule will handle all the traffic for the internal
+ LAN:
+
+ map dc0 10.0.10.0/29 -> 0/32 proxy port 21 ftp/tcp
+
+ This rule handles the FTP traffic from the gateway.
+
+ map dc0 0.0.0.0/0 -> 0/32 proxy port 21 ftp/tcp
+
+ This rule handles all non-FTP traffic from the internal
+ LAN.
+
+ map dc0 10.0.10.0/29 -> 0/32
+
+ The FTP map rule goes before our regular map rule. All
+ packets are tested against the first rule from the top.
+ Matches on interface name, then private LAN source IP
+ address, and then is it a FTP packet. If all that matches
+ then the special FTP proxy creates temp filter rules to let
+ the FTP session packets pass in and out, in addition to also
+ NATing the FTP packets. All LAN packets
+ that are not FTP do not match the first rule and fall
+ through to the third rule and are tested, matching on
+ interface and source IP, then are
+ NATed.
+
+
+
+ IPNAT FTP Filter Rules
+
+ Only one filter rule is needed for FTP if the
+ NAT FTP proxy is used.
+
+ Without the FTP Proxy you will need the following three
+ rules
+
+ # Allow out LAN PC client FTP to public Internet
+# Active and passive modes
+pass out quick on rl0 proto tcp from any to any port = 21 flags S keep state
+
+# Allow out passive mode data channel high order port numbers
+pass out quick on rl0 proto tcp from any to any port > 1024 flags S keep state
+
+# Active mode let data channel in from FTP server
+pass in quick on rl0 proto tcp from any to any port = 20 flags S keep state
+
+
+
+ FTP NAT Proxy Bug
+
+ As of &os; 4.9 which includes IPFILTER version 3.4.31
+ the FTP proxy works as documented during the FTP session
+ until the session is told to close. When the close happens
+ packets returning from the remote FTP server are blocked and
+ logged coming in on port 21. The NAT
+ FTP/proxy appears to remove its temp rules prematurely,
+ before receiving the response from the remote FTP server
+ acknowledging the close. Posted problem report to ipf
+ mailing list.
+
+ Solution is to add filter rule like this one to get rid
+ of these unwanted log messages or do nothing and ignore FTP
+ inbound error messages in your log. Not like you do FTP
+ session to the public Internet all the time, so this is not
+ a big deal.
+
+ Block in quick on rl0 proto tcp from any to any port = 21
+
+
+
+
+
+ IPFW
+
+ The IPFIREWALL (IPFW) is a &os; sponsored firewall software
+ application authored and maintained by &os; volunteer staff
+ members. It uses the legacy Stateless rules and a legacy rule
+ coding technique to achieve what is referred to as Simple
+ Stateful logic.
+
+ The IPFW stateless rule syntax is empowered with technically
+ sophisticated selection capabilities which far surpasses the
+ knowledge level of the customary firewall installer. IPFW is
+ targeted at the professional user or the advanced technical
+ computer hobbyist who have advanced packet selection
+ requirements. A high degree of detailed knowledge into how
+ different protocols use and create their unique packet header
+ information is necessary before the power of the IPFW rules can
+ be unleashed. Providing that level of explanation is out of the
+ scope of this section of the handbook.
+
+ IPFW is composed of 7 components, the primary component is
+ the kernel firewall filter rule processor and its integrated
+ packet accounting facility, the logging facility, the 'divert'
+ rule which triggers the NAT facility, and the
+ advanced special purpose facilities, the dummynet traffic shaper
+ facilities, the 'fwd rule' forward facility, the bridge
+ facility, and the ipstealth facility.
+
+
+ Enabling IPFW
+
+ IPFW is included in the basic &os; install as a separate
+ run time loadable module. IPFW will dynamically load the
+ kernel module when the rc.conf statement
+ firewall_enable="YES" is used. You do not
+ need to compile IPFW into the &os; kernel unless you want
+ NAT function enabled.
+
+ After rebooting your system with
+ firewall_enable="YES" in
+ rc.conf the following white highlighted
+ message is displayed on the screen as part of the boot
+ process:
+
+ IP packet filtering initialized, divert disabled,
+ rule-based forwarding enabled, default to deny, logging
+ disabled
+
+ You can disregard this message as it is out dated and no
+ longer is the true status of the IPFW loadable module. The
+ loadable module really does have logging ability compiled in.
+
+ To set the verbose logging limit, There is a knob you can
+ set in /etc/sysctl.conf by adding this
+ statement, logging will be enabled on future reboots.
+
+ net.inet.ip.fw.verbose_limit=5
+
+
+
+ Kernel Options
+
+ It is not a mandatory requirement that you enable IPFW by
+ compiling the following options into the &os; kernel unless
+ you need NAT function. It is presented here
+ as background information.
+
+ options IPFIREWALL
+
+ This option enables IPFW as part of the kernel
+
+ options IPFIREWALL_VERBOSE
+
+ Enables logging of packets that pass through IPFW and have
+ the 'log' keyword specified in the rule set.
+
+ options IPFIREWALL_VERBOSE_LIMIT=5
+
+ This specifies the default number of packets from a
+ particular rule is to be logged. Without this option, each
+ repeated occurrences of the same packet will be logged, and
+ eventually consuming all the free disk space resulting in
+ services being denied do to lack of resources. The 5 is the
+ number of consecutive times to log evidence of this unique
+ occurrence.
+
+ options IPFIREWALL_DEFAULT_TO_ACCEPT
+
+ This option will allow everything to pass through the
+ firewall by default. Which is a good idea when you are first
+ setting up your firewall.
+
+ options IPV6FIREWALL
+options IPV6FIREWALL_VERBOSE
+options IPV6FIREWALL_VERBOSE_LIMIT
+options IPV6FIREWALL_DEFAULT_TO_ACCEPT
+
+ These options are exactly the same as the IPv4 options but
+ they are for IPv6. If you don't use IPv6 you might want to use
+ IPV6FIREWALL without any rules to block all IPv6
+
+ options IPDIVERT
+
+ This enables the use of NAT
+ functionality.
+
+
+ If you don't include IPFIREWALL_DEFAULT_TO_ACCEPT or set
+ your rules to allow incoming packets you will block all
+ packets going to and from this machine.
+
+
+
+
+ /etc/rc.conf Options
+
+ If you do not have IPFW compiled into your kernel you will
+ need to load it with the following statement in your
+ /etc/rc.conf:
+
+ firewall_enable="YES"
+
+ Set the script to run to activate your rules:
+
+ firewall_script="/etc/ipfw.rules"
+
+ Enable logging:
+
+ firewall_logging="YES"
+
+
+
+ The IPFW Command
+
+ The ipfw command is the normal vehicle for making manual
+ single rule additions or deletions to the firewall active
+ internal rules while it is running. The problem with using
+ this method is once your system is shutdown or halted all the
+ rules you added or changed or deleted are lost. Writing all
+ your rules in a file and using that file to load the rules at
+ boot time, or to replace in mass the currently running
+ firewall rules with changes you made to the files content is
+ the recommended method used here.
+
+ The IPFW command is still a very useful to display the
+ running firewall rules to the console screen. The IPFW
+ accounting facility dynamically creates a counter for each
+ rule that counts each packet that matches the rule. During the
+ process of testing a rule, listing the rule with its counter
+ is the only way of determining if the rule is functioning.
+
+ To list all the rules in sequence:
+
+ ipfw list
+
+ To list all the rules with a time stamp of when the last
+ time the rule was matched:
+
+ ipfw -t list
+
+ To list the accounting information, packet count for
+ matched rules along with the rules themselves. The first
+ column is the rule number, followed by the number of outgoing
+ matched packets, followed by the number of incoming matched
+ packets, and then the rule itself.
+
+ ipfw -a list
+
+ List the dynamic rules in addition to the static
+ rules:
+
+ ipfw -d list
+
+ Also show the expired dynamic rules:
+
+ ipfw -d -e list
+
+ Zero the counters:
+
+ ipfw zero
+
+ Zero the counters for just rule NUM
+ :
+
+ ipfw zero NUM
+
+
+
+ IPFW Rule Sets
+
+ A rule set is a group of ipfw rules coded to allow or deny
+ packets based on the values contained in the packet. The
+ bi-directional exchange of packets between hosts comprises a
+ session conversation. The firewall rule set processes the
+ packet 2 times, once on its arrival from the public Internet
+ host and again as it leaves for its return trip back to the
+ public Internet host. Each tcp/ip service (i.e. telnet, www,
+ mail, etc.) is predefined by its protocol, and port number.
+ This is the basic selection criteria used to create rules
+ which will allow or deny services.
+
+ When a packet enters the firewall it is compared against
+ the first rule in the rule set and progress one rule at a time
+ moving from top to bottom of the set in ascending rule number
+ sequence order. When the packet matches a rule selection
+ parameters, the rules action field value is executed and the
+ search of the rule set terminates for that packet. This is
+ referred to as the 'first match wins' search method. If the
+ packet does not match any of the rules, it gets caught by the
+ mandatory ipfw default rule, number 65535 which denies all
+ packets and discards them without any reply back to the
+ originating destination.
+
+ The instructions contained here are based on using rules
+ that contain the stateful 'keep state', 'limit', 'in'/'out',
+ and via options. This is the basic framework for coding an
+ inclusive type firewall rule set.
+
+ An inclusive firewall only allows services matching the
+ rules through. This way you can control what services can
+ originate behind the firewall destine for the public Internet
+ and also control the services which can originate from the
+ public Internet accessing your private network. Everything
+ else is denied by default design. Inclusive firewalls are
+ much, much more secure than exclusive firewall rule sets and
+ is the only rule set type covered here in.
+
+
+ When working with the firewall rules be careful, you can
+ end up locking your self out.
+
+
+
+ Rule Syntax
+
+ The rule syntax presented here has been simplified to
+ what is necessary to create a standard inclusive type
+ firewall rule set. For a complete rule syntax description
+ see the &man.ipfw.8; manual page.
+
+ Rules contain keywords, These keywords have to be coded
+ in a specific order from left to right on the line. Keywords
+ are identified in bold type. Some keywords have sub-options
+ which may be keywords them selves and also include more
+ sub-options.
+
+ # is used to mark the start of a
+ comment and may appear at the end of a rule line or on its
+ own lines. Blank lines are ignored.
+
+ CMD RULE# ACTION LOGGING SELECTION
+ STATEFUL
+
+
+ CMD
+
+ Each rule has to be prefixed with 'add' to add the
+ rule to the internal table.
+
+
+
+ RULE#
+ Each rule has to have a rule number to go with it.
+
+
+
+ ACTION
+
+ A rule can be associated with one of the following
+ actions, which will be executed when the packet matches
+ the selection criterion of the rule.
+
+ allow | accept | pass |
+ permit
+
+ These all mean the same thing which is to allow
+ packets that match the rule to exit the firewall rule
+ processing. The search terminates at this rule.
+
+ check-state
+
+ Checks the packet against the dynamic rules table. If
+ a match is found, execute the action associated with the
+ rule which generated this dynamic rule, otherwise move to
+ the next rule. The Check-state rule does not have
+ selection criterion. If no check-state rule is present in
+ the rule set, the dynamic rules table is checked at the
+ first keep-state or limit rule.
+
+ deny | drop
+
+ Both words mean the same thing which is to discard
+ packets that match this rule. The search terminates.
+
+
+
+ Logging
+ log or
+ logamount
+
+ When a packet matches a rule with the log keyword, a
+ message will be logged to syslogd with a facility name of
+ SECURITY. The logging only occurs if the number of
+ packets logged so far for that particular rule does not
+ exceed the logamount parameter. If no logamount is
+ specified, the limit is taken from the sysctl variable
+ net.inet.ip.fw.verbose_limit. In both cases, a value of
+ zero removes the logging limit. Once the limit is
+ reached, logging can be re-enabled by clearing the
+ logging counter or the packet counter for that rule, see
+ the ipfw reset log command. Note: logging is done after
+ all other packet matching conditions have been
+ successfully verified, and before performing the final
+ action (accept, deny) on the packet. It is up to you to
+ decide which rules you want to enable logging on.
+
+
+
+ Selection
+
+ The keywords described in this section are used to
+ describe attributes of the packet to be interrogated when
+ determining whether rules match or don't match the packet.
+ The following general-purpose attributes are provided for
+ matching, and must be used in this order:
+
+ udp | tcp | icmp
+
+ or any protocol names found in /etc/protocols are
+ recognized and may be used. The value specified is
+ protocol to be matched against. This is a mandatory
+ requirement.
+
+ from src to dst
+
+ The from and to keywords are used to match against IP
+ addresses. Rules must specify BOTH source and destination
+ parameters. any is a special keyword that matches any IP
+ address. me is a special keyword that matches any IP
+ address configured on an interface in your &os; system to
+ represent the PC the firewall is running on. (i.e. this
+ box) As in from me to any or from any to me or from
+ 0.0.0.0/0 to any or from any to 0.0.0.0/0 or from 0.0.0.0
+ to any or from any to 0.0.0.0 or from me to 0.0.0.0. IP
+ addresses are specified as a dotted IP address numeric
+ form/mask-length, or as single dotted IP address numeric
+ form. This is a mandatory requirement. See this link for
+ help on writing mask-lengths.
+
+ port number
+
+ For protocols which support port numbers (such as
+ TCP and UDP). It is mandatory that you
+ code the port number of the service you want to match
+ on. Service names (from
+ /etc/services) may be used instead of
+ numeric port values.
+
+ in | out
+
+ Matches incoming or outgoing packets,
+ respectively. The in and out are keywords and it is
+ mandatory that you code one or the other as part of your
+ rule matching criterion.
+
+ via IF
+
+ Matches packets going through the interface specified
+ by exact name. The via keyword causes the interface to
+ always be checked as part of the match process.
+
+ setup
+
+ This is a mandatory keyword that identifies the
+ session start request for TCP
+ packets.
+
+ keep-state
+
+ This is a mandatory> keyword. Upon a match, the
+ firewall will create a dynamic rule, whose default
+ behavior is to match bidirectional traffic between source
+ and destination IP/port using the same protocol.
+
+ limit {src-addr | src-port | dst-addr |
+ dst-port}
+
+ The firewall will only allow
+ N connections with the same set
+ of parameters as specified in the rule. One or more of
+ source and destination addresses and ports can be
+ specified. The 'limit' and 'keep-state' can not be used on
+ same rule. Limit provides the same stateful function as
+ 'keep-state' plus its own functions.
+
+
+
+
+
+ Stateful Rule Option
+
+ Stateful filtering treats traffic as a bi-directional
+ exchange of packets comprising a session conversation. It
+ has the interrogation abilities to determine if the session
+ conversation between the originating sender and the
+ destination are following the valid procedure of
+ bi-directional packet exchange. Any packets that do not
+ properly fit the session conversation template are
+ automatically rejected as impostors.
+
+ 'check-state' is used to identify where in the IPFW
+ rules set the packet is to be tested against the dynamic
+ rules facility. On a match the packet exits the firewall to
+ continue on its way and a new rule is dynamic created for
+ the next anticipated packet being exchanged during this
+ bi-directional session conversation. On a no match the
+ packet advances to the next rule in the rule set for
+ testing.
+
+ The dynamic rules facility is vulnerable to resource
+ depletion from a SYN-flood attack which would open a huge
+ number of dynamic rules. To counter this attack, &os;
+ version 4.5 added another new option named limit. This
+ option is used to limit the number of simultaneous session
+ conversations by interrogating the rules source or
+ destinations fields as directed by the limit option and
+ using the packet's IP address found there, in a search of
+ the open dynamic rules counting the number of times this
+ rule and IP address combination occurred, if this count is
+ greater that the value specified on the limit option, the
+ packet is discarded.
+
+
+
+ Logging Firewall Messages
+ The benefits of logging are obvious, provides the
+ ability to review after the fact the rules you activated
+ logging on which provides information like, what packets had
+ been dropped, what addresses they came from, where they were
+ going, giving you a significant edge in tracking down
+ attackers.
+
+ Even with the logging facility enabled, IPFW will not
+ generate any rule logging on it's own. The firewall
+ administrator decides what rules in the rule set he wants
+ to log and adds the log verb to those rules. Normally only
+ deny rules are logged. Like the deny rule for incoming
+ ICMP pings. It is very customary to
+ duplicate the ipfw default deny everything rule with the
+ log verb included as your last rule in the rule set. This
+ way you get to see all the packets that did not match any
+ of the rules in the rule set.
+
+ Logging is a two edged sword, if you're not careful, you
+ can lose yourself in the over abundance of log data and fill
+ your disk up with growing log files. DoS attacks that fill
+ up disk drives is one of the oldest attacks around. These
+ log message are not only written to syslogd, but also are
+ displayed on the root console screen and soon become very
+ annoying.
+
+ The IPFIREWALL_VERBOSE_LIMIT=5
+ kernel option limits the number of consecutive messages
+ sent to the system logger syslogd, concerning the packet
+ matching of a given rule. When this option is enabled in
+ the kernel, the number of consecutive messages concerning
+ a particular rule is capped at the number specified. There
+ is nothing to be gained from 200 log messages saying the
+ same identical thing. For instance, 5 consecutive messages
+ concerning a particular rule would be logged to syslogd,
+ the remainder identical consecutive messages would be
+ counted and posted to the syslogd with a phrase like
+ this:
+
+ last message repeated 45 times
+
+ All logged packets messages are written by default to
+ /var/log/security file, which is
+ defined in the /etc/syslog.conf file.
+
+
+
+
+ Building a Rule Script
+ Most experienced IPFW users create a file containing the
+ rules and code them in a manner compatible with running them
+ as a script. The major benefit of doing this is the firewall
+ rules can be refreshed in mass without the need of
+ rebooting the system to activate the new rules. This method
+ is very convenient in testing new rules as the procedure can
+ be executed as many times as needed. Being a script, you can
+ use symbolic substitution to code frequent used values and
+ substitution them in multiple rules. You will see this in
+ the following example.
+
+ The script syntax used here is compatible with the 'sh',
+ 'csh', 'tcsh' shells. Symbolic substitution fields are
+ prefixed with a dollar sign $. Symbolic fields do not have
+ the $ prefix. The value to populate the Symbolic field must
+ be enclosed to "double quotes".
+
+ Start your rules file like this:
+
+ ############### start of example ipfw rules script #############
+#
+ipfw -q -f flush # Delete all rules
+# Set defaults
+oif="tun0" # out interface
+odns="192.0.2.11" # ISP's dns server IP address
+cmd="ipfw -q add " # build rule prefix
+ks="keep-state" # just too lazy to key this each time
+$cmd 00500 check-state
+$cmd 00502 deny all from any to any frag
+$cmd 00501 deny tcp from any to any established
+$cmd 00600 allow tcp from any to any 80 out via $oif setup $ks
+$cmd 00610 allow tcp from any to $odns 53 out via $oif setup $ks
+$cmd 00611 allow udp from any to $odns 53 out via $oif $ks
+################### End of example ipfw rules script ############
+
+ That is all there is to it. The rules are not important
+ in this example, how the Symbolic substitution field are
+ populated and used are.
+
+ If the above example was in
+ /etc/ipfw.rules file, you could reload
+ these rules by entering on the command line.
+
+ sh /etc/ipfw.rules
+
+
+ The /etc/ipfw.rules file could be
+ located any where you want and the file could be named any
+ thing you would like.
+
+ The same thing could also be accomplished by running
+ these commands by hand:
+
+ ipfw -q -f flush
+ipfw -q add check-state
+ipfw -q add deny all from any to any frag
+ipfw -q add deny tcp from any to any established
+ipfw -q add allow tcp from any to any 80 out via tun0 setup keep-state
+ipfw -q add allow tcp from any to 192.0.2.11 53 out via tun0 setup keep-state
+ipfw -q add 00611 allow udp from any to 192.0.2.11 53 out via tun0 keep-state
+
+
+
+ Stateful Ruleset
+ The following non-NATed rule set is a example of how to
+ code a very secure 'inclusive' type of firewall. An
+ inclusive firewall only allows services matching pass rules
+ through and blocks all other by default. All firewalls have
+ at the minimum two interfaces which have to have rules to
+ allow the firewall to function.
+
+ All &unix; flavored operating systems, &os; included, are designed to
+ use interface lo and IP address
+ 127.0.0.1 for internal
+ communication with in &os;. The firewall rules must contain
+ rules to allow free unmolested movement of these special
+ internally used packets.
+
+ The interface which faces the public Internet, is the
+ one which you code your rules to authorize and control
+ access out to the public Internet and access requests
+ arriving from the public Internet. This can be your ppp tun0
+ interface or your NIC that is connected to your DSL or cable
+ modem.
+
+ In cases where one or more than one NIC are connected to
+ a private LANs behind the firewall, those interfaces must
+ have rules coded to allow free unmolested movement of
+ packets originating from those LAN interfaces.
+
+ The rules should be first organized into three major
+ sections, all the free unmolested interfaces, public
+ interface outbound, and the public interface inbound.
+
+
+ The order of the rules in each of the public interface
+ sections should be in order of the most used rules being
+ placed before less often used rules with the last rule in
+ the section being a block log all packets on that interface
+ and direction.
+
+ The Outbound section in the following rule set only
+ contains 'allow' rules which contain selection values that
+ uniquely identify the service that is authorized for public
+ Internet access. All the rules have the, proto, port,
+ in/out, via and keep state option coded. The 'proto tcp'
+ rules have the 'setup' option included to identify the start
+ session request as the trigger packet to be posted to the
+ keep state stateful table.
+
+ The Inbound section has all the blocking of undesirable
+ packets first for 2 different reasons. First is these things
+ being blocked may be part of an otherwise valid packet which
+ may be allowed in by the later authorized service rules.
+ Second reason is that by having a rule that explicitly
+ blocks selected packets that I receive on an infrequent
+ bases and don't want to see in the log, this keeps them from
+ being caught by the last rule in the section which blocks
+ and logs all packets which have fallen through the rules.
+ The last rule in the section which blocks and logs all
+ packets is how you create the legal evidence needed to
+ prosecute the people who are attacking your system.
+
+ Another thing you should take note of, is there is no
+ response returned for any of the undesirable stuff, their
+ packets just get dropped and vanish. This way the attackers
+ has no knowledge if his packets have reached your system.
+ The less the attackers can learn about your system the more
+ secure it is. When you log packets with port numbers you do
+ not recognize, go to
+
+ and do a port number lookup to find what the purpose of that
+ port number is. Check out this link for port numbers used by
+ Trojans:
+
+ .
+
+
+ An Example Inclusive Ruleset
+ The following non-NATed rule set is a complete inclusive
+ type ruleset. You can not go wrong using this rule set for
+ you own. Just comment out any pass rules for services you
+ do not want. If you see messages in your log that you want to
+ stop seeing just add a deny rule in the inbound section. You
+ have to change the 'dc0' interface name in every rule to the
+ interface name of the NIC that connects your system to the
+ public Internet. For user ppp it would be 'tun0'.
+
+ You will see a pattern in the usage of these rules.
+
+
+
+
+ All statements that are a request to start a session
+ to the public Internet use keep-state.
+
+
+
+ All the authorized services that originate from the
+ public Internet have the limit option to stop flooding.
+
+
+
+
+ All rules use in or out to clarify direction.
+
+
+
+
+ All rules use via interface name to specify the
+ interface the packet is traveling over.
+
+
+
+ The following rules go into
+ /etc/ipfw.rules.
+
+ ################ Start of IPFW rules file ###############################
+# Flush out the list before we begin.
+ipfw -q -f flush
+
+# Set rules command prefix
+cmd="ipfw -q add"
+pif="dc0" # public interface name of Nic card
+ # facing the public Internet
+
+#################################################################
+# No restrictions on Inside Lan Interface for private network
+# Not needed unless you have Lan.
+# Change xl0 to your Lan Nic card interface name
+#################################################################
+#$cmd 00005 allow all from any to any via xl0
+
+#################################################################
+# No restrictions on Loopback Interface
+#################################################################
+$cmd 00010 allow all from any to any via lo0
+
+#################################################################
+# Allow the packet through if it has previous been added to the
+# the "dynamic" rules table by a allow keep-state statement.
+#################################################################
+$cmd 00015 check-state
+
+#################################################################
+# Interface facing Public Internet (Outbound Section)
+# Interrogate session start requests originating from behind the
+# firewall on the private network or from this gateway server
+# destine for the public Internet.
+#################################################################
+
+# Allow out access to my ISP's Domain name server.
+# x.x.x.x must be the IP address of your ISP.s DNS
+# Dup these lines if your ISP has more than one DNS server
+# Get the IP addresses from /etc/resolv.conf file
+$cmd 00110 allow tcp from any to x.x.x.x 53 out via $pif setup keep-state
+$cmd 00111 allow udp from any to x.x.x.x 53 out via $pif keep-state
+
+# Allow out access to my ISP's DHCP server for cable/DSL configurations.
+# This rule is not needed for .user ppp. connection to the public Internet.
+# so you can delete this whole group.
+# Use the following rule and check log for IP address.
+# Then put IP address in commented out rule & delete first rule
+$cmd 00120 allow log udp from any to any 67 out via $pif keep-state
+#$cmd 00120 allow udp from any to x.x.x.x 67 out via $pif keep-state
+
+# Allow out non-secure standard www function
+$cmd 00200 allow tcp from any to any 80 out via $pif setup keep-state
+
+# Allow out secure www function https over TLS SSL
+$cmd 00220 allow tcp from any to any 443 out via $pif setup keep-state
+
+# Allow out send & get email function
+$cmd 00230 allow tcp from any to any 25 out via $pif setup keep-state
+$cmd 00231 allow tcp from any to any 110 out via $pif setup keep-state
+
+# Allow out FBSD (make install & CVSUP) functions
+# Basically give user root "GOD" privileges.
+$cmd 00240 allow tcp from me to any out via $pif setup keep-state uid root
+
+# Allow out ping
+$cmd 00250 allow icmp from any to any out via $pif keep-state
+
+# Allow out Time
+$cmd 00260 allow tcp from any to any 37 out via $pif setup keep-state
+
+# Allow out nntp news (i.e. news groups)
+$cmd 00270 allow tcp from any to any 119 out via $pif setup keep-state
+
+# Allow out secure FTP, Telnet, and SCP
+# This function is using SSH (secure shell)
+$cmd 00280 allow tcp from any to any 22 out via $pif setup keep-state
+
+# Allow out whois
+$cmd 00290 allow tcp from any to any 43 out via $pif setup keep-state
+
+# deny and log everything else that.s trying to get out.
+# This rule enforces the block all by default logic.
+$cmd 00299 deny log all from any to any out via $pif
+
+#################################################################
+# Interface facing Public Internet (Inbound Section)
+# Interrogate packets originating from the public Internet
+# destine for this gateway server or the private network.
+#################################################################
+
+# Deny all inbound traffic from non-routable reserved address spaces
+$cmd 00300 deny all from 192.168.0.0/16 to any in via $pif #RFC 1918 private IP
+$cmd 00301 deny all from 172.16.0.0/12 to any in via $pif #RFC 1918 private IP
+$cmd 00302 deny all from 10.0.0.0/8 to any in via $pif #RFC 1918 private IP
+$cmd 00303 deny all from 127.0.0.0/8 to any in via $pif #loopback
+$cmd 00304 deny all from 0.0.0.0/8 to any in via $pif #loopback
+$cmd 00305 deny all from 169.254.0.0/16 to any in via $pif #DHCP auto-config
+$cmd 00306 deny all from 192.0.2.0/24 to any in via $pif #reserved for docs
+$cmd 00307 deny all from 204.152.64.0/23 to any in via $pif #Sun cluster interconnect
+$cmd 00308 deny all from 224.0.0.0/3 to any in via $pif #Class D & E multicast
+
+# Deny public pings
+$cmd 00310 deny icmp from any to any in via $pif
+
+# Deny ident
+$cmd 00315 deny tcp from any to any 113 in via $pif
+
+# Deny all Netbios service. 137=name, 138=datagram, 139=session
+# Netbios is MS/Windows sharing services.
+# Block MS/Windows hosts2 name server requests 81
+$cmd 00320 deny tcp from any to any 137 in via $pif
+$cmd 00321 deny tcp from any to any 138 in via $pif
+$cmd 00322 deny tcp from any to any 139 in via $pif
+$cmd 00323 deny tcp from any to any 81 in via $pif
+
+# Deny any late arriving packets
+$cmd 00330 deny all from any to any frag in via $pif
+
+# Deny ACK packets that did not match the dynamic rule table
+$cmd 00332 deny tcp from any to any established in via $pif
+
+# Allow traffic in from ISP's DHCP server. This rule must contain
+# the IP address of your ISP.s DHCP server as it.s the only
+# authorized source to send this packet type.
+# Only necessary for cable or DSL configurations.
+# This rule is not needed for .user ppp. type connection to
+# the public Internet. This is the same IP address you captured
+# and used in the outbound section.
+#$cmd 00360 allow udp from any to x.x.x.x 67 in via $pif keep-state
+
+# Allow in standard www function because I have apache server
+$cmd 00400 allow tcp from any to me 80 in via $pif setup limit src-addr 2
+
+# Allow in secure FTP, Telnet, and SCP from public Internet
+$cmd 00410 allow tcp from any to me 22 in via $pif setup limit src-addr 2
+
+# Allow in non-secure Telnet session from public Internet
+# labeled non-secure because ID & PW are passed over public
+# Internet as clear text.
+# Delete this sample group if you do not have telnet server enabled.
+$cmd 00420 allow tcp from any to me 23 in via $pif setup limit src-addr 2
+
+# Reject & Log all incoming connections from the outside
+$cmd 00499 deny log all from any to any in via $pif
+
+# Everything else is denied by default
+# deny and log all packets that fell through to see what they are
+$cmd 00999 deny log all from any to any
+################ End of IPFW rules file ###############################
+
+
+
+
+ An Example NAT and Stateful Ruleset
+ There are some additional configuration statements that
+ need to be enabled to activate the NAT function of IPFW. The
+ kernel source needs 'option divert' statement added to the
+ other IPFIREWALL statements compiled into a custom kernel.
+
+
+ In addition to the normal IPFW options in
+ /etc/rc.conf, the following are needed.
+
+
+ natd_enable="YES" # Enable NATD function
+natd_interface="rl0" # interface name of public Internet NIC
+natd_flags="-dynamic -m" # -m = preserve port numbers if possible
+
+ Utilizing stateful rules with divert natd rule (Network
+ Address Translation) greatly complicates the rule set coding
+ logic. The positioning of the check-state, and 'divert natd'
+ rules in the rule set becomes very critical. This is no
+ longer a simple fall-through logic flow. A new action type
+ is used, called 'skipto'. To use the skipto command it is
+ mandatory that you number each rule so you know exactly
+ where the skipto rule number is you are really jumping to.
+
+
+ The following is an uncommented example of one coding
+ method, selected here to explain the sequence of the packet
+ flow through the rule sets.
+
+ The processing flow starts with the first rule from the
+ top of the rule file and progress one rule at a time deeper
+ into the file until the end is reach or the packet being
+ tested to the selection criteria matches and the packet is
+ released out of the firewall. It is important to take notice
+ of the location of rule numbers 100 101, 450, 500, and 510.
+ These rules control the translation of the outbound and
+ inbound packets so their entries in the keep-state dynamic
+ table always register the private Lan IP address. Next
+ notice that all the allow and deny rules specified the
+ direction the packet is going (IE outbound or inbound) and
+ the interface. Also notice that all the start outbound
+ session requests all skipto rule 500 for the network address
+ translation.
+
+ Lets say a LAN user uses their web browser to get a web
+ page. Web pages use port 80 to communicate over. So the
+ packet enters the firewall, It does not match 100 because
+ it is headed out not in. It passes rule 101 because this is
+ the first packet so it has not been posted to the keep-state
+ dynamic table yet. The packet finally comes to rule 125 a
+ matches. It is outbound through the NIC facing the public
+ Internet. The packet still has it's source IP address as a
+ private Lan IP address. On the match to this rule, two
+ actions take place. The keep-state option will post this rule
+ into the keep-state dynamic rules table and the specified
+ action is executed. The action is part of the info posted to
+ the dynamic table. In this case it is "skipto rule 500". Rule
+ 500 NATs the packet IP address and out it goes. Remember
+ this, this is very important. This packet makes it's way to
+ the destination and returns and enters the top of the rule
+ set. This time it does match rule 100 and has it destination
+ IP address mapped back to it's corresponding Lan IP address.
+ It then is processed by the check-state rule, it's found in
+ the table as an existing session conversation and released
+ to the LAN. It goes to the LAN PC that sent it and a new
+ packet is sent requesting another segment of the data from
+ the remote server. This time it gets checked by the
+ check-state rule and it's outbound entry is found, the
+ associated action, 'skipto 500', is executed. The packet
+ jumps to rule 500 gets NATed and released on it's way out.
+
+
+ On the inbound side, everything coming in that is part
+ of an existing session conversation is being automatically
+ handled by the check-state rule and the properly placed
+ divert natd rules. All we have to address is denying all the
+ bad packets and only allowing in the authorized services.
+ Lets say there is a apache server running on the firewall
+ box and we want people on the public Internet to be able to
+ access the local web site. The new inbound start request
+ packet matches rule 100 and its IP address is mapped to LAN
+ IP for the firewall box. The packet is them matched against
+ all the nasty things we want to check for and finally
+ matches against rule 425. On a match two things occur, the
+ limit option is an extension to keep-state. The packet rule
+ is posted to the keep-state dynamic table but this time any
+ new session requests originating from that source IP address
+ is limited to 2. This defends against DoS attacks of service
+ running on the specified port number. The action is allow so
+ the packet is released to the LAN. On return the check-state
+ rule recognizes the packet as belonging to an existing
+ session conversation sends it to rule 500 for NATing and
+ released to outbound interface.
+
+ Example Ruleset #1:
+
+ #!/bin/sh
+cmd="ipfw -q add"
+skip="skipto 500"
+pif=rl0
+ks="keep-state"
+good_tcpo="22,25,37,43,53,80,443,110,119"
+
+ipfw -q -f flush
+
+$cmd 002 allow all from any to any via xl0 # exclude Lan traffic
+$cmd 003 allow all from any to any via lo0 # exclude loopback traffic
+
+$cmd 100 divert natd ip from any to any in via $pif
+$cmd 101 check-state
+
+# Authorized outbound packets
+$cmd 120 $skip udp from any to xx.168.240.2 53 out via $pif $ks
+$cmd 121 $skip udp from any to xx.168.240.5 53 out via $pif $ks
+$cmd 125 $skip tcp from any to any $good_tcpo out via $pif setup $ks
+$cmd 130 $skip icmp from any to any out via $pif $ks
+$cmd 135 $skip udp from any to any 123 out via $pif $ks
+
+
+# Deny all inbound traffic from non-routable reserved address spaces
+$cmd 300 deny all from 192.168.0.0/16 to any in via $pif #RFC 1918 private IP
+$cmd 301 deny all from 172.16.0.0/12 to any in via $pif #RFC 1918 private IP
+$cmd 302 deny all from 10.0.0.0/8 to any in via $pif #RFC 1918 private IP
+$cmd 303 deny all from 127.0.0.0/8 to any in via $pif #loopback
+$cmd 304 deny all from 0.0.0.0/8 to any in via $pif #loopback
+$cmd 305 deny all from 169.254.0.0/16 to any in via $pif #DHCP auto-config
+$cmd 306 deny all from 192.0.2.0/24 to any in via $pif #reserved for docs
+$cmd 307 deny all from 204.152.64.0/23 to any in via $pif #Sun cluster
+$cmd 308 deny all from 224.0.0.0/3 to any in via $pif #Class D & E multicast
+
+# Authorized inbound packets
+$cmd 400 allow udp from xx.70.207.54 to any 68 in $ks
+$cmd 420 allow tcp from any to me 80 in via $pif setup limit src-addr 1
+
+
+$cmd 450 deny log ip from any to any
+
+# This is skipto location for outbound stateful rules
+$cmd 500 divert natd ip from any to any out via $pif
+$cmd 510 allow ip from any to any
+
+######################## end of rules ##################
+
+ The following is pretty much the same as above, but uses
+ a self documenting coding style full of description comments
+ to help the inexperienced IPFW rule writer to better
+ understand what the rules are doing.
+
+ Example Ruleset #2:
+
+
+#!/bin/sh
+################ Start of IPFW rules file ###############################
+# Flush out the list before we begin.
+ipfw -q -f flush
+
+# Set rules command prefix
+cmd="ipfw -q add"
+skip="skipto 800"
+pif="rl0" # public interface name of Nic card
+ # facing the public Internet
+
+#################################################################
+# No restrictions on Inside Lan Interface for private network
+# Change xl0 to your Lan Nic card interface name
+#################################################################
+$cmd 005 allow all from any to any via xl0
+
+#################################################################
+# No restrictions on Loopback Interface
+#################################################################
+$cmd 010 allow all from any to any via lo0
+
+#################################################################
+# check if packet is inbound and nat address if it is
+#################################################################
+$cmd 014 divert natd ip from any to any in via $pif
+
+#################################################################
+# Allow the packet through if it has previous been added to the
+# the "dynamic" rules table by a allow keep-state statement.
+#################################################################
+$cmd 015 check-state
+
+#################################################################
+# Interface facing Public Internet (Outbound Section)
+# Interrogate session start requests originating from behind the
+# firewall on the private network or from this gateway server
+# destine for the public Internet.
+#################################################################
+
+# Allow out access to my ISP's Domain name server.
+# x.x.x.x must be the IP address of your ISP's DNS
+# Dup these lines if your ISP has more than one DNS server
+# Get the IP addresses from /etc/resolv.conf file
+$cmd 020 $skip tcp from any to x.x.x.x 53 out via $pif setup keep-state
+
+
+# Allow out access to my ISP's DHCP server for cable/DSL configurations.
+$cmd 030 $skip udp from any to x.x.x.x 67 out via $pif keep-state
+
+# Allow out non-secure standard www function
+$cmd 040 $skip tcp from any to any 80 out via $pif setup keep-state
+
+# Allow out secure www function https over TLS SSL
+$cmd 050 $skip tcp from any to any 443 out via $pif setup keep-state
+
+# Allow out send & get email function
+$cmd 060 $skip tcp from any to any 25 out via $pif setup keep-state
+$cmd 061 $skip tcp from any to any 110 out via $pif setup keep-state
+
+# Allow out FreeBSD (make install & CVSUP) functions
+# Basically give user root "GOD" privileges.
+$cmd 070 $skip tcp from me to any out via $pif setup keep-state uid root
+
+# Allow out ping
+$cmd 080 $skip icmp from any to any out via $pif keep-state
+
+# Allow out Time
+$cmd 090 $skip tcp from any to any 37 out via $pif setup keep-state
+
+# Allow out nntp news (i.e. news groups)
+$cmd 100 $skip tcp from any to any 119 out via $pif setup keep-state
+
+# Allow out secure FTP, Telnet, and SCP
+# This function is using SSH (secure shell)
+$cmd 110 $skip tcp from any to any 22 out via $pif setup keep-state
+
+# Allow out whois
+$cmd 120 $skip tcp from any to any 43 out via $pif setup keep-state
+
+# Allow ntp time server
+$cmd 130 $skip udp from any to any 123 out via $pif keep-state
+
+#################################################################
+# Interface facing Public Internet (Inbound Section)
+# Interrogate packets originating from the public Internet
+# destine for this gateway server or the private network.
+#################################################################
+
+# Deny all inbound traffic from non-routable reserved address spaces
+$cmd 300 deny all from 192.168.0.0/16 to any in via $pif #RFC 1918 private IP
+$cmd 301 deny all from 172.16.0.0/12 to any in via $pif #RFC 1918 private IP
+$cmd 302 deny all from 10.0.0.0/8 to any in via $pif #RFC 1918 private IP
+$cmd 303 deny all from 127.0.0.0/8 to any in via $pif #loopback
+$cmd 304 deny all from 0.0.0.0/8 to any in via $pif #loopback
+$cmd 305 deny all from 169.254.0.0/16 to any in via $pif #DHCP auto-config
+$cmd 306 deny all from 192.0.2.0/24 to any in via $pif #reserved for docs
+$cmd 307 deny all from 204.152.64.0/23 to any in via $pif #Sun cluster
+$cmd 308 deny all from 224.0.0.0/3 to any in via $pif #Class D & E multicast
+
+# Deny ident
+$cmd 315 deny tcp from any to any 113 in via $pif
+
+# Deny all Netbios service. 137=name, 138=datagram, 139=session
+# Netbios is MS/Windows sharing services.
+# Block MS/Windows hosts2 name server requests 81
+$cmd 320 deny tcp from any to any 137 in via $pif
+$cmd 321 deny tcp from any to any 138 in via $pif
+$cmd 322 deny tcp from any to any 139 in via $pif
+$cmd 323 deny tcp from any to any 81 in via $pif
+
+# Deny any late arriving packets
+$cmd 330 deny all from any to any frag in via $pif
+
+# Deny ACK packets that did not match the dynamic rule table
+$cmd 332 deny tcp from any to any established in via $pif
+
+# Allow traffic in from ISP's DHCP server. This rule must contain
+# the IP address of your ISP's DHCP server as it's the only
+# authorized source to send this packet type.
+# Only necessary for cable or DSL configurations.
+# This rule is not needed for 'user ppp' type connection to
+# the public Internet. This is the same IP address you captured
+# and used in the outbound section.
+$cmd 360 allow udp from x.x.x.x to any 68 in via $pif keep-state
+
+# Allow in standard www function because I have apache server
+$cmd 370 allow tcp from any to me 80 in via $pif setup limit src-addr 2
+
+# Allow in secure FTP, Telnet, and SCP from public Internet
+$cmd 380 allow tcp from any to me 22 in via $pif setup limit src-addr 2
+
+# Allow in non-secure Telnet session from public Internet
+# labeled non-secure because ID & PW are passed over public
+# Internet as clear text.
+# Delete this sample group if you do not have telnet server enabled.
+$cmd 390 allow tcp from any to me 23 in via $pif setup limit src-addr 2
+
+# Reject & Log all unauthorized incoming connections from the public Internet
+$cmd 400 deny log all from any to any in via $pif
+
+# Reject & Log all unauthorized out going connections to the public Internet
+$cmd 450 deny log all from any to any out via $pif
+
+# This is skipto location for outbound stateful rules
+$cmd 800 divert natd ip from any to any out via $pif
+$cmd 801 allow ip from any to any
+
+# Everything else is denied by default
+# deny and log all packets that fell through to see what they are
+$cmd 999 deny log all from any to any
+################ End of IPFW rules file ###############################
+
+
+
+
+
diff --git a/en_US.ISO8859-1/books/handbook/security/chapter.sgml b/en_US.ISO8859-1/books/handbook/security/chapter.sgml
index cd199d79df..ea298e6b22 100644
--- a/en_US.ISO8859-1/books/handbook/security/chapter.sgml
+++ b/en_US.ISO8859-1/books/handbook/security/chapter.sgml
@@ -1,7582 +1,4812 @@
MatthewDillonMuch of this chapter has been taken from the
security(7) manual page by SecuritysecuritySynopsisThis chapter will provide a basic introduction to system security
concepts, some general good rules of thumb, and some advanced topics
under &os;. A lot of the topics covered here can be applied
to system and Internet security in general as well. The Internet
is no longer a friendly place in which everyone
wants to be your kind neighbor. Securing your system is imperative
to protect your data, intellectual property, time, and much more
from the hands of hackers and the like.&os; provides an array of utilities and mechanisms to ensure
the integrity and security of your system and network.After reading this chapter, you will know:Basic system security concepts, in respect to &os;.About the various crypt mechanisms available in &os;,
such as DES and MD5.How to set up one-time password authentication.How to configure TCP Wrappers for use
with inetd.How to set up KerberosIV on &os;
releases prior to 5.0.How to set up Kerberos5 on
post &os; 5.0 releases.
-
- How to create firewalls using PF,
- IPFILTER (IPF) or IPFW.
-
-
How to configure IPsec and create a VPN between
&os;/&windows; machines.How to configure and use OpenSSH, &os;'s SSH
implementation.What file system ACLs are and how to use them.How to utilize the &os; security advisories
publications.Before reading this chapter, you should:Understand basic &os; and Internet concepts.
+ Additional security topics are covered throughout this book.
+ For example, Mandatory Access Control is discussed in and Internet Firewalls are discussed in .IntroductionSecurity is a function that begins and ends with the system
administrator. While all BSD &unix; multi-user systems have some
inherent security, the job of building and maintaining additional
security mechanisms to keep those users honest is
probably one of the single largest undertakings of the sysadmin.
Machines are only as secure as you make them, and security concerns
are ever competing with the human necessity for convenience. &unix;
systems, in general, are capable of running a huge number of
simultaneous processes and many of these processes operate as
servers — meaning that external entities can connect and talk
to them. As yesterday's mini-computers and mainframes become
today's desktops, and as computers become networked and
internetwork, security becomes an even bigger issue.Security is best implemented through a layered
onion approach. In a nutshell, what you want to do is
to create as many layers of security as are convenient and then
carefully monitor the system for intrusions. You do not want to
overbuild your security or you will interfere with the detection
side, and detection is one of the single most important aspects of
any security mechanism. For example, it makes little sense to set
the schg flags (see &man.chflags.1;) on every
system binary because
while this may temporarily protect the binaries, it prevents an
attacker who has broken in from making an easily detectable change
that may result in your security mechanisms not detecting the attacker
at all.System security also pertains to dealing with various forms of
attack, including attacks that attempt to crash, or otherwise make a
system unusable, but do not attempt to compromise the
root account (break root).
Security concerns
can be split up into several categories:Denial of service attacks.User account compromises.Root compromise through accessible servers.Root compromise via user accounts.Backdoor creation.DoS attacksDenial of Service (DoS)securityDoS attacksDenial of Service (DoS)Denial of Service (DoS)A denial of service attack is an action that deprives the
machine of needed resources. Typically, DoS attacks are
brute-force mechanisms that attempt to crash or otherwise make a
machine unusable by overwhelming its servers or network stack. Some
DoS attacks try to take advantage of bugs in the networking
stack to crash a machine with a single packet. The latter can only
be fixed by applying a bug fix to the kernel. Attacks on servers
can often be fixed by properly specifying options to limit the load
the servers incur on the system under adverse conditions.
Brute-force network attacks are harder to deal with. A
spoofed-packet attack, for example, is nearly impossible to stop,
short of cutting your system off from the Internet. It may not be
able to take your machine down, but it can saturate your
Internet connection.securityaccount compromisesA user account compromise is even more common than a DoS
attack. Many sysadmins still run standard
telnetd, rlogind,
rshd,
and ftpd servers on their machines.
These servers, by default, do
not operate over encrypted connections. The result is that if you
have any moderate-sized user base, one or more of your users logging
into your system from a remote location (which is the most common
and convenient way to login to a system) will have his or her
password sniffed. The attentive system admin will analyze his
remote access logs looking for suspicious source addresses even for
successful logins.One must always assume that once an attacker has access to a
user account, the attacker can break root.
However, the reality is that in a well secured and maintained system,
access to a user account does not necessarily give the attacker
access to root. The distinction is important
because without access to root the attacker
cannot generally hide his tracks and may, at best, be able to do
nothing more than mess with the user's files, or crash the machine.
User account compromises are very common because users tend not to
take the precautions that sysadmins take.securitybackdoorsSystem administrators must keep in mind that there are
potentially many ways to break root on a machine.
The attacker may know the root password,
the attacker may find a bug in a root-run server and be able
to break root over a network
connection to that server, or the attacker may know of a bug in
a suid-root program that allows the attacker to break
root once he has broken into a user's account.
If an attacker has found a way to break root
on a machine, the attacker may not have a need
to install a backdoor. Many of the root holes
found and closed to date involve a considerable amount of work
by the attacker to cleanup after himself, so most attackers install
backdoors. A backdoor provides the attacker with a way to easily
regain root access to the system, but it
also gives the smart system administrator a convenient way
to detect the intrusion.
Making it impossible for an attacker to install a backdoor may
actually be detrimental to your security, because it will not
close off the hole the attacker found to break in the first
place.Security remedies should always be implemented with a
multi-layered onion peel approach and can be
categorized as follows:Securing root and staff accounts.Securing root–run servers
and suid/sgid binaries.Securing user accounts.Securing the password file.Securing the kernel core, raw devices, and
file systems.Quick detection of inappropriate changes made to the
system.Paranoia.The next section of this chapter will cover the above bullet
items in greater depth.Securing &os;securitysecuring &os;Command vs. ProtocolThroughout this document, we will use
bold text to refer to an
application, and a monospaced font to refer
to specific commands. Protocols will use a normal font. This
typographical distinction is useful for instances such as ssh,
since it is
a protocol as well as command.The sections that follow will cover the methods of securing your
&os; system that were mentioned in the last section of this chapter.Securing the root Account and
Staff AccountssuFirst off, do not bother securing staff accounts if you have
not secured the root account.
Most systems have a password assigned to the root
account. The first thing you do is assume
that the password is always compromised.
This does not mean that you should remove the password. The
password is almost always necessary for console access to the
machine. What it does mean is that you should not make it
possible to use the password outside of the console or possibly
even with the &man.su.1; command. For example, make sure that
your ptys are specified as being insecure in the
/etc/ttys file so that direct
root logins
via telnet or rlogin are
disallowed. If using other login services such as
sshd, make sure that direct
root logins are disabled there as well.
You can do this by editing
your /etc/ssh/sshd_config file, and making
sure that PermitRootLogin is set to
NO. Consider every access method —
services such as FTP often fall through the cracks.
Direct root logins should only be allowed
via the system console.wheelOf course, as a sysadmin you have to be able to get to
root, so we open up a few holes.
But we make sure these holes require additional password
verification to operate. One way to make root
accessible is to add appropriate staff accounts to the
wheel group (in
/etc/group). The staff members placed in the
wheel group are allowed to
su to root.
You should never give staff
members native wheel access by putting them in the
wheel group in their password entry. Staff
accounts should be placed in a staff group, and
then added to the wheel group via the
/etc/group file. Only those staff members
who actually need to have root access
should be placed in the
wheel group. It is also possible, when using
an authentication method such as Kerberos, to use Kerberos'
.k5login file in the root
account to allow a &man.ksu.1; to root
without having to place anyone at all in the
wheel group. This may be the better solution
since the wheel mechanism still allows an
intruder to break root if the intruder
has gotten hold of your
password file and can break into a staff account. While having
the wheel mechanism is better than having
nothing at all, it is not necessarily the safest option.An indirect way to secure staff accounts, and ultimately
root access is to use an alternative
login access method and
do what is known as starring out the encrypted
password for the staff accounts. Using the &man.vipw.8;
command, one can replace each instance of an encrypted password
with a single * character.
This command will update the /etc/master.passwd
file and user/password database to disable password-authenticated
logins.A staff account entry such as:foobar:R9DT/Fa1/LV9U:1000:1000::0:0:Foo Bar:/home/foobar:/usr/local/bin/tcshShould be changed to this:foobar:*:1000:1000::0:0:Foo Bar:/home/foobar:/usr/local/bin/tcshThis change will prevent normal logins from occurring,
since the encrypted password will never match
*. With this done,
staff members must use
another mechanism to authenticate themselves such as
&man.kerberos.1; or &man.ssh.1; using a public/private key
pair. When using something like Kerberos, one generally must
secure the machines which run the Kerberos servers and your
desktop workstation. When using a public/private key pair
with ssh, one must generally secure
the machine used to login from (typically
one's workstation). An additional layer of protection can be
added to the key pair by password protecting the key pair when
creating it with &man.ssh-keygen.1;. Being able to
star out the passwords for staff accounts also
guarantees that staff members can only login through secure
access methods that you have set up. This forces all staff
members to use secure, encrypted connections for all of their
sessions, which closes an important hole used by many
intruders: sniffing the network from an unrelated,
less secure machine.The more indirect security mechanisms also assume that you are
logging in from a more restrictive server to a less restrictive
server. For example, if your main box is running all sorts of
servers, your workstation should not be running any. In order for
your workstation to be reasonably secure you should run as few
servers as possible, up to and including no servers at all, and
you should run a password-protected screen blanker. Of course,
given physical access to a workstation an attacker can break any
sort of security you put on it. This is definitely a problem that
you should consider, but you should also consider the fact that the
vast majority of break-ins occur remotely, over a network, from
people who do not have physical access to your workstation or
servers.KerberosIVUsing something like Kerberos also gives you the ability to
disable or change the password for a staff account in one place,
and have it immediately affect all the machines on which the staff
member may have an account. If a staff member's account gets
compromised, the ability to instantly change his password on all
machines should not be underrated. With discrete passwords,
changing a password on N machines can be a mess. You can also
impose re-passwording restrictions with Kerberos: not only can a
Kerberos ticket be made to timeout after a while, but the Kerberos
system can require that the user choose a new password after a
certain period of time (say, once a month).Securing Root-run Servers and SUID/SGID BinariesntalkcomsatfingersandboxessshdtelnetdrshdrlogindThe prudent sysadmin only runs the servers he needs to, no
more, no less. Be aware that third party servers are often the
most bug-prone. For example, running an old version of
imapd or
popper is like giving a universal
root ticket out to the entire world.
Never run a server that you have not checked out carefully.
Many servers do not need to be run as root.
For example, the ntalk,
comsat, and
finger daemons can be run in special
user sandboxes. A sandbox is not perfect,
unless you go through a large amount of trouble, but the onion
approach to security still stands: If someone is able to break
in through a server running in a sandbox, they still have to
break out of the sandbox. The more layers the attacker must
break through, the lower the likelihood of his success. Root
holes have historically been found in virtually every server
ever run as root, including basic system servers.
If you are running a machine through which people only login via
sshd and never login via
telnetd or
rshd or
rlogind, then turn off those
services!&os; now defaults to running
ntalkd,
comsat, and
finger in a sandbox. Another program
which may be a candidate for running in a sandbox is &man.named.8;.
/etc/defaults/rc.conf includes the arguments
necessary to run named in a sandbox in a
commented-out form. Depending on whether you are installing a new
system or upgrading an existing system, the special user accounts
used by these sandboxes may not be installed. The prudent
sysadmin would research and implement sandboxes for servers
whenever possible.sendmailThere are a number of other servers that typically do not run
in sandboxes: sendmail,
popper,
imapd, ftpd,
and others. There are alternatives to some of these, but
installing them may require more work than you are willing to
perform (the convenience factor strikes again). You may have to
run these servers as root and rely on other
mechanisms to detect break-ins that might occur through them.The other big potential root holes in a
system are the
suid-root and sgid binaries installed on the system. Most of
these binaries, such as rlogin, reside
in /bin, /sbin,
/usr/bin, or /usr/sbin.
While nothing is 100% safe, the system-default suid and sgid
binaries can be considered reasonably safe. Still,
root holes are occasionally found in these
binaries. A root hole was found in
Xlib in 1998 that made
xterm (which is typically suid)
vulnerable. It is better to be safe than sorry and the prudent
sysadmin will restrict suid binaries, that only staff should run,
to a special group that only staff can access, and get rid of
(chmod 000) any suid binaries that nobody uses.
A server with no display generally does not need an
xterm binary. Sgid binaries can be
almost as dangerous. If an intruder can break an sgid-kmem binary,
the intruder might be able to read /dev/kmem
and thus read the encrypted password file, potentially compromising
any passworded account. Alternatively an intruder who breaks
group kmem can monitor keystrokes sent through
ptys, including Pt's used by users who login through secure
methods. An intruder that breaks the tty
group can write to
almost any user's tty. If a user is running a terminal program or
emulator with a keyboard-simulation feature, the intruder can
potentially generate a data stream that causes the user's terminal
to echo a command, which is then run as that user.Securing User AccountsUser accounts are usually the most difficult to secure. While
you can impose Draconian access restrictions on your staff and
star out their passwords, you may not be able to
do so with any general user accounts you might have. If you do
have sufficient control, then you may win out and be able to secure
the user accounts properly. If not, you simply have to be more
vigilant in your monitoring of those accounts. Use of
ssh and Kerberos for user accounts is
more problematic, due to the extra administration and technical
support required, but still a very good solution compared to a
crypted password file.Securing the Password FileThe only sure fire way is to * out as many
passwords as you can and use ssh or
Kerberos for access to those accounts. Even though the encrypted
password file (/etc/spwd.db) can only be read
by root, it may be possible for an intruder
to obtain read access to that file even if the attacker cannot
obtain root-write access.Your security scripts should always check for and report
changes to the password file (see the Checking file integrity section
below).Securing the Kernel Core, Raw Devices, and
File systemsIf an attacker breaks root he can do
just about anything, but
there are certain conveniences. For example, most modern kernels
have a packet sniffing device driver built in. Under &os; it
is called the bpf device. An intruder
will commonly attempt to run a packet sniffer on a compromised
machine. You do not need to give the intruder the capability and
most systems do not have the need for the
bpf device compiled in.sysctlBut even if you turn off the bpf
device, you still have
/dev/mem and
/dev/kmem
to worry about. For that matter, the intruder can still write to
raw disk devices. Also, there is another kernel feature called
the module loader, &man.kldload.8;. An enterprising intruder can
use a KLD module to install his own bpf
device, or other sniffing
device, on a running kernel. To avoid these problems you have to
run the kernel at a higher secure level, at least securelevel 1.
The securelevel can be set with a sysctl on
the kern.securelevel variable. Once you have
set the securelevel to 1, write access to raw devices will be
denied and special chflags flags,
such as schg,
will be enforced. You must also ensure that the
schg flag is set on critical startup binaries,
directories, and script files — everything that gets run up
to the point where the securelevel is set. This might be overdoing
it, and upgrading the system is much more difficult when you
operate at a higher secure level. You may compromise and run the
system at a higher secure level but not set the
schg flag for every system file and directory
under the sun. Another possibility is to simply mount
/ and /usr read-only.
It should be noted that being too Draconian in what you attempt to
protect may prevent the all-important detection of an
intrusion.Checking File Integrity: Binaries, Configuration Files,
Etc.When it comes right down to it, you can only protect your core
system configuration and control files so much before the
convenience factor rears its ugly head. For example, using
chflags to set the schg bit
on most of the files in / and
/usr is probably counterproductive, because
while it may protect the files, it also closes a detection window.
The last layer of your security onion is perhaps the most
important — detection. The rest of your security is pretty
much useless (or, worse, presents you with a false sense of
safety) if you cannot detect potential incursions. Half the job
of the onion is to slow down the attacker, rather than stop him, in
order to give the detection side of the equation a chance to catch
him in the act.The best way to detect an incursion is to look for modified,
missing, or unexpected files. The best way to look for modified
files is from another (often centralized) limited-access system.
Writing your security scripts on the extra-secure limited-access
system makes them mostly invisible to potential attackers, and this
is important. In order to take maximum advantage you generally
have to give the limited-access box significant access to the
other machines in the business, usually either by doing a
read-only NFS export of the other machines to the limited-access
box, or by setting up ssh key-pairs to
allow the limited-access box to ssh to
the other machines. Except for its network traffic, NFS is the
least visible method — allowing you to monitor the
file systems on each client box virtually undetected. If your
limited-access server is connected to the client boxes through a
switch, the NFS method is often the better choice. If your
limited-access server is connected to the client boxes through a
hub, or through several layers of routing, the NFS method may be
too insecure (network-wise) and using
ssh may be the better choice even with
the audit-trail tracks that ssh
lays.Once you give a limited-access box, at least read access to the
client systems it is supposed to monitor, you must write scripts
to do the actual monitoring. Given an NFS mount, you can write
scripts out of simple system utilities such as &man.find.1; and
&man.md5.1;. It is best to physically md5 the client-box files
at least once a day, and to test control files such as those
found in /etc and
/usr/local/etc even more often. When
mismatches are found, relative to the base md5 information the
limited-access machine knows is valid, it should scream at a
sysadmin to go check it out. A good security script will also
check for inappropriate suid binaries and for new or deleted files
on system partitions such as / and
/usr.When using ssh rather than NFS,
writing the security script is much more difficult. You
essentially have to scp the scripts to the client
box in order to
run them, making them visible, and for safety you also need to
scp the binaries (such as find) that those
scripts use. The ssh client on the
client box may already be compromised. All in all, using
ssh may be necessary when running over
insecure links, but it is also a lot harder to deal with.A good security script will also check for changes to user and
staff members access configuration files:
.rhosts, .shosts,
.ssh/authorized_keys and so forth…
files that might fall outside the purview of the
MD5 check.If you have a huge amount of user disk space, it may take too
long to run through every file on those partitions. In this case,
setting mount flags to disallow suid binaries and devices on those
partitions is a good idea. The nodev and
nosuid options (see &man.mount.8;) are what you
want to look into. You should probably scan them anyway, at least
once a week, since the object of this layer is to detect a break-in
whether or not the break-in is effective.Process accounting (see &man.accton.8;) is a relatively
low-overhead feature of the operating system which might help
as a post-break-in evaluation mechanism. It is especially
useful in tracking down how an intruder has actually broken into
a system, assuming the file is still intact after the break-in
occurs.Finally, security scripts should process the log files, and the
logs themselves should be generated in as secure a manner as
possible — remote syslog can be very useful. An intruder
tries to cover his tracks, and log files are critical to the
sysadmin trying to track down the time and method of the initial
break-in. One way to keep a permanent record of the log files is
to run the system console to a serial port and collect the
information on a continuing basis through a secure machine
monitoring the consoles.ParanoiaA little paranoia never hurts. As a rule, a sysadmin can add
any number of security features, as long as they do not affect
convenience, and can add security features that
do affect convenience with some added thought.
Even more importantly, a security administrator should mix it up a
bit — if you use recommendations such as those given by this
document verbatim, you give away your methodologies to the
prospective attacker who also has access to this document.Denial of Service AttacksDenial of Service (DoS)This section covers Denial of Service attacks. A DoS attack
is typically a packet attack. While there is not much you can do
about modern spoofed packet attacks that saturate your network,
you can generally limit the damage by ensuring that the attacks
cannot take down your servers.Limiting server forks.Limiting springboard attacks (ICMP response attacks, ping
broadcast, etc.).Kernel Route Cache.A common DoS attack is against a forking server that attempts
to cause the server to eat processes, file descriptors, and memory,
until the machine dies. inetd
(see &man.inetd.8;) has several
options to limit this sort of attack. It should be noted that
while it is possible to prevent a machine from going down, it is
not generally possible to prevent a service from being disrupted
by the attack. Read the inetd manual
page carefully and pay
specific attention to the , ,
and options. Note that spoofed-IP attacks
will circumvent the option to
inetd, so
typically a combination of options must be used. Some standalone
servers have self-fork-limitation parameters.Sendmail has its
option, which tends to work
much better than trying to use sendmail's load limiting options
due to the load lag. You should specify a
MaxDaemonChildren parameter, when you start
sendmail, high enough to handle your
expected load, but not so high that the computer cannot handle that
number of sendmails without falling on
its face. It is also prudent to run sendmail in queued mode
() and to run the daemon
(sendmail -bd) separate from the queue-runs
(sendmail -q15m). If you still want real-time
delivery you can run the queue at a much lower interval, such as
, but be sure to specify a reasonable
MaxDaemonChildren option for
that sendmail to prevent cascade failures.Syslogd can be attacked directly
and it is strongly recommended that you use the
option whenever possible, and the option
otherwise.You should also be fairly careful with connect-back services
such as tcpwrapper's reverse-identd,
which can be attacked directly. You generally do not want to use
the reverse-ident feature of
tcpwrappers for this reason.It is a very good idea to protect internal services from
external access by firewalling them off at your border routers.
The idea here is to prevent saturation attacks from outside your
LAN, not so much to protect internal services from network-based
root compromise.
Always configure an exclusive firewall, i.e.,
firewall everything except ports A, B,
C, D, and M-Z. This way you can firewall off all of your
low ports except for certain specific services such as
named (if you are primary for a zone),
ntalkd,
sendmail, and other Internet-accessible
services. If you try to configure the firewall the other way
— as an inclusive or permissive firewall, there is a good
chance that you will forget to close a couple of
services, or that you will add a new internal service and forget
to update the firewall. You can still open up the high-numbered
port range on the firewall, to allow permissive-like operation,
without compromising your low ports. Also take note that &os;
allows you to control the range of port numbers used for dynamic
binding, via the various net.inet.ip.portrangesysctl's (sysctl -a | fgrep
portrange), which can also ease the complexity of your
firewall's configuration. For example, you might use a normal
first/last range of 4000 to 5000, and a hiport range of 49152 to
65535, then block off everything under 4000 in your firewall
(except for certain specific Internet-accessible ports, of
course).ICMP_BANDLIMAnother common DoS attack is called a springboard attack
— to attack a server in a manner that causes the server to
generate responses which overloads the server, the local
network, or some other machine. The most common attack of this
nature is the ICMP ping broadcast attack.
The attacker spoofs ping packets sent to your LAN's broadcast
address with the source IP address set to the actual machine they
wish to attack. If your border routers are not configured to
stomp on ping's to broadcast addresses, your LAN winds up
generating sufficient responses to the spoofed source address to
saturate the victim, especially when the attacker uses the same
trick on several dozen broadcast addresses over several dozen
different networks at once. Broadcast attacks of over a hundred
and twenty megabits have been measured. A second common
springboard attack is against the ICMP error reporting system.
By constructing packets that generate ICMP error responses, an
attacker can saturate a server's incoming network and cause the
server to saturate its outgoing network with ICMP responses. This
type of attack can also crash the server by running it out of
mbuf's, especially if the server cannot drain the ICMP responses
it generates fast enough. The &os; kernel has a new kernel
compile option called
which limits the effectiveness
of these sorts of attacks. The last major class of springboard
attacks is related to certain internal
inetd services such as the
udp echo service. An attacker simply spoofs a UDP packet with the
source address being server A's echo port, and the destination
address being server B's echo port, where server A and B are both
on your LAN. The two servers then bounce this one packet back and
forth between each other. The attacker can overload both servers
and their LANs simply by injecting a few packets in this manner.
Similar problems exist with the internal
chargen port. A
competent sysadmin will turn off all of these inetd-internal test
services.Spoofed packet attacks may also be used to overload the kernel
route cache. Refer to the net.inet.ip.rtexpire,
rtminexpire, and rtmaxcachesysctl parameters. A spoofed packet attack
that uses a random source IP will cause the kernel to generate a
temporary cached route in the route table, viewable with
netstat -rna | fgrep W3. These routes
typically timeout in 1600 seconds or so. If the kernel detects
that the cached route table has gotten too big it will dynamically
reduce the rtexpire but will never decrease it
to less than rtminexpire. There are two
problems:The kernel does not react quickly enough when a lightly
loaded server is suddenly attacked.The rtminexpire is not low enough for
the kernel to survive a sustained attack.If your servers are connected to the Internet via a T3 or
better, it may be prudent to manually override both
rtexpire and rtminexpire
via &man.sysctl.8;. Never set either parameter to zero (unless
you want to crash the machine). Setting both
parameters to 2 seconds should be sufficient to protect the route
table from attack.Access Issues with Kerberos and SSHsshKerberosIVThere are a few issues with both Kerberos and
ssh that need to be addressed if
you intend to use them. Kerberos V is an excellent
authentication protocol, but there are bugs in the kerberized
telnet and
rlogin applications that make them
unsuitable for dealing with binary streams. Also, by default
Kerberos does not encrypt a session unless you use the
option. ssh
encrypts everything by default.ssh works quite well in every
respect except that it forwards encryption keys by default. What
this means is that if you have a secure workstation holding keys
that give you access to the rest of the system, and you
ssh to an insecure machine, your keys
are usable. The actual keys themselves are not exposed, but
ssh installs a forwarding port for the
duration of your login, and if an attacker has broken
root on the
insecure machine he can utilize that port to use your keys to gain
access to any other machine that your keys unlock.We recommend that you use ssh in
combination with Kerberos whenever possible for staff logins.
ssh can be compiled with Kerberos
support. This reduces your reliance on potentially exposed
ssh keys while at the same time
protecting passwords via Kerberos. ssh
keys should only be used for automated tasks from secure machines
(something that Kerberos is unsuited to do). We also recommend that
you either turn off key-forwarding in the
ssh configuration, or that you make use
of the from=IP/DOMAIN option that
ssh allows in its
authorized_keys file to make the key only
usable to entities logging in from specific machines.BillSwingleParts rewritten and updated by DES, MD5, and CryptsecuritycryptcryptDESMD5Every user on a &unix; system has a password associated with
their account. It seems obvious that these passwords need to be
known only to the user and the actual operating system. In
order to keep these passwords secret, they are encrypted with
what is known as a one-way hash, that is, they can
only be easily encrypted but not decrypted. In other words, what
we told you a moment ago was obvious is not even true: the
operating system itself does not really know
the password. It only knows the encrypted
form of the password. The only way to get the
plain-text password is by a brute force search of the
space of possible passwords.Unfortunately the only secure way to encrypt passwords when
&unix; came into being was based on DES, the Data Encryption
Standard. This was not such a problem for users resident in
the US, but since the source code for DES could not be exported
outside the US, &os; had to find a way to both comply with
US law and retain compatibility with all the other &unix;
variants that still used DES.The solution was to divide up the encryption libraries
so that US users could install the DES libraries and use
DES but international users still had an encryption method
that could be exported abroad. This is how &os; came to
use MD5 as its default encryption method. MD5 is believed to
be more secure than DES, so installing DES is offered primarily
for compatibility reasons.Recognizing Your Crypt MechanismBefore &os; 4.4 libcrypt.a was a
symbolic link pointing to the library which was used for
encryption. &os; 4.4 changed libcrypt.a to
provide a configurable password authentication hash library.
Currently the library supports DES, MD5 and Blowfish hash
functions. By default &os; uses MD5 to encrypt
passwords.It is pretty easy to identify which encryption method
&os; is set up to use. Examining the encrypted passwords in
the /etc/master.passwd file is one way.
Passwords encrypted with the MD5 hash are longer than those
encrypted with the DES hash and also begin with the characters
$1$. Passwords starting with
$2a$ are encrypted with the
Blowfish hash function. DES password strings do not
have any particular identifying characteristics, but they are
shorter than MD5 passwords, and are coded in a 64-character
alphabet which does not include the $
character, so a relatively short string which does not begin with
a dollar sign is very likely a DES password.The password format used for new passwords is controlled
by the passwd_format login capability in
/etc/login.conf, which takes values of
des, md5 or
blf. See the &man.login.conf.5; manual page
for more information about login capabilities.One-time Passwordsone-time passwordssecurityone-time passwordsS/Key is a one-time password scheme based on a one-way hash
function. &os; uses the MD4 hash for compatibility but other
systems have used MD5 and DES-MAC. S/Key has been part of the
&os; base system since version 1.1.5 and is also used on a
growing number of other operating systems. S/Key is a registered
trademark of Bell Communications Research, Inc.From version 5.0 of &os;, S/Key has been replaced with
the functionally equivalent OPIE (One-time Passwords In
Everything). OPIE uses the MD5 hash by default.There are three different sorts of passwords which we will discuss
below. The first is your usual &unix; style or
Kerberos password; we will call this a &unix; password.
The second sort is the one-time password which is generated by the
S/Key key program or the OPIE
&man.opiekey.1; program and accepted by the
keyinit or &man.opiepasswd.1; programs
and the login prompt; we will
call this a one-time password. The final sort of
password is the secret password which you give to the
key/opiekey programs (and
sometimes the
keyinit/opiepasswd programs)
which it uses to generate
one-time passwords; we will call it a secret password
or just unqualified password.The secret password does not have anything to do with your &unix;
password; they can be the same but this is not recommended. S/Key
and OPIE secret passwords are not limited to 8 characters like old
&unix; passwordsUnder &os; the standard login
password may be up to 128 characters in length.,
they can be as long as you like. Passwords of six or
seven word long phrases are fairly common. For the most part, the
S/Key or OPIE system operates completely independently of the &unix;
password system.Besides the password, there are two other pieces of data that
are important to S/Key and OPIE. One is what is known as the
seed or key, consisting of two letters
and five digits. The other is what is called the iteration
count, a number between 1 and 100. S/Key creates the
one-time password by concatenating the seed and the secret password,
then applying the MD4/MD5 hash as many times as specified by the
iteration count and turning the result into six short English words.
These six English words are your one-time password. The
authentication system (primarily PAM) keeps
track of the last one-time password used, and the user is
authenticated if the hash of the user-provided password is equal to
the previous password. Because a one-way hash is used it is
impossible to generate future one-time passwords if a successfully
used password is captured; the iteration count is decremented after
each successful login to keep the user and the login program in
sync. When the iteration count gets down to 1, S/Key and OPIE must be
reinitialized.There are three programs involved in each system
which we will discuss below. The key and
opiekey programs accept an iteration
count, a seed, and a secret password, and generate a one-time
password or a consecutive list of one-time passwords. The
keyinit and opiepasswd
programs are used to initialize S/Key and OPIE respectively,
and to change passwords, iteration counts, or seeds; they
take either a secret passphrase, or an iteration count,
seed, and one-time password. The keyinfo
and opieinfo programs examine the
relevant credentials files (/etc/skeykeys or
/etc/opiekeys) and print out the invoking user's
current iteration count and seed.There are four different sorts of operations we will cover. The
first is using keyinit or
opiepasswd over a secure connection to set up
one-time-passwords for the first time, or to change your password
or seed. The second operation is using keyinit
or opiepasswd over an insecure connection, in
conjunction with key or opiekey
over a secure connection, to do the same. The third is using
key/opiekey to log in over
an insecure connection. The fourth is using key
or opiekey to generate a number of keys which
can be written down or printed out to carry with you when going to
some location without secure connections to anywhere.Secure Connection InitializationTo initialize S/Key for the first time, change your password,
or change your seed while logged in over a secure connection
(e.g. on the console of a machine or via ssh), use the
keyinit command without any parameters while
logged in as yourself:&prompt.user; keyinit
Adding unfurl:
Reminder - Only use this method if you are directly connected.
If you are using telnet or rlogin exit with no password and use keyinit -s.
Enter secret password:
Again secret password:
ID unfurl s/key is 99 to17757
DEFY CLUB PRO NASH LACE SOFTFor OPIE, opiepasswd is used instead:&prompt.user; opiepasswd -c
[grimreaper] ~ $ opiepasswd -f -c
Adding unfurl:
Only use this method from the console; NEVER from remote. If you are using
telnet, xterm, or a dial-in, type ^C now or exit with no password.
Then run opiepasswd without the -c parameter.
Using MD5 to compute responses.
Enter new secret pass phrase:
Again new secret pass phrase:
ID unfurl OTP key is 499 to4268
MOS MALL GOAT ARM AVID COED
At the Enter new secret pass phrase: or
Enter secret password: prompts, you
should enter a password or phrase. Remember, this is not the
password that you will use to login with, this is used to generate
your one-time login keys. The ID line gives the
parameters of your particular instance: your login name, the
iteration count, and seed. When logging in the system
will remember these parameters and present them back to you so you
do not have to remember them. The last line gives the particular
one-time password which corresponds to those parameters and your
secret password; if you were to re-login immediately, this
one-time password is the one you would use.Insecure Connection InitializationTo initialize or change your secret password over an
insecure connection, you will need to already have a secure
connection to some place where you can run key
or opiekey; this might be in the form of a
desk accessory on a &macintosh;, or a shell prompt on a machine you
trust. You will also need to make up an iteration count (100 is
probably a good value), and you may make up your own seed or use a
randomly-generated one. Over on the insecure connection (to the
machine you are initializing), use the keyinit
-s command:&prompt.user; keyinit -s
Updating unfurl:
Old key: to17758
Reminder you need the 6 English words from the key command.
Enter sequence count from 1 to 9999: 100
Enter new key [default to17759]:
s/key 100 to 17759
s/key access password:
s/key access password:CURE MIKE BANE HIM RACY GOREFor OPIE, you need to use opiepasswd:&prompt.user; opiepasswd
Updating unfurl:
You need the response from an OTP generator.
Old secret pass phrase:
otp-md5 498 to4268 ext
Response: GAME GAG WELT OUT DOWN CHAT
New secret pass phrase:
otp-md5 499 to4269
Response: LINE PAP MILK NELL BUOY TROY
ID mark OTP key is 499 gr4269
LINE PAP MILK NELL BUOY TROY
To accept the default seed (which the
keyinit program confusingly calls a
key), press Return.
Then before entering an
access password, move over to your secure connection or S/Key desk
accessory, and give it the same parameters:&prompt.user; key 100 to17759
Reminder - Do not use this program while logged in via telnet or rlogin.
Enter secret password: <secret password>
CURE MIKE BANE HIM RACY GOREOr for OPIE:&prompt.user; opiekey 498 to4268
Using the MD5 algorithm to compute response.
Reminder: Don't use opiekey from telnet or dial-in sessions.
Enter secret pass phrase:
GAME GAG WELT OUT DOWN CHAT
Now switch back over to the insecure connection, and copy the
one-time password generated over to the relevant program.Generating a Single One-time PasswordOnce you have initialized S/Key or OPIE, when you login you will be
presented with a prompt like this:&prompt.user; telnet example.com
Trying 10.0.0.1...
Connected to example.com
Escape character is '^]'.
FreeBSD/i386 (example.com) (ttypa)
login: <username>
s/key 97 fw13894
Password: Or for OPIE:&prompt.user; telnet example.com
Trying 10.0.0.1...
Connected to example.com
Escape character is '^]'.
FreeBSD/i386 (example.com) (ttypa)
login: <username>
otp-md5 498 gr4269 ext
Password: As a side note, the S/Key and OPIE prompts have a useful feature
(not shown here): if you press Return
at the password prompt, the
prompter will turn echo on, so you can see what you are
typing. This can be extremely useful if you are attempting to
type in a password by hand, such as from a printout.MS-DOSWindowsMacOSAt this point you need to generate your one-time password to
answer this login prompt. This must be done on a trusted system
that you can run key or
opiekey on. (There are versions of these for DOS,
&windows; and &macos; as well.) They need both the iteration count and
the seed as command line options. You can cut-and-paste these
right from the login prompt on the machine that you are logging
in to.On the trusted system:&prompt.user; key 97 fw13894
Reminder - Do not use this program while logged in via telnet or rlogin.
Enter secret password:
WELD LIP ACTS ENDS ME HAAGFor OPIE:&prompt.user; opiekey 498 to4268
Using the MD5 algorithm to compute response.
Reminder: Don't use opiekey from telnet or dial-in sessions.
Enter secret pass phrase:
GAME GAG WELT OUT DOWN CHATNow that you have your one-time password you can continue
logging in:login: <username>
s/key 97 fw13894
Password: <return to enable echo>
s/key 97 fw13894
Password [echo on]: WELD LIP ACTS ENDS ME HAAG
Last login: Tue Mar 21 11:56:41 from 10.0.0.2 ... Generating Multiple One-time PasswordsSometimes you have to go places where you do not have
access to a trusted machine or secure connection. In this case,
it is possible to use the key and
opiekey commands to
generate a number of one-time passwords beforehand to be printed
out and taken with you. For example:&prompt.user; key -n 5 30 zz99999
Reminder - Do not use this program while logged in via telnet or rlogin.
Enter secret password: <secret password>
26: SODA RUDE LEA LIND BUDD SILT
27: JILT SPY DUTY GLOW COWL ROT
28: THEM OW COLA RUNT BONG SCOT
29: COT MASH BARR BRIM NAN FLAG
30: CAN KNEE CAST NAME FOLK BILKOr for OPIE:&prompt.user; opiekey -n 5 30 zz99999
Using the MD5 algorithm to compute response.
Reminder: Don't use opiekey from telnet or dial-in sessions.
Enter secret pass phrase: <secret password>
26: JOAN BORE FOSS DES NAY QUIT
27: LATE BIAS SLAY FOLK MUCH TRIG
28: SALT TIN ANTI LOON NEAL USE
29: RIO ODIN GO BYE FURY TIC
30: GREW JIVE SAN GIRD BOIL PHIThe requests five keys in sequence, the
specifies what the last iteration number
should be. Note that these are printed out in
reverse order of eventual use. If you are
really paranoid, you might want to write the results down by hand;
otherwise you can cut-and-paste into lpr. Note
that each line shows both the iteration count and the one-time
password; you may still find it handy to scratch off passwords as
you use them.Restricting Use of &unix; PasswordsS/Key can place restrictions on the use of &unix; passwords based
on the host name, user name, terminal port, or IP address of a
login session. These restrictions can be found in the
configuration file /etc/skey.access. The
&man.skey.access.5; manual page has more information on the complete
format of the file and also details some security cautions to be
aware of before depending on this file for security.If there is no /etc/skey.access file
(this is the default on &os; 4.X systems), then all users will
be allowed to use &unix; passwords. If the file exists, however,
then all users will be required to use S/Key unless explicitly
permitted to do otherwise by configuration statements in the
skey.access file. In all cases, &unix;
passwords are permitted on the console.Here is a sample skey.access configuration
file which illustrates the three most common sorts of configuration
statements:permit internet 192.168.0.0 255.255.0.0
permit user fnord
permit port ttyd0The first line (permit internet) allows
users whose IP source address (which is vulnerable to spoofing)
matches the specified value and mask, to use &unix; passwords. This
should not be considered a security mechanism, but rather, a means
to remind authorized users that they are using an insecure network
and need to use S/Key for authentication.The second line (permit user) allows the
specified username, in this case fnord, to use
&unix; passwords at any time. Generally speaking, this should only
be used for people who are either unable to use the
key program, like those with dumb terminals, or
those who are ineducable.The third line (permit port) allows all
users logging in on the specified terminal line to use &unix;
passwords; this would be used for dial-ups.OPIE can restrict the use of &unix; passwords based on the IP
address of a login session just like S/Key does. The relevant file
is /etc/opieaccess, which is present by default
on &os; 5.0 and newer systems. Please check &man.opieaccess.5;
for more information on this file and which security considerations
you should be aware of when using it.Here is a sample opieaccess file:permit 192.168.0.0 255.255.0.0This line allows users whose IP source address (which is
vulnerable to spoofing) matches the specified value and mask,
to use &unix; passwords at any time.If no rules in opieaccess are matched,
the default is to deny non-OPIE logins.TomRhodesWritten by: TCP WrappersTCP WrappersAnyone familiar with &man.inetd.8; has probably heard
of TCP Wrappers at some point. But few
individuals seem to fully comprehend its usefulness in a
network environment. It seems that everyone wants to
install a firewall to handle network connections. While a
firewall has a wide variety of uses, there are some things
that a firewall not handle such as sending text back to the
connection originator. The TCP software
does this and much more. In the next few sections many of
the TCP Wrappers features will be discussed,
and, when applicable, example configuration lines will be
provided.The TCP Wrappers software extends the
abilities of inetd to provide support for
every server daemon under its control. Using this method it
is possible to provide logging support, return messages to
connections, permit a daemon to only accept internal connections,
etc. While some of these features can be provided by implementing
a firewall, this will add not only an extra layer of protection
but go beyond the amount of control a firewall can
provide.The added functionality of TCP Wrappers
should not be considered a replacement for a good firewall;
however, but should used in conjunction with a firewall and
other security configurations to add an extra layer of protection
for the system.Since this is an extension to the configuration of
inetd, the reader is expected have
read the inetd configuration
section.While programs run by &man.inetd.8; are not exactly
daemons, they have traditionally been called
daemons. This is the term we will use in this section too.Initial ConfigurationThe only requirement of using TCP
Wrappers in &os; is to ensure the inetd
server is started from rc.conf with the
option; this is the default setting. Of
course, proper configuration of
/etc/hosts.allow is also expected, but
&man.syslogd.8; will throw messages in the system logs in
these cases.Unlike other implementations of TCP
Wrappers, the use of hosts.deny has
been deprecated. All configuration options should be placed
in /etc/hosts.allow.In the simplest configuration, daemon connection policies
are set to either be permitted or blocked depending on the
options in /etc/hosts.allow. The default
configuration in &os; is to allow a connection to every daemon
started with inetd. Changing this will be
discussed only after the basic configuration is covered.Basic configuration usually takes the form of
daemon : address : action. Where
daemon is the daemon name which
inetd started. The
address can be a valid hostname, an
IP address or an IPv6 address enclosed in
brackets ([ ]). The action field can be either allow
or deny to grant or deny access appropriately. Keep in mind
that configuration works off a first rule match semantic,
meaning that the configuration file is scanned in ascending
order for a matching rule. When a match is found the rule
is applied and the search process will halt.Several other options exist but they will be explained
in a later section. A simple configuration line may easily be
constructed from that information alone. For example, to
allow POP3 connections via the
mail/qpopper daemon,
the following lines should be appended to
hosts.allow:# This line is required for POP3 connections:
qpopper : ALL : allowAfter adding this line, inetd will need
restarted. This can be accomplished by use of the &man.kill.1;
command, or with the restart parameter
with /etc/rc.d/inetd.Advanced ConfigurationTCP Wrappers has advanced
options too; they will allow for more control over the
way connections are handled. In some cases it may be
a good idea to return a comment to certain hosts or
daemon connections. In other cases, perhaps a log file
should be recorded or an email sent to the administrator.
Other situations may require the use of a service for local
connections only. This is all possible through the use of
configuration options known as wildcards,
expansion characters and external command execution. The
next two sections are written to cover these situations.External CommandsSuppose that a situation occurs where a connection
should be denied yet a reason should be sent to the
individual who attempted to establish that connection. How
could it be done? That action can be made possible by
using the option. When a connection
attempt is made, will be called to
execute a shell command or script. An example already exists
in the hosts.allow file:# The rest of the daemons are protected.
ALL : ALL \
: severity auth.info \
: twist /bin/echo "You are not welcome to use %d from %h."This example shows that the message,
You are not allowed to use daemon
from hostname. will be returned
for any daemon not previously configured in the access file.
This is extremely useful for sending a reply back to the
connection initiator right after the established connection
is dropped. Note that any message returned
must be wrapped in quote
" characters; there are no exceptions to
this rule.It may be possible to launch a denial of service attack
on the server if an attacker, or group of attackers could
flood these daemons with connection requests.Another possibility is to use the
option in these cases. Like , the
implicitly denies the connection and
may be used to run external shell commands or scripts.
Unlike , will
not send a reply back to the individual who established the
connection. For an example, consider the following
configuration line:# We do not allow connections from example.com:
ALL : .example.com \
: spawn (/bin/echo %a from %h attempted to access %d >> \
/var/log/connections.log) \
: denyThis will deny all connection attempts from the
*.example.com domain;
simultaneously logging the hostname, IP
address and the daemon which they attempted to access in the
/var/log/connections.log file.Aside from the already explained substitution characters
above, e.g. %a, a few others exist. See the
&man.hosts.access.5; manual page for the complete list.Wildcard OptionsThus far the ALL example has been used
continuously throughout the examples. Other options exist
which could extend the functionality a bit further. For
instance, ALL may be used to match every
instance of either a daemon, domain or an
IP address. Another wildcard available is
PARANOID which may be used to match any
host which provides an IP address that may
be forged. In other words, paranoid may
be used to define an action to be taken whenever a connection
is made from an IP address that differs
from its hostname. The following example may shed some more
light on this discussion:# Block possibly spoofed requests to sendmail:
sendmail : PARANOID : denyIn that example all connection requests to
sendmail which have an
IP address that varies from its hostname
will be denied.Using the PARANOID may severely
cripple servers if the client or server has a broken
DNS setup. Administrator discretion
is advised.To learn more about wildcards and their associated
functionality, see the &man.hosts.access.5; manual
page.Before any of the specific configuration lines above will
work, the first configuration line should be commented out
in hosts.allow. This was noted at the
beginning of this section.MarkMurrayContributed by MarkDapozBased on a contribution by KerberosIVKerberos is a network add-on system/protocol that allows users to
authenticate themselves through the services of a secure server.
Services such as remote login, remote copy, secure inter-system file
copying and other high-risk tasks are made considerably safer and more
controllable.The following instructions can be used as a guide on how to set up
Kerberos as distributed for &os;. However, you should refer to the
relevant manual pages for a complete description.Installing KerberosIVMITKerberosIVInstallingKerberos is an optional component of &os;. The easiest
way to install this software is by selecting the krb4 or
krb5 distribution in sysinstall
during the initial installation of &os;. This will install
the eBones (KerberosIV) or Heimdal (Kerberos5)
implementation of Kerberos. These implementations are
included because they are developed outside the USA/Canada and
were thus available to system owners outside those countries
during the era of restrictive export controls on cryptographic
code from the USA.Alternatively, the MIT implementation of Kerberos is
available from the ports collection as
security/krb5.Creating the Initial DatabaseThis is done on the Kerberos server only. First make sure that
you do not have any old Kerberos databases around. You should change
to the directory /etc/kerberosIV and check that
only the following files are present:&prompt.root; cd /etc/kerberosIV
&prompt.root; ls
README krb.conf krb.realmsIf any additional files (such as principal.*
or master_key) exist, then use the
kdb_destroy command to destroy the old Kerberos
database, or if Kerberos is not running, simply delete the extra
files.You should now edit the krb.conf and
krb.realms files to define your Kerberos realm.
In this case the realm will be EXAMPLE.COM and the
server is grunt.example.com. We edit
or create the krb.conf file:&prompt.root; cat krb.conf
EXAMPLE.COM
EXAMPLE.COM grunt.example.com admin server
CS.BERKELEY.EDU okeeffe.berkeley.edu
ATHENA.MIT.EDU kerberos.mit.edu
ATHENA.MIT.EDU kerberos-1.mit.edu
ATHENA.MIT.EDU kerberos-2.mit.edu
ATHENA.MIT.EDU kerberos-3.mit.edu
LCS.MIT.EDU kerberos.lcs.mit.edu
TELECOM.MIT.EDU bitsy.mit.edu
ARC.NASA.GOV trident.arc.nasa.govIn this case, the other realms do not need to be there. They are
here as an example of how a machine may be made aware of multiple
realms. You may wish to not include them for simplicity.The first line names the realm in which this system works. The
other lines contain realm/host entries. The first item on a line is a
realm, and the second is a host in that realm that is acting as a
key distribution center. The words admin
server following a host's name means that host also
provides an administrative database server. For further explanation
of these terms, please consult the Kerberos manual pages.Now we have to add grunt.example.com
to the EXAMPLE.COM realm and also add an entry to
put all hosts in the .example.com
domain in the EXAMPLE.COM realm. The
krb.realms file would be updated as
follows:&prompt.root; cat krb.realms
grunt.example.com EXAMPLE.COM
.example.com EXAMPLE.COM
.berkeley.edu CS.BERKELEY.EDU
.MIT.EDU ATHENA.MIT.EDU
.mit.edu ATHENA.MIT.EDUAgain, the other realms do not need to be there. They are here as
an example of how a machine may be made aware of multiple realms. You
may wish to remove them to simplify things.The first line puts the specific system into
the named realm. The rest of the lines show how to default systems of
a particular subdomain to a named realm.Now we are ready to create the database. This only needs to run
on the Kerberos server (or Key Distribution Center). Issue the
kdb_init command to do this:&prompt.root; kdb_initRealm name [default ATHENA.MIT.EDU ]:EXAMPLE.COM
You will be prompted for the database Master Password.
It is important that you NOT FORGET this password.
Enter Kerberos master key:Now we have to save the key so that servers on the local machine
can pick it up. Use the kstash command to do
this:&prompt.root; kstashEnter Kerberos master key:
Current Kerberos master key version is 1.
Master key entered. BEWARE!This saves the encrypted master password in
/etc/kerberosIV/master_key.Making It All RunKerberosIVInital StartupTwo principals need to be added to the database for
each system that will be secured with Kerberos.
Their names are kpasswd and rcmd.
These two principals are made for each system, with the instance being
the name of the individual system.These daemons, kpasswd and
rcmd allow other systems to change Kerberos
passwords and run commands like &man.rcp.1;,
&man.rlogin.1; and &man.rsh.1;.Now let us add these entries:&prompt.root; kdb_edit
Opening database...
Enter Kerberos master key:
Current Kerberos master key version is 1.
Master key entered. BEWARE!
Previous or default values are in [brackets] ,
enter return to leave the same, or new value.
Principal name:passwdInstance:grunt
<Not found>, Create [y] ?y
Principal: passwd, Instance: grunt, kdc_key_ver: 1
New Password: <---- enter RANDOM here
Verifying password
New Password: <---- enter RANDOM here
Random password [y] ?y
Principal's new key version = 1
Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?Max ticket lifetime (*5 minutes) [ 255 ] ?Attributes [ 0 ] ?
Edit O.K.
Principal name:rcmdInstance:grunt
<Not found>, Create [y] ?
Principal: rcmd, Instance: grunt, kdc_key_ver: 1
New Password: <---- enter RANDOM here
Verifying password
New Password: <---- enter RANDOM here
Random password [y] ?
Principal's new key version = 1
Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?Max ticket lifetime (*5 minutes) [ 255 ] ?Attributes [ 0 ] ?
Edit O.K.
Principal name: <---- null entry here will cause an exitCreating the Server FileWe now have to extract all the instances which define the
services on each machine. For this we use the
ext_srvtab command. This will create a file
which must be copied or moved by secure
means to each Kerberos client's
/etc/kerberosIV directory. This file must
be present on each server and client, and is crucial to the
operation of Kerberos.&prompt.root; ext_srvtab gruntEnter Kerberos master key:
Current Kerberos master key version is 1.
Master key entered. BEWARE!
Generating 'grunt-new-srvtab'....Now, this command only generates a temporary file which must be
renamed to srvtab so that all the servers can pick
it up. Use the &man.mv.1; command to move it into place on
the original system:&prompt.root; mv grunt-new-srvtab srvtabIf the file is for a client system, and the network is not deemed
safe, then copy the
client-new-srvtab to
removable media and transport it by secure physical means. Be sure to
rename it to srvtab in the client's
/etc/kerberosIV directory, and make sure it is
mode 600:&prompt.root; mv grumble-new-srvtab srvtab
&prompt.root; chmod 600 srvtabPopulating the DatabaseWe now have to add some user entries into the database. First
let us create an entry for the user jane. Use the
kdb_edit command to do this:&prompt.root; kdb_edit
Opening database...
Enter Kerberos master key:
Current Kerberos master key version is 1.
Master key entered. BEWARE!
Previous or default values are in [brackets] ,
enter return to leave the same, or new value.
Principal name:janeInstance:
<Not found>, Create [y] ?y
Principal: jane, Instance: , kdc_key_ver: 1
New Password: <---- enter a secure password here
Verifying password
New Password: <---- re-enter the password here
Principal's new key version = 1
Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?Max ticket lifetime (*5 minutes) [ 255 ] ?Attributes [ 0 ] ?
Edit O.K.
Principal name: <---- null entry here will cause an exitTesting It All OutFirst we have to start the Kerberos daemons. Note that if you
have correctly edited your /etc/rc.conf then this
will happen automatically when you reboot. This is only necessary on
the Kerberos server. Kerberos clients will automatically get what
they need from the /etc/kerberosIV
directory.&prompt.root; kerberos &
Kerberos server starting
Sleep forever on error
Log file is /var/log/kerberos.log
Current Kerberos master key version is 1.
Master key entered. BEWARE!
Current Kerberos master key version is 1
Local realm: EXAMPLE.COM
&prompt.root; kadmind -n &
KADM Server KADM0.0A initializing
Please do not use 'kill -9' to kill this job, use a
regular kill instead
Current Kerberos master key version is 1.
Master key entered. BEWARE!Now we can try using the kinit command to get a
ticket for the ID jane that we created
above:&prompt.user; kinit jane
MIT Project Athena (grunt.example.com)
Kerberos Initialization for "jane"
Password:Try listing the tokens using klist to see if we
really have them:&prompt.user; klist
Ticket file: /tmp/tkt245
Principal: jane@EXAMPLE.COM
Issued Expires Principal
Apr 30 11:23:22 Apr 30 19:23:22 krbtgt.EXAMPLE.COM@EXAMPLE.COMNow try changing the password using &man.passwd.1; to
check if the kpasswd daemon can get
authorization to the Kerberos database:&prompt.user; passwd
realm EXAMPLE.COM
Old password for jane:New Password for jane:
Verifying password
New Password for jane:
Password changed.Adding su PrivilegesKerberos allows us to give each user
who needs root privileges their own
separate &man.su.1; password.
We could now add an ID which is authorized to
&man.su.1; to root. This is
controlled by having an instance of root
associated with a principal. Using kdb_edit
we can create the entry jane.root in the
Kerberos database:&prompt.root; kdb_edit
Opening database...
Enter Kerberos master key:
Current Kerberos master key version is 1.
Master key entered. BEWARE!
Previous or default values are in [brackets] ,
enter return to leave the same, or new value.
Principal name:janeInstance:root
<Not found>, Create [y] ? y
Principal: jane, Instance: root, kdc_key_ver: 1
New Password: <---- enter a SECURE password here
Verifying password
New Password: <---- re-enter the password here
Principal's new key version = 1
Expiration date (enter yyyy-mm-dd) [ 2000-01-01 ] ?Max ticket lifetime (*5 minutes) [ 255 ] ?12 <--- Keep this short!
Attributes [ 0 ] ?
Edit O.K.
Principal name: <---- null entry here will cause an exitNow try getting tokens for it to make sure it works:&prompt.root; kinit jane.root
MIT Project Athena (grunt.example.com)
Kerberos Initialization for "jane.root"
Password:Now we need to add the user to root's
.klogin file:&prompt.root; cat /root/.klogin
jane.root@EXAMPLE.COMNow try doing the &man.su.1;:&prompt.user; suPassword:and take a look at what tokens we have:&prompt.root; klist
Ticket file: /tmp/tkt_root_245
Principal: jane.root@EXAMPLE.COM
Issued Expires Principal
May 2 20:43:12 May 3 04:43:12 krbtgt.EXAMPLE.COM@EXAMPLE.COMUsing Other CommandsIn an earlier example, we created a principal called
jane with an instance root.
This was based on a user with the same name as the principal, and this
is a Kerberos default; that a
<principal>.<instance> of the form
<username>.root will allow
that <username> to &man.su.1; to
root if the necessary entries are in the
.klogin file in root's
home directory:&prompt.root; cat /root/.klogin
jane.root@EXAMPLE.COMLikewise, if a user has in their own home directory lines of the
form:&prompt.user; cat ~/.klogin
jane@EXAMPLE.COM
jack@EXAMPLE.COMThis allows anyone in the EXAMPLE.COM realm
who has authenticated themselves as jane or
jack (via kinit, see above)
to access to jane's
account or files on this system (grunt) via
&man.rlogin.1;, &man.rsh.1; or
&man.rcp.1;.For example, jane now logs into another system using
Kerberos:&prompt.user; kinit
MIT Project Athena (grunt.example.com)
Password:
&prompt.user; rlogin grunt
Last login: Mon May 1 21:14:47 from grumble
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
The Regents of the University of California. All rights reserved.
FreeBSD BUILT-19950429 (GR386) #0: Sat Apr 29 17:50:09 SAT 1995Or jack logs into jane's account on the same machine
(jane having
set up the .klogin file as above, and the person
in charge of Kerberos having set up principal
jack with a null instance):&prompt.user; kinit
&prompt.user; rlogin grunt -l jane
MIT Project Athena (grunt.example.com)
Password:
Last login: Mon May 1 21:16:55 from grumble
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
The Regents of the University of California. All rights reserved.
FreeBSD BUILT-19950429 (GR386) #0: Sat Apr 29 17:50:09 SAT 1995TillmanHodgsonContributed by MarkMurrayBased on a contribution by Kerberos5Every &os; release beyond &os;-5.1 includes support
only for Kerberos5. Hence
Kerberos5 is the only version
included, and its configuration is similar in many aspects
to that of KerberosIV. The following
information only applies to
Kerberos5 in post &os;-5.0
releases. Users who wish to use the
KerberosIV package may install the
security/krb4 port.Kerberos is a network add-on
system/protocol that allows users to authenticate themselves
through the services of a secure server. Services such as remote
login, remote copy, secure inter-system file copying and other
high-risk tasks are made considerably safer and more
controllable.Kerberos can be described as an
identity-verifying proxy system. It can also be described as a
trusted third-party authentication system.
Kerberos provides only one
function — the secure authentication of users on the network.
It does not provide authorization functions (what users are
allowed to do) or auditing functions (what those users did).
After a client and server have used
Kerberos to prove their identity, they
can also encrypt all of their communications to assure privacy
and data integrity as they go about their business.Therefore it is highly recommended that
Kerberos be used with other security
methods which provide authorization and audit services.The following instructions can be used as a guide on how to set
up Kerberos as distributed for &os;.
However, you should refer to the relevant manual pages for a complete
description.For purposes of demonstrating a Kerberos
installation, the various name spaces will be handled as follows:The DNS domain (zone)
will be example.org.The Kerberos realm will be
EXAMPLE.ORG.Please use real domain names when setting up
Kerberos even if you intend to run
it internally. This avoids DNS problems
and assures inter-operation with other
Kerberos realms.HistoryKerberos5HistoryKerberos was created by
MIT as a solution to network security problems.
The Kerberos protocol uses strong
cryptography so that a client can prove its identity to a server
(and vice versa) across an insecure network connection.Kerberos is both the name of a
network authentication protocol and an adjective to describe
programs that implement the program
(Kerberos telnet, for example). The
current version of the protocol is version 5, described in
RFC 1510.Several free implementations of this protocol are available,
covering a wide range of operating systems. The Massachusetts
Institute of Technology (MIT), where
Kerberos was originally developed,
continues to develop their Kerberos
package. It is commonly used in the US
as a cryptography product, as such it
has historically been affected by US export
regulations. The MIT
Kerberos is available as a port
(security/krb5). Heimdal
Kerberos is another version 5
implementation, and was explicitly developed outside of the
US to avoid export
regulations (and is thus often included in non-commercial &unix;
variants). The Heimdal Kerberos
distribution is available as a port
(security/heimdal), and a
minimal installation of it is included in the base &os;
install.In order to reach the widest audience, these instructions assume
the use of the Heimdal distribution included in &os;.Setting up a Heimdal KDCKerberos5Key Distribution Center ConfigurationThe Key Distribution Center (KDC) is the
centralized authentication service that
Kerberos provides — it is the
computer that issues Kerberos tickets.
The KDC is considered trusted by
all other computers in the Kerberos
realm, and thus has heightened security concerns.Note that while running the Kerberos
server requires very few computing resources, a dedicated machine
acting only as a KDC is recommended for security
reasons.To begin setting up a KDC, ensure that your
/etc/rc.conf file contains the correct
settings to act as a KDC (you may need to adjust
paths to reflect your own system):kerberos5_server_enable="YES"
kadmind5_server_enable="YES"
kerberos_stash="YES"The is only available in
&os; 4.X.Next we will set up your Kerberos
config file, /etc/krb5.conf:[libdefaults]
default_realm = EXAMPLE.ORG
[realms]
EXAMPLE.ORG = {
kdc = kerberos.example.org
admin_server = kerberos.example.org
}
[domain_realm]
.example.org = EXAMPLE.ORGNote that this /etc/krb5.conf file implies
that your KDC will have the fully-qualified
hostname of kerberos.example.org.
You will need to add a CNAME (alias) entry to your zone file to
accomplish this if your KDC has a different
hostname.For large networks with a properly configured
BIND DNS server, the
above example could be trimmed to:[libdefaults]
default_realm = EXAMPLE.ORGWith the following lines being appended to the
example.org zonefile:_kerberos._udp IN SRV 01 00 88 kerberos.example.org.
_kerberos._tcp IN SRV 01 00 88 kerberos.example.org.
_kpasswd._udp IN SRV 01 00 464 kerberos.example.org.
_kerberos-adm._tcp IN SRV 01 00 749 kerberos.example.org.
_kerberos IN TXT EXAMPLE.ORG.For clients to be able to find the
Kerberos services, you
must have either a fully configured
/etc/krb5.conf or a miminally configured
/etc/krb5.confand a
properly configured DNS server.Next we will create the Kerberos
database. This database contains the keys of all principals encrypted
with a master password. You are not
required to remember this password, it will be stored in a file
(/var/heimdal/m-key). To create the master
key, run kstash and enter a password.Once the master key has been created, you can initialize the
database using the kadmin program with the
-l option (standing for local).
This option instructs kadmin to modify the
database files directly rather than going through the
kadmind network service. This handles the
chicken-and-egg problem of trying to connect to the database
before it is created. Once you have the kadmin
prompt, use the init command to create your
realms initial database.Lastly, while still in kadmin, create your
first principal using the add command. Stick
to the defaults options for the principal for now, you can always
change them later with the modify command.
Note that you can use the ? command at any
prompt to see the available options.A sample database creation session is shown below:&prompt.root; kstash
Master key: xxxxxxxx
Verifying password - Master key: xxxxxxxx
&prompt.root; kadmin -l
kadmin> init EXAMPLE.ORG
Realm max ticket life [unlimited]:
kadmin> add tillman
Max ticket life [unlimited]:
Max renewable life [unlimited]:
Attributes []:
Password: xxxxxxxx
Verifying password - Password: xxxxxxxxNow it is time to start up the KDC services.
Run /etc/rc.d/kerberos start and
/etc/rc.d/kadmind start to bring up the
services. Note that you won't have any kerberized daemons running
at this point but you should be able to confirm the that the
KDC is functioning by obtaining and listing a
ticket for the principal (user) that you just created from the
command-line of the KDC itself:&prompt.user; k5init tillman
tillman@EXAMPLE.ORG's Password:
&prompt.user; k5list
Credentials cache: FILE:/tmp/krb5cc_500
Principal: tillman@EXAMPLE.ORG
Issued Expires Principal
Aug 27 15:37:58 Aug 28 01:37:58 krbtgt/EXAMPLE.ORG@EXAMPLE.ORGKerberos enabling a server with
Heimdal servicesKerberos5Enabling ServicesFirst, we need a copy of the Kerberos
configuration file, /etc/krb5.conf. To do
so, simply copy it over to the client computer from the
KDC in a secure fashion (using network utilities,
such as &man.scp.1;, or physically via a
floppy disk).Next you need a /etc/krb5.keytab file.
This is the major difference between a server providing
Kerberos enabled daemons and a
workstation — the server must have a
keytab file. This file
contains the servers host key, which allows it and the
KDC to verify each others identity. It
must be transmitted to the server in a secure fashion, as the
security of the server can be broken if the key is made public.
This explicitly means that transferring it via a clear text
channel, such as FTP, is a very bad idea.Typically, you transfer to the keytab
to the server using the kadmin program.
This is handy because you also need to create the host principal
(the KDC end of the
krb5.keytab) using
kadmin.Note that you must have already obtained a ticket and that this
ticket must be allowed to use the kadmin
interface in the kadmind.acl. See the section
titled Remote administration in the Heimdal info
pages (info heimdal) for details on designing
access control lists. If you do not want to enable remote
kadmin access, you can simply securely connect
to the KDC (via local console,
&man.ssh.1; or Kerberos
&man.telnet.1;) and perform administration locally
using kadmin -l.After installing the /etc/krb5.conf file,
you can use kadmin from the
Kerberos server. The
add --random-key command will let you add the
servers host principal, and the ext command
will allow you to extract the servers host principal to its own
keytab. For example:&prompt.root; kadmin
kadmin> add --random-key host/myserver.example.org
Max ticket life [unlimited]:
Max renewable life [unlimited]:
Attributes []:
kadmin> ext host/myserver.example.org
kadmin> exitNote that the ext command (short for
extract) stores the extracted key in
/etc/krb5.keytab by default.If you do not have kadmind running on the
KDC (possibly for security reasons) and thus
do not have access to kadmin remotely, you
can add the host principal
(host/myserver.EXAMPLE.ORG) directly on the
KDC and then extract it to a temporary file
(to avoid over-writing the /etc/krb5.keytab
on the KDC) using something like this:&prompt.root; kadmin
kadmin> ext --keytab=/tmp/example.keytab host/myserver.example.org
kadmin> exitYou can then securely copy the keytab to the server
computer (using scp or a floppy, for
example). Be sure to specify a non-default keytab name
to avoid over-writing the keytab on the
KDC.At this point your server can communicate with the
KDC (due to its krb5.conf
file) and it can prove its own identity (due to the
krb5.keytab file). It is now ready for
you to enable some Kerberos services.
For this example we will enable the telnet
service by putting a line like this into your
/etc/inetd.conf and then restarting the
&man.inetd.8; service with
/etc/rc.d/inetd restart:telnet stream tcp nowait root /usr/libexec/telnetd telnetd -a userThe critical bit is that the -a
(for authentication) type is set to user. Consult the
&man.telnetd.8; manual page for more details.Kerberos enabling a client with HeimdalKerberos5Client ConfigurationSetting up a client computer is almost trivially easy. As
far as Kerberos configuration goes,
you only need the Kerberos
configuration file, located at /etc/krb5.conf.
Simply securely copy it over to the client computer from the
KDC.Test your client computer by attempting to use
kinit, klist, and
kdestroy from the client to obtain, show, and
then delete a ticket for the principal you created above. You
should also be able to use Kerberos
applications to connect to Kerberos
enabled servers, though if that does not work and obtaining a
ticket does the problem is likely with the server and not with
the client or the KDC.When testing an application like telnet,
try using a packet sniffer (such as &man.tcpdump.1;)
to confirm that your password is not sent in the clear. Try
using telnet with the -x
option, which encrypts the entire data stream (similar to
ssh).The core Kerberos client applications
(traditionally named kinit,
klist, kdestroy, and
kpasswd) are installed in
the base &os; install. Note that &os; versions prior to 5.0
renamed them to k5init,
k5list, k5destroy,
k5passwd, and k5stash
(though it is typically only used once).Various non-core Kerberos client
applications are also installed by default. This is where the
minimal nature of the base Heimdal installation is
felt: telnet is the only
Kerberos enabled service.The Heimdal port adds some of the missing client applications:
Kerberos enabled versions of
ftp, rsh,
rcp, rlogin, and a few
other less common programs. The MIT port also
contains a full suite of Kerberos
client applications.User configuration files: .k5login and .k5usersKerberos5User Configuration FilesUsers within a realm typically have their
Kerberos principal (such as
tillman@EXAMPLE.ORG) mapped to a local
user account (such as a local account named
tillman). Client applications such as
telnet usually do not require a user name
or a principal.Occasionally, however, you want to grant access to a local
user account to someone who does not have a matching
Kerberos principal. For example,
tillman@EXAMPLE.ORG may need access to the
local user account webdevelopers. Other
principals may also need access to that local account.The .k5login and
.k5users files, placed in a users home
directory, can be used similar to a powerful combination of
.hosts and .rhosts,
solving this problem. For example, if a
.k5login with the following
contents:tillman@example.org
jdoe@example.orgWere to be placed into the home directory of the local user
webdevelopers then both principals listed
would have access to that account without requiring a shared
password.Reading the manual pages for these commands is recommended.
Note that the ksu manual page covers
.k5users.Kerberos Tips, Tricks, and TroubleshootingKerberos5TroubleshootingWhen using either the Heimdal or MIT
Kerberos ports ensure that your
PATH environment variable lists the
Kerberos versions of the client
applications before the system versions.Do all the computers in your realm have synchronized
time settings? If not, authentication may fail.
describes how to synchronize
clocks using NTP.MIT and Heimdal inter-operate nicely.
Except for kadmin, the protocol for
which is not standardized.If you change your hostname, you also need to change your
host/ principal and update your keytab.
This also applies to special keytab entries like the
www/ principal used for Apache's
www/mod_auth_kerb.All hosts in your realm must be resolvable (both forwards
and reverse) in DNS (or
/etc/hosts as a minimum). CNAMEs
will work, but the A and PTR records must be correct and in
place. The error message isn't very intuitive:
Kerberos5 refuses authentication because Read req
failed: Key table entry not found.Some operating systems that may being acting as clients
to your KDC do not set the permissions
for ksu to be setuid
root. This means that
ksu does not work, which is a good
security idea but annoying. This is not a
KDC error.With MIT
Kerberos, if you want to allow a
principal to have a ticket life longer than the default ten
hours, you must use modify_principal in
kadmin to change the maxlife of both the
principal in question and the krbtgt
principal. Then the principal can use the
-l option with kinit
to request a ticket with a longer lifetime.If you run a packet sniffer on your
KDC to add in troubleshooting and then
run kinit from a workstation, you will
notice that your TGT is sent
immediately upon running kinit —
even before you type your password! The explanation is
that the Kerberos server freely
transmits a TGT (Ticket Granting
Ticket) to any unauthorized request; however, every
TGT is encrypted in a key derived from
the user's password. Therefore, when a user types their
password it is not being sent to the KDC,
it is being used to decrypt the TGT that
kinit already obtained. If the decryption
process results in a valid ticket with a valid time stamp,
the user has valid Kerberos
credentials. These credentials include a session key for
establishing secure communications with the
Kerberos server in the future, as
well as the actual ticket-granting ticket, which is actually
encrypted with the Kerberos
server's own key. This second layer of encryption is
unknown to the user, but it is what allows the
Kerberos server to verify
the authenticity of each TGT.If you want to use long ticket lifetimes (a week, for
example) and you are using OpenSSH
to connect to the machine where your ticket is stored, make
sure that Kerberos
is set to no
in your sshd_config or else your tickets
will be deleted when you log out.Remember that host principals can have a longer ticket
lifetime as well. If your user principal has a lifetime of a
week but the host you are connecting to has a lifetime of nine
hours, you will have an expired host principal in your cache
and the ticket cache will not work as expected.When setting up a krb5.dict file to
prevent specific bad passwords from being used (the manual page
for kadmind covers this briefly), remember
that it only applies to principals that have a password policy
assigned to them. The krb5.dict files
format is simple: one string per line. Creating a symbolic
link to /usr/share/dict/words might be
useful.Differences with the MIT portThe major difference between the MIT
and Heimdal installs relates to the kadmin
program which has a different (but equivalent) set of commands
and uses a different protocol. This has a large implications
if your KDC is MIT as you
will not be able to use the Heimdal kadmin
program to administer your KDC remotely
(or vice versa, for that matter).The client applications may also take slightly different
command line options to accomplish the same tasks. Following
the instructions on the MIT
Kerberos web site
()
is recommended. Be careful of path issues: the
MIT port installs into
/usr/local/ by default, and the
normal system applications may be run instead
of MIT if your PATH
environment variable lists the system directories first.With the MIT
security/krb5 port
that is provided by &os;, be sure to read the
/usr/local/share/doc/krb5/README.FreeBSD
file installed by the port if you want to understand why logins
via telnetd and klogind
behave somewhat oddly. Most importantly, correcting the
incorrect permissions on cache file behavior
requires that the login.krb5 binary be used
for authentication so that it can properly change ownership for
the forwarded credentials.Mitigating limitations found in KerberosKerberos5Limitations and ShortcomingsKerberos is an all-or-nothing approachEvery service enabled on the network must be modified to
work with Kerberos (or be otherwise
secured against network attacks) or else the users credentials
could be stolen and re-used. An example of this would be
Kerberos enabling all remote shells
(via rsh and telnet, for
example) but not converting the POP3 mail
server which sends passwords in plain text.Kerberos is intended for single-user workstationsIn a multi-user environment,
Kerberos is less secure.
This is because it stores the tickets in the
/tmp directory, which is readable by all
users. If a user is sharing a computer with several other
people simultaneously (i.e. multi-user), it is possible that
the user's tickets can be stolen (copied) by another
user.This can be overcome with the -c
filename command-line option or (preferably) the
KRB5CCNAME environment variable, but this
is rarely done. In principal, storing the ticket in the users
home directory and using simple file permissions can mitigate
this problem.The KDC is a single point of failureBy design, the KDC must be as secure as
the master password database is contained on it. The
KDC should have absolutely no other
services running on it and should be physically secured. The
danger is high because Kerberos
stores all passwords encrypted with the same key (the
master key), which in turn is stored as a file
on the KDC.As a side note, a compromised master key is not quite as
bad as one might normally fear. The master key is only used
to encrypt the Kerberos database
and as a seed for the random number generator. As long as
access to your KDC is secure, an attacker
cannot do much with the master key.Additionally, if the KDC is unavailable
(perhaps due to a denial of service attack or network problems)
the network services are unusable as authentication can not be
performed, a recipe for a denial-of-service attack. This can
alleviated with multiple KDCs (a single
master and one or more slaves) and with careful implementation
of secondary or fall-back authentication
(PAM is excellent for this).Kerberos ShortcomingsKerberos allows users, hosts
and services to authenticate between themselves. It does not
have a mechanism to authenticate the KDC
to the users, hosts or services. This means that a trojanned
kinit (for example) could record all user
names and passwords. Something like
security/tripwire or
other file system integrity checking tools can alleviate
this.Resources and further informationKerberos5External Resources
The Kerberos FAQDesigning
an Authentication System: a Dialog in Four ScenesRFC 1510,
The Kerberos Network Authentication Service
(V5)MIT
Kerberos home pageHeimdal
Kerberos home page
-
-
-
-
- Joseph J.
- Barbish
- Contributed by
-
-
-
-
- Brad
- Davis
- Converted to SGML and updated by
-
-
-
- Firewalls
-
- firewall
-
- security
- firewalls
-
-
- Introduction
- All software-based firewalls provide some way to filter
- incoming and outgoing traffic that flows through your system.
- The firewall uses one or more sets of rules to
- inspect the network packets as they come in or go out of your
- network connections and either allows the traffic through or
- blocks it. The rules of the firewall can inspect one or more
- characteristics of the packets, including but not limited to
- the protocol type, the source or destination host address and
- the source or destination port.
-
- Firewalls greatly enhance the security of your network,
- your applications and services. They can be used to do one of
- more of the following things:
-
-
-
- To protect and insulate the applications, services and
- machines of your internal network from unwanted traffic
- coming in from the public Internet.
-
-
-
- To limit or disable access from hosts of the internal
- network to services of the public Internet.
-
-
-
- To support network address translation (NAT), which
- allows your internal network to use private IP addresses
- and share a single connection to the public Internet
- (either with a single IP address or by a shared pool of
- automatically assigned public addresses).
-
-
-
-
-
- Firewall Rule Set Types
- Constructing a software application firewall rule set may
- seem to be trivial, but most people get it wrong. The most
- common mistake is to create an exclusive firewall rather
- than an inclusive firewall.
-
- An exclusive firewall allows all services through except
- for those matching a set of rules that block certain
- services.
-
- An inclusive firewall does the reverse. It only allows
- services matching the rules through and blocks everything else.
- This way you can control what services can originate behind the
- firewall destined for the public Internet and also control which
- services originating from the public Internet may access your
- network. Inclusive firewalls are much, much safer than exclusive
- firewalls.
-
- When you use your browser to access a web site there are
- many internal functions that happen before your screen fills
- with the data from the target web site. Your browser does not
- receive one large file containing all the data and display
- format instructions at one time. Each internal function accesses
- the public Internet in multiple send/receive cycles of packets
- of information. When all the packets containing the data finally
- arrive, the data contained in the packets is combined together
- to fill your screen. Each service (DNS, HTTP, etc) has its own
- port number. The port number 80 is for HTTP services. So you
- can code your firewall to only allow web page session start
- requests originating from your LAN to pass through the firewall
- out to the public Internet.
-
- Security can be tightened further by telling the firewall to
- monitor the send/receive cycles of all the packets making up
- that session until the session completes. These are called
- stateful capabilities and provides the maximum level of
- protection.
-
- A firewall rule set that does not implement stateful
- capabilities on all the services being authorized is an insecure
- firewall that is still open to many of the most common methods
- of attack.
-
-
-
- Firewall Software Applications
- &os; has two different firewall software products built
- into the base system. They are IPFILTER (i.e. also known as IPF)
- and IPFIREWALL (i.e. also known as IPFW). IPFIREWALL has the
- built in DUMMYNET traffic shaper facilities for controlling
- bandwidth usage. IPFILTER does not have a built in traffic
- shaper facility for controlling bandwidth usage, but the ALTQ
- port application can be used to accomplish the same function.
- The DUMMYNET feature and ALTQ is generally useful only to large
- ISPs or commercial users. Both IPF and IPFW use rules to control
- the access of packets to and from your system, although they go
- about it different ways and have different rule syntaxes.
-
- The IPFW sample rule set (found in
- /etc/rc.firewall) delivered in the basic
- install is outdated, complicated and does not use stateful
- rules on the interface facing the public Internet. It
- exclusively uses legacy stateless rules which only have the
- ability to open or close the service ports. The IPFW example
- stateful rules sets presented here supercede the
- /etc/rc.firewall file distributed with the
- system.
-
- Stateful rules have technically advanced interrogation
- abilities capable of defending against the flood of different
- methods currently employed by attackers.
-
- Both of these firewall software solutions IPF and IPFW still
- maintain their legacy heritage of their original rule processing
- order and reliance on non-stateful rules. These outdated
- concepts are not covered here, only the new, modern stateful
- rule construct and rule processing order is presented.
-
- You should read about both of them and make your own
- decision on which one best fits your needs.
-
- The author prefers IPFILTER because its stateful rules are
- much less complicated to use in a NAT environment and it has a
- built in ftp proxy that simplifies the rules to allow secure
- outbound FTP usage. If is also more appropriate to the knowledge
- level of the inexperienced firewall user.
-
- Since all firewalls are based on interrogating the values
- of selected packet control fields, the creator of the firewall
- rules must have an understanding of how TCP/IP works, what the
- different values in the packet control fields are and how these
- values are used in a normal session conversation. For a good
- explanation go to:
- .
-
-
-
- The Packet Filter Firewall
-
- As of July 2003 the OpenBSD firewall software application
- known as PF was ported to &os; 5.3.
- PF is a complete, fully featured firewall
- that contains ALTQ
- for bandwidth usage management in a way similar to the dummynet
- provides in IPFW.
- The OpenBSD project does an outstanding job of maintaining the
- PF users' guide that it will not be made part of this handbook
- firewall section as that would just be duplicated effort.
-
- For older 5.X version of &os; you can find
- PF in the &os; ports collection here:
- security/pf.
-
- More info can be found at the PF for &os; web site:
- .
-
- The OpenBSD PF user's guide is here:
- .
-
-
-
- PF in &os; 5.X is at the level of OpenBSD version 3.5. The
- port from the &os; ports collection at the level of OpenBSD
- version 3.4. Keep that in mind when browsing the user's
- guide.
-
-
-
- Enabling PF
- PF is included in the basic &os; install for versions newer than
- 5.3 as a separate run time loadable module. PF will dynamically load
- its kernel loadable module when the rc.conf statement
- pf_enable="YES" is used. The
- loadable module was created with &man.pflog.4; logging
- enabled.
-
-
-
- Kernel options
- It is not a mandatory requirement that you enable PF by
- compiling the following options into the &os; kernel. It is only
- presented here as background information. Compiling PF into the
- kernel causes the loadable module to never be used.
-
- Sample kernel config PF option statements are in the
- /usr/src/sys/conf/NOTES kernel source and are
- reproduced here:
-
- device pf
-device pflog
-device pfsync
-
- device pf tells the compile to include
- Packet Filter as part of its core kernel.
-
- device pflog enables the optional
- &man.pflog.4; pseudo network device which can be used to log traffic
- to a &man.bpf.4; descriptor. The &man.pflogd.8; daemon can be used to
- store the logging information to disk.
-
- device pfsync enables the optional
- &man.pfsync.4; pseudo network device that is used to monitor
- state changes. As this is not part of the loadable
- module one has to build a custom kernel to use it.
-
- These settings will take affect only after you have built and
- installed a kernel with them set.
-
-
-
- Available rc.conf Options
-
- You need the following statements in /etc/rc.conf
- to activate PF at boot time:
-
- pf_enable="YES" # Enable PF (load module if required)
-pf_rules="/etc/pf.conf" # rules definition file for pf
-pf_flags="" # additional flags for pfctl startup
-pflog_enable="YES" # start pflogd(8)
-pflog_logfile="/var/log/pflog" # where pflogd should store the logfile
-pflog_flags="" # additional flags for pflogd startup
-
- If you have a LAN behind this firewall and have to forward
- packets for the computers in the LAN or want to do NAT you have to
- enable the following option as well:
-
- gateway_enable="YES" # Enable as Lan gateway
-
-
-
-
-
- The IPFILTER (IPF) Firewall
- The author of IPFILTER is Darren Reed. IPFILTER is not
- operating system dependent. IPFILTER is a open source
- application and has been ported to &os;, NetBSD, OpenBSD,
- SunOS, HP/UX, and Solaris operating systems. IPFILTER is
- actively being supported and maintained, with updated versions
- being released regularly.
-
- IPFILTER is based on a kernel-side firewall and NAT
- mechanism that can be controlled and monitored by userland
- interface programs. The firewall rules can be set or deleted
- with the &man.ipf.8; utility. The NAT rules can be set or
- deleted with the &man.ipnat.1; utility. The &man.ipfstat.8;
- utility can print run-time statistics for the kernel parts of
- IPFILTER. The &man.ipmon.8; program can log IPFILTER actions
- to the system log files.
-
- IPF was originally written using a rule processing logic
- of the last matching rule wins and used only
- stateless type of rules. Over time IPF has been enhanced to
- include a quick option and a stateful
- keep state option which drastically modernized
- the rules processing logic. IPF's official documentation covers
- the legacy rule coding parameters and the legacy rule file
- processing logic. the modernized functions are only included as
- additional options, completely understating their benefits in
- producing a far superior secure firewall.
-
- The instructions contained in this section are based on
- using rules that contain the quick option and
- the stateful keep state option. This is the
- basic framework for coding an inclusive firewall rule set.
-
-
- An inclusive firewall only allows packets matching the
- rules to pass through. This way you can control what services
- can originate behind the firewall destine for the public
- Internet and also control the services which can originate from
- the public Internet accessing your private network. Everything
- else is blocked and logged by default design. Inclusive
- firewalls are much, much more secure than exclusive firewall
- rule sets and is the only rule set type covered here in.
-
- For detailed explanation of the legacy rules processing
- method see:
-
- and
-
- .
-
- The IPF FAQ is at
- .
-
-
-
- Enabling IPF
- IPF is included in the basic &os; install as a separate
- run time loadable module. IPF will dynamically load its kernel
- loadable module when the rc.conf statement
- ipfilter_enable="YES" is used. The loadable
- module was created with logging enabled and the default
- pass all options. You do not need to compile IPF into
- the &os; kernel just to change the default to block all
- , you can do that by just coding a block all rule at
- the end of your rule set.
-
-
-
- Kernel options
- It is not a mandatory requirement that you enable IPF by
- compiling the following options into the &os; kernel. It is
- only presented here as background information. Compiling IPF
- into the kernel causes the loadable module to never be used.
-
-
- Sample kernel config IPF option statements are in the
- /usr/src/sys/i386/conf/LINT kernel source
- and are reproduced here.
-
- options IPFILTER
-options IPFILTER_LOG
-options IPFILTER_DEFAULT_BLOCK
-
- options IPFILTER tells the compile
- to include IPFILTER as part of its core kernel.
-
- options IPFILTER_LOG enables the
- option to have IPF log traffic by writing to the ipl packet
- logging pseudo—device for every rule that has the log
- keyword.
-
- options IPFILTER_DEFAULT_BLOCK
- changes the default behavior so any packet not matching a
- firewall pass rule gets blocked.
-
- These settings will take affect only after you have built
- and installed a kernel with them set.
-
-
-
- Available rc.conf Options
- You need the following statements in /etc/rc.conf
- to activate IPF at boot time:
-
- ipfilter_enable="YES" # Start ipf firewall
-ipfilter_rules="/etc/ipf.rules" # loads rules definition text file
-ipmon_enable="YES" # Start IP monitor log
-ipmon_flags="-Ds" # D = start as daemon
- # s = log to syslog
- # v = log tcp window, ack, seq
- # n = map IP & port to names
- If you have a LAN behind this firewall that uses the
- reserved private IP address ranges, then you need to add the
- following to enable NAT function.
-
- gateway_enable="YES" # Enable as Lan gateway
-ipnat_enable="YES" # Start ipnat function
-ipnat_rules="/etc/ipnat.rules" # rules definition file for ipnat
-
-
-
-
- IPF
- The ipf command is used to load your rules file. Normally
- you create a file containing your custom rules and use this
- command to replace in mass the currently running firewall
- internal rules.
-
- ipf -Fa -f /etc/ipf.rules
-
- -Fa means flush all internal rules tables.
- -f means this is the file to read for the rules to load.
-
- This gives you the ability to make changes to their custom
- rules file, run the above IPF command thus updating the running
- firewall with a fresh copy of all the rules without having to
- reboot the system. This method is very convenient for testing new
- rules as the procedure can be executed as many times as needed.
-
-
- See the &man.ipf.8; manual page for details on the other flags
- available with this command.
-
- The &man.ipf.8; command expects the rules file to be a
- standard text file. It will not accept a rules file written as a
- script with symbolic substitution.
-
- There is a way to build IPF rules that utilities the power of
- script symbolic substitution. For more information, see .
-
-
-
- IPFSTAT
- The default behavior of &man.ipfstat.8; is to retrieve and
- display the totals of the accumulated statistics gathered as a
- result of applying the user coded rules against packets going
- in and out of the firewall since it was last started, or since
- the last time the accumulators were reset to zero by
- ipf -Z command.
-
- See the &man.ipfstat.8; manual page for details.
-
- The default &man.ipfstat.8; command output will look
- something like this:
-
- input packets: blocked 99286 passed 1255609 nomatch 14686 counted 0
- output packets: blocked 4200 passed 1284345 nomatch 14687 counted 0
- input packets logged: blocked 99286 passed 0
- output packets logged: blocked 0 passed 0
- packets logged: input 0 output 0
- log failures: input 3898 output 0
- fragment state(in): kept 0 lost 0
- fragment state(out): kept 0 lost 0
- packet state(in): kept 169364 lost 0
- packet state(out): kept 431395 lost 0
- ICMP replies: 0 TCP RSTs sent: 0
- Result cache hits(in): 1215208 (out): 1098963
- IN Pullups succeeded: 2 failed: 0
- OUT Pullups succeeded: 0 failed: 0
- Fastroute successes: 0 failures: 0
- TCP cksum fails(in): 0 (out): 0
- Packet log flags set: (0)
-
- When supplied with either -i for inbound or -o for outbound,
- it will retrieve and display the appropriate list of filter
- rules currently installed and in use by the kernel.
-
- ipfstat -in displays the inbound internal
- rules table with rule number.
-
- ipfstat -on displays the outbound
- internal rules table with the rule number.
-
- The output will look something like this:
-
- @1 pass out on xl0 from any to any
-@2 block out on dc0 from any to any
-@3 pass out quick on dc0 proto tcp/udp from any to any keep state
-
- ipfstat -ih displays the inbound internal
- rules table prefixed each rule with count of how many times the
- rule was matched.
-
- ipfstat -oh displays the outbound
- internal rules table prefixed each rule with count of how many
- times the rule was matched.
-
- The output will look something like this:
-
- 2451423 pass out on xl0 from any to any
-354727 block out on dc0 from any to any
-430918 pass out quick on dc0 proto tcp/udp from any to any keep state
-
- One of the most important functions of the ipfstat command
- is the -t flag which activates the display state table in a way
- similar to the way &man.top.1; shows the &os; running process
- table. When your firewall is under attack this function gives
- you the ability to identify, drill down to, and see the
- attacking packets. The optional sub-flags give the ability to
- select destination or source IP, port, protocol, you want to
- monitor in real time. See the &man.ipfstat.8; manual page for
- details.
-
-
-
-
- IPMON
- In order for ipmon to properly work, the
- kernel option IPFILTER_LOG must be turned on. This command has
- 2 different modes it can be used in. Native mode is the default
- mode when you type the command on the command line without the
- -D flag.
-
- Daemon mode is for when you want to have a continuous
- system log file available so you can review logging of past
- events. This is how &os; and IPFILTER are configured to work
- together. &os; has a built in facility to automatically
- rotate syslogs. That is why outputting the log information to
- syslogd is better than the default of outputting to a regular
- file. In rc.conf file you see the
- ipmon_flags statement uses the "-Ds" flags
-
- ipmon_flags="-Ds" # D = start as daemon
- # s = log to syslog
- # v = log tcp window, ack, seq
- # n = map IP & port to names
-
- The benefits of logging are obvious. It provides the
- ability to review, after the fact, information like: what
- packets had been dropped, what addresses they came from and
- where they were going. These all give you a significant edge in
- tracking down attackers.
-
- Even with the logging facility enabled, IPF will not
- generate any rule logging on its own. The firewall
- administrator decides what rules in the rule set he wants to
- log and adds the log keyword to those rules. Normally only
- deny rules are logged.
-
- Its very customary to include a default deny everything
- rule with the log keyword included as your last rule in the
- rule set. This way you get to see all the packets that did not
- match any of the rules in the rule set.
-
-
-
- IPMON Logging
-
- Syslogd uses its own special method for segregation of log
- data. It uses special grouping called facility
- and level. IPMON in -Ds mode uses Local0 as the
- facility name. All IPMON logged data goes to
- Local0. The following levels can be used to further segregate
- the logged data if desired.
-
- LOG_INFO - packets logged using the "log" keyword as the action rather than pass or block.
-LOG_NOTICE - packets logged which are also passed
-LOG_WARNING - packets logged which are also blocked
-LOG_ERR - packets which have been logged and which can be considered short
-
- To setup IPFILTER to log all data to
- /var/log/ipfilter.log, you will need to create the
- file. The following command will do that:
-
- touch /var/log/ipfilter.log
-
- The syslog function is controlled by definition statements
- in the /etc/syslog.conf file. The syslog.conf file offers
- considerable flexibility in how syslog will deal with system
- messages issued by software applications like IPF.
-
- Add the following statement to /etc/syslog.conf
- :
-
- Local0.* /var/log/ipfilter.log
-
- The Local0.* means to write all the logged messages to the
- coded file location.
-
- To activate the changes to /etc/syslog.conf
- you can reboot or bump the syslog task into
- re-reading /etc/syslog.conf by
- kill -HUP <pid>. You get the pid (i.e. process
- number) by listing the tasks with the ps -ax
- command. Find syslog in the display and the pid is the number
- in the left column.
-
- Do not forget to change /etc/newsyslog.conf
- to rotate the new log you just created above.
-
-
-
-
-
- The Format of Logged Messages
-
- Messages generated by ipmon consist of data fields
- separated by white space. Fields common to all messages are:
-
-
-
-
- The date of packet receipt.
-
-
-
- The time of packet receipt. This is in the form
- HH:MM:SS.F, for hours, minutes, seconds, and fractions of a
- second (which can be several digits long).
-
-
-
- The name of the interface the packet was processed on,
- e.g. dc0.
-
-
-
- The group and rule number of the rule, e.g. @0:17.
-
-
-
-
- These can be viewed with ipfstat -in.
-
-
-
- The action: p for passed, b for blocked, S for a short
- packet, n did not match any rules, L for a log rule. The
- order of precedence in showing flags is: S, p, b, n, L. A
- capital P or B means that the packet has been logged due to
- a global logging setting, not a particular rule.
-
-
-
- The addresses. This is actually three fields: the
- source address and port (separated by a comma), the ->
- symbol, and the destination address and port.
- 209.53.17.22,80 -> 198.73.220.17,1722.
-
-
-
- PR followed by the protocol name or number, e.g. PR
- tcp.
-
-
-
- len followed by the header length and total length of
- the packet, e.g. len 20 40.
-
-
-
- If the packet is a TCP packet, there will be an additional
- field starting with a hyphen followed by letters corresponding
- to any flags that were set. See the &man.ipmon.8; manual page
- for a list of letters and their flags.
-
- If the packet is an ICMP packet, there will be two fields
- at the end, the first always being ICMP, and
- the next being the ICMP message and sub-message type,
- separated by a slash, e.g. ICMP 3/3 for a port unreachable
- message.
-
-
-
-
- Building the Rule Script
-
- Some experienced IPF users create a file containing the
- rules and code them in a manner compatible with running them
- as a script with symbolic substitution. The major benefit of
- doing this is you only have to change the value associated
- with the symbolic name and when the script is run all the rules
- containing the symbolic name will have the value substituted in
- the rules. Being a script, you can use symbolic substitution to
- code frequent used values and substitute them in multiple
- rules. You will see this in the following example.
-
- The script syntax used here is compatible with the sh, csh,
- and tcsh shells.
-
- Symbolic substitution fields are prefixed with a dollar
- sign $.
-
- Symbolic fields do not have the $ prefix
-
- The value to populate the Symbolic field must be enclosed
- with "double quotes".
-
- Start your rule file with something like this:
-
-
-############# Start of IPF rules script ########################
-
-oif="dc0" # name of the outbound interface
-odns="192.0.2.11" # ISP's dns server IP address Symbolic>
-myip="192.0.2.7" # My Static IP address from ISP
-ks="keep state"
-fks="flags S keep state"
-
-# You can use this same to build the /etc/ipf.rules file
-#cat >> /etc/ipf.rules << EOF
-
-# exec ipf command and read inline data, stop reading
-# when word EOF is found. There has to be one line
-# after the EOF line to work correctly.
-/sbin/ipf -Fa -f - << EOF
-
-# Allow out access to my ISP's Domain name server.
-pass out quick on $oif proto tcp from any to $odns port = 53 $fks
-pass out quick on $oif proto udp from any to $odns port = 53 $ks
-
-# Allow out non-secure standard www function
-pass out quick on $oif proto tcp from $myip to any port = 80 $fks
-
-# Allow out secure www function https over TLS SSL
-pass out quick on $oif proto tcp from $myip to any port = 443 $fks
-EOF
-################## End of IPF rules script ########################
-
- That is all there is to it. The rules are not important in
- this example, how the Symbolic substitution field are populated
- and used are. If the above example was in /etc/ipf.rules.script
- file, you could reload these rules by entering on the command
- line.
-
- sh /etc/ipf.rules.script
-
-
- There is one problem with using a rules file with embedded
- symbolics. IPF has no problem with it, but the rc startup
- scripts that read rc.conf will have
- problems.
-
- To get around this limitation with a rc scripts, remove
- the following line:
-
- ipfilter_rules=
-
-
- Add a script like the following to your
- /usr/local/etc/rc.d/ startup directory. The script
- should have a obvious name like loadipfrules.sh
- . The .sh extension is mandatory.
-
- #!/bin/sh
-sh /etc/ipf.rules.script
-
- The permission on this script file must be read, write,
- exec for owner root.
-
- chmod 700 /usr/local/etc/rc.d/ipf.loadrules.sh
-
- Now when you system boots your IPF rules will be loaded
- using the script.
-
-
-
-
- IPF Rule Sets
- A rule set is a group of ipf rules coded to pass or block
- packets based on the values contained in the packet. The
- bi-directional exchange of packets between hosts comprises a
- session conversation. The firewall rule set processes the
- packet 2 times, once on its arrival from the public Internet
- host and again as it leaves for its return trip back to the
- public Internet host. Each tcp/ip service (i.e. telnet, www,
- mail, etc.) is predefined by its protocol, source and
- destination IP address, or the source and destination port
- number. This is the basic selection criteria used to create
- rules which will pass or block services.
-
- IPF was originally written using a rules processing logic
- of 'the last matching rule wins' and used only stateless
- rules. Over time IPF has been enhanced to include a 'quick'
- option and a stateful 'keep state' option which drastically
- modernized the rules processing logic.
-
- The instructions contained in this section is based on
- using rules that contain the 'quick' option. and the stateful
- 'keep state' option. This is the basic framework for coding an
- inclusive firewall rule set.
-
- An inclusive firewall only allows services matching the
- rules through. This way you can control what services can
- originate behind the firewall destined for the public Internet
- and also control the services which can originate from the
- public Internet accessing your private network. Everything
- else is blocked and logged by default design. Inclusive
- firewalls are much, much securer than exclusive firewall rule
- sets and is the only rule set type covered herein.
-
-
- Warning, when working with the firewall rules, always,
- always do it from the root console of the system running the
- firewall or you can end up locking your self out.
-
-
-
-
- Rule Syntax
- The rule syntax presented here has been simplified to only
- address the modern stateful rule context and first matching
- rule wins logic. For the complete legacy rule syntax
- description see the &man.ipf.8; manual page.
-
- # is used to mark the start of a comment and may appear at
- the end of a rule line or on its own lines. Blank lines are
- ignored.
-
- Rules contain keywords, These keywords have to be coded in
- a specific order from left to right on the line. Keywords are
- identified in bold type. Some keywords have sub-options which
- may be keywords them selves and also include more sub-options.
- Each of the headings in the below syntax has a bold section
- header which expands on the content.
-
-
-
- ACTION IN-OUT OPTIONS SELECTION STATEFUL
- PROTO SRC_ADDR,DST_ADDR OBJECT PORT_NUM TCP_FLAG STATEFUL
-
-
- ACTION = block | pass
-
- IN-OUT = in | out
-
- OPTIONS = log | quick | on
- interface-name
-
- SELECTION = proto value |
- source/destination IP | port = number | flags flag-value
-
- PROTO = tcp/udp | udp | tcp |
- icmp
-
- SRC_ADD,DST_ADDR = all | from
- object to object
-
- OBJECT = IP address | any
-
- PORT_NUM = port number
-
- TCP_FLAG = S
-
- STATEFUL = keep state
-
-
- ACTION
-
- The action indicates what to do with the packet if it
- matches the rest of the filter rule. Each rule must have a
- action. The following actions are recognized:
-
- block indicates that the packet should be dropped if
- the selection parameters match the packet.
-
- pass indicates that the packet should exit the firewall
- if the selection parameters match the packet.
-
-
-
- IN-OUT
- This is a mandatory requirement that each filter rule
- explicitly state which side of the I/O it is to be used on.
- The next keyword must be either in or out and one or the
- other has to be coded or the rule will not pass syntax
- check.
-
- in means this rule is being applied against an inbound
- packet which has just been received on the interface
- facing the public Internet.
-
- out means this rule is being applied against an
- outbound packet destined for the interface facing the public
- Internet.
-
-
-
- OPTIONS
-
- These options must be used in the order shown here.
-
-
-
- log indicates that the packet header will be written to
- the ipl log (as described in the LOGGING section below) if
- the selection parameters match the packet.
-
- quick indicates that if the selection parameters match
- the packet, this rule will be the last rule checked,
- allowing a "short-circuit" path to avoid processing any
- following rules for this packet. This option is a mandatory
- requirement for the modernized rules processing logic.
-
-
- on indicates the interface name to be incorporated into
- the selection parameters. Interface names are as displayed
- by ifconfig. Using this option, the rule will only match if
- the packet is going through that interface in the specified
- direction (in/out). This option is a mandatory requirement
- for the modernized rules processing logic.
-
- When a packet is logged, the headers of the packet are
- written to the IPL packet logging pseudo-device.
- Immediately following the log keyword, the following
- qualifiers may be used (in this order):
-
- body indicates that the first 128 bytes of the packet
- contents will be logged after the headers.
-
- first If the 'log' keyword is being used in conjunction
- with a "keep state" option, it is recommended that this
- option is also applied so that only the triggering packet
- is logged and not every packet which there after matches
- the 'keep state' information.
-
-
-
- SELECTION
- The keywords described in this section are used to
- describe attributes of the packet to be interrogated when
- determining whether rules match or don't match. There is a
- keyword subject, and it has sub-option keywords, one of
- which has to be selected. The following general-purpose
- attributes are provided for matching, and must be used in
- this order:
-
-
-
- PROTO
- Proto is the subject keyword, it must be coded along
- with one of it.s corresponding keyword sub-option values.
- The value allows a specific protocol to be matched against.
- This option is a mandatory requirement for the modernized
- rules processing logic.
-
- tcp/udp | udp | tcp | icmp or any protocol names found
- in /etc/protocols are recognized and may be used. The
- special protocol keyword tcp/udp may be used to match
- either a TCP or a UDP packet, and has been added as a
- convenience to save duplication of otherwise identical
- rules.
-
-
-
- SRC_ADDR/DST_ADDR
- The 'all' keyword is essentially a synonym for "from
- any to any" with no other match parameters.
-
- from src to dst The from and to keywords are used to
- match against IP addresses. Rules must specify BOTH source
- and destination parameters. .any. is a special keyword that
- matches any IP address. As in 'from any to any' or 'from
- 0.0.0.0/0 to any' or 'from any to 0.0.0.0/0' or 'from
- 0.0.0.0 to any' or 'from any to 0.0.0.0'
-
- IP addresses may be specified as a dotted IP address
- numeric form/mask-length, or as single dotted IP address
- numeric form.
-
- There isn't a way to match ranges of IP addresses which
- do not express themselves easily as mask-length. See this
- link for help on writing mask-length:
-
-
-
-
- PORT
- If a port match is included, for either or both of
- source and destination, then it is only applied to TCP and
- UDP packets. When composing port comparisons, either the
- service name from /etc/services or an integer port number
- may be used. When the port appears as part of the from
- object, it matches the source port number, when it appears
- as part of the to object, it matches the destination port
- number. The use of the port option with the .to. object is
- a mandatory requirement for the modernized rules processing
- logic. As in 'from any to any port = 80'
-
- Port comparisons may be done in a number of forms, with
- a number of comparison operators, or port ranges may be
- specified.
-
- port "=" | "!=" | "<" | ">" | "<=" | ">=" | "eq" | "ne"
- | "lt" | "gt" | "le" | "ge".
-
- To specify port ranges, port "<>" | "><"
-
-
- Following the source and destination matching
- parameters, the following two parameters are mandatory
- requirements for the modernized rules processing logic.
-
-
-
-
-
- TCP_FLAG
- Flags are only effective for TCP filtering. The letters
- represents one of the possible flags that can be
- interrogated in the TCP packet header.
-
- The modernized rules processing logic uses the 'flags
- S' parameter to identify the tcp session start request.
-
-
-
-
- STATEFUL
- 'keep state' indicates that on a pass rule, any packets
- that match the rules selection parameters is to activate
- the stateful filtering facility.
-
-
- This option is a mandatory requirement for the
- modernized rules processing logic.
-
-
-
-
-
- Stateful Filtering
- Stateful filtering treats traffic as a bi-directional
- exchange of packets comprising a session conversation. When
- activated keep-state dynamically generates internal rules for
- each anticipated packet being exchanged during the
- bi-directional session conversation. It has the interrogation
- abilities to determine if the session conversation between the
- originating sender and the destination are following the valid
- procedure of bi-directional packet exchange. Any packets that
- do not properly fit the session conversation template are
- automatically rejected as impostors.
-
- Keep state will also allow ICMP packets related to a TCP
- or UDP session through. So if you get ICMP type 3 code 4 in
- response to some web surfing allowed out by a keep state rule,
- they will be automatically allowed in. Any packet that IPF can
- be certain is part of a active session, even if it is a
- different protocol, will be let in.
-
- What happens is:
-
- Packets destined to go out the interface connected to the
- public Internet are first checked against the dynamic state
- table, if the packet matches the next expected packet
- comprising in a active session conversation, then it exits
- the firewall and the state of the session conversation flow
- is updated in the dynamic state table, the remaining packets
- get checked against the outbound rule set.
-
- Packets coming in to the interface connected to the public
- Internet are first checked against the dynamic state table, if
- the packet matches the next expected packet comprising a
- active session conversation, then it exits the firewall and
- the state of the session conversation flow is updated in the
- dynamic state table, the remaining packets get checked against
- the inbound rule set.
-
- When the conversation completes it is removed from the
- dynamic state table.
-
- Stateful filtering allows you to focus on blocking/passing
- new sessions. If the new session is passed, all its subsequent
- packets will be allowed through automatically and any
- impostors automatically rejected. If a new session is blocked,
- none of its subsequent packets will be allowed through.
- Stateful filtering has technically advanced interrogation
- abilities capable of defending against the flood of different
- attack methods currently employed by attackers.
-
-
-
- Inclusive Rule set Example
- The following rule set is an example of how to code a very
- secure inclusive type of firewall. An inclusive firewall only
- allows services matching pass rules through and blocks all
- other by default. All firewalls have at the minimum two
- interfaces which have to have rules to allow the firewall to
- function.
-
- All Unix flavored systems including &os; are designed
- to use interface l0 and IP address 127.0.0.1 for internal
- communication with in the &os; operating system. The
- firewall rules must contain rules to allow free unmolested
- movement of these special internally used packets.
-
- The interface which faces the public Internet, is the one
- which you code your rules to authorize and control access out
- to the public Internet and access requests arriving from the
- public Internet. This can be your .user ppp. tun0 interface
- or your NIC card that is cabled to your DSL or cable modem.
-
-
- In cases where one or more than one NICs are cabled to
- Private LANs (local area networks) behind the firewall, those
- interfaces must have a rule coded to allow free unmolested
- movement of packets originating from those LAN interfaces.
-
-
- The rules should be first organized into three major
- sections, all the free unmolested interfaces, public interface
- outbound, and the public interface inbound.
-
- The order of the rules in each of the public interface
- sections should be in order of the most used rules being
- placed before less often used rules with the last rule in the
- section being a block log all packets on that interface and
- direction.
-
- The Outbound section in the following rule set only
- contains 'pass' rules which contain selection values that
- uniquely identify the service that is authorized for public
- Internet access. All the rules have the 'quick', 'on',
- 'proto', 'port', and 'keep state' option coded. The 'proto
- tcp' rules have the 'flag' option included to identify the
- session start request as the triggering packet to activate the
- stateful facility.
-
- The Inbound section has all the blocking of undesirable
- packets first for two different reasons. First is these things
- being blocked may be part of an otherwise valid packet which
- may be allowed in by the later authorized service rules.
- Second reason is that by having a rule that explicitly blocks
- selected packets that I receive on an infrequent bases and
- don't want to see in the log, this keeps them from being
- caught by the last rule in the section which blocks and logs
- all packets which have fallen through the rules. The last rule
- in the section which blocks and logs all packets is how you
- create the legal evidence needed to prosecute the people who
- are attacking your system.
-
- Another thing you should take note of, is there is no
- response returned for any of the undesirable stuff, their
- packets just get dropped and vanish. This way the attackers
- has no knowledge if his packets have reached your system.
- The less the attackers can learn about your system the more
- secure it is. The inbound 'nmap OS fingerprint' attempts
- rule I log the first occurrence because this is something a
- attacker would do.
-
- Any time you see log messages on a rule with .log first.
- You should do an ipfstat -hio command to see the number of times
- the rule has been matched so you know if your are being
- flooded, i.e. under attack.
-
- When you log packets with port numbers you do not
- recognize, go to
-
- and do a port number lookup to find what the purpose of that
- port number is.
-
- Check out this link for port numbers used by Trojans
-
-
-
- The following rule set is a complete very secure
- 'inclusive' type of firewall rule set that I have used on my
- system. You can not go wrong using this rule set for your own.
- Just comment out any pass rules for services to don.t want to
- authorize.
-
- If you see messages in your log that you want to stop
- seeing just add a block rule in the inbound section.
-
- You have to change the dc0 interface name in every rule
- to the interface name of the Nic card that connects your
- system to the public Internet. For user PPP it would be
- tun0.
-
- Add the following statements to /etc/ipf.rules:
-
- #################################################################
-# No restrictions on Inside Lan Interface for private network
-# Not needed unless you have Lan
-#################################################################
-
-#pass out quick on xl0 all
-#pass in quick on xl0 all
-
-#################################################################
-# No restrictions on Loopback Interface
-#################################################################
-pass in quick on lo0 all
-pass out quick on lo0 all
-
-#################################################################
-# Interface facing Public Internet (Outbound Section)
-# Interrogate session start requests originating from behind the
-# firewall on the private network
-# or from this gateway server destine for the public Internet.
-#################################################################
-
-# Allow out access to my ISP's Domain name server.
-# xxx must be the IP address of your ISP.s DNS.
-# Dup these lines if your ISP has more than one DNS server
-# Get the IP addresses from /etc/resolv.conf file
-pass out quick on dc0 proto tcp from any to xxx port = 53 flags S keep state
-pass out quick on dc0 proto udp from any to xxx port = 53 keep state
-
-# Allow out access to my ISP's DHCP server for cable or DSL networks.
-# This rule is not needed for .user ppp. type connection to the
-# public Internet, so you can delete this whole group.
-# Use the following rule and check log for IP address.
-# Then put IP address in commented out rule & delete first rule
-pass out log quick on dc0 proto udp from any to any port = 67 keep state
-#pass out quick on dc0 proto udp from any to z.z.z.z port = 67 keep state
-
-
-# Allow out non-secure standard www function
-pass out quick on dc0 proto tcp from any to any port = 80 flags S keep state
-
-# Allow out secure www function https over TLS SSL
-pass out quick on dc0 proto tcp from any to any port = 443 flags S keep state
-
-# Allow out send & get email function
-pass out quick on dc0 proto tcp from any to any port = 110 flags S keep state
-pass out quick on dc0 proto tcp from any to any port = 25 flags S keep state
-
-# Allow out Time
-pass out quick on dc0 proto tcp from any to any port = 37 flags S keep state
-
-# Allow out nntp news
-pass out quick on dc0 proto tcp from any to any port = 119 flags S keep state
-
-# Allow out gateway & LAN users non-secure FTP ( both passive & active modes)
-# This function uses the IPNAT built in FTP proxy function coded in
-# the nat rules file to make this single rule function correctly.
-# If you want to use the pkg_add command to install application packages
-# on your gateway system you need this rule.
-pass out quick on dc0 proto tcp from any to any port = 21 flags S keep state
-
-# Allow out secure FTP, Telnet, and SCP
-# This function is using SSH (secure shell)
-pass out quick on dc0 proto tcp from any to any port = 22 flags S keep state
-
-# Allow out non-secure Telnet
-pass out quick on dc0 proto tcp from any to any port = 23 flags S keep state
-
-# Allow out FBSD CVSUP function
-pass out quick on dc0 proto tcp from any to any port = 5999 flags S keep state
-
-# Allow out ping to public Internet
-pass out quick on dc0 proto icmp from any to any icmp-type 8 keep state
-
-# Allow out whois for LAN PC to public Internet
-pass out quick on dc0 proto tcp from any to any port = 43 flags S keep state
-
-# Block and log only the first occurrence of everything
-# else that.s trying to get out.
-# This rule enforces the block all by default logic.
-block out log first quick on dc0 all
-
-#################################################################
-# Interface facing Public Internet (Inbound Section)
-# Interrogate packets originating from the public Internet
-# destine for this gateway server or the private network.
-#################################################################
-
-# Block all inbound traffic from non-routable or reserved address spaces
-block in quick on dc0 from 192.168.0.0/16 to any #RFC 1918 private IP
-block in quick on dc0 from 172.16.0.0/12 to any #RFC 1918 private IP
-block in quick on dc0 from 10.0.0.0/8 to any #RFC 1918 private IP
-block in quick on dc0 from 127.0.0.0/8 to any #loopback
-block in quick on dc0 from 0.0.0.0/8 to any #loopback
-block in quick on dc0 from 169.254.0.0/16 to any #DHCP auto-config
-block in quick on dc0 from 192.0.2.0/24 to any #reserved for docs
-block in quick on dc0 from 204.152.64.0/23 to any #Sun cluster interconnect
-block in quick on dc0 from 224.0.0.0/3 to any #Class D & E multicast
-
-##### Block a bunch of different nasty things. ############
-# That I don't want to see in the log
-
-# Block frags
-block in quick on dc0 all with frags
-
-# Block short tcp packets
-block in quick on dc0 proto tcp all with short
-
-# block source routed packets
-block in quick on dc0 all with opt lsrr
-block in quick on dc0 all with opt ssrr
-
-# Block nmap OS fingerprint attempts
-# Log first occurrence of these so I can get their IP address
-block in log first quick on dc0 proto tcp from any to any flags FUP
-
-# Block anything with special options
-block in quick on dc0 all with ipopts
-
-# Block public pings
-block in quick on dc0 proto icmp all icmp-type 8
-
-# Block ident
-block in quick on dc0 proto tcp from any to any port = 113
-
-# Block all Netbios service. 137=name, 138=datagram, 139=session
-# Netbios is MS/Windows sharing services.
-# Block MS/Windows hosts2 name server requests 81
-block in log first quick on dc0 proto tcp/udp from any to any port = 137
-block in log first quick on dc0 proto tcp/udp from any to any port = 138
-block in log first quick on dc0 proto tcp/udp from any to any port = 139
-block in log first quick on dc0 proto tcp/udp from any to any port = 81
-
-# Allow traffic in from ISP's DHCP server. This rule must contain
-# the IP address of your ISP.s DHCP server as it.s the only
-# authorized source to send this packet type. Only necessary for
-# cable or DSL configurations. This rule is not needed for
-# .user ppp. type connection to the public Internet.
-# This is the same IP address you captured and
-# used in the outbound section.
-pass in quick on dc0 proto udp from z.z.z.z to any port = 68 keep state
-
-# Allow in standard www function because I have apache server
-pass in quick on dc0 proto tcp from any to any port = 80 flags S keep state
-
-# Allow in non-secure Telnet session from public Internet
-# labeled non-secure because ID/PW passed over public Internet as clear text.
-# Delete this sample group if you do not have telnet server enabled.
-#pass in quick on dc0 proto tcp from any to any port = 23 flags S keep state
-
-# Allow in secure FTP, Telnet, and SCP from public Internet
-# This function is using SSH (secure shell)
-pass in quick on dc0 proto tcp from any to any port = 22 flags S keep state
-
-# Block and log only first occurrence of all remaining traffic
-# coming into the firewall. The logging of only the first
-# occurrence stops a .denial of service. attack targeted
-# at filling up your log file space.
-# This rule enforces the block all by default logic.
-block in log first quick on dc0 all
-################### End of rules file #####################################
-
-
-
-
- NAT
- NAT stands for Network Address Translation. To those
- familiar with Linux, this concept is called IP Masquerading,
- NAT and IP Masquerading are the same thing. One of the many
- things the IPF NAT function enables, is the ability to have a
- private Local Area Network (LAN) behind the firewall sharing a
- single ISP assigned IP address to the public Internet.
-
- You ask why would someone want to do this. ISPs normally
- assign a dynamic IP address to their non-commercial users.
- Dynamic means the IP address can be different each time you
- dial in and logon to your ISP, or for cable and DSL modem
- users when you power off and then power on your modems you can
- get assigned a different IP address. This IP address is how
- you are known to the public Internet.
-
- Now lets say you have 5 PCs at home and each one needs
- Internet access. You would have to pay your ISP for an
- individual Internet account for each PC and have 5 phone
- lines.
-
- With NAT you only need a single account with your ISP,
- then cable your other 4 PC.s to a switch and the switch to
- the NIC in your &os; system which is going to service your
- LAN as a gateway. NAT will automatically translate the private
- LAN IP address for each separate PC on the LAN to the single
- public IP address as it exits the firewall bound for the
- public Internet. It also does the reverse translation for
- returning packets.
-
- NAT is most often accomplished without the approval, or
- knowledge, of your ISP and in most cases is grounds for your
- ISP terminating your account if found out. Commercial users
- pay a lot more for their Internet connection and usually get
- assigned a block of static IP address which never change. The
- ISP also expects and consents to their Commercial customers
- using NAT for their internal private LANs.
-
- There is a special range of IP addresses reserved for
- NATed private LAN IP address. According to RFC 1918, you can
- use the following IP ranges for private nets which will never
- be routed directly to the public Internet.
-
-
-
-
-
-
-
-
- Start IP 10.0.0.0
-
- -
- Ending IP 10.255.255.255
-
-
-
-
- Start IP 172.16.0.0
-
- -
- Ending IP 172.31.255.255
-
-
-
-
- Start IP 192.168.0.0
-
- -
- Ending IP 192.168.255.255
-
-
-
-
-
-
-
-
- IPNAT
- NAT rules are loaded by using the ipnat command. Typically
- the NAT rules are stored in /etc/ipnat.rules
- . See &man.ipnat.1 for details.
-
- When changing the NAT rules after NAT has been started,
- Make your changes to the file containing the nat rules, then
- run ipnat command with the -CF flags to delete the internal
- in use NAT rules and flush the contents of the translation
- table of all active entries.
-
- To reload the NAT rules issue a command like this:
-
- ipnat -CF -f /etc/ipnat.rules
-
- To display some statistics about your NAT, use this
- command:
-
- ipnat -s
-
- To list the NAT table's current mappings, use this
- command:
-
- ipnat -l
-
- To turn verbose mode on, and display information relating
- to rule processing and active rules/table entries:
-
- ipnat -v
-
-
-
- IPNAT Rules
- NAT rules are very flexible and can accomplish many
- different things to fit the needs of commercial and home
- users.
-
- The rule syntax presented here has been simplified to
- what is most commonly used in a non-commercial environment.
- For a complete rule syntax description see the &man.ipnat.5; manual page.
-
- The syntax for a NAT rule looks something like this:
-
-
- map IFLAN_IP_RANGE -> PUBLIC_ADDRESS
-
- The keyword map starts the rule.
-
- Replace IF with the external
- interface.
-
- The LAN_IP_RANGE is what your
- internal clients use for IP Addressing, usually this is
- something like 192.168.1.0/24.
-
-
- The PUBLIC_ADDRESS can either
- be the external IP address or the special keyword `0.32',
- which means to use the IP address assigned to
- IF.
-
-
-
- How NAT works
- A packet arrives at the firewall from the LAN with a
- public destination. It passes through the outbound filter
- rules, NAT gets his turn at the packet and applies its rules
- top down, first matching rule wins. NAT tests each of its
- rules against the packets interface name and source IP
- address. When a packets interface name matches a NAT rule then
- the [source IP address, i.e. private Lan IP address] of the
- packet is checked to see if it falls within the IP address
- range specified to the left of the arrow symbol on the NAT
- rule. On a match the packet has its source IP address
- rewritten with the public IP address obtained by the `0.32'
- keyword. NAT posts a entry in its internal NAT table so when
- the packet returns from the public Internet it can be mapped
- back to its original private IP address and then passed to
- the filter rules for processing.
-
-
-
-
- Enabling IPNAT
- To enable IPNAT add these statements to
- /etc/rc.conf
-
- To enable your machine to route traffic between
- interfaces.
-
- gateway_enable="YES"
-
- To start IPNAT automatically each time:
-
- ipnat_enable="YES"
-
- To specify where to load the IPNAT rules from
-
- ipnat_rules="/etc/ipnat.rules"
-
-
-
- NAT for a very large LAN
- For networks that have large numbers of PC's on the Lan or
- networks with more that a single LAN the process of funneling
- all those private IP address into a single public IP address
- becomes a resource problem that may cause problems with same
- port numbers being used many times across many NATed LAN PC's
- causing collisions. There are 2 ways to relieve this resource
- problem.
-
-
- Assigning Ports to Use
- BLAH
- map dc0 192.168.1.0/24 -> 0.32
-
- In the above rule the packet's source port is unchanged
- as the packet passes through IPNAT. By adding the portmap
- keyword you can tell IPNAT to only use source ports in a
- range. For example the following rule will tell IPNAT to
- modify the source port to be within that range.
-
- map dc0 192.168.1.0/24 -> 0.32 portmap tcp/udp 20000:60000
-
- Additionally we can make things even easier by using
- the `auto' keyword to tell IPNAT to determine by itself
- which ports are available to use:
-
- map dc0 192.168.1.0/24 -> 0.32 portmap tcp/udp auto
-
-
-
- Using a pool of public addresses
- In very large LANs there comes a point where there are
- just too many LAN addresses to fit into a single public
- address. By changing the following rule:
-
- map dc0 192.168.1.0/24 -> 204.134.75.1
-
- Currently this rule maps all connections through
- 204.134.75.1. This can be
- changed to specify a range:
-
- map dc0 192.168.1.0/24 -> 204.134.75.1-10
-
- Or a subnet using CIDR notation such as:
-
- map dc0 192.168.1.0/24 -> 204.134.75.0/24
-
-
-
-
- Port Redirection
- An very common practice is to have a web server, email
- server, database server and DNS server each segregated to a
- different PC on the LAN. In this case the traffic from these
- servers still have to be NATed, but there has to be some way
- to direct the inbound traffic to the correct LAN PC's. IPNAT
- has the redirection facilities of NAT to solve this problem.
- Lets say you have your web server on LAN address
- 10.0.10.25 and your single
- public IP address is 20.20.20.5
- you would code the rule like this:
-
- map dc0 20.20.20.5/32 port 80 -> 10.0.10.25 port 80
-
- or
-
- map dc0 0/32 port 80 -> 10.0.10.25 port 80
-
- or for a LAN DNS Server on LAN address of
- 10.0.10.33 that needs to
- receive public DNS requests
-
- map dc0 20.20.20.5/32 port 53 -> 10.0.10.33 port 53 udp
-
-
-
- FTP and NAT
- FTP is a dinosaur left over from the time before the
- Internet as it is known today, when research universities were
- leased lined together and FTP was used to share files among
- research Scientists. This was a time when data security was
- not even an idea yet. Over the years the FTP protocol became
- buried into the backbone of the emerging Internet and its
- username and password being sent in clear text was never
- changed to address new security concerns. FTP has two flavors,
- it can run in active mode or passive mode. The difference is
- in how the data channel is acquired. Passive mode is more
- secure as the data channel is acquired be the ordinal ftp
- session requester. For a real good explanation of FTP and the
- different modes see
-
-
-
-
- IPNAT Rules
-
- IPNAT has a special built in FTP proxy option which can be
- specified on the NAT map rule. It can monitor all outbound
- packet traffic for FTP active or passive start session
- requests and dynamically create temporary filter rules
- containing only the port number really in use for the data
- channel. This eliminates the security risk FTP normally
- exposes the firewall to from having large ranges of high order
- port numbers open.
-
- This rule will handle all the traffic for the internal
- LAN:
-
- map dc0 10.0.10.0/29 -> 0/32 proxy port 21 ftp/tcp
-
- This rule handles the FTP traffic from the gateway.
-
- map dc0 0.0.0.0/0 -> 0/32 proxy port 21 ftp/tcp
-
- This rule handles all non-FTP traffic from the internal
- LAN.
-
- map dc0 10.0.10.0/29 -> 0/32
-
- The FTP map rule goes before our regular map rule. All
- packets are tested against the first rule from the top.
- Matches on interface name, then private LAN source IP
- address, and then is it a FTP packet. If all that matches
- then the special FTP proxy creates temp filter rules to let
- the FTP session packets pass in and out, in addition to also
- NATing the FTP packets. All LAN packets that are not FTP do
- not match the first rule and fall through to the third rule
- and are tested, matching on interface and source IP, then
- are NATed.
-
-
- IPNAT FTP Filter Rules
- Only one filter rule is needed for FTP if the NAT FTP
- proxy is used.
-
- Without the FTP Proxy you will need the following three
- rules
-
- # Allow out LAN PC client FTP to public Internet
-# Active and passive modes
-pass out quick on rl0 proto tcp from any to any port = 21 flags S keep state
-
-# Allow out passive mode data channel high order port numbers
-pass out quick on rl0 proto tcp from any to any port > 1024 flags S keep state
-
-# Active mode let data channel in from FTP server
-pass in quick on rl0 proto tcp from any to any port = 20 flags S keep state
-
-
- FTP NAT Proxy Bug
- As of &os; 4.9 which includes IPFILTER version 3.4.31
- the FTP proxy works as documented during the FTP session
- until the session is told to close. When the close happens
- packets returning from the remote FTP server are blocked and
- logged coming in on port 21. The NAT FTP/proxy appears to
- remove its temp rules prematurely, before receiving the
- response from the remote FTP server acknowledging the close.
- Posted problem report to ipf mailing list.
-
- Solution is to add filter rule like this one to get rid
- of these unwanted log messages or do nothing and ignore FTP
- inbound error messages in your log. Not like you do FTP
- session to the public Internet all the time, so this is not
- a big deal.
-
- Block in quick on rl0 proto tcp from any to any port = 21
-
-
-
-
-
- IPFW
- The IPFIREWALL (IPFW) is a &os; sponsored firewall
- software application authored and maintained by &os;
- volunteer staff members. It uses the legacy Stateless rules and
- a legacy rule coding technique to achieve what is referred to as
- Simple Stateful logic.
-
- The IPFW stateless rule syntax is empowered with technically
- sophisticated selection capabilities which far surpasses the
- knowledge level of the customary firewall installer. IPFW is
- targeted at the professional user or the advanced technical
- computer hobbyist who have advanced packet selection
- requirements. A high degree of detailed knowledge into how
- different protocols use and create their unique packet header
- information is necessary before the power of the IPFW rules can
- be unleashed. Providing that level of explanation is out of the
- scope of this section of the handbook.
-
- IPFW is composed of 7 components, the primary component is
- the kernel firewall filter rule processor and its integrated
- packet accounting facility, the logging facility, the 'divert'
- rule which triggers the NAT facility, and the advanced special
- purpose facilities, the dummynet traffic shaper facilities, the
- 'fwd rule' forward facility, the bridge facility, and the
- ipstealth facility.
-
-
- Enabling IPFW
- IPFW is included in the basic &os; install as a
- separate run time loadable module. IPFW will dynamically load
- the kernel module when the rc.conf
- statement firewall_enable="YES" is used. You do not need to
- compile IPFW into the &os; kernel unless you want NAT
- function enabled.
-
- After rebooting your system with firewall_enable="YES" in
- rc.conf the following white highlighted
- message is displayed on the screen as part of the boot
- process:
-
- IP packet filtering initialized, divert disabled, rule-based forwarding
-enabled, default to deny, logging disabled
-
- You can disregard this message as it is out dated and no
- longer is the true status of the IPFW loadable module. The
- loadable module really does have logging ability compiled in.
-
-
- To set the verbose logging limit, There is a knob you can
- set in /etc/sysctl.conf by adding this
- statement, logging will be enabled on future reboots.
-
- net.inet.ip.fw.verbose_limit=5
-
-
-
- Kernel Options
- It is not a mandatory requirement that you enable IPFW by
- compiling the following options into the &os; kernel unless
- you need NAT function. It is presented here as background
- information.
-
- options IPFIREWALL
-
- This option enables IPFW as part of the kernel
-
- options IPFIREWALL_VERBOSE
-
- Enables logging of packets that pass through IPFW and
- have the 'log' keyword specified in the rule set.
-
- options IPFIREWALL_VERBOSE_LIMIT=5
-
- This specifies the default number of packets from a
- particular rule is to be logged. Without this option, each
- repeated occurrences of the same packet will be logged, and
- eventually consuming all the free disk space resulting in
- services being denied do to lack of resources. The 5 is the
- number of consecutive times to log evidence of this unique
- occurrence.
-
- options IPFIREWALL_DEFAULT_TO_ACCEPT
-
- This option will allow everything to pass through the
- firewall by default. Which is a good idea when you are first
- setting up your firewall.
-
- options IPV6FIREWALL
-options IPV6FIREWALL_VERBOSE
-options IPV6FIREWALL_VERBOSE_LIMIT
-options IPV6FIREWALL_DEFAULT_TO_ACCEPT
-
- These options are exactly the same as the IPv4 options
- but they are for IPv6. If you don't use IPv6 you might want
- to use IPV6FIREWALL without any rules to block all IPv6
-
- options IPDIVERT
-
- This enables the use of NAT functionality.
-
-
- If you don't include IPFIREWALL_DEFAULT_TO_ACCEPT or set
- your rules to allow incoming packets you will block all
- packets going to and from this machine.
-
-
-
-
- /etc/rc.conf Options
- If you do not have IPFW compiled into your kernel you will
- need to load it with the following statement in your
- /etc/rc.conf:
-
- firewall_enable="YES"
-
- Set the script to run to activate your rules:
-
- firewall_script="/etc/ipfw.rules"
-
- Enable logging:
-
- firewall_logging="YES"
-
-
-
- The IPFW Command
- The ipfw command is the normal vehicle for making manual
- single rule additions or deletions to the firewall active
- internal rules while it is running. The problem with using this
- method is once your system is shutdown or halted all the rules
- you added or changed or deleted are lost. Writing all your
- rules in a file and using that file to load the rules at boot
- time, or to replace in mass the currently running firewall
- rules with changes you made to the files content is the
- recommended method used here.
-
- The IPFW command is still a very useful to display the
- running firewall rules to the console screen. The IPFW
- accounting facility dynamically creates a counter for each
- rule that counts each packet that matches the rule. During the
- process of testing a rule, listing the rule with its counter
- is the only way of determining if the rule is functioning.
-
-
- To list all the rules in sequence:
-
- ipfw list
-
- To list all the rules with a time stamp of when the last
- time the rule was matched:
-
- ipfw -t list
-
- To list the accounting information, packet count for
- matched rules along with the rules themselves. The first
- column is the rule number, followed by the number of outgoing
- matched packets, followed by the number of incoming matched
- packets, and then the rule itself.
-
- ipfw -a list
-
- List the dynamic rules in addition to the static rules:
-
-
- ipfw -d list
-
- Also show the expired dynamic rules:
-
- ipfw -d -e list
-
- Zero the counters:
-
- ipfw zero
-
- Zero the counters for just rule NUM
- :
-
- ipfw zero NUM
-
-
-
- IPFW Rule Sets
- A rule set is a group of ipfw rules coded to allow or deny
- packets based on the values contained in the packet. The
- bi-directional exchange of packets between hosts comprises a
- session conversation. The firewall rule set processes the
- packet 2 times, once on its arrival from the public Internet
- host and again as it leaves for its return trip back to the
- public Internet host. Each tcp/ip service (i.e. telnet, www,
- mail, etc.) is predefined by its protocol, and port number.
- This is the basic selection criteria used to create rules
- which will allow or deny services.
-
- When a packet enters the firewall it is compared against
- the first rule in the rule set and progress one rule at a
- time moving from top to bottom of the set in ascending rule
- number sequence order. When the packet matches a rule
- selection parameters, the rules action field value is executed
- and the search of the rule set terminates for that packet.
- This is referred to as the 'first match wins' search method.
- If the packet does not match any of the rules, it gets caught
- by the mandatory ipfw default rule, number 65535 which denies
- all packets and discards them without any reply back to the
- originating destination.
-
- The instructions contained here are based on using rules
- that contain the stateful 'keep state', 'limit', 'in'/'out',
- and via options. This is the basic framework for coding an
- inclusive type firewall rule set.
-
- An inclusive firewall only allows services matching the
- rules through. This way you can control what services can
- originate behind the firewall destine for the public Internet
- and also control the services which can originate from the
- public Internet accessing your private network. Everything
- else is denied by default design. Inclusive firewalls are
- much, much more secure than exclusive firewall rule sets and
- is the only rule set type covered here in.
-
-
- When working with the firewall rules be
- careful, you can end up locking your self out.
-
-
-
- Rule Syntax
- The rule syntax presented here has been simplified to
- what is necessary to create a standard inclusive type
- firewall rule set. For a complete rule syntax description
- see the &man.ipfw.8; manual page.
-
- Rules contain keywords, These keywords have to be coded
- in a specific order from left to right on the line. Keywords
- are identified in bold type. Some keywords have sub-options
- which may be keywords them selves and also include more
- sub-options.
-
- # is used to mark the start of a comment and may appear
- at the end of a rule line or on its own lines. Blank lines
- are ignored.
-
- CMD RULE# ACTION LOGGING SELECTION STATEFUL
-
-
-
- CMD
- Each rule has to be prefixed with 'add' to add the
- rule to the internal table.
-
-
-
- RULE#
- Each rule has to have a rule number to go with it.
-
-
-
-
- ACTION
- A rule can be associated with one of the following
- actions, which will be executed when the packet matches
- the selection criterion of the rule.
-
- allow | accept | pass | permit
-
-
- These all mean the same thing which is to allow
- packets that match the rule to exit the firewall rule
- processing. The search terminates at this rule.
-
- check-state
-
- Checks the packet against the dynamic rules table. If
- a match is found, execute the action associated with the
- rule which generated this dynamic rule, otherwise move to
- the next rule. The Check-state rule does not have
- selection criterion. If no check-state rule is present in
- the rule set, the dynamic rules table is checked at the
- first keep-state or limit rule.
-
- deny | drop
-
- Both words mean the same thing which is to discard
- packets that match this rule. The search terminates.
-
-
-
-
- Logging
- log or logamount
-
-
- When a packet matches a rule with the log keyword, a
- message will be logged to syslogd with a facility name of
- SECURITY. The logging only occurs if the number of
- packets logged so far for that particular rule does not
- exceed the logamount parameter. If no logamount is
- specified, the limit is taken from the sysctl variable
- net.inet.ip.fw.verbose_limit. In both cases, a value of
- zero removes the logging limit. Once the limit is
- reached, logging can be re-enabled by clearing the
- logging counter or the packet counter for that rule, see
- the ipfw reset log command. Note: logging is done after
- all other packet matching conditions have been
- successfully verified, and before performing the final
- action (accept, deny) on the packet. It is up to you to
- decide which rules you want to enable logging on.
-
-
-
- Selection
- The keywords described in this section are used to
- describe attributes of the packet to be interrogated when
- determining whether rules match or don't match the packet.
- The following general-purpose attributes are provided for
- matching, and must be used in this order:
-
- udp | tcp | icmp
-
- or any protocol names found in /etc/protocols are
- recognized and may be used. The value specified is
- protocol to be matched against. This is a mandatory
- requirement.
-
- from src to dst
-
- The from and to keywords are used to match against IP
- addresses. Rules must specify BOTH source and destination
- parameters. any is a special keyword that matches any IP
- address. me is a special keyword that matches any IP
- address configured on an interface in your &os; system to
- represent the PC the firewall is running on. (i.e. this
- box) As in from me to any or from any to me or from
- 0.0.0.0/0 to any or from any to 0.0.0.0/0 or from 0.0.0.0
- to any or from any to 0.0.0.0 or from me to 0.0.0.0. IP
- addresses are specified as a dotted IP address numeric
- form/mask-length, or as single dotted IP address numeric
- form. This is a mandatory requirement. See this link for
- help on writing mask-lengths.
-
- port number
-
- For protocols which support port numbers (such as TCP
- and UDP). It is mandatory that you code the port number of
- the service you want to match on. Service names (from
- /etc/services) may be used instead of
- numeric port values.
-
- in | out
-
- Matches incoming or outgoing packets, respectively. The in
- and out are keywords and it is mandatory that you code one
- or the other as part of your rule matching criterion.
-
-
- via IF
-
- Matches packets going through the interface specified
- by exact name. The via keyword causes the interface to
- always be checked as part of the match process.
-
- setup
-
- This is a mandatory keyword that identifies the
- session start request for TCP packets.
-
- keep-state
-
- This is a mandatory> keyword. Upon a match, the
- firewall will create a dynamic rule, whose default
- behavior is to match bidirectional traffic between source
- and destination IP/port using the same protocol.
-
- limit {src-addr | src-port | dst-addr |
- dst-port}
-
- The firewall will only allow N connections with the
- same set of parameters as specified in the rule. One or
- more of source and destination addresses and ports can be
- specified. The 'limit' and 'keep-state' can not be used on
- same rule. Limit provides the same stateful function as
- 'keep-state' plus its own functions.
-
-
-
-
-
- Stateful Rule Option
- Stateful filtering treats traffic as a bi-directional
- exchange of packets comprising a session conversation. It
- has the interrogation abilities to determine if the session
- conversation between the originating sender and the
- destination are following the valid procedure of
- bi-directional packet exchange. Any packets that do not
- properly fit the session conversation template are
- automatically rejected as impostors.
-
- 'check-state' is used to identify where in the IPFW
- rules set the packet is to be tested against the dynamic
- rules facility. On a match the packet exits the firewall to
- continue on its way and a new rule is dynamic created for
- the next anticipated packet being exchanged during this
- bi-directional session conversation. On a no match the
- packet advances to the next rule in the rule set for
- testing.
-
- The dynamic rules facility is vulnerable to resource
- depletion from a SYN-flood attack which would open a huge
- number of dynamic rules. To counter this attack, &os;
- version 4.5 added another new option named limit. This
- option is used to limit the number of simultaneous session
- conversations by interrogating the rules source or
- destinations fields as directed by the limit option and
- using the packet's IP address found there, in a search of
- the open dynamic rules counting the number of times this
- rule and IP address combination occurred, if this count is
- greater that the value specified on the limit option, the
- packet is discarded.
-
-
-
- Logging Firewall Messages
- The benefits of logging are obvious, provides the
- ability to review after the fact the rules you activated
- logging on which provides information like, what packets had
- been dropped, what addresses they came from, where they were
- going, giving you a significant edge in tracking down
- attackers.
-
- Even with the logging facility enabled, IPFW will not
- generate any rule logging on it's own. The firewall
- administrator decides what rules in the rule set he wants to
- log and adds the log verb to those rules. Normally only deny
- rules are logged. Like the deny rule for incoming ICMP
- pings. It is very customary to duplicate the ipfw default
- deny everything rule with the log verb included as your
- last rule in the rule set. This way you get to see all the
- packets that did not match any of the rules in the rule set.
-
- Logging is a two edged sword, if you're not careful, you
- can lose yourself in the over abundance of log data and fill
- your disk up with growing log files. DoS attacks that fill
- up disk drives is one of the oldest attacks around. These
- log message are not only written to syslogd, but also are
- displayed on the root console screen and soon become very
- annoying.
-
- The IPFIREWALL_VERBOSE_LIMIT=5 kernel option limits the
- number of consecutive messages sent to the system logger
- syslogd, concerning the packet matching of a given rule.
- When this option is enabled in the kernel, the number of
- consecutive messages concerning a particular rule is capped
- at the number specified. There is nothing to be gained from
- 200 log messages saying the same identical thing. For
- instance, 5 consecutive messages concerning a particular
- rule would be logged to syslogd, the remainder identical
- consecutive messages would be counted and posted to the
- syslogd with a phrase like this:
-
- last message repeated 45 times
-
- All logged packets messages are written by default to
- /var/log/security file, which is
- defined in the /etc/syslog.conf file.
-
-
-
-
- Building a Rule Script
- Most experienced IPFW users create a file containing the
- rules and code them in a manner compatible with running them
- as a script. The major benefit of doing this is the firewall
- rules can be refreshed in mass without the need of
- rebooting the system to activate the new rules. This method
- is very convenient in testing new rules as the procedure can
- be executed as many times as needed. Being a script, you can
- use symbolic substitution to code frequent used values and
- substitution them in multiple rules. You will see this in
- the following example.
-
- The script syntax used here is compatible with the 'sh',
- 'csh', 'tcsh' shells. Symbolic substitution fields are
- prefixed with a dollar sign $. Symbolic fields do not have
- the $ prefix. The value to populate the Symbolic field must
- be enclosed to "double quotes".
-
- Start your rules file like this:
-
- ############### start of example ipfw rules script #############
-#
-ipfw -q -f flush # Delete all rules
-# Set defaults
-oif="tun0" # out interface
-odns="192.0.2.11" # ISP's dns server IP address
-cmd="ipfw -q add " # build rule prefix
-ks="keep-state" # just too lazy to key this each time
-$cmd 00500 check-state
-$cmd 00502 deny all from any to any frag
-$cmd 00501 deny tcp from any to any established
-$cmd 00600 allow tcp from any to any 80 out via $oif setup $ks
-$cmd 00610 allow tcp from any to $odns 53 out via $oif setup $ks
-$cmd 00611 allow udp from any to $odns 53 out via $oif $ks
-################### End of example ipfw rules script ############
-
- That is all there is to it. The rules are not important
- in this example, how the Symbolic substitution field are
- populated and used are.
-
- If the above example was in
- /etc/ipfw.rules file, you could reload
- these rules by entering on the command line.
-
- sh /etc/ipfw.rules
-
-
- The /etc/ipfw.rules file could be
- located any where you want and the file could be named any
- thing you would like.
-
- The same thing could also be accomplished by running
- these commands by hand:
-
- ipfw -q -f flush
-ipfw -q add check-state
-ipfw -q add deny all from any to any frag
-ipfw -q add deny tcp from any to any established
-ipfw -q add allow tcp from any to any 80 out via tun0 setup keep-state
-ipfw -q add allow tcp from any to 192.0.2.11 53 out via tun0 setup keep-state
-ipfw -q add 00611 allow udp from any to 192.0.2.11 53 out via tun0 keep-state
-
-
-
- Stateful Ruleset
- The following non-NATed rule set is a example of how to
- code a very secure 'inclusive' type of firewall. An
- inclusive firewall only allows services matching pass rules
- through and blocks all other by default. All firewalls have
- at the minimum two interfaces which have to have rules to
- allow the firewall to function.
-
- All &unix; flavored operating systems, &os; included, are designed to
- use interface lo and IP address
- 127.0.0.1 for internal
- communication with in &os;. The firewall rules must contain
- rules to allow free unmolested movement of these special
- internally used packets.
-
- The interface which faces the public Internet, is the
- one which you code your rules to authorize and control
- access out to the public Internet and access requests
- arriving from the public Internet. This can be your ppp tun0
- interface or your NIC that is connected to your DSL or cable
- modem.
-
- In cases where one or more than one NIC are connected to
- a private LANs behind the firewall, those interfaces must
- have rules coded to allow free unmolested movement of
- packets originating from those LAN interfaces.
-
- The rules should be first organized into three major
- sections, all the free unmolested interfaces, public
- interface outbound, and the public interface inbound.
-
-
- The order of the rules in each of the public interface
- sections should be in order of the most used rules being
- placed before less often used rules with the last rule in
- the section being a block log all packets on that interface
- and direction.
-
- The Outbound section in the following rule set only
- contains 'allow' rules which contain selection values that
- uniquely identify the service that is authorized for public
- Internet access. All the rules have the, proto, port,
- in/out, via and keep state option coded. The 'proto tcp'
- rules have the 'setup' option included to identify the start
- session request as the trigger packet to be posted to the
- keep state stateful table.
-
- The Inbound section has all the blocking of undesirable
- packets first for 2 different reasons. First is these things
- being blocked may be part of an otherwise valid packet which
- may be allowed in by the later authorized service rules.
- Second reason is that by having a rule that explicitly
- blocks selected packets that I receive on an infrequent
- bases and don't want to see in the log, this keeps them from
- being caught by the last rule in the section which blocks
- and logs all packets which have fallen through the rules.
- The last rule in the section which blocks and logs all
- packets is how you create the legal evidence needed to
- prosecute the people who are attacking your system.
-
- Another thing you should take note of, is there is no
- response returned for any of the undesirable stuff, their
- packets just get dropped and vanish. This way the attackers
- has no knowledge if his packets have reached your system.
- The less the attackers can learn about your system the more
- secure it is. When you log packets with port numbers you do
- not recognize, go to
-
- and do a port number lookup to find what the purpose of that
- port number is. Check out this link for port numbers used by
- Trojans:
-
- .
-
-
- An Example Inclusive Ruleset
- The following non-NATed rule set is a complete inclusive
- type ruleset. You can not go wrong using this rule set for
- you own. Just comment out any pass rules for services you
- do not want. If you see messages in your log that you want to
- stop seeing just add a deny rule in the inbound section. You
- have to change the 'dc0' interface name in every rule to the
- interface name of the NIC that connects your system to the
- public Internet. For user ppp it would be 'tun0'.
-
- You will see a pattern in the usage of these rules.
-
-
-
-
- All statements that are a request to start a session
- to the public Internet use keep-state.
-
-
-
- All the authorized services that originate from the
- public Internet have the limit option to stop flooding.
-
-
-
-
- All rules use in or out to clarify direction.
-
-
-
-
- All rules use via interface name to specify the
- interface the packet is traveling over.
-
-
-
- The following rules go into
- /etc/ipfw.rules.
-
- ################ Start of IPFW rules file ###############################
-# Flush out the list before we begin.
-ipfw -q -f flush
-
-# Set rules command prefix
-cmd="ipfw -q add"
-pif="dc0" # public interface name of Nic card
- # facing the public Internet
-
-#################################################################
-# No restrictions on Inside Lan Interface for private network
-# Not needed unless you have Lan.
-# Change xl0 to your Lan Nic card interface name
-#################################################################
-#$cmd 00005 allow all from any to any via xl0
-
-#################################################################
-# No restrictions on Loopback Interface
-#################################################################
-$cmd 00010 allow all from any to any via lo0
-
-#################################################################
-# Allow the packet through if it has previous been added to the
-# the "dynamic" rules table by a allow keep-state statement.
-#################################################################
-$cmd 00015 check-state
-
-#################################################################
-# Interface facing Public Internet (Outbound Section)
-# Interrogate session start requests originating from behind the
-# firewall on the private network or from this gateway server
-# destine for the public Internet.
-#################################################################
-
-# Allow out access to my ISP's Domain name server.
-# x.x.x.x must be the IP address of your ISP.s DNS
-# Dup these lines if your ISP has more than one DNS server
-# Get the IP addresses from /etc/resolv.conf file
-$cmd 00110 allow tcp from any to x.x.x.x 53 out via $pif setup keep-state
-$cmd 00111 allow udp from any to x.x.x.x 53 out via $pif keep-state
-
-# Allow out access to my ISP's DHCP server for cable/DSL configurations.
-# This rule is not needed for .user ppp. connection to the public Internet.
-# so you can delete this whole group.
-# Use the following rule and check log for IP address.
-# Then put IP address in commented out rule & delete first rule
-$cmd 00120 allow log udp from any to any 67 out via $pif keep-state
-#$cmd 00120 allow udp from any to x.x.x.x 67 out via $pif keep-state
-
-# Allow out non-secure standard www function
-$cmd 00200 allow tcp from any to any 80 out via $pif setup keep-state
-
-# Allow out secure www function https over TLS SSL
-$cmd 00220 allow tcp from any to any 443 out via $pif setup keep-state
-
-# Allow out send & get email function
-$cmd 00230 allow tcp from any to any 25 out via $pif setup keep-state
-$cmd 00231 allow tcp from any to any 110 out via $pif setup keep-state
-
-# Allow out FBSD (make install & CVSUP) functions
-# Basically give user root "GOD" privileges.
-$cmd 00240 allow tcp from me to any out via $pif setup keep-state uid root
-
-# Allow out ping
-$cmd 00250 allow icmp from any to any out via $pif keep-state
-
-# Allow out Time
-$cmd 00260 allow tcp from any to any 37 out via $pif setup keep-state
-
-# Allow out nntp news (i.e. news groups)
-$cmd 00270 allow tcp from any to any 119 out via $pif setup keep-state
-
-# Allow out secure FTP, Telnet, and SCP
-# This function is using SSH (secure shell)
-$cmd 00280 allow tcp from any to any 22 out via $pif setup keep-state
-
-# Allow out whois
-$cmd 00290 allow tcp from any to any 43 out via $pif setup keep-state
-
-# deny and log everything else that.s trying to get out.
-# This rule enforces the block all by default logic.
-$cmd 00299 deny log all from any to any out via $pif
-
-#################################################################
-# Interface facing Public Internet (Inbound Section)
-# Interrogate packets originating from the public Internet
-# destine for this gateway server or the private network.
-#################################################################
-
-# Deny all inbound traffic from non-routable reserved address spaces
-$cmd 00300 deny all from 192.168.0.0/16 to any in via $pif #RFC 1918 private IP
-$cmd 00301 deny all from 172.16.0.0/12 to any in via $pif #RFC 1918 private IP
-$cmd 00302 deny all from 10.0.0.0/8 to any in via $pif #RFC 1918 private IP
-$cmd 00303 deny all from 127.0.0.0/8 to any in via $pif #loopback
-$cmd 00304 deny all from 0.0.0.0/8 to any in via $pif #loopback
-$cmd 00305 deny all from 169.254.0.0/16 to any in via $pif #DHCP auto-config
-$cmd 00306 deny all from 192.0.2.0/24 to any in via $pif #reserved for docs
-$cmd 00307 deny all from 204.152.64.0/23 to any in via $pif #Sun cluster interconnect
-$cmd 00308 deny all from 224.0.0.0/3 to any in via $pif #Class D & E multicast
-
-# Deny public pings
-$cmd 00310 deny icmp from any to any in via $pif
-
-# Deny ident
-$cmd 00315 deny tcp from any to any 113 in via $pif
-
-# Deny all Netbios service. 137=name, 138=datagram, 139=session
-# Netbios is MS/Windows sharing services.
-# Block MS/Windows hosts2 name server requests 81
-$cmd 00320 deny tcp from any to any 137 in via $pif
-$cmd 00321 deny tcp from any to any 138 in via $pif
-$cmd 00322 deny tcp from any to any 139 in via $pif
-$cmd 00323 deny tcp from any to any 81 in via $pif
-
-# Deny any late arriving packets
-$cmd 00330 deny all from any to any frag in via $pif
-
-# Deny ACK packets that did not match the dynamic rule table
-$cmd 00332 deny tcp from any to any established in via $pif
-
-# Allow traffic in from ISP's DHCP server. This rule must contain
-# the IP address of your ISP.s DHCP server as it.s the only
-# authorized source to send this packet type.
-# Only necessary for cable or DSL configurations.
-# This rule is not needed for .user ppp. type connection to
-# the public Internet. This is the same IP address you captured
-# and used in the outbound section.
-#$cmd 00360 allow udp from any to x.x.x.x 67 in via $pif keep-state
-
-# Allow in standard www function because I have apache server
-$cmd 00400 allow tcp from any to me 80 in via $pif setup limit src-addr 2
-
-# Allow in secure FTP, Telnet, and SCP from public Internet
-$cmd 00410 allow tcp from any to me 22 in via $pif setup limit src-addr 2
-
-# Allow in non-secure Telnet session from public Internet
-# labeled non-secure because ID & PW are passed over public
-# Internet as clear text.
-# Delete this sample group if you do not have telnet server enabled.
-$cmd 00420 allow tcp from any to me 23 in via $pif setup limit src-addr 2
-
-# Reject & Log all incoming connections from the outside
-$cmd 00499 deny log all from any to any in via $pif
-
-# Everything else is denied by default
-# deny and log all packets that fell through to see what they are
-$cmd 00999 deny log all from any to any
-################ End of IPFW rules file ###############################
-
-
-
-
- An Example NAT and Stateful Ruleset
- There are some additional configuration statements that
- need to be enabled to activate the NAT function of IPFW. The
- kernel source needs 'option divert' statement added to the
- other IPFIREWALL statements compiled into a custom kernel.
-
-
- In addition to the normal IPFW options in
- /etc/rc.conf, the following are needed.
-
-
- natd_enable="YES" # Enable NATD function
-natd_interface="rl0" # interface name of public Internet NIC
-natd_flags="-dynamic -m" # -m = preserve port numbers if possible
-
- Utilizing stateful rules with divert natd rule (Network
- Address Translation) greatly complicates the rule set coding
- logic. The positioning of the check-state, and 'divert natd'
- rules in the rule set becomes very critical. This is no
- longer a simple fall-through logic flow. A new action type
- is used, called 'skipto'. To use the skipto command it is
- mandatory that you number each rule so you know exactly
- where the skipto rule number is you are really jumping to.
-
-
- The following is an uncommented example of one coding
- method, selected here to explain the sequence of the packet
- flow through the rule sets.
-
- The processing flow starts with the first rule from the
- top of the rule file and progress one rule at a time deeper
- into the file until the end is reach or the packet being
- tested to the selection criteria matches and the packet is
- released out of the firewall. It is important to take notice
- of the location of rule numbers 100 101, 450, 500, and 510.
- These rules control the translation of the outbound and
- inbound packets so their entries in the keep-state dynamic
- table always register the private Lan IP address. Next
- notice that all the allow and deny rules specified the
- direction the packet is going (IE outbound or inbound) and
- the interface. Also notice that all the start outbound
- session requests all skipto rule 500 for the network address
- translation.
-
- Lets say a LAN user uses their web browser to get a web
- page. Web pages use port 80 to communicate over. So the
- packet enters the firewall, It does not match 100 because
- it is headed out not in. It passes rule 101 because this is
- the first packet so it has not been posted to the keep-state
- dynamic table yet. The packet finally comes to rule 125 a
- matches. It is outbound through the NIC facing the public
- Internet. The packet still has it's source IP address as a
- private Lan IP address. On the match to this rule, two
- actions take place. The keep-state option will post this rule
- into the keep-state dynamic rules table and the specified
- action is executed. The action is part of the info posted to
- the dynamic table. In this case it is "skipto rule 500". Rule
- 500 NATs the packet IP address and out it goes. Remember
- this, this is very important. This packet makes it's way to
- the destination and returns and enters the top of the rule
- set. This time it does match rule 100 and has it destination
- IP address mapped back to it's corresponding Lan IP address.
- It then is processed by the check-state rule, it's found in
- the table as an existing session conversation and released
- to the LAN. It goes to the LAN PC that sent it and a new
- packet is sent requesting another segment of the data from
- the remote server. This time it gets checked by the
- check-state rule and it's outbound entry is found, the
- associated action, 'skipto 500', is executed. The packet
- jumps to rule 500 gets NATed and released on it's way out.
-
-
- On the inbound side, everything coming in that is part
- of an existing session conversation is being automatically
- handled by the check-state rule and the properly placed
- divert natd rules. All we have to address is denying all the
- bad packets and only allowing in the authorized services.
- Lets say there is a apache server running on the firewall
- box and we want people on the public Internet to be able to
- access the local web site. The new inbound start request
- packet matches rule 100 and its IP address is mapped to LAN
- IP for the firewall box. The packet is them matched against
- all the nasty things we want to check for and finally
- matches against rule 425. On a match two things occur, the
- limit option is an extension to keep-state. The packet rule
- is posted to the keep-state dynamic table but this time any
- new session requests originating from that source IP address
- is limited to 2. This defends against DoS attacks of service
- running on the specified port number. The action is allow so
- the packet is released to the LAN. On return the check-state
- rule recognizes the packet as belonging to an existing
- session conversation sends it to rule 500 for NATing and
- released to outbound interface.
-
- Example Ruleset #1:
-
- #!/bin/sh
-cmd="ipfw -q add"
-skip="skipto 500"
-pif=rl0
-ks="keep-state"
-good_tcpo="22,25,37,43,53,80,443,110,119"
-
-ipfw -q -f flush
-
-$cmd 002 allow all from any to any via xl0 # exclude Lan traffic
-$cmd 003 allow all from any to any via lo0 # exclude loopback traffic
-
-$cmd 100 divert natd ip from any to any in via $pif
-$cmd 101 check-state
-
-# Authorized outbound packets
-$cmd 120 $skip udp from any to xx.168.240.2 53 out via $pif $ks
-$cmd 121 $skip udp from any to xx.168.240.5 53 out via $pif $ks
-$cmd 125 $skip tcp from any to any $good_tcpo out via $pif setup $ks
-$cmd 130 $skip icmp from any to any out via $pif $ks
-$cmd 135 $skip udp from any to any 123 out via $pif $ks
-
-
-# Deny all inbound traffic from non-routable reserved address spaces
-$cmd 300 deny all from 192.168.0.0/16 to any in via $pif #RFC 1918 private IP
-$cmd 301 deny all from 172.16.0.0/12 to any in via $pif #RFC 1918 private IP
-$cmd 302 deny all from 10.0.0.0/8 to any in via $pif #RFC 1918 private IP
-$cmd 303 deny all from 127.0.0.0/8 to any in via $pif #loopback
-$cmd 304 deny all from 0.0.0.0/8 to any in via $pif #loopback
-$cmd 305 deny all from 169.254.0.0/16 to any in via $pif #DHCP auto-config
-$cmd 306 deny all from 192.0.2.0/24 to any in via $pif #reserved for docs
-$cmd 307 deny all from 204.152.64.0/23 to any in via $pif #Sun cluster
-$cmd 308 deny all from 224.0.0.0/3 to any in via $pif #Class D & E multicast
-
-# Authorized inbound packets
-$cmd 400 allow udp from xx.70.207.54 to any 68 in $ks
-$cmd 420 allow tcp from any to me 80 in via $pif setup limit src-addr 1
-
-
-$cmd 450 deny log ip from any to any
-
-# This is skipto location for outbound stateful rules
-$cmd 500 divert natd ip from any to any out via $pif
-$cmd 510 allow ip from any to any
-
-######################## end of rules ##################
-
- The following is pretty much the same as above, but uses
- a self documenting coding style full of description comments
- to help the inexperienced IPFW rule writer to better
- understand what the rules are doing.
-
- Example Ruleset #2:
-
-
-#!/bin/sh
-################ Start of IPFW rules file ###############################
-# Flush out the list before we begin.
-ipfw -q -f flush
-
-# Set rules command prefix
-cmd="ipfw -q add"
-skip="skipto 800"
-pif="rl0" # public interface name of Nic card
- # facing the public Internet
-
-#################################################################
-# No restrictions on Inside Lan Interface for private network
-# Change xl0 to your Lan Nic card interface name
-#################################################################
-$cmd 005 allow all from any to any via xl0
-
-#################################################################
-# No restrictions on Loopback Interface
-#################################################################
-$cmd 010 allow all from any to any via lo0
-
-#################################################################
-# check if packet is inbound and nat address if it is
-#################################################################
-$cmd 014 divert natd ip from any to any in via $pif
-
-#################################################################
-# Allow the packet through if it has previous been added to the
-# the "dynamic" rules table by a allow keep-state statement.
-#################################################################
-$cmd 015 check-state
-
-#################################################################
-# Interface facing Public Internet (Outbound Section)
-# Interrogate session start requests originating from behind the
-# firewall on the private network or from this gateway server
-# destine for the public Internet.
-#################################################################
-
-# Allow out access to my ISP's Domain name server.
-# x.x.x.x must be the IP address of your ISP's DNS
-# Dup these lines if your ISP has more than one DNS server
-# Get the IP addresses from /etc/resolv.conf file
-$cmd 020 $skip tcp from any to x.x.x.x 53 out via $pif setup keep-state
-
-
-# Allow out access to my ISP's DHCP server for cable/DSL configurations.
-$cmd 030 $skip udp from any to x.x.x.x 67 out via $pif keep-state
-
-# Allow out non-secure standard www function
-$cmd 040 $skip tcp from any to any 80 out via $pif setup keep-state
-
-# Allow out secure www function https over TLS SSL
-$cmd 050 $skip tcp from any to any 443 out via $pif setup keep-state
-
-# Allow out send & get email function
-$cmd 060 $skip tcp from any to any 25 out via $pif setup keep-state
-$cmd 061 $skip tcp from any to any 110 out via $pif setup keep-state
-
-# Allow out FreeBSD (make install & CVSUP) functions
-# Basically give user root "GOD" privileges.
-$cmd 070 $skip tcp from me to any out via $pif setup keep-state uid root
-
-# Allow out ping
-$cmd 080 $skip icmp from any to any out via $pif keep-state
-
-# Allow out Time
-$cmd 090 $skip tcp from any to any 37 out via $pif setup keep-state
-
-# Allow out nntp news (i.e. news groups)
-$cmd 100 $skip tcp from any to any 119 out via $pif setup keep-state
-
-# Allow out secure FTP, Telnet, and SCP
-# This function is using SSH (secure shell)
-$cmd 110 $skip tcp from any to any 22 out via $pif setup keep-state
-
-# Allow out whois
-$cmd 120 $skip tcp from any to any 43 out via $pif setup keep-state
-
-# Allow ntp time server
-$cmd 130 $skip udp from any to any 123 out via $pif keep-state
-
-#################################################################
-# Interface facing Public Internet (Inbound Section)
-# Interrogate packets originating from the public Internet
-# destine for this gateway server or the private network.
-#################################################################
-
-# Deny all inbound traffic from non-routable reserved address spaces
-$cmd 300 deny all from 192.168.0.0/16 to any in via $pif #RFC 1918 private IP
-$cmd 301 deny all from 172.16.0.0/12 to any in via $pif #RFC 1918 private IP
-$cmd 302 deny all from 10.0.0.0/8 to any in via $pif #RFC 1918 private IP
-$cmd 303 deny all from 127.0.0.0/8 to any in via $pif #loopback
-$cmd 304 deny all from 0.0.0.0/8 to any in via $pif #loopback
-$cmd 305 deny all from 169.254.0.0/16 to any in via $pif #DHCP auto-config
-$cmd 306 deny all from 192.0.2.0/24 to any in via $pif #reserved for docs
-$cmd 307 deny all from 204.152.64.0/23 to any in via $pif #Sun cluster
-$cmd 308 deny all from 224.0.0.0/3 to any in via $pif #Class D & E multicast
-
-# Deny ident
-$cmd 315 deny tcp from any to any 113 in via $pif
-
-# Deny all Netbios service. 137=name, 138=datagram, 139=session
-# Netbios is MS/Windows sharing services.
-# Block MS/Windows hosts2 name server requests 81
-$cmd 320 deny tcp from any to any 137 in via $pif
-$cmd 321 deny tcp from any to any 138 in via $pif
-$cmd 322 deny tcp from any to any 139 in via $pif
-$cmd 323 deny tcp from any to any 81 in via $pif
-
-# Deny any late arriving packets
-$cmd 330 deny all from any to any frag in via $pif
-
-# Deny ACK packets that did not match the dynamic rule table
-$cmd 332 deny tcp from any to any established in via $pif
-
-# Allow traffic in from ISP's DHCP server. This rule must contain
-# the IP address of your ISP's DHCP server as it's the only
-# authorized source to send this packet type.
-# Only necessary for cable or DSL configurations.
-# This rule is not needed for 'user ppp' type connection to
-# the public Internet. This is the same IP address you captured
-# and used in the outbound section.
-$cmd 360 allow udp from x.x.x.x to any 68 in via $pif keep-state
-
-# Allow in standard www function because I have apache server
-$cmd 370 allow tcp from any to me 80 in via $pif setup limit src-addr 2
-
-# Allow in secure FTP, Telnet, and SCP from public Internet
-$cmd 380 allow tcp from any to me 22 in via $pif setup limit src-addr 2
-
-# Allow in non-secure Telnet session from public Internet
-# labeled non-secure because ID & PW are passed over public
-# Internet as clear text.
-# Delete this sample group if you do not have telnet server enabled.
-$cmd 390 allow tcp from any to me 23 in via $pif setup limit src-addr 2
-
-# Reject & Log all unauthorized incoming connections from the public Internet
-$cmd 400 deny log all from any to any in via $pif
-
-# Reject & Log all unauthorized out going connections to the public Internet
-$cmd 450 deny log all from any to any out via $pif
-
-# This is skipto location for outbound stateful rules
-$cmd 800 divert natd ip from any to any out via $pif
-$cmd 801 allow ip from any to any
-
-# Everything else is denied by default
-# deny and log all packets that fell through to see what they are
-$cmd 999 deny log all from any to any
-################ End of IPFW rules file ###############################
-
-
-
-
-
-
TomRhodesWritten by: OpenSSLsecurityOpenSSLOne feature that many users overlook is the
OpenSSL toolkit included
in &os;. OpenSSL provides an
encryption transport layer on top of the normal communications
layer; thus allowing it to be intertwined with many network
applications and services.Some uses of OpenSSL may include
encrypted authentication of mail clients, web based transactions
such as credit card payments and more. Many ports such as
www/apache13-ssl, and
mail/sylpheed-claws
will offer compilation support for building with
OpenSSL.In most cases the ports collection will attempt to build
the security/openssl
unless the WITH_OPENSSL_BASE make variable
is explicitly set to yes.The version of OpenSSL included
in &os; supports Secure Sockets Layer v2/v3 (SSLv2/SSLv3),
Transport Layer Security v1 (TLSv1) network security protocols
and can be used as a general cryptographic library for use
with applications.While OpenSSL supports the
IDEA algorithm, it is disabled by default
due to United States patents. To use it, the license should
be reviewed and, if the restrictions are acceptable, the
MAKE_IDEA variable must be set in
make.conf.Perhaps one of the most common uses of
OpenSSL provide certificates for
use with software applications. These certificates ensure
that the credentials of the company or individual is valid
and are not fraudulent. If the certificate in question has
not been verified by one of the several Certificate Authorities,
or CAs, a warning is usually produced. A
Certificate Authority is a company, such as VeriSign, who will
sign certificates in order to validate credentials of individuals
or companies. This process has a cost associated with it and
is definitely not a requirement for using certificates; however,
it can put some of the more paranoid users at ease.Generating CertificatesOpenSSLcertificate generationTo generate a certificate, the following command is
available:&prompt.root; openssl req -new -nodes -out req.pem -keyout cert.pem
Generating a 1024 bit RSA private key
................++++++
.......................................++++++
writing new private key to 'cert.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:PA
Locality Name (eg, city) []:Pittsburgh
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Company
Organizational Unit Name (eg, section) []:Systems Administrator
Common Name (eg, YOUR name) []:localhost.example.org
Email Address []:trhodes@FreeBSD.org
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:SOME PASSWORD
An optional company name []:Another NameNotice the response directly after the
Common Name prompt shows a domain name.
This prompt requires a server name to be entered for
verification purposes; placing anything but a domain name
would yield a useless certificate. Other options for
instance expire time, alternate encryption algorithms, etc.
are available. A complete list may be obtained by viewing
the &man.openssl.1; manual page.A file, cert.pem should now exist in
the directory which the aforementioned command was issued. This
is the certificate which may be sent to any one of the many
CAs for signing.In cases where a signature from a CA is
not required, a self signed certificate can be created. First,
generate the CA key:&prompt.root; openssl gendsa -des3 -out \
myca.key 1024Use this key to create the certificate:&prompt.root; openssl req -new -x509 -days 365 -key \
myca.key -out new.crtTwo new files should appear in the directory: a certificate
authority signature file, myca.key and the
certificate itself, new.crt. These should
be placed in a directory, preferably under
/etc, which is readable
only by root. Permissions of 0700 should be fine for this and
they can be set with the chmod
utility.Using Certificates, an ExampleSo what can these files do? A good use would be to
encrypt connections to the Sendmail
MTA. This would dissolve the use of clear
text authentication for users who send mail via the local
MTA.This is not the best use in the world as some
MUAs will present the user with an
error if they have not installed the certificate locally.
Refer to the documentation included with the software for
more information on certificate installation.The following lines should be placed inside the
local .mc file:dnl SSL Options
define(`confCACERT_PATH',`/etc/certs')dnl
define(`confCACERT',`/etc/certs/new.crt')dnl
define(`confSERVER_CERT',`/etc/certs/new.crt')dnl
define(`confSERVER_KEY',`/etc/certs/myca.key')dnl
define(`confTLS_SRV_OPTIONS', `V')dnlWhere /etc/certs/
is the directory to be used for storing the certificate
and key files locally. The last few requirements are a rebuild
of the local .cf file. This is easily
achieved by typing makeinstall within the
/etc/mail
directory. Follow that up with makerestart which should start the
Sendmail daemon.If all went well there will be no error messages in the
/var/log/maillog file and
Sendmail will show up in the process
list.For a simple test, simply connect to the mail server
using the &man.telnet.1; utility:&prompt.root; telnet example.com 25
Trying 192.0.34.166...
Connected to example.com.
Escape character is '^]'.
220 example.com ESMTP Sendmail 8.12.10/8.12.10; Tue, 31 Aug 2004 03:41:22 -0400 (EDT)
ehlo example.com
250-example.com Hello example.com [192.0.34.166], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH LOGIN PLAIN
250-STARTTLS
250-DELIVERBY
250 HELP
quit
221 2.0.0 example.com closing connection
Connection closed by foreign host.If the STARTTLS line appears in the output
then everything is working correctly.NikClaytonnik@FreeBSD.orgWritten by VPN over IPsecCreating a VPN between two networks, separated by the
Internet, using FreeBSD gateways.Hiten M.Pandyahmp@FreeBSD.orgWritten by Understanding IPsecThis section will guide you through the process of setting
up IPsec, and to use it in an environment which consists of
FreeBSD and µsoft.windows; 2000/XP
machines, to make them communicate securely. In order to set up
IPsec, it is necessary that you are familiar with the concepts
of building a custom kernel (see
).IPsec is a protocol which sits on top
of the Internet Protocol (IP) layer. It allows two or more
hosts to communicate in a secure manner (hence the name). The
FreeBSD IPsec network stack is based on the
KAME implementation,
which has support for both protocol families, IPv4 and
IPv6.FreeBSD 5.X contains a hardware
accelerated IPsec stack, known as Fast
IPsec, that was obtained from OpenBSD. It employs
cryptographic hardware (whenever possible) via the
&man.crypto.4; subsystem to optimize the performance of IPsec.
This subsystem is new, and does not support all the features
that are available in the KAME version of IPsec. However, in
order to enable hardware-accelerated IPsec, the following
kernel option has to be added to your kernel configuration
file:
options FAST_IPSEC # new IPsec (cannot define w/ IPSEC)
Note, that it is not currently possible to use the
Fast IPsec subsystem in lue with the KAME
implementation of IPsec. Consult the &man.fast.ipsec.4;
manual page for more information.IPsec consists of two sub-protocols:Encapsulated Security Payload
(ESP), protects the IP packet data from third
party interference, by encrypting the contents using
symmetric cryptography algorithms (like Blowfish,
3DES).Authentication Header (AH),
protects the IP packet header from third party interference
and spoofing, by computing a cryptographic checksum and
hashing the IP packet header fields with a secure hashing
function. This is then followed by an additional header
that contains the hash, to allow the information in the
packet to be authenticated.ESP and AH can
either be used together or separately, depending on the
environment.IPsec can either be used to directly encrypt the traffic
between two hosts (known as Transport
Mode); or to build virtual tunnels
between two subnets, which could be used for secure
communication between two corporate networks (known as
Tunnel Mode). The latter is more commonly
known as a Virtual Private Network (VPN).
The &man.ipsec.4; manual page should be consulted for detailed
information on the IPsec subsystem in FreeBSD.To add IPsec support to your kernel, add the following
options to your kernel configuration file:
options IPSEC #IP security
options IPSEC_ESP #IP security (crypto; define w/ IPSEC)
If IPsec debugging support is desired, the following
kernel option should also be added:
options IPSEC_DEBUG #debug for IP security
The ProblemThere is no standard for what constitutes a VPN. VPNs can
be implemented using a number of different technologies, each of
which have their own strengths and weaknesses. This section
presents a scenario, and the strategies used for implementing a
VPN for this scenario.The Scenario: Two networks, connected to the Internet, to
behave as oneThe premise is as follows:You have at least two sitesBoth sites are using IP internallyBoth sites are connected to the Internet, through a
gateway that is running FreeBSD.The gateway on each network has at least one public IP
address.The internal addresses of the two networks can be
public or private IP addresses, it doesn't matter. You can
be running NAT on the gateway machine if necessary.The internal IP addresses of the two networks
do not collide. While I expect it is
theoretically possible to use a combination of VPN
technology and NAT to get this to work, I expect it to be a
configuration nightmare.If you find that you are trying to connect two networks,
both of which, internally, use the same private IP address range
(e.g. both of them use 192.168.1.x), then one of the networks will
have to be renumbered.The network topology might look something like this:Network #1 [ Internal Hosts ] Private Net, 192.168.1.2-254
[ Win9x/NT/2K ]
[ UNIX ]
|
|
.---[fxp1]---. Private IP, 192.168.1.1
| FreeBSD |
`---[fxp0]---' Public IP, A.B.C.D
|
|
-=-=- Internet -=-=-
|
|
.---[fxp0]---. Public IP, W.X.Y.Z
| FreeBSD |
`---[fxp1]---' Private IP, 192.168.2.1
|
|
Network #2 [ Internal Hosts ]
[ Win9x/NT/2K ] Private Net, 192.168.2.2-254
[ UNIX ]Notice the two public IP addresses. I'll use the letters to
refer to them in the rest of this article. Anywhere you see those
letters in this article, replace them with your own public IP
addresses. Note also that internally, the two gateway
machines have .1 IP addresses, and that the two networks have
different private IP addresses (192.168.1.x and 192.168.2.x respectively). All the
machines on the private networks have been configured to use the
.1 machine as their default
gateway.The intention is that, from a network point of view, each
network should view the machines on the other network as though
they were directly attached the same router -- albeit a slightly
slow router with an occasional tendency to drop packets.This means that (for example), machine 192.168.1.20 should be able to runping 192.168.2.34and have it work, transparently. &windows; machines should
be able to see the machines on the other network, browse file
shares, and so on, in exactly the same way that they can browse
machines on the local network.And the whole thing has to be secure. This means that
traffic between the two networks has to be encrypted.Creating a VPN between these two networks is a multi-step
process. The stages are as follows:Create a virtual network link between the two
networks, across the Internet. Test it, using tools like
&man.ping.8;, to make sure it works.Apply security policies to ensure that traffic between
the two networks is transparently encrypted and decrypted as
necessary. Test this, using tools like &man.tcpdump.1;, to
ensure that traffic is encrypted.Configure additional software on the FreeBSD gateways,
to allow &windows; machines to see one another across the
VPN.Step 1: Creating and testing a virtual
network linkSuppose that you were logged in to the gateway machine on
network #1 (with public IP address A.B.C.D, private IP address 192.168.1.1), and you ran ping
192.168.2.1, which is the private address of the machine
with IP address W.X.Y.Z. What
needs to happen in order for this to work?The gateway machine needs to know how to reach 192.168.2.1. In other words, it needs
to have a route to 192.168.2.1.Private IP addresses, such as those in the 192.168.x range are not supposed to
appear on the Internet at large. Instead, each packet you
send to 192.168.2.1 will need
to be wrapped up inside another packet. This packet will need
to appear to be from A.B.C.D,
and it will have to be sent to W.X.Y.Z. This process is called
encapsulation.Once this packet arrives at W.X.Y.Z it will need to
unencapsulated, and delivered to 192.168.2.1.You can think of this as requiring a tunnel
between the two networks. The two tunnel mouths are the IP
addresses A.B.C.D and W.X.Y.Z, and the tunnel must be told the
addresses of the private IP addresses that will be allowed to pass
through it. The tunnel is used to transfer traffic with private
IP addresses across the public Internet.This tunnel is created by using the generic interface, or
gif devices on FreeBSD. As you can
imagine, the gif interface on each
gateway host must be configured with four IP addresses; two for
the public IP addresses, and two for the private IP
addresses.Support for the gif device must be compiled in to the
&os; kernel on both machines. You can do this by adding the
line:pseudo-device gifto the kernel configuration files on both machines, and
then compile, install, and reboot as normal.Configuring the tunnel is a two step process. First the
tunnel must be told what the outside (or public) IP addresses
are, using &man.gifconfig.8;. Then the private IP addresses must be
configured using &man.ifconfig.8;.In &os; 5.X, the functionality provided by the
&man.gifconfig.8; utility has been merged into
&man.ifconfig.8;.On the gateway machine on network #1 you would run the
following two commands to configure the tunnel.gifconfig gif0 A.B.C.D W.X.Y.Z
ifconfig gif0 inet 192.168.1.1 192.168.2.1 netmask 0xffffffff
On the other gateway machine you run the same commands,
but with the order of the IP addresses reversed.gifconfig gif0 W.X.Y.Z A.B.C.D
ifconfig gif0 inet 192.168.2.1 192.168.1.1 netmask 0xffffffff
You can then run:gifconfig gif0to see the configuration. For example, on the network #1
gateway, you would see this:&prompt.root; gifconfig gif0
gif0: flags=8011<UP,POINTTOPOINT,MULTICAST> mtu 1280
inet 192.168.1.1 --> 192.168.2.1 netmask 0xffffffff
physical address inet A.B.C.D --> W.X.Y.Z
As you can see, a tunnel has been created between the
physical addresses A.B.C.D and
W.X.Y.Z, and the traffic allowed
through the tunnel is that between 192.168.1.1 and 192.168.2.1.This will also have added an entry to the routing table
on both machines, which you can examine with the command netstat -rn.
This output is from the gateway host on network #1.&prompt.root; netstat -rn
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
...
192.168.2.1 192.168.1.1 UH 0 0 gif0
...
As the Flags value indicates, this is a
host route, which means that each gateway knows how to reach the
other gateway, but they do not know how to reach the rest of
their respective networks. That problem will be fixed
shortly.It is likely that you are running a firewall on both
machines. This will need to be circumvented for your VPN
traffic. You might want to allow all traffic between both
networks, or you might want to include firewall rules that
protect both ends of the VPN from one another.It greatly simplifies testing if you configure the
firewall to allow all traffic through the VPN. You can always
tighten things up later. If you are using &man.ipfw.8; on the
gateway machines then a command likeipfw add 1 allow ip from any to any via gif0will allow all traffic between the two end points of the
VPN, without affecting your other firewall rules. Obviously
you will need to run this command on both gateway hosts.This is sufficient to allow each gateway machine to ping
the other. On 192.168.1.1, you
should be able to runping 192.168.2.1and get a response, and you should be able to do the same
thing on the other gateway machine.However, you will not be able to reach internal machines
on either network yet. This is because of the routing --
although the gateway machines know how to reach one another,
they do not know how to reach the network behind each one.To solve this problem you must add a static route on each
gateway machine. The command to do this on the first gateway
would be:route add 192.168.2.0 192.168.2.1 netmask 0xffffff00
This says In order to reach the hosts on the
network 192.168.2.0, send the
packets to the host 192.168.2.1. You will need to
run a similar command on the other gateway, but with the
192.168.1.x addresses
instead.IP traffic from hosts on one network will now be able to
reach hosts on the other network.That has now created two thirds of a VPN between the two
networks, in as much as it is virtual and it is a
network. It is not private yet. You can test
this using &man.ping.8; and &man.tcpdump.1;. Log in to the
gateway host and runtcpdump dst host 192.168.2.1In another log in session on the same host runping 192.168.2.1You will see output that looks something like this:
16:10:24.018080 192.168.1.1 > 192.168.2.1: icmp: echo request
16:10:24.018109 192.168.1.1 > 192.168.2.1: icmp: echo reply
16:10:25.018814 192.168.1.1 > 192.168.2.1: icmp: echo request
16:10:25.018847 192.168.1.1 > 192.168.2.1: icmp: echo reply
16:10:26.028896 192.168.1.1 > 192.168.2.1: icmp: echo request
16:10:26.029112 192.168.1.1 > 192.168.2.1: icmp: echo reply
As you can see, the ICMP messages are going back and forth
unencrypted. If you had used the parameter to
&man.tcpdump.1; to grab more bytes of data from the packets you
would see more information.Obviously this is unacceptable. The next section will
discuss securing the link between the two networks so that it
all traffic is automatically encrypted.Summary:Configure both kernels with pseudo-device
gif.Edit /etc/rc.conf on gateway host
#1 and add the following lines (replacing IP addresses as
necessary).gifconfig_gif0="A.B.C.D W.X.Y.Z"
ifconfig_gif0="inet 192.168.1.1 192.168.2.1 netmask 0xffffffff"
static_routes="vpn"
route_vpn="192.168.2.0 192.168.2.1 netmask 0xffffff00"
Edit your firewall script
(/etc/rc.firewall, or similar) on both
hosts, and addipfw add 1 allow ip from any to any via gif0Make similar changes to
/etc/rc.conf on gateway host #2,
reversing the order of IP addresses.Step 2: Securing the linkTo secure the link we will be using IPsec. IPsec provides
a mechanism for two hosts to agree on an encryption key, and to
then use this key in order to encrypt data between the two
hosts.The are two areas of configuration to be considered here.There must be a mechanism for two hosts to agree on the
encryption mechanism to use. Once two hosts have agreed on
this mechanism there is said to be a security association
between them.There must be a mechanism for specifying which traffic
should be encrypted. Obviously, you don't want to encrypt
all your outgoing traffic -- you only want to encrypt the
traffic that is part of the VPN. The rules that you put in
place to determine what traffic will be encrypted are called
security policies.Security associations and security policies are both
maintained by the kernel, and can be modified by userland
programs. However, before you can do this you must configure the
kernel to support IPsec and the Encapsulated Security Payload
(ESP) protocol. This is done by configuring a kernel with:options IPSEC
options IPSEC_ESP
and recompiling, reinstalling, and rebooting. As before
you will need to do this to the kernels on both of the gateway
hosts.You have two choices when it comes to setting up security
associations. You can configure them by hand between two hosts,
which entails choosing the encryption algorithm, encryption keys,
and so forth, or you can use daemons that implement the Internet
Key Exchange protocol (IKE) to do this for you.I recommend the latter. Apart from anything else, it is
easier to set up.Editing and displaying security policies is carried out
using &man.setkey.8;. By analogy, setkey is
to the kernel's security policy tables as &man.route.8; is to
the kernel's routing tables. setkey can
also display the current security associations, and to continue
the analogy further, is akin to netstat -r
in that respect.There are a number of choices for daemons to manage
security associations with FreeBSD. This article will describe
how to use one of these, racoon. racoon is in the FreeBSD ports
collection, in the security/ category, and is installed in the
usual way.racoon must be run on both gateway hosts. On each host it
is configured with the IP address of the other end of the VPN,
and a secret key (which you choose, and must be the same on both
gateways).The two daemons then contact one another, confirm that they
are who they say they are (by using the secret key that you
configured). The daemons then generate a new secret key, and use
this to encrypt the traffic over the VPN. They periodically
change this secret, so that even if an attacker were to crack one
of the keys (which is as theoretically close to unfeasible as it
gets) it won't do them much good -- by the time they've cracked
the key the two daemons have chosen another one.racoon's configuration is stored in
${PREFIX}/etc/racoon. You should find a
configuration file there, which should not need to be changed
too much. The other component of racoon's configuration,
which you will need to change, is the pre-shared
key.The default racoon configuration expects to find this in
the file ${PREFIX}/etc/racoon/psk.txt. It is important to note
that the pre-shared key is not the key that will be used to
encrypt your traffic across the VPN link, it is simply a token
that allows the key management daemons to trust one another.psk.txt contains a line for each
remote site you are dealing with. In this example, where there
are two sites, each psk.txt file will contain one line (because
each end of the VPN is only dealing with one other end).On gateway host #1 this line should look like this:W.X.Y.Z secretThat is, the public IP address of the remote end,
whitespace, and a text string that provides the secret.
Obviously, you shouldn't use secret as your key -- the normal
rules for choosing a password apply.On gateway host #2 the line would look like thisA.B.C.D secretThat is, the public IP address of the remote end, and the
same secret key. psk.txt must be mode
0600 (i.e., only read/write to
root) before racoon will run.You must run racoon on both gateway machines. You will
also need to add some firewall rules to allow the IKE traffic,
which is carried over UDP to the ISAKMP (Internet Security Association
Key Management Protocol) port. Again, this should be fairly early in
your firewall ruleset.ipfw add 1 allow udp from A.B.C.D to W.X.Y.Z isakmp
ipfw add 1 allow udp from W.X.Y.Z to A.B.C.D isakmp
Once racoon is running you can try pinging one gateway host
from the other. The connection is still not encrypted, but
racoon will then set up the security associations between the two
hosts -- this might take a moment, and you may see this as a
short delay before the ping commands start responding.Once the security association has been set up you can
view it using &man.setkey.8;. Runsetkey -Don either host to view the security association information.That's one half of the problem. They other half is setting
your security policies.To create a sensible security policy, let's review what's
been set up so far. This discussions hold for both ends of the
link.Each IP packet that you send out has a header that contains
data about the packet. The header includes the IP addresses of
both the source and destination. As we already know, private IP
addresses, such as the 192.168.x.y
range are not supposed to appear on the public Internet.
Instead, they must first be encapsulated inside another packet.
This packet must have the public source and destination IP
addresses substituted for the private addresses.So if your outgoing packet started looking like this:
.----------------------.
| Src: 192.168.1.1 |
| Dst: 192.168.2.1 |
| <other header info> |
+----------------------+
| <packet data> |
`----------------------'Then it will be encapsulated inside another packet, looking
something like this:
.--------------------------.
| Src: A.B.C.D |
| Dst: W.X.Y.Z |
| <other header info> |
+--------------------------+
| .----------------------. |
| | Src: 192.168.1.1 | |
| | Dst: 192.168.2.1 | |
| | <other header info> | |
| +----------------------+ |
| | <packet data> | |
| `----------------------' |
`--------------------------'This encapsulation is carried out by the
gif device. As
you can see, the packet now has real IP addresses on the outside,
and our original packet has been wrapped up as data inside the
packet that will be put out on the Internet.Obviously, we want all traffic between the VPNs to be
encrypted. You might try putting this in to words, as:If a packet leaves from A.B.C.D, and it is destined for W.X.Y.Z, then encrypt it, using the
necessary security associations.If a packet arrives from W.X.Y.Z, and it is destined for A.B.C.D, then decrypt it, using the
necessary security associations.That's close, but not quite right. If you did this, all
traffic to and from W.X.Y.Z, even
traffic that was not part of the VPN, would be encrypted. That's
not quite what you want. The correct policy is as followsIf a packet leaves from A.B.C.D, and that packet is encapsulating
another packet, and it is destined for W.X.Y.Z, then encrypt it, using the
necessary security associations.If a packet arrives from W.X.Y.Z, and that packet is encapsulating
another packet, and it is destined for A.B.C.D, then decrypt it, using the
necessary security associations.A subtle change, but a necessary one.Security policies are also set using &man.setkey.8;.
&man.setkey.8; features a configuration language for defining the
policy. You can either enter configuration instructions via
stdin, or you can use the option to specify a
filename that contains configuration instructions.The configuration on gateway host #1 (which has the public
IP address A.B.C.D) to force all
outbound traffic to W.X.Y.Z to be
encrypted is:
spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P out ipsec esp/tunnel/A.B.C.D-W.X.Y.Z/require;
Put these commands in a file (e.g.
/etc/ipsec.conf) and then run&prompt.root; setkey -f /etc/ipsec.conf tells &man.setkey.8; that we want
to add a rule to the secure policy database. The rest of this
line specifies which packets will match this policy. A.B.C.D/32 and W.X.Y.Z/32 are the IP addresses and
netmasks that identify the network or hosts that this policy will
apply to. In this case, we want it to apply to traffic between
these two hosts. tells the kernel that
this policy should only apply to packets that encapsulate other
packets. says that this policy applies
to outgoing packets, and says that the
packet will be secured.The second line specifies how this packet will be
encrypted. is the protocol that will be
used, while indicates that the packet
will be further encapsulated in an IPsec packet. The repeated
use of A.B.C.D and W.X.Y.Z is used to select the security
association to use, and the final
mandates that packets must be encrypted if they match this
rule.This rule only matches outgoing packets. You will need a
similar rule to match incoming packets.spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P in ipsec esp/tunnel/W.X.Y.Z-A.B.C.D/require;Note the instead of
in this case, and the necessary reversal of
the IP addresses.The other gateway host (which has the public IP address
W.X.Y.Z) will need similar rules.spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P out ipsec esp/tunnel/W.X.Y.Z-A.B.C.D/require;
spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P in ipsec esp/tunnel/A.B.C.D-W.X.Y.Z/require;Finally, you need to add firewall rules to allow ESP and
IPENCAP packets back and forth. These rules will need to be
added to both hosts.ipfw add 1 allow esp from A.B.C.D to W.X.Y.Z
ipfw add 1 allow esp from W.X.Y.Z to A.B.C.D
ipfw add 1 allow ipencap from A.B.C.D to W.X.Y.Z
ipfw add 1 allow ipencap from W.X.Y.Z to A.B.C.D
Because the rules are symmetric you can use the same rules
on each gateway host.Outgoing packets will now look something like this:
.------------------------------. --------------------------.
| Src: A.B.C.D | |
| Dst: W.X.Y.Z | |
| <other header info> | | Encrypted
+------------------------------+ | packet.
| .--------------------------. | -------------. | contents
| | Src: A.B.C.D | | | | are
| | Dst: W.X.Y.Z | | | | completely
| | <other header info> | | | |- secure
| +--------------------------+ | | Encap'd | from third
| | .----------------------. | | -. | packet | party
| | | Src: 192.168.1.1 | | | | Original |- with real | snooping
| | | Dst: 192.168.2.1 | | | | packet, | IP addr |
| | | <other header info> | | | |- private | |
| | +----------------------+ | | | IP addr | |
| | | <packet data> | | | | | |
| | `----------------------' | | -' | |
| `--------------------------' | -------------' |
`------------------------------' --------------------------'
When they are received by the far end of the VPN they will
first be decrypted (using the security associations that have
been negotiated by racoon). Then they will enter the
gif interface, which will unwrap
the second layer, until you are left with the innermost
packet, which can then travel in to the inner network.You can check the security using the same &man.ping.8; test from
earlier. First, log in to the
A.B.C.D gateway machine, and
run:tcpdump dst host 192.168.2.1In another log in session on the same host runping 192.168.2.1This time you should see output like the following:XXX tcpdump outputNow, as you can see, &man.tcpdump.1; shows the ESP packets. If
you try to examine them with the option you will see
(apparently) gibberish, because of the encryption.Congratulations. You have just set up a VPN between two
remote sites.SummaryConfigure both kernels with:options IPSEC
options IPSEC_ESP
Install security/racoon. Edit
${PREFIX}/etc/racoon/psk.txt on both
gateway hosts, adding an entry for the remote host's IP
address and a secret key that they both know. Make sure
this file is mode 0600.Add the following lines to
/etc/rc.conf on each host:ipsec_enable="YES"
ipsec_file="/etc/ipsec.conf"
Create an /etc/ipsec.conf on each
host that contains the necessary spdadd lines. On gateway
host #1 this would be:
spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P out ipsec
esp/tunnel/A.B.C.D-W.X.Y.Z/require;
spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P in ipsec
esp/tunnel/W.X.Y.Z-A.B.C.D/require;
On gateway host #2 this would be:
spdadd W.X.Y.Z/32 A.B.C.D/32 ipencap -P out ipsec
esp/tunnel/W.X.Y.Z-A.B.C.D/require;
spdadd A.B.C.D/32 W.X.Y.Z/32 ipencap -P in ipsec
esp/tunnel/A.B.C.D-W.X.Y.Z/require;
Add firewall rules to allow IKE, ESP, and IPENCAP
traffic to both hosts:
ipfw add 1 allow udp from A.B.C.D to W.X.Y.Z isakmp
ipfw add 1 allow udp from W.X.Y.Z to A.B.C.D isakmp
ipfw add 1 allow esp from A.B.C.D to W.X.Y.Z
ipfw add 1 allow esp from W.X.Y.Z to A.B.C.D
ipfw add 1 allow ipencap from A.B.C.D to W.X.Y.Z
ipfw add 1 allow ipencap from W.X.Y.Z to A.B.C.D
The previous two steps should suffice to get the VPN up and
running. Machines on each network will be able to refer to one
another using IP addresses, and all traffic across the link will
be automatically and securely encrypted.ChernLeeContributed by OpenSSHOpenSSHsecurityOpenSSHOpenSSH is a set of network connectivity tools used to
access remote machines securely. It can be used as a direct
replacement for rlogin,
rsh, rcp, and
telnet. Additionally, any other TCP/IP
connections can be tunneled/forwarded securely through SSH.
OpenSSH encrypts all traffic to effectively eliminate eavesdropping,
connection hijacking, and other network-level attacks.OpenSSH is maintained by the OpenBSD project, and is based
upon SSH v1.2.12 with all the recent bug fixes and updates. It
is compatible with both SSH protocols 1 and 2. OpenSSH has been
in the base system since FreeBSD 4.0.Advantages of Using OpenSSHNormally, when using &man.telnet.1; or &man.rlogin.1;,
data is sent over the network in an clear, un-encrypted form.
Network sniffers anywhere in between the client and server can
steal your user/password information or data transferred in
your session. OpenSSH offers a variety of authentication and
encryption methods to prevent this from happening.Enabling sshdOpenSSHenablingBe sure to make the following addition to your
rc.conf file:sshd_enable="YES"This will load &man.sshd.8;, the daemon program for OpenSSH,
the next time your system initializes. Alternatively, you can
simply run directly the sshd daemon by typing sshd on the command line.SSH ClientOpenSSHclientThe &man.ssh.1; utility works similarly to
&man.rlogin.1;.&prompt.root; ssh user@example.com
Host key not found from the list of known hosts.
Are you sure you want to continue connecting (yes/no)? yes
Host 'example.com' added to the list of known hosts.
user@example.com's password: *******The login will continue just as it would have if a session was
created using rlogin or
telnet. SSH utilizes a key fingerprint
system for verifying the authenticity of the server when the
client connects. The user is prompted to enter
yes only when
connecting for the first time. Future attempts to login are all
verified against the saved fingerprint key. The SSH client
will alert you if the saved fingerprint differs from the
received fingerprint on future login attempts. The fingerprints
are saved in ~/.ssh/known_hosts, or
~/.ssh/known_hosts2 for SSH v2
fingerprints.By default, OpenSSH servers are configured to accept both
SSH v1 and SSH v2 connections. The client, however, can choose
between the two. Version 2 is known to be more robust and
secure than its predecessor.The &man.ssh.1; command can be forced to use either protocol
by passing it the or argument
for v1 and v2, respectively.Secure CopyOpenSSHsecure copyscpThe &man.scp.1; command works similarly to
&man.rcp.1;; it copies a file to or from a remote machine,
except in a secure fashion.&prompt.root; scp user@example.com:/COPYRIGHT COPYRIGHT
user@example.com's password: *******
COPYRIGHT 100% |*****************************| 4735
00:00
&prompt.root;Since the fingerprint was already saved for this host in the
previous example, it is verified when using &man.scp.1;
here.The arguments passed to &man.scp.1; are similar
to &man.cp.1;, with the file or files in the first
argument, and the destination in the second. Since the file is
fetched over the network, through SSH, one or more of the file
arguments takes on the form
.ConfigurationOpenSSHconfigurationThe system-wide configuration files for both the
OpenSSH daemon and client reside
within the /etc/ssh directory.ssh_config configures the client
settings, while sshd_config configures the
daemon.Additionally, the
(/usr/sbin/sshd by default), and
rc.conf
options can provide more levels of configuration.ssh-keygenInstead of using passwords, &man.ssh-keygen.1; can
be used to generate RSA keys to authenticate a user:&prompt.user; ssh-keygen -t rsa1
Initializing random number generator...
Generating p: .++ (distance 66)
Generating q: ..............................++ (distance 498)
Computing the keys...
Key generation complete.
Enter file in which to save the key (/home/user/.ssh/identity):
Enter passphrase:
Enter the same passphrase again:
Your identification has been saved in /home/user/.ssh/identity.
...&man.ssh-keygen.1; will create a public and private
key pair for use in authentication. The private key is stored in
~/.ssh/identity, whereas the public key is
stored in ~/.ssh/identity.pub. The public
key must be placed in ~/.ssh/authorized_keys
of the remote machine in order for the setup to work.This will allow connection to the remote machine based upon
RSA authentication instead of passwords.The option will create RSA
keys for use by SSH protocol version 1. If you want to use
RSA keys with the SSH protocol version 2, you have to use the
command ssh-keygen -t rsa.If a passphrase is used in &man.ssh-keygen.1;, the user
will be prompted for a password each time in order to use the private
key.A SSH protocol version 2 DSA key can be created for the same purpose by using
the ssh-keygen -t dsa command.
This will
create a public/private DSA key for use in SSH protocol version 2 sessions only.
The public key is stored in ~/.ssh/id_dsa.pub,
while the private key is in ~/.ssh/id_dsa.DSA public keys are also placed in
~/.ssh/authorized_keys on the remote
machine.&man.ssh-agent.1; and &man.ssh-add.1; are
utilities used in managing multiple passworded private keys.The various options and files can be different
according to the OpenSSH version you have on your system, to
avoid problems you should consult the &man.ssh-keygen.1;
manual page.SSH TunnelingOpenSSHtunnelingOpenSSH has the ability to create a tunnel to encapsulate
another protocol in an encrypted session.The following command tells &man.ssh.1; to create a tunnel
for telnet:&prompt.user; ssh -2 -N -f -L 5023:localhost:23 user@foo.example.com
&prompt.user;The ssh command is used with the
following options:Forces ssh to use version 2 of
the protocol. (Do not use if you are working with older
SSH servers)Indicates no command, or tunnel only. If omitted,
ssh would initiate a normal
session.Forces ssh to run in the
background.Indicates a local tunnel in
localport:remotehost:remoteport
fashion.The remote SSH server.An SSH tunnel works by creating a listen socket on
localhost on the specified port.
It then forwards any connection received
on the local host/port via the SSH connection to the specified
remote host and port.In the example, port 5023 on
localhost is being forwarded to port
23 on localhost
of the remote machine. Since 23 is telnet,
this would create a secure telnet session through an SSH tunnel.This can be used to wrap any number of insecure TCP
protocols such as SMTP, POP3, FTP, etc.Using SSH to Create a Secure Tunnel for SMTP&prompt.user; ssh -2 -N -f -L 5025:localhost:25 user@mailserver.example.com
user@mailserver.example.com's password: *****
&prompt.user; telnet localhost 5025
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mailserver.example.com ESMTPThis can be used in conjunction with an
&man.ssh-keygen.1; and additional user accounts to create a
more seamless/hassle-free SSH tunneling environment. Keys
can be used in place of typing a password, and the tunnels
can be run as a separate user.Practical SSH Tunneling ExamplesSecure Access of a POP3 ServerAt work, there is an SSH server that accepts
connections from the outside. On the same office network
resides a mail server running a POP3 server. The network,
or network path between your home and office may or may not
be completely trustable. Because of this, you need to check
your e-mail in a secure manner. The solution is to create
an SSH connection to your office's SSH server, and tunnel
through to the mail server.&prompt.user; ssh -2 -N -f -L 2110:mail.example.com:110 user@ssh-server.example.com
user@ssh-server.example.com's password: ******When the tunnel is up and running, you can point your
mail client to send POP3 requests to localhost
port 2110. A connection here will be forwarded securely across
the tunnel to mail.example.com.Bypassing a Draconian FirewallSome network administrators impose extremely draconian
firewall rules, filtering not only incoming connections,
but outgoing connections. You may be only given access
to contact remote machines on ports 22 and 80 for SSH
and web surfing.You may wish to access another (perhaps non-work
related) service, such as an Ogg Vorbis server to stream
music. If this Ogg Vorbis server is streaming on some other
port than 22 or 80, you will not be able to access it.The solution is to create an SSH connection to a machine
outside of your network's firewall, and use it to tunnel to
the Ogg Vorbis server.&prompt.user; ssh -2 -N -f -L 8888:music.example.com:8000 user@unfirewalled-system.example.org
user@unfirewalled-system.example.org's password: *******Your streaming client can now be pointed to
localhost port 8888, which will be
forwarded over to music.example.com port
8000, successfully evading the firewall.Further ReadingOpenSSH&man.ssh.1; &man.scp.1; &man.ssh-keygen.1;
&man.ssh-agent.1; &man.ssh-add.1;&man.sshd.8; &man.sftp-server.8;TomRhodesContributed by ACLFile System Access Control ListsIn conjunction with file system enhancements like snapshots, FreeBSD 5.0
and later offers the security of File System Access Control Lists
(ACLs).Access Control Lists extend the standard &unix;
permission model in a highly compatible (&posix;.1e) way. This feature
permits an administrator to make use of and take advantage of a
more sophisticated security model.To enable ACL support for UFS
file systems, the following:options UFS_ACLmust be compiled into the kernel. If this option has
not been compiled in, a warning message will be displayed
when attempting to mount a file system supporting ACLs.
This option is included in the GENERIC kernel.
ACLs rely on extended attributes being enabled on
the file system. Extended attributes are natively supported in the next generation
&unix; file system, UFS2.A higher level of administrative overhead is required to
configure extended attributes on UFS1 than on
UFS2. The performance of extended attributes
on UFS2 is also substantially higher. As a
result, UFS2 is generally recommended in preference
to UFS1 for use with access control lists.ACLs are enabled by the mount-time administrative
flag, , which may be added to /etc/fstab.
The mount-time flag can also be automatically set in a persistent manner using
&man.tunefs.8; to modify a superblock ACLs flag in the
file system header. In general, it is preferred to use the superblock flag
for several reasons:The mount-time ACLs flag cannot be changed by a
remount (&man.mount.8; ), only by means of a complete
&man.umount.8; and fresh &man.mount.8;. This means that
ACLs cannot be enabled on the root file system after boot.
It also means that you cannot change the disposition of a file system once
it is in use.Setting the superblock flag will cause the file system to always be
mounted with ACLs enabled even if there is not an
fstab entry or if the devices re-order. This prevents
accidental mounting of the file system without ACLs
enabled, which can result in ACLs being improperly enforced,
and hence security problems.We may change the ACLs behavior to allow the flag to
be enabled without a complete fresh &man.mount.8;, but we consider it desirable to
discourage accidental mounting without ACLs enabled, because you
can shoot your feet quite nastily if you enable ACLs, then disable
them, then re-enable them without flushing the extended attributes. In general, once
you have enabled ACLs on a file system, they should not be disabled,
as the resulting file protections may not be compatible with those intended by the
users of the system, and re-enabling ACLs may re-attach the previous
ACLs to files that have since had their permissions changed,
resulting in other unpredictable behavior.File systems with ACLs enabled will show a +
(plus) sign in their permission settings when viewed. For example:drwx------ 2 robert robert 512 Dec 27 11:54 private
drwxrwx---+ 2 robert robert 512 Dec 23 10:57 directory1
drwxrwx---+ 2 robert robert 512 Dec 22 10:20 directory2
drwxrwx---+ 2 robert robert 512 Dec 27 11:57 directory3
drwxr-xr-x 2 robert robert 512 Nov 10 11:54 public_htmlHere we see that the directory1,
directory2, and directory3
directories are all taking advantage of ACLs. The
public_html directory is not.Making Use of ACLsThe file system ACLs can be viewed by the
&man.getfacl.1; utility. For instance, to view the
ACL settings on the test
file, one would use the command:&prompt.user; getfacl test
#file:test
#owner:1001
#group:1001
user::rw-
group::r--
other::r--To change the ACL settings on this file,
invoke the &man.setfacl.1; utility. Observe:&prompt.user; setfacl -k testThe flag will remove all of the
currently defined ACLs from a file or file
system. The more preferable method would be to use
as it leaves the basic fields required for
ACLs to work.&prompt.user; setfacl -m u:trhodes:rwx,group:web:r--,o::--- testIn the aforementioned command, the
option was used to modify the default ACL
entries. Since there were no pre-defined entries, as they were
removed by the previous command, this will restore the default
options and assign the options listed. Take care to notice that
if you add a user or group which does not exist on the system,
an Invalid argument error will be printed
to stdout.TomRhodesContributed by FreeBSD Security Advisories&os; Security AdvisoriesLike many production quality operating systems, &os; publishes
Security Advisories. These advisories are usually
mailed to the security lists and noted in the Errata only
after the appropriate releases have been patched. This section
will work to explain what an advisory is, how to understand it,
and what measures to take in order to patch a system.What does an advisory look like?The &os; security advisories look similar to the one below,
taken from the &a.security-notifications.name; mailing list.=============================================================================
&os;-SA-XX:XX.UTIL Security Advisory
The &os; Project
Topic: denial of service due to some problem
Category: core
Module: sys
Announced: 2003-09-23
Credits: Person@EMAIL-ADDRESS
Affects: All releases of &os;
&os; 4-STABLE prior to the correction date
Corrected: 2003-09-23 16:42:59 UTC (RELENG_4, 4.9-PRERELEASE)
2003-09-23 20:08:42 UTC (RELENG_5_1, 5.1-RELEASE-p6)
2003-09-23 20:07:06 UTC (RELENG_5_0, 5.0-RELEASE-p15)
2003-09-23 16:44:58 UTC (RELENG_4_8, 4.8-RELEASE-p8)
2003-09-23 16:47:34 UTC (RELENG_4_7, 4.7-RELEASE-p18)
2003-09-23 16:49:46 UTC (RELENG_4_6, 4.6-RELEASE-p21)
2003-09-23 16:51:24 UTC (RELENG_4_5, 4.5-RELEASE-p33)
2003-09-23 16:52:45 UTC (RELENG_4_4, 4.4-RELEASE-p43)
2003-09-23 16:54:39 UTC (RELENG_4_3, 4.3-RELEASE-p39)
&os; only: NO
For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit
http://www.FreeBSD.org/security/.
I. Background
II. Problem Description
III. Impact
IV. Workaround
V. Solution
VI. Correction details
VII. ReferencesThe Topic field indicates exactly what the problem is.
It is basically an introduction to the current security
advisory and notes the utility with the
vulnerability.The Category refers to the affected part of the system
which may be one of core, contrib, or ports. The core
category means that the vulnerability affects a core
component of the &os; operating system. The contrib
category means that the vulnerability affects software
contributed to the &os; Project, such as
sendmail. Finally the ports
category indicates that the vulnerability affects add on
software available as part of the ports collection.The Module field refers to the component location, for
instance sys. In this example, we see that the module,
sys, is affected; therefore, this vulnerability
affects a component used within the kernel.The Announced field reflects the date said security
advisory was published, or announced to the world. This
means that the security team has verified that the problem
does exist and that a patch has been committed to the &os;
source code repository.The Credits field gives credit to the individual or
organization who noticed the vulnerability and reported
it.The Affects field explains which releases of &os; are
affected by this vulnerability. For the kernel, a quick
look over the output from ident on the
affected files will help in determining the revision.
For ports, the version number is listed after the port name
in /var/db/pkg. If the system does not
sync with the &os; CVS repository and rebuild
daily, chances are that it is affected.The Corrected field indicates the date, time, time
offset, and release that was corrected.The &os; only field indicates whether this vulnerability
affects just &os;, or if it affects other operating systems
as well.The Background field gives information on exactly what
the affected utility is. Most of the time this is why
the utility exists in &os;, what it is used for, and a bit
of information on how the utility came to be.The Problem Description field explains the security hole
in depth. This can include information on flawed code, or
even how the utility could be maliciously used to open
a security hole.The Impact field describes what type of impact the
problem could have on a system. For example, this could
be anything from a denial of service attack, to extra
privileges available to users, or even giving the attacker
superuser access.The Workaround field offers a feasible workaround to
system administrators who may be incapable of upgrading
the system. This may be due to time constraints, network
availability, or a slew of other reasons. Regardless,
security should not be taken lightly, and an affected system
should either be patched or the security hole workaround
should be implemented.The Solution field offers instructions on patching the
affected system. This is a step by step tested and verified
method for getting a system patched and working
securely.The Correction Details field displays the
CVS branch or release name with the
periods changed to underscore characters. It also shows
the revision number of the affected files within each
branch.The References field usually offers sources of other
information. This can included web URLs,
books, mailing lists, and newsgroups.