SlideShare a Scribd company logo
05/201320
How To
Useful Utilities for PF
This article explores some of the third-party utilities which
are available to help you analyze the log and state table of a
PF firewall.
What you will learn…
• 	 How to view the PF state table in real time
• 	 How to convert the PF log to HTML format or graph format
What you should know…
• 	 How to restart PF
• 	 How to install third-party software on your BSD system
T
he PF firewall is developed by the OpenBSD Proj-
ect. PF has also been ported to FreeBSD, NetBSD,
and DragonFly BSD. You can learn more about PF
and its features in the PF User’s Guide at http://www.
openbsd.org/faq/pf/.
PF is a stateful firewall, meaning that it tracks the state
of existing connections in a state table, allowing the fire-
wall to quickly determine if packets are part of an es-
tablished connection. PF also provides a logging facility
and the firewall administrator controls which packets get
logged by including the log keyword in only the firewall
rules which should be logged when matched.
PF provides the pfctl utility for displaying the state ta-
ble and the built-in tcpdump utility can be used to view the
PF log. In addition to these tools, some third-party pack-
ages can be installed on BSD systems. These can be
used to manipulate information from the state table and
the PF logging facility in order to get a different view on
what is happening with the firewall. This article provides
an overview of the following utilities: pftop, pflogx, and
pfstat. These utilities were tested on a PC-BSD system
and the utilities were installed using FreeBSD packages.
This article assumes that you already know how to restart
PF and how to install software on your BSD system using
packages, ports, or pkgsrc.
pftop
• 	 Website: http://www.eee.metu.edu.tr/~canacar/pftop/
• 	 Availability: pkgsrc, FreeBSD and OpenBSD packages
• 	 Description: provides real time display of PF state ta-
ble and rule statistics
This utility is similar to top as it provides a real time, co-
lumnar display. However, instead of displaying the top
processes running on the system, it displays real time
information about the current connections in the PF
state table.
Listing 1. pfctl View of State Table
pfctl -s states
all tcp 192.168.1.71:19348 → 204.152.184.134:21 ESTABLISHED:ESTABLISHED
all tcp 192.168.1.71:34852 → 204.152.184.134:42342 ESTABLISHED:ESTABLISHED
all udp 192.168.1.71:5353 → 224.0.0.251:5353 SINGLE:NOTRAFFIC
(snip rest of output...)
05/201322
How To
Figure 1. Default pftop Display
Figure 2. Viewing Loaded Rules Using pfctl
www.bsdmag.org 23
Useful Utilities for PF
Typically, the state table is read using pfctl as seen in
the following example. This output is from a PC-BSD sys-
tem that is downloading a PBI using AppCafe.
Figure 1 shows the same state table. This time, the dis-
play is generated by typing pftop.
In order, the columns in this default view list the proto-
col (TCP or UDP), the direction (into the system or out of
the system), the source address and socket, the destina-
tion address and port, the state of the connection, the age
of the connection, how long until that connection expires
from the state table, the number of packets in that connec-
tion, and the number of bytes transferred.
pftop also provides a view for displaying which rules are
currently loaded. First, Figure 2 shows which firewall rules
have been loaded using the built-in pfctl.
Next, Figure 3 shows the same rules, this time viewed
using pftop. This display adds information such as the
number of packets, bytes, and established connections
(states) associated with each rule.
pftop also provides an interactive mode where key-
strokes can be used to modify the view, sort the column
order, change the number of lines to display, and to pause
or restart the display. Display filters can also be created
using tcpdump syntax. Refer to pftop(8) for details.
pflogx
• 	 Website: http://akldev.free.fr/pflogx/
• 	 Availability: FreeBSD and OpenBSD packages
• 	 Description: generates an XML file from a PF log
which can then be optionally transformed into HTML
or csv format
PF writes its logs in a binary format, meaning that they
cannot be read using head, tail, more, less, or an editor.
While the logs can be read in real time using the com-
mand tcpdump -n -e -ttt -i pflog0, it is sometimes con-
venient to convert the logging information to another for-
mat in order to study it and analyze trends. pflogx ren-
ders the PF log in XML format and includes the ability to
transform the XML into HTML or csv format. Optionally,
the generated XML file can be passed to other third-par-
ty tools for conversion to other formats.
In order to use pflogx, the PF logging module must be
loaded and at least one rule in the PF rulebase must in-
clude the log keyword. You can double-check that log en-
tries exist by typing pflogx -i /var/log/pflog. As seen in
this example, this command displays the log entries to the
screen: Listing 2.
Figure 3. Viewing Loaded Rules Using pftop
05/201324
How To
To instead save the log to an XML file, after the input
(-i /var/log/pflog), specify the name of the output file
(-o filename.xml).
Optional filters can be placed between the input and out-
put. They can be defined by action (-a pass or -a drop), di-
rection (-d in, -d out, or -d in-out), protocol (-p icmp, -p
ip, -p tcp, or -p udp), and interface (-n interface_name).
If a filter is not included, all packets in the input log file
will be generated to the output XML file. Several filter ex-
amples can be found in the README file that is installed
with pflogx.
The package installs several XSLT files which are used
to transform the XML file to HTML, XHTML, or csv format.
To transform a generated XML file, copy it to the directory
Listing 2. Sample XML File
pflogx -i /var/log/pflog
<?xml version=ā€1.0ā€ encoding=ā€UTF-8ā€?>
<pflogx version=ā€0.86ā€ >
<logs>
<log date=ā€2013-04-23 12:43:48.261661ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€udpā€ src_
adr=ā€205.233.73.201ā€ src_port=ā€123ā€ dest_adr=ā€192.168.1.71ā€ dest_port=ā€123ā€ />
<log date=ā€2013-04-23 12:44:24.41857ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€(2)ā€ src_
adr=ā€192.168.1.254ā€ src_port=ā€ā€ dest_adr=ā€224.0.0.1ā€ dest_port=ā€ā€ />
<log date=ā€2013-04-23 12:46:29.44070ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€(2)ā€ src_
adr=ā€192.168.1.254ā€ src_port=ā€ā€ dest_adr=ā€224.0.0.1ā€ dest_port=ā€ā€ />
<log date=ā€2013-04-23 12:47:50.298105ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€udpā€ src_
adr=ā€192.168.1.71ā€ src_port=ā€138ā€ dest_adr=ā€192.168.1.255ā€ dest_port=ā€138ā€ />
<log date=ā€2013-04-23 12:47:50.298145ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€udpā€ src_
adr=ā€192.168.1.71ā€ src_port=ā€138ā€ dest_adr=ā€192.168.1.255ā€ dest_port=ā€138ā€ />
(rest of output snipped....)
Figure 4. Sample PF log in HTML Format
05/201326
How To
containing these files. On a FreeBSD or PC-BSD system,
these files are located in /usr/local/share/examples/
pflogx/. In the generated XML file, the first line should be:
<?xml version=ā€1.0ā€ encoding=ā€UTF-8ā€?>
Insert a second line that contains the name of the XSLT
file. For example, to transform to HTML, add this line:
<?xml-stylesheet type=ā€text/xslā€ href=ā€export_html.xslā€?>
Save the edit and you should now be able to view the XML
file in a web browser, as seen in the example in Figure 4.
pflogx provides a merge option (-m) which can be used
to append new log entries to an existing XML file, allowing
you to visualize the transformed log over time.
pfstat
• 	 Website: http://www.benzedrine.cx/pfstat.html
• 	 Availability: pkgsrc, FreeBSD and OpenBSD packages
• 	 Description: automatically generates graphs from PF
statistics
If you prefer to visualize the PF logs in a graph format,
install pfstat. Once installed, create its log directory and
log file if they do not exist:
# mkdir /var/log/pflog
# touch /var/log/pflog/pflog
Next, create a configuration file named /usr/local/etc/
pfstat.conf. This file controls which graphs get creat-
ed. A comprehensive file with comments on the various
graphs it creates can be downloaded from http://www.
benzedrine.cx/pfstat.conf. The following example shows
a simpler configuration file which creates two graphs:
one displays bandwidth in bits per second and the oth-
er charts the state table. Edit the text in red to point to
an existing directory path. The filename (e.g. bandwidth.
jpg) should not already exist in the specified directory as
pfstat will generate it for you.
Next, type crontab -e as the superuser to edit the root
user’s crontab. Add the following line:
*/5 * * * * /usr/local/bin/pfstat -q >> /var/log/pfstat
Listing 3. Sample pfstat Configuration
# more /usr/local/etc/pfstat.conf
collect 1 = interface ā€œem0ā€ pass bytes in ipv4 diff
collect 2 = interface ā€œem0ā€ pass bytes out ipv4
diff
image ā€œ/usr/home/dru/bandwidth.jpgā€ {
	 from 7 days to now
	 width 1000 height 400
	 left
		 graph 1 bps ā€œinā€ ā€œbits/sā€ color 0 192 0
filled
	 right
		 graph 2 bps ā€œoutā€ ā€œbits/sā€ color 0 0 255
}
collect 3 = global states entries
image ā€œ/usr/home/dru/states.jpgā€ {
	 from 12 months to now
	 width 800 height 200
	 left
		 graph 3 ā€œstatesā€ ā€œentriesā€ color 200 0 0
}
Figure 5. Sample Graph
www.bsdmag.org
This instructs pfstat to query the logging interface ev-
ery five minutes and to store the received logging infor-
mation in its own database, which it uses to generate
graphs.
Finally, add this line to the beginning of /etc/pf.conf
in order to set the logging interface. Replace em0 with the
name of the interface you wish to collect statistics on. Re-
start the PF firewall after saving this edit.
set loginterface em0
Wait a bit (at least five minutes) to allow pfstat to add
logging information to its database. The amount of infor-
mation added to the database will depend upon how of-
ten a logged rule matches the criteria you have config-
ured pfstat to graph.
Whenever you want to generate a graph, type pfstat
-p. This instructs pfstat to read the entries in its data-
base and to generate the images to the locations that you
specified in /usr/local/etc/pfstat.conf. Figure 5 shows
a sample /usr/home/dru/bandwidth.jpg from the configu-
ration file above, after running pfstat for one day on a
home desktop system.
pfstat(8) provides some more information on how to use
pfstat, remove old entries from the database, and query
a remote host running pfstatd.
Summary
pftop, pflogx, and pfstat can be used to help the admin-
istrator visualize the traffic flowing through a PF firewall.
These utilities are easy to install and configure. If you are
using the PF firewall, consider adding them to your admin-
istrative toolkit.
Dru Lavigne
Dru Lavigne is author of BSD Hacks, The Best of FreeBSD Basics,
and The Definitive Guide to PC-BSD. As Director of Communi-
ty Development for the PC-BSD Project, she leads the documen-
tation team, assists new users, helps to find and fix bugs, and
reaches out to the community to discover their needs. She is the
former Managing Editor of the Open Source Business Resource,
a free monthly publication covering open source and the com-
mercialization of open source assets. She is founder and cur-
rent Chair of the BSD Certification Group Inc., a non-profit orga-
nization with a mission to create the standard for certifying BSD
system administrators, and serves on the Board of the FreeBSD
Foundation.

