Skip to content

Instantly share code, notes, and snippets.

@mudge

mudge/blocklist.sh

Last active Oct 6, 2020
Embed
What would you like to do?
A Bash script to generate an Unbound configuration to block all domains on The Firebog's "The Big Blocklist Collection" and allow all domains on Anudeep's list
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Download all ticked blocklists from The Firebog's "The Big Blocklist
# Collection" [0] and block access to them with Unbound by redirecting traffic
# to 0.0.0.0.
#
# [0]: https://firebog.net
(
# Suspicious Lists
curl -sSf "https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts_without_controversies.txt" ;
curl -sSf "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts" ;
curl -sSf "https://v.firebog.net/hosts/static/w3kbl.txt" ;
# Advertising Lists
curl -sSf "https://adaway.org/hosts.txt" ;
curl -sSf "https://v.firebog.net/hosts/AdguardDNS.txt" ;
curl -sSf "https://v.firebog.net/hosts/Admiral.txt" ;
curl -sSf "https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt" ;
curl -sSf "https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt" ;
curl -sSf "https://v.firebog.net/hosts/Easylist.txt" ;
curl -sSf "https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" ;
curl -sSf "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts" ;
curl -sSf "https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts" ;
# Tracking & Telemetry Lists
curl -sSf "https://v.firebog.net/hosts/Easyprivacy.txt" ;
curl -sSf "https://v.firebog.net/hosts/Prigent-Ads.txt" ;
curl -sSf "https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt" ;
curl -sSf "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts" ;
curl -sSf "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt" ;
curl -sSf "https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt" ;
# Malicious Lists
curl -sSf "https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt" ;
curl -sSf "https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt" ;
curl -sSf "https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt" ;
curl -sSf "https://mirror1.malwaredomains.com/files/justdomains" ;
curl -sSf "https://v.firebog.net/hosts/Prigent-Crypto.txt" ;
curl -sSf "https://v.firebog.net/hosts/Prigent-Malware.txt" ;
curl -sSf "https://mirror.cedia.org.ec/malwaredomains/immortal_domains.txt" ;
curl -sSf "https://www.malwaredomainlist.com/hostslist/hosts.txt" ;
curl -sSf "https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt" ;
curl -sSf "https://phishing.army/download/phishing_army_blocklist_extended.txt" ;
curl -sSf "https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt" ;
curl -sSf "https://v.firebog.net/hosts/Shalla-mal.txt" ;
curl -sSf "https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt" ;
curl -sSf "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts" ;
curl -sSf "https://urlhaus.abuse.ch/downloads/hostfile/" ;
# Other Lists
curl -sSf "https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser" ;
) |
cat | # Combine all lists into one
grep '^0\.0\.0\.0' | # Filter out any comments, etc. that aren't rules
tr -d '\r' | # Normalize line endings by removing Windows carriage returns
sort -u | # Remove any duplicates
awk '{print "local-zone: \""$2".\" redirect\nlocal-data: \""$2". IN A 0.0.0.0\"\nlocal-data: \""$2". IN AAAA ::\""}' # Convert to Unbound configuration
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Download Anudeep's commonly safelisted domains [0] and allow Unbound lookups to them.
#
# [0]: https://github.com/anudeepND/whitelist
curl -sSf "https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt" |
sort -u | # Remove any duplicates
awk '{print "local-zone: \""$1".\" always_transparent"}' # Convert to Unbound configuration
server:
verbosity: 0
interface: 0.0.0.0
access-control: 192.168.1.0/24 allow
port: 53
do-ip4: yes
do-ip6: no
do-udp: yes
do-tcp: yes
root-hints: "/var/lib/unbound/root.hints"
harden-glue: yes
# Require DNSSEC data for trust-anchored zones, if such data is absent, the zone becomes BOGUS
harden-dnssec-stripped: yes
# Don't use Capitalization randomization as it known to cause DNSSEC issues sometimes
# see https://discourse.pi-hole.net/t/unbound-stubby-or-dnscrypt-proxy/9378 for further details
use-caps-for-id: no
# Reduce EDNS reassembly buffer size.
# Suggested by the unbound man page to reduce fragmentation reassembly problems
edns-buffer-size: 1472
# Perform prefetching of close to expired message cache entries
# This only applies to domains that have been frequently queried
prefetch: yes
# One thread should be sufficient, can be increased on beefy machines. In reality for most users running on small networks or on a single machine, it should be unnecessary to seek performance enhancement by increasing num-threads above 1.
num-threads: 1
# Ensure kernel buffer is large enough to not lose messages in traffic spikes
so-rcvbuf: 1m
# Ensure privacy of local IP ranges
private-address: 192.168.0.0/16
private-address: 169.254.0.0/16
private-address: 172.16.0.0/12
private-address: 10.0.0.0/8
private-address: fd00::/8
private-address: fe80::/10
# Include blocklist and safelist
include: /etc/unbound/lists.d/*.conf
#!/bin/bash
set -euo pipefail
/opt/blocklists/safelist.sh > /etc/unbound/lists.d/01-safelist.conf
/opt/blocklists/blocklist.sh > /etc/unbound/lists.d/02-blocklist.conf
service unbound reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.