PF-BADHOST(8) | System Manager's Manual | PF-BADHOST(8) |
pf-badhost
—
fetch, validate and parse blocklist data for pf
pf-badhost |
[-4 | -6 |
-B ] [-ADVbnx ]
[-C config-file]
[-H maxauthtries
[-E extract-tool
-J log-file
-K log-file]]
[-P maxprocs]
[-R retrylimit]
[-T
allow |block |block-exit ]
[-U useragent]
[-W output-file]
[-a asn]
[-c ip-address]
[-f blocklist-file]
[-g cctld]
[-i ip-file]
[-j asn-file]
[-l url-file]
[-m asn-url-file]
[-o long-option]
[-r rule]
[-s cctld-file]
[-t asn-url]
[-u url]
[-w rule-file]
[file ...] |
pf-badhost |
-h | -v |
pf-badhost
fetches, validates and parses
IP, ASN, and geo-location data into a format suitable for ingestion by the
pf(4) firewall.
By default the generated blocklist is output to the file /etc/pf-badhost.txt and loaded into a pf(4) table named pfbadhost.
pf-badhost
expects to be run as an
unprivileged user named _pfbadhost. This user must have
permission to use pfctl(8) granted to it via either
doas(1) or sudo(1).
Blocklists may be generated and exported to stdout without any special permissions.
Comments can be included in the various files passed to
pf-badhost
by starting the line with a hash mark
(‘#’) or semi-colon (‘;’) and will continue to
the end of the line.
The options are as follows:
-4
-6
-A
-B
-C
config-file-D
pf-badhost
expects
to be run as the unpriviliged user _pfbadhost and this
option disables that check.-E
extract-tool-H
maxauthtriesWhen enabled, the systems default authentication logs will be
used. Alternate log files may be specified with the
-J
and -K
options.
-J
log-file-K
log-file-P
maxproc0
may be specified to disable parallelism.-R
retrylimit0
may be specified to disable re-attempts.-T
argallow
block
block-exit
-U
useragent-V
-W
output-file-a
asn-b
-c
ip-address-f
blocklist-file-g
cctld-h
-i
ip-file-c
.-j
asn-file-l
url-file-m
asn-url-file-n
-o
long-optioncustom-filter
|
no-custom-filter
-C
option. Disabled by default.export-raw
-x
.ipv4-reserved
|
no-ipv4-reserved
ipv6-reserved
|
no-ipv6-reserved
log
|
no-log
mirror
|
no-mirror
ssh-nopass
-H
description.
Use of this option with SSH password authentication enabled will
likely result in incorrect accounting of bruteforcer attempts.strict
|
no-strict
uid-check
|
no-uid-check
-D
description. Enabled by
default.verbose
|
no-verbose
The following options are useful for debugging, statistics and firewall table manipulation. These options are mutually exclusive and the last specified option will take precedence.
flush-table
print-debug
show-stats
show-stats-address
show-stats-global
The following URL fetch utilities are supported and unless overridden by specifying one of the options below, will be used in the following order of preference if found on the system: aria2c, wget, curl, fetch, ftp.
The following grep(1) utilities are supported and unless overridden by specifying one of the options below, will be used in the following order of preference if found on the system: ripgrep, ugrep, ggrep, grep.
The following awk(1) utilities are supported and unless overridden by specifying one of the options below, will be used in the following order of preference if found on the system: mawk, gawk, goawk, awk.
-r
rule-s
cctld-file-t
asn-url-u
url-v
-w
rule-file-x
-D
and -o
no-log.The pf-badhost
utility exits 0 on
success, and >0 if an error occurs.
Fetch IP blocklist data from URL list and print to stdout:
$ pf-badhost -Bxl /etc/pf-badhost/urls
Verify configuration file validity:
$ pf-badhost -C /etc/pf-badhost.conf -n
Block bogons and specify custom rule to whitelist local subnet:
$ pf-badhost -br '!192.0.2.0/24'
Block an aggregated list of all IP addresses registered to Australia:
$ pf-badhost -ABg AU
Block an aggregated list of all IPv4 addresses announced from Apple's ASN:
$ pf-badhost -4Aa AS714
Enforce sanctions by blocking a list of country codes from a file:
$ pf-badhost -s /etc/pf-badhost/axis-of-evil
Add any IP address with 25 or more failed sshd(8) logins to blocklist:
$ pf-badhost -H 25
Enabled sshd(8) authentication log analysis with custom paths:
$ pf-badhost -H 25 -J /tmp/authlog
pf-badhost
does not strictly conform to
the POSIX shell specification and instead aims for ksh(1)
compatibility.
Jordan Geoghegan <jordan@geoghegan.ca>
The IPv6 address parser may fail to match against IPv6 addresses terminated with a carriage return (0x0d). This is due to a limitation in both BSD and GNU grep(1) but can be mitigated by using ripgrep or ugrep.
The IPv6 address parser requires addresses to be formatted one per line. This is in contrast to the IPv4 address parser which supports arbitrary input formatting (text, JSON, XML, HTML, etc).
On platforms that use FreeGrep (OpenBSD, MacOS) performance may be very slow and may even (on MacOS) segfault on the IPv6 regex. It is strongly recommended to replace the use of FreeGrep with ripgrep or ugrep.
If the pfbadhost table exceeds the default pf(4) table size limit of 100,000 entries then the limit will need to be raised. Users with large blocklists are additionally encouraged to enable subnet aggregation. The pf(4) table size limit can be raised by adding the following line to pf.conf(5).
set limit table-entries 500000
October 28, 2021 | OpenBSD 7.0 |