More Related Content

PDF
olf10
Dru Lavigne
Ā 
PDF
Nelf2013
Dru Lavigne
Ā 
PDF
Fsoss12
Dru Lavigne
Ā 
PDF
Tlf2013
Dru Lavigne
Ā 
PDF
Nycbsdcon14
Dru Lavigne
Ā 
PDF
Asiabsdcon15
Dru Lavigne
Ā 
PDF
Fosscon2013
Dru Lavigne
Ā 
PDF
Ilf2012
Dru Lavigne
Ā 
olf10
Dru Lavigne
Ā 
Nelf2013
Dru Lavigne
Ā 
Fsoss12
Dru Lavigne
Ā 
Tlf2013
Dru Lavigne
Ā 
Nycbsdcon14
Dru Lavigne
Ā 
Asiabsdcon15
Dru Lavigne
Ā 
Fosscon2013
Dru Lavigne
Ā 
Ilf2012
Dru Lavigne
Ā 

What's hot (20)

PDF
Nelf2012
Dru Lavigne
Ā 
PDF
Scale13
Dru Lavigne
Ā 
PDF
Olf2013
Dru Lavigne
Ā 
PDF
Sweden11
Dru Lavigne
Ā 
PDF
Tlf2012
Dru Lavigne
Ā 
PDF
Olf2012
Dru Lavigne
Ā 
PDF
Introduction to FreeNAS development by John Hixson
iXsystems
Ā 
PDF
Article may11 bsdmag
Dru Lavigne
Ā 
PDF
Scale9x sun
Dru Lavigne
Ā 
PDF
Ilf2011
Dru Lavigne
Ā 
PDF
Dru lavigne servers-tutorial
Dru Lavigne
Ā 
PDF
Fsoss2011
Dru Lavigne
Ā 
PDF
Oclug 2010
Dru Lavigne
Ā 
PDF
Posscon2013
Dru Lavigne
Ā 
PDF
Ilf2013
Dru Lavigne
Ā 
PDF
Flourish11
Dru Lavigne
Ā 
PDF
Lavigne bsdmag sept12
Dru Lavigne
Ā 
PDF
Self2013
Dru Lavigne
Ā 
PDF
Scale 2010: BSD for Linux Users
Dru Lavigne
Ā 
PDF
Lavigne bsdmag-jan2012
Dru Lavigne
Ā 
Nelf2012
Dru Lavigne
Ā 
Scale13
Dru Lavigne
Ā 
Olf2013
Dru Lavigne
Ā 
Sweden11
Dru Lavigne
Ā 
Tlf2012
Dru Lavigne
Ā 
Olf2012
Dru Lavigne
Ā 
Introduction to FreeNAS development by John Hixson
iXsystems
Ā 
Article may11 bsdmag
Dru Lavigne
Ā 
Scale9x sun
Dru Lavigne
Ā 
Ilf2011
Dru Lavigne
Ā 
Dru lavigne servers-tutorial
Dru Lavigne
Ā 
Fsoss2011
Dru Lavigne
Ā 
Oclug 2010
Dru Lavigne
Ā 
Posscon2013
Dru Lavigne
Ā 
Ilf2013
Dru Lavigne
Ā 
Flourish11
Dru Lavigne
Ā 
Lavigne bsdmag sept12
Dru Lavigne
Ā 
Self2013
Dru Lavigne
Ā 
Scale 2010: BSD for Linux Users
Dru Lavigne
Ā 
Lavigne bsdmag-jan2012
Dru Lavigne
Ā 
Ad

