################################################################### # pf-badhost 0.6 MacOS Installation Instructions # Copyright 2018-2021 Jordan Geoghegan ################################################################### ################################################################### # Table of Contents: ################################################################### * Upgrade Instructions (upgrade from 0.5) * Fresh Install Instructions * Post Install Notes ################################################################### # Upgrade from pf-badhost 0.5 ################################################################### 1) Download updated script: $ ftp https://geoghegan.ca/pub/pf-badhost/0.6/pf-badhost.sh 2) Install script with appropriate permissions # install -m 755 -o root -g bin pf-badhost.sh /usr/local/bin/pf-badhost 3) Update pf.conf. The rules you added to your pf.conf when you installed pf-badhost should be updated to include the following: ... set limit table-entries 500000 table persist counters file "/etc/pf-badhost.txt" block in quick on egress from block out quick on egress to ... 4) pf-badhost has undergone some major changes. Please see the changelog and man page for details. pf-badhost now receives all configuration input via commandline flags. As a result, the "User Configuration Area" has been made optional, and moved to an external file that can be referenced with the '-C' flag. Users are now encouraged to use pf-badhost in a commandline driven fashion. You will need to update your cronjob to reflect these changes in configuration semantics. -- A list of blocklists maintained by members of the pf-badhost community may be found here: https://geoghegan.ca/pub/pf-badhost/data/community_lists.txt A list of common, popular blocklists may be found here: https://geoghegan.ca/pub/pf-badhost/data/popular_lists.txt An example configuration file to be loaded with '-C' may be found here: https://geoghegan.ca/pub/pf-badhost/data/pf-badhost.conf Please read the man page for information on how to configure pf-badhost. The manpage can be found here: https://geoghegan.ca/pub/pf-badhost/0.6/man/man.txt To receive notification of new pf-badhost releases and updates please send an email to 'announce@geoghegan.ca' with a subject line and body of "subscribe pf-badhost" ################################################################### # Fresh Installation Guide ################################################################### 1) Create a new user (we'll call ours "_pfbadhost"): The user should be created with default shell of "nologin" and an empty password (disables password logins) NOTE: Make sure you set the "UniqueID" and "PrimaryGroupID" to an unused value! # dscl . -create /Users/_pfbadhost # dscl . -create /Users/_pfbadhost UserShell /sbin/nologin # dscl . -create /Users/_pfbadhost RealName “_pfbadhost" # dscl . -create /Users/_pfbadhost UniqueID 1011 # Pick an unused UID here # dscl . -create /Users/_pfbadhost PrimaryGroupID 1011 # Pick an unused GID here 1.b) You may need to give the user admin privledges, but you shouldn't need to: # dscl . -append /Groups/admin GroupMembership _pfbadhost 2) Download script: $ curl https://geoghegan.ca/pub/pf-badhost/0.6/pf-badhost.sh 3) Install script with appropriate permissions: # install -m 755 -o root -g bin pf-badhost.sh /usr/local/bin/pf-badhost 4) Create required files: # install -m 640 -o _pfbadhost -g wheel /dev/null /etc/pf-badhost.txt # install -d -m 755 -o root -g wheel /var/log/pf-badhost # install -m 640 -o _pfbadhost -g wheel /dev/null /var/log/pf-badhost/pf-badhost.log # install -m 640 -o _pfbadhost -g wheel /dev/null /var/log/pf-badhost/pf-badhost.log.0.gz 5.a) Install GNU sort and RipGrep: NOTE: brew is just used as an example here, feel free to use your preferred package manager. # brew install coreutils ripgrep 5.b) OPTIONAL: Install RipGrep, mawk and/or aria2c/wget for greatly improved performance: Note: RipGrep is not available on all CPU architectures, use 'ugrep' if affected. # brew install ripgrep mawk aria2 wget 5.c) OPTIONAL: Install subnet aggregation utilities: Note: See 'Post Install Notes' section below for info on installing optional utilities. 6) Give "_pfbadhost" user permission to use sudo without a password: Run "sudo visudo" and then add the following line near the end of the file: _pfbadhost ALL = (ALL) NOPASSWD: ALL 7) Add the following lines to your pf.conf: (Putting it higher-up/earlier in the ruleset is recommended) ... set limit table-entries 500000 table persist counters file "/etc/pf-badhost.txt" block in quick on egress from block out quick on egress to ... 8) Reload your pf rule set: # pfctl -f /etc/pf.conf 9) Run pfbadhost as user "_pfbadhost": # sudo -u _pfbadhost pf-badhost Note: All configuration options must be passed via commandline options. Please read the manpage for a list of all available configuration options. You can enable additional features such as IPv6, Subnet Aggregation, Geo-Blocking, Bogon Filtering and Authlog Scanning by passing the appropriate flag on the commandline. 10) Edit _pfbadhost crontab to run pf-badhost every night at midnight: # crontab -u _pfbadhost -e ... @daily pf-badhost ... Yay! pf-badhost is now installed! With the nightly cron job, the list will be regularly updated with the latest known bad hosts. Please read the man page for information on how to configure pf-badhost. The manpage can be found here: https://geoghegan.ca/pub/pf-badhost/0.5/man/man.txt To receive notification of new pf-badhost releases and updates please send an email to 'announce@geoghegan.ca' with a subject line and body of "subscribe pf-badhost" ################################################################### # Post Install Notes: ################################################################### x) NOTE: authlog analysis is not supported on MacOS 1) The script is able to detect which (if any) subnet aggregation utilities are installed and will try to "Do The Right Thing(tm)" and fallback to the best available option. If no subnet aggregation utility is found, the script will fallback to using a pure Perl IPv4 aggregator if Perl is installed. Despite its name, "aggregate6" supports both IPv4 and IPv6 addresses and is written in Python, whereas the "aggregate" utility supports only IPv4 addresses and is written in C and uses less memory and runs slightly faster. If both utilities are installed, the C based "aggregate" utility will be preferred for IPv4 aggregation, but the script will happily function if only one or the other is installed (or neither). --- Note: Subnet aggregation can be enabled with the '-A' switch on the commandline. * "aggregate" can be installed via: # brew install aggregate * "aggregate6" can be installed via: # pip install aggregate6 * The experimental aggregator "aggy" can be installed like so: ... # brew install go $ curl https://geoghegan.ca/pub/aggy/0.1/aggy.go $ go build aggy.go # install -m 755 -o root -g bin aggy /usr/local/bin/aggy ... 2) If you intend to run pf-badhost on a LAN or are using NAT etc, you will want to negate your local subnet range from the filter. This can be equally achieved via three different methods: i) Specify rule on command line: $ pf-badhost -r '!192.0.2.0/24' -r '!2001:db8::/64' ii) Specify path to text file containing list of rules (1 per line): $ pf-badhost -w '/path/to/rules.txt' iii) Conversely, you can add a pass quick rule to your pf.conf appearing BEFORE the pf-badhost rules allowing traffic to and from your local subnet so that you can still access your gateway and any DNS servers. Something like this should do: # vi /etc/pf.conf ... pass in quick on egress from 192.0.2.0/24 pass out quick on egress to 192.0.2.0/24 table persist file "/etc/pf-badhost.txt" block in quick on egress from block out quick on egress to ...