• Stars
    star
    400
  • Rank 107,843 (Top 3 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Firewall and Privatizing Proxy for Trackers, Attackers, Malware, Adware, and Spammers with Anti-Virus On-Demand and On-Access Scanning (PF, squid, privoxy, hphosts, dshield, emergingthreats, hostsfile, PAC file, clamav)

macOS-Fortress

macOS-Fortress: Firewall, Blackhole, and Privatizing Proxy for Trackers, Attackers, Malware, Adware, and Spammers; with On-Demand and On-Access Anti-Virus Scanning

Kernel-level, OS-level, and client-level security for macOS. Built to address a steady stream of attacks visible on snort and server logs, as well as blocks ads, malicious scripts, and conceal information used to track you around the web. After this package was installed, snort and other detections have fallen to a fraction with a few simple blocking actions. This setup is a lot more capable and effective than using a simple adblocking browser add-on. There's a world of difference between ad-filled web pages with and without a filtering proxy server. It's also saved me from inadvertantly clicking on phishing links.

Proxy features

Anti-Virus features

  • Configures clamAV for macOS with regular on-demand scans and on-access scanning of user Downloads and Desktop directories.
  • See the MacPorts port clamav-server for details, port notes clamav-server.

Installation

sudo port install macos-fortress
port notes macos-fortress
sudo port load macos-fortress

After initial installation, it is necessary to kickstart these launch daemons, which run on a schedule, and do not run at load time:

sudo launchctl kickstart -k system/org.macports.macos-fortress-dshield
sudo launchctl kickstart -k system/org.macports.macos-fortress-emergingthreats
sudo launchctl kickstart -k system/org.macports.macos-fortress-hphosts
sudo launchctl kickstart -k system/org.macports.adblock2privoxy
sudo launchctl kickstart -k system/org.macports.macos-fortress-easylistpac

The default web server is native macOS Apache, which must be started with the command:

sudo apachectl start

Note that all files in this repo are superceded by the MacPorts port macos-fortress, including the deprecated installation script readme-and-install.sh.

Firewall-only installation

sudo port install macos-fortress-pf
port notes macos-fortress-pf
sudo port load macos-fortress-pf

Proxy-only installation

sudo port install macos-fortress-proxy
port notes macos-fortress-proxy
sudo port load macos-fortress-proxy

Check and troubleshoot setup

sudo sh macosfortress_setup_check.sh

Working output:

Checking macOS-Fortress installed items (run as sudo)…

Checking launchd.plist files…
[βœ…] /Library/LaunchDaemons/net.openbsd.pf.plist exists
[βœ…] /Library/LaunchDaemons/net.openbsd.pf.brutexpire.plist exists
[βœ…] /Library/LaunchDaemons/net.emergingthreats.blockips.plist exists
[βœ…] /Library/LaunchDaemons/net.dshield.block.plist exists
[βœ…] /Library/LaunchDaemons/net.hphosts.hosts.plist exists
[βœ…] /Library/LaunchDaemons/com.github.essandess.easylist-pac.plist exists
[βœ…] /Library/LaunchDaemons/com.github.essandess.adblock2privoxy.plist exists
[βœ…] /Library/LaunchDaemons/com.github.essandess.adblock2privoxy.nginx.plist exists
[βœ…] /Library/LaunchDaemons/org.squid-cache.squid-rotate.plist exists
[βœ…] /Library/LaunchDaemons/org.macports.Privoxy.plist exists
[βœ…] /Library/LaunchDaemons/org.macports.clamd.plist exists
[βœ…] /Library/LaunchDaemons/org.macports.freshclam.plist exists
[βœ…] /Library/LaunchDaemons/org.macports.ClamavScanSchedule.plist exists
[βœ…] /Library/LaunchDaemons/org.macports.ClamavScanOnAccess.plist exists

Checking launchd.plist's. These should all be installed with return
code 0 (2d column of `sudo launchctl list`)…
[βœ…]	-	0	com.github.essandess.easylist-pac
[βœ…]	-	0	net.dshield.block
[βœ…]	91695	0	org.macports.ClamdScanOnAccess
[βœ…]	-	0	org.macports.freshclam
[βœ…]	-	0	net.openbsd.pf
[βœ…]	-	0	com.github.essandess.adblock2privoxy
[βœ…]	35403	0	org.macports.clamd
[βœ…]	-	0	org.macports.ClamavScanSchedule
[βœ…]	-	0	net.openbsd.pf.brutexpire
[βœ…]	-	0	net.emergingthreats.blockips
[βœ…]	36183	0	org.macports.Privoxy
[βœ…]	5578	0	com.github.essandess.adblock2privoxy.nginx
[βœ…]	-	0	net.hphosts.hosts

Checking PF files…
[βœ…] /etc/pf.conf exists
[βœ…] /usr/local/etc/blockips.conf exists
[βœ…] /usr/local/etc/emerging-Block-IPs.txt exists
[βœ…] /usr/local/etc/compromised-ips.txt exists
[βœ…] /usr/local/etc/dshield_block_ip.txt exists
[βœ…] /usr/local/etc/block.txt exists
[βœ…] /usr/local/etc/block.txt.asc exists

Checking PF…
[βœ…] PF is enabled and running

Checking hphosts files…
[βœ…] /etc/hosts-hphosts exists
[βœ…] /usr/local/etc/hosts.zip exists
[βœ…] /usr/local/etc/hphosts-partial.asp exists
[βœ…] /usr/local/etc/whitelist.txt exists
[βœ…] /usr/local/etc/blacklist.txt exists

Checking /etc/hosts-hphosts creation…
[βœ…] /etc/hosts-hphosts exists

Checking proxy PAC and proxy chain files…
[βœ…] /Library/WebServer/Documents/proxy.pac.orig exists
[βœ…] /Library/WebServer/Documents/proxy.pac exists
[βœ…] /usr/local/bin/easylist_pac.py exists
[βœ…] /usr/local/bin/adblock2privoxy exists
[βœ…] /usr/local/etc/proxy.pac exists
[βœ…] /usr/local/etc/adblock2privoxy/nginx.conf exists
[βœ…] /usr/local/etc/adblock2privoxy/css/default.html exists
[βœ…] /usr/local/etc/adblock2privoxy/privoxy/ab2p.action exists
[βœ…] /usr/local/etc/adblock2privoxy/privoxy/ab2p.filter exists
[βœ…] /usr/local/etc/adblock2privoxy/privoxy/ab2p.system.action exists
[βœ…] /usr/local/etc/adblock2privoxy/privoxy/ab2p.system.filter exists
[βœ…] /opt/local/etc/privoxy/config exists
[βœ…] /opt/local/var/log/privoxy/logfile exists

Checking proxy status…
[βœ…] Privoxy is running properly
[βœ…] Privoxy config http://p.p/ via http://localhost:3128 is running properly
[βœ…] nginx is running properly
[βœ…] PAC /Library/WebServer/Documents/proxy.pac.orig passes Javascript parsing
[βœ…] PAC /Library/WebServer/Documents/proxy.pac passes Javascript parsing
[βœ…] Web server for http://localhost/proxy.pac is running properly
[βœ…] Blackhole server for http://localhost:8119/ is running properly

Disabling

sudo port unload macos-fortress

or

sudo port uninstall macos-fortress

This repo is superceded by the MacPorts port macos-fortress, including the deprecated disable/uninstall script disable.sh, which was originally used to unload all launch daemons, disable the pf firewall, and list all installed files without removing them.

Configuration modifications

There are three major, independent, and configurable components to the repo: the PF firewall, the proxy chain, and the AV scanner. Here are a few configuration pointers.

PF firewall

The file pf.conf controls the firewall ruleset and likely must be edited on a specific computer and network, or edited for a VPN server configuration.

  • The PF firewall can be disabled with the command:

sudo pfctl -d

  • The variable int_if for the internal interface is set to en0. This should be changed to the active interface on your computer, which can be determined with the command ifconfig -a, or more specificall:

ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active' | egrep -o -m 1 '^[^\t:]+'

  • The table <lan_inet> is set to the standard reserved ranges { 10/8, 172.16/12, 192.168/16 }. This must be changed to the CIDR ranges on the specific LAN.
  • Specific services accessible only on the LAN and on the open internet should be selected and set in the appropriate variables. See /etc/services.
  • The PF firewall ruleset can be flushed, enabled, and reintialized with the command:

sudo pfctl -Fall && sudo pfctl -ef /etc/pf.conf

  • See the pfctl commands in the script pf_attacks to determine IP addresses and counts for the various blocked IPs. E.g., the adaptive table <bruteforce> is shown using the command:

sudo pfctl -t bruteforce -Ts

Proxy

Privoxy on port 8118 is configured in config to sent web requests to the internet, wih HTTPS inspection configured for blocking content within TLS encrypted tunnelsβ€”the great majorityof we content. An auxiliary nginx webserver for CSS-based element hiding is configured on port 8119. Privoxy .action and .filter files, and nginx .css files are created from Easylist rules using the repo adblock2privoxy.

Browsing to the privoxy configuration page http://p.p/ through any of these proxy configurations is a check on whether the proxy is running and configured correctly.

To provide these services on a firewalled LAN, edit the privoxy and nginx configuration files config, and nginx.conf so that they're available for devices on the LAN, or connecting from a VPN tunnel.

Macports updates

Update Macports packages regularly. This command with update the Macports database, update all installed packages, and uninstall all older, inactive versions.

sudo bash -c 'port selfupdate ; port -puN upgrade outdated ; port uninstall inactive'

Warning about Privoxy compression

Though it's possible to build Privoxy with the configure --enable-compression option, compressed HTTP traffic within a VPN tunnel exposes your traffic to the CRIME/BEAST/VORACLE attacks and is generally not recommended.

Installation details

The MacPorts port macos-fortress (sudo port install macos-fortress) installs and configures an macOS Firewall and Privatizing Proxy. It will:

  • Uses Macports to download and install several key utilities and applications (wget gnupg p7zip squid privoxy nmap)
  • Configure macOS's PF native firewall (man pfctl, man pf.conf), and privoxy
  • Networking on the local computer can be set up to use this Automatic Proxy Configuration without breaking App Store or other updates (see Privoxy config)
  • Uncomment the nat directive in pf.conf if you wish to set up an OpenVPN server
  • Install and launch daemons that download and regularly update open source IP and host blacklists. The sources are emergingthreats.net (net.emergingthreats.blockips.plist), dshield.org (net.dshield.block.plist), hosts-file.net (net.hphosts.hosts.plist)
  • After installation the connection between clients and the internet looks this this:

Application ➑️ proxy.pac ➑️port 8118➑️ Privoxy ➑️ Internet

An auxilliary nginx-based webserver (nominally on localhost:8119) is used for both a proxy.pac ad and tracker blackhole and for CSS element blocking rules with the Privoxy configuration generated by adblock2privoxy.

Public Service Announcement

This firewall is configured to block all known tracker and adware contentβ€”in the browser, in-app, wherever it finds them. Many websites now offer an additional way to block ads: subscribe to their content. Security and privacy will always necessitate ad blocking, but now that this software has become mainstream with mainstream effects, ad blocker users must consider the potential impact of ad blocking on the writers and publications that are important to them. Personally, two publications that I gladly pay for, especially for their important 2016 US Presidential election coverage, are the New York Times and The Atlantic. I encourage all users to subscribe to their own preferred publications and writers.

Tracker blocking

Lightbeam, the tracking tracker Firefox add-on, shows how ad- and tracker-blocking works to prevent third parties monitoring you or your children's online activities. My daughter enjoys the learning exercises at the children's website ABCya!. The Lightbeam graph below on the left shows all the third party trackers after less than a minute of browser activity, without using a privatizing proxy. The graph on the right shows all this tracker activity blocked when this privatizing proxy is used.

Lightbeam graph without proxy Lightbeam graph without proxy
Lightbeam graph without proxy Lightbeam graph with proxy

This problem is the subject of Gary Kovacs's TED talk, Tracking Our Online Trackers:

Tracking our online trackers

Attack blocking

The snort intrusion detection system reports far fewer events when known attack sites are blackholed by the packet filter:

snort+BASE Overview snort+BASE Events
snort+BASE Overview snort+BASE Events

Notes

  • Configure the squid proxy to accept connections on the LAN IP and set LAN device Automatic Proxy Configurations to http://lan_ip/proxy.pac to protect devices on the LAN.
  • Count the number of attacks since boot with the script pf_attacks. ``Attack'' is defined as the number of blocked IPs in PF's bruteforce table plus the number of denied connections from blacklisted IPs in the tables compromised_ips, dshield_block_ip, and emerging_threats.
  • Both squid and Privoxy are configured to forge the User-Agent. The default is an iPad to allow mobile device access. Change this to your local needs if necessary.
  • Whitelist or blacklist specific domain names with the files /usr/local/etc/whitelist.txt and /usr/local/etc/blacklist.txt. After editing these file, use launchctl to unload and load the plist /Library/LaunchDaemons/net.hphosts.hosts.plist, which recreates the hostfile /etc/hosts-hphost and reconfigures the squid proxy to use the updates.
  • Sometimes pf and privoxy do not launch at boot, in spite of the use of the use of their launch daemons. Fix this by hand after boot with the scripts macosfortress_boot_check, or individually using pf_restart, privoxy_restart, and squid_restart. And please post a solution if you find one.
  • All open source updates are done using the wget -N option to save everyone's bandwidth

Security

  • These services are intended to be run on a secure LAN behind a router firewall.
  • The default proxy configuration will only accept connections made from the local computer (localhost). If you change this to accept connections from any client on your LAN, do not configure the router to forward ports 8118, or you will be running an open web proxy.