Viewers also liked (7)

PDF
Fame, Fortune, and Technical Writing
Dru Lavigne
Ā 
PDF
Lisa2011
Dru Lavigne
Ā 
PDF
Lavigne bsdmag dec2012
Dru Lavigne
Ā 
PDF
Dru lavigne oss-sysadmin
Dru Lavigne
Ā 
PDF
Meetbsd12
Dru Lavigne
Ā 
ODP
BSD Certification: Using Open Source and Education to Accelerate Technology T...
Dru Lavigne
Ā 
PDF
SummerCamp 2010
Dru Lavigne
Ā 
Fame, Fortune, and Technical Writing
Dru Lavigne
Ā 
Lisa2011
Dru Lavigne
Ā 
Lavigne bsdmag dec2012
Dru Lavigne
Ā 
Dru lavigne oss-sysadmin
Dru Lavigne
Ā 
Meetbsd12
Dru Lavigne
Ā 
BSD Certification: Using Open Source and Education to Accelerate Technology T...
Dru Lavigne
Ā 
SummerCamp 2010
Dru Lavigne
Ā 
Ad

Similar to Lavigne bsdmag may13 (20)

PPT
wireshark.08f for all in the world careful
reachadhinvs
Ā 
PPT
Juniper Trouble Shooting
Mike(Haobin) Zheng
Ā 
PDF
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
Wirabumi Software
Ā 
PPT
101 3.2 process text streams using filters
AcƔcio Oliveira
Ā 
PPT
Linux presentation
Ajaigururaj R
Ā 
PPT
Power point on linux commands,appache,php,mysql,html,css,web 2.0
venkatakrishnan k
Ā 
PDF
Linux internet server security and configuration tutorial
annik147
Ā 
PDF
C library for input output operations.cstdio.(stdio.h)
leonard horobet-stoian
Ā 
PDF
Working with the IFS on System i
Chuck Walker
Ā 
PDF
Cacoo enterprise installation_manual
joseig23
Ā 
PDF
2009-03-13 Atlanda System z Council Meeting
Shawn Wells
Ā 
PDF
linux installation.pdf
MuhammadShoaibHussai2
Ā 
DOCX
Backtrack Manual Part6
Nutan Kumar Panda
Ā 
PPT
3.2 process text streams using filters
AcƔcio Oliveira
Ā 
PDF
TekTape Manual
Yasin KAPLAN
Ā 
PPT
Linux filesystemhierarchy
Dr. C.V. Suresh Babu
Ā 
PDF
Odoo command line interface
Jalal Zahid
Ā 
PPT
101 3.2 process text streams using filters
AcƔcio Oliveira
Ā 
PPT
101 3.2 process text streams using filters
AcƔcio Oliveira
Ā 
PPT
Slim Server Practical
Gaurav Paliwal
Ā 
wireshark.08f for all in the world careful
reachadhinvs
Ā 
Juniper Trouble Shooting
Mike(Haobin) Zheng
Ā 
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
Wirabumi Software
Ā 
101 3.2 process text streams using filters
AcƔcio Oliveira
Ā 
Linux presentation
Ajaigururaj R
Ā 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
venkatakrishnan k
Ā 
Linux internet server security and configuration tutorial
annik147
Ā 
C library for input output operations.cstdio.(stdio.h)
leonard horobet-stoian
Ā 
Working with the IFS on System i
Chuck Walker
Ā 
Cacoo enterprise installation_manual
joseig23
Ā 
2009-03-13 Atlanda System z Council Meeting
Shawn Wells
Ā 
linux installation.pdf
MuhammadShoaibHussai2
Ā 
Backtrack Manual Part6
Nutan Kumar Panda
Ā 
3.2 process text streams using filters
AcƔcio Oliveira
Ā 
TekTape Manual
Yasin KAPLAN
Ā 
Linux filesystemhierarchy
Dr. C.V. Suresh Babu
Ā 
Odoo command line interface
Jalal Zahid
Ā 
101 3.2 process text streams using filters
AcƔcio Oliveira
Ā 
101 3.2 process text streams using filters
AcƔcio Oliveira
Ā 
Slim Server Practical
Gaurav Paliwal
Ā 

More from Dru Lavigne (20)

PDF
Olf2018
Dru Lavigne
Ā 
PDF
Olf2017
Dru Lavigne
Ā 
PDF
FreeBSD System Administration Using SysAdm
Dru Lavigne
Ā 
PDF
Asiabsdcon2017
Dru Lavigne
Ā 
PDF
Olf2016
Dru Lavigne
Ā 
PDF
Tlf2016
Dru Lavigne
Ā 
PDF
Knoxbug2016
Dru Lavigne
Ā 
PDF
Lfnw2016
Dru Lavigne
Ā 
PDF
Flourish16
Dru Lavigne
Ā 
PDF
Scale2016
Dru Lavigne
Ā 
PDF
Fossetcon15
Dru Lavigne
Ā 
PDF
Lfnw15
Dru Lavigne
Ā 
PDF
Scale2015
Dru Lavigne
Ā 
PDF
Olf2014
Dru Lavigne
Ā 
PDF
Ghc14
Dru Lavigne
Ā 
PDF
Fossetcon14
Dru Lavigne
Ā 
PDF
Tlf2014
Dru Lavigne
Ā 
PDF
Asiabsdcon14 lavigne
Dru Lavigne
Ā 
PDF
Asiabsdcon14
Dru Lavigne
Ā 
PDF
Scale2014
Dru Lavigne
Ā 
Olf2018
Dru Lavigne
Ā 
Olf2017
Dru Lavigne
Ā 
FreeBSD System Administration Using SysAdm
Dru Lavigne
Ā 
Asiabsdcon2017
Dru Lavigne
Ā 
Olf2016
Dru Lavigne
Ā 
Tlf2016
Dru Lavigne
Ā 
Knoxbug2016
Dru Lavigne
Ā 
Lfnw2016
Dru Lavigne
Ā 
Flourish16
Dru Lavigne
Ā 
Scale2016
Dru Lavigne
Ā 
Fossetcon15
Dru Lavigne
Ā 
Lfnw15
Dru Lavigne
Ā 
Scale2015
Dru Lavigne
Ā 
Olf2014
Dru Lavigne
Ā 
Ghc14
Dru Lavigne
Ā 
Fossetcon14
Dru Lavigne
Ā 
Tlf2014
Dru Lavigne
Ā 
Asiabsdcon14 lavigne
Dru Lavigne
Ā 
Asiabsdcon14
Dru Lavigne
Ā 
Scale2014
Dru Lavigne
Ā 

Recently uploaded (20)

PDF
Software Development Methodologies in 2025
KodekX
Ā 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PDF
The Future of Artificial Intelligence (AI)
Mukul
Ā 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
Ā 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
Ā 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
Ā 
PDF
Doc9.....................................
SofiaCollazos
Ā 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
Ā 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
Ā 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
Ā 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
Software Development Methodologies in 2025
KodekX
Ā 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
The Future of Artificial Intelligence (AI)
Mukul
Ā 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
Ā 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
Ā 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
Ā 
Doc9.....................................
SofiaCollazos
Ā 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
Ā 
Presentation about Hardware and Software in Computer
snehamodhawadiya
Ā 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
Ā 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 

Lavigne bsdmag may13

  • 1. 05/201320 How To Useful Utilities for PF This article explores some of the third-party utilities which are available to help you analyze the log and state table of a PF firewall. What you will learn… • How to view the PF state table in real time • How to convert the PF log to HTML format or graph format What you should know… • How to restart PF • How to install third-party software on your BSD system T he PF firewall is developed by the OpenBSD Proj- ect. PF has also been ported to FreeBSD, NetBSD, and DragonFly BSD. You can learn more about PF and its features in the PF User’s Guide at http://www. openbsd.org/faq/pf/. PF is a stateful firewall, meaning that it tracks the state of existing connections in a state table, allowing the fire- wall to quickly determine if packets are part of an es- tablished connection. PF also provides a logging facility and the firewall administrator controls which packets get logged by including the log keyword in only the firewall rules which should be logged when matched. PF provides the pfctl utility for displaying the state ta- ble and the built-in tcpdump utility can be used to view the PF log. In addition to these tools, some third-party pack- ages can be installed on BSD systems. These can be used to manipulate information from the state table and the PF logging facility in order to get a different view on what is happening with the firewall. This article provides an overview of the following utilities: pftop, pflogx, and pfstat. These utilities were tested on a PC-BSD system and the utilities were installed using FreeBSD packages. This article assumes that you already know how to restart PF and how to install software on your BSD system using packages, ports, or pkgsrc. pftop • Website: http://www.eee.metu.edu.tr/~canacar/pftop/ • Availability: pkgsrc, FreeBSD and OpenBSD packages • Description: provides real time display of PF state ta- ble and rule statistics This utility is similar to top as it provides a real time, co- lumnar display. However, instead of displaying the top processes running on the system, it displays real time information about the current connections in the PF state table. Listing 1. pfctl View of State Table pfctl -s states all tcp 192.168.1.71:19348 → 204.152.184.134:21 ESTABLISHED:ESTABLISHED all tcp 192.168.1.71:34852 → 204.152.184.134:42342 ESTABLISHED:ESTABLISHED all udp 192.168.1.71:5353 → 224.0.0.251:5353 SINGLE:NOTRAFFIC (snip rest of output...)
  • 2. 05/201322 How To Figure 1. Default pftop Display Figure 2. Viewing Loaded Rules Using pfctl
  • 3. www.bsdmag.org 23 Useful Utilities for PF Typically, the state table is read using pfctl as seen in the following example. This output is from a PC-BSD sys- tem that is downloading a PBI using AppCafe. Figure 1 shows the same state table. This time, the dis- play is generated by typing pftop. In order, the columns in this default view list the proto- col (TCP or UDP), the direction (into the system or out of the system), the source address and socket, the destina- tion address and port, the state of the connection, the age of the connection, how long until that connection expires from the state table, the number of packets in that connec- tion, and the number of bytes transferred. pftop also provides a view for displaying which rules are currently loaded. First, Figure 2 shows which firewall rules have been loaded using the built-in pfctl. Next, Figure 3 shows the same rules, this time viewed using pftop. This display adds information such as the number of packets, bytes, and established connections (states) associated with each rule. pftop also provides an interactive mode where key- strokes can be used to modify the view, sort the column order, change the number of lines to display, and to pause or restart the display. Display filters can also be created using tcpdump syntax. Refer to pftop(8) for details. pflogx • Website: http://akldev.free.fr/pflogx/ • Availability: FreeBSD and OpenBSD packages • Description: generates an XML file from a PF log which can then be optionally transformed into HTML or csv format PF writes its logs in a binary format, meaning that they cannot be read using head, tail, more, less, or an editor. While the logs can be read in real time using the com- mand tcpdump -n -e -ttt -i pflog0, it is sometimes con- venient to convert the logging information to another for- mat in order to study it and analyze trends. pflogx ren- ders the PF log in XML format and includes the ability to transform the XML into HTML or csv format. Optionally, the generated XML file can be passed to other third-par- ty tools for conversion to other formats. In order to use pflogx, the PF logging module must be loaded and at least one rule in the PF rulebase must in- clude the log keyword. You can double-check that log en- tries exist by typing pflogx -i /var/log/pflog. As seen in this example, this command displays the log entries to the screen: Listing 2. Figure 3. Viewing Loaded Rules Using pftop
  • 4. 05/201324 How To To instead save the log to an XML file, after the input (-i /var/log/pflog), specify the name of the output file (-o filename.xml). Optional filters can be placed between the input and out- put. They can be defined by action (-a pass or -a drop), di- rection (-d in, -d out, or -d in-out), protocol (-p icmp, -p ip, -p tcp, or -p udp), and interface (-n interface_name). If a filter is not included, all packets in the input log file will be generated to the output XML file. Several filter ex- amples can be found in the README file that is installed with pflogx. The package installs several XSLT files which are used to transform the XML file to HTML, XHTML, or csv format. To transform a generated XML file, copy it to the directory Listing 2. Sample XML File pflogx -i /var/log/pflog <?xml version=ā€1.0ā€ encoding=ā€UTF-8ā€?> <pflogx version=ā€0.86ā€ > <logs> <log date=ā€2013-04-23 12:43:48.261661ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€udpā€ src_ adr=ā€205.233.73.201ā€ src_port=ā€123ā€ dest_adr=ā€192.168.1.71ā€ dest_port=ā€123ā€ /> <log date=ā€2013-04-23 12:44:24.41857ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€(2)ā€ src_ adr=ā€192.168.1.254ā€ src_port=ā€ā€ dest_adr=ā€224.0.0.1ā€ dest_port=ā€ā€ /> <log date=ā€2013-04-23 12:46:29.44070ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€(2)ā€ src_ adr=ā€192.168.1.254ā€ src_port=ā€ā€ dest_adr=ā€224.0.0.1ā€ dest_port=ā€ā€ /> <log date=ā€2013-04-23 12:47:50.298105ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€udpā€ src_ adr=ā€192.168.1.71ā€ src_port=ā€138ā€ dest_adr=ā€192.168.1.255ā€ dest_port=ā€138ā€ /> <log date=ā€2013-04-23 12:47:50.298145ā€ if=ā€em0ā€ action=ā€dropā€ rule=ā€2ā€ direction=ā€inā€ protocol=ā€udpā€ src_ adr=ā€192.168.1.71ā€ src_port=ā€138ā€ dest_adr=ā€192.168.1.255ā€ dest_port=ā€138ā€ /> (rest of output snipped....) Figure 4. Sample PF log in HTML Format
  • 5. 05/201326 How To containing these files. On a FreeBSD or PC-BSD system, these files are located in /usr/local/share/examples/ pflogx/. In the generated XML file, the first line should be: <?xml version=ā€1.0ā€ encoding=ā€UTF-8ā€?> Insert a second line that contains the name of the XSLT file. For example, to transform to HTML, add this line: <?xml-stylesheet type=ā€text/xslā€ href=ā€export_html.xslā€?> Save the edit and you should now be able to view the XML file in a web browser, as seen in the example in Figure 4. pflogx provides a merge option (-m) which can be used to append new log entries to an existing XML file, allowing you to visualize the transformed log over time. pfstat • Website: http://www.benzedrine.cx/pfstat.html • Availability: pkgsrc, FreeBSD and OpenBSD packages • Description: automatically generates graphs from PF statistics If you prefer to visualize the PF logs in a graph format, install pfstat. Once installed, create its log directory and log file if they do not exist: # mkdir /var/log/pflog # touch /var/log/pflog/pflog Next, create a configuration file named /usr/local/etc/ pfstat.conf. This file controls which graphs get creat- ed. A comprehensive file with comments on the various graphs it creates can be downloaded from http://www. benzedrine.cx/pfstat.conf. The following example shows a simpler configuration file which creates two graphs: one displays bandwidth in bits per second and the oth- er charts the state table. Edit the text in red to point to an existing directory path. The filename (e.g. bandwidth. jpg) should not already exist in the specified directory as pfstat will generate it for you. Next, type crontab -e as the superuser to edit the root user’s crontab. Add the following line: */5 * * * * /usr/local/bin/pfstat -q >> /var/log/pfstat Listing 3. Sample pfstat Configuration # more /usr/local/etc/pfstat.conf collect 1 = interface ā€œem0ā€ pass bytes in ipv4 diff collect 2 = interface ā€œem0ā€ pass bytes out ipv4 diff image ā€œ/usr/home/dru/bandwidth.jpgā€ { from 7 days to now width 1000 height 400 left graph 1 bps ā€œinā€ ā€œbits/sā€ color 0 192 0 filled right graph 2 bps ā€œoutā€ ā€œbits/sā€ color 0 0 255 } collect 3 = global states entries image ā€œ/usr/home/dru/states.jpgā€ { from 12 months to now width 800 height 200 left graph 3 ā€œstatesā€ ā€œentriesā€ color 200 0 0 } Figure 5. Sample Graph
  • 6. www.bsdmag.org This instructs pfstat to query the logging interface ev- ery five minutes and to store the received logging infor- mation in its own database, which it uses to generate graphs. Finally, add this line to the beginning of /etc/pf.conf in order to set the logging interface. Replace em0 with the name of the interface you wish to collect statistics on. Re- start the PF firewall after saving this edit. set loginterface em0 Wait a bit (at least five minutes) to allow pfstat to add logging information to its database. The amount of infor- mation added to the database will depend upon how of- ten a logged rule matches the criteria you have config- ured pfstat to graph. Whenever you want to generate a graph, type pfstat -p. This instructs pfstat to read the entries in its data- base and to generate the images to the locations that you specified in /usr/local/etc/pfstat.conf. Figure 5 shows a sample /usr/home/dru/bandwidth.jpg from the configu- ration file above, after running pfstat for one day on a home desktop system. pfstat(8) provides some more information on how to use pfstat, remove old entries from the database, and query a remote host running pfstatd. Summary pftop, pflogx, and pfstat can be used to help the admin- istrator visualize the traffic flowing through a PF firewall. These utilities are easy to install and configure. If you are using the PF firewall, consider adding them to your admin- istrative toolkit. Dru Lavigne Dru Lavigne is author of BSD Hacks, The Best of FreeBSD Basics, and The Definitive Guide to PC-BSD. As Director of Communi- ty Development for the PC-BSD Project, she leads the documen- tation team, assists new users, helps to find and fix bugs, and reaches out to the community to discover their needs. She is the former Managing Editor of the Open Source Business Resource, a free monthly publication covering open source and the com- mercialization of open source assets. She is founder and cur- rent Chair of the BSD Certification Group Inc., a non-profit orga- nization with a mission to create the standard for certifying BSD system administrators, and serves on the Board of the FreeBSD Foundation.