4831d27db87c45a30ffc1639ad1f9a469d5f76e3
[feed/packages.git] / net / adblock / files / README.md
1 # dns based ad/abuse domain blocking
2
3 ## Description
4 A lot of people already use adblocker plugins within their desktop browsers, but what if you are using your (smart) phone, tablet, watch or any other wlan gadget...getting rid of annoying ads, trackers and other abuse sites (like facebook ;-) is simple: block them with your router. When the dns server on your router receives dns requests, you will sort out queries that ask for the resource records of ad servers and return the local ip address of your router and the internal web server delivers a transparent pixel instead.
5
6 ## Main Features
7 * support of the following domain blocklist sources (free for private usage, for commercial use please check their individual licenses):
8 * [adaway](https://adaway.org)
9 * => infrequent updates, approx. 400 entries (enabled by default)
10 * [blacklist]()
11 * => static local blacklist, located by default in '/etc/adblock/adblock.blacklist'
12 * [disconnect](https://disconnect.me)
13 * => numerous updates on the same day, approx. 6.500 entries (enabled by default)
14 * [dshield](http://dshield.org)
15 * => daily updates, approx. 4.500 entries
16 * [feodotracker](https://feodotracker.abuse.ch)
17 * => daily updates, approx. 0-10 entries
18 * [malwaredomains](http://malwaredomains.com)
19 * => daily updates, approx. 16.000 entries
20 * [malwaredomainlist](http://www.malwaredomainlist.com)
21 * => daily updates, approx. 1.500 entries
22 * [openphish](https://openphish.com)
23 * => numerous updates on the same day, approx. 1.800 entries
24 * [palevo tracker](https://palevotracker.abuse.ch)
25 * => daily updates, approx. 15 entries
26 * [ransomware tracker](https://ransomwaretracker.abuse.ch)
27 * => daily updates, approx. 150 entries
28 * [rolist/easylist](https://easylist-downloads.adblockplus.org/rolist+easylist.txt)
29 * => weekly updates, approx. 600 entries
30 * [ruadlist/easylist](https://code.google.com/p/ruadlist)
31 * => weekly updates, approx. 2.000 entries
32 * [shallalist](http://www.shallalist.de) (categories "adv" "costtraps" "spyware" "tracker" "warez" enabled by default)
33 * => daily updates, approx. 32.000 entries (a short description of all shallalist categories can be found [online](http://www.shallalist.de/categories.html))
34 * [spam404](http://www.spam404.com)
35 * => infrequent updates, approx. 5.000 entries
36 * [sysctl/cameleon](http://sysctl.org/cameleon)
37 * => weekly updates, approx. 21.000 entries
38 * [whocares](http://someonewhocares.org)
39 * => weekly updates, approx. 12.000 entries
40 * [winhelp](http://winhelp2002.mvps.org)
41 * => infrequent updates, approx. 15.000 entries
42 * [winspy](https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/hosts/windows10_spy.txt)
43 * => infrequent updates, approx. 120 entries
44 * [yoyo](http://pgl.yoyo.org/adservers)
45 * => weekly updates, approx. 2.500 entries (enabled by default)
46 * [zeus tracker](https://zeustracker.abuse.ch)
47 * => daily updates, approx. 440 entries
48 * zero-conf like automatic installation & setup, usually no manual changes needed (i.e. ip address, network devices etc.)
49 * supports a wide range of router modes (incl. AP mode), as long as the firewall and the DNS server are enabled
50 * full IPv4 and IPv6 support
51 * each blocklist source will be updated and processed separately
52 * timestamp check to download and process only updated adblock list sources
53 * overall duplicate removal in separate adblock lists (will be automatically disabled on low memory systems)
54 * adblock source list parsing by fast & flexible regex rulesets
55 * additional whitelist for manual overrides, located by default in /etc/adblock/adblock.whitelist
56 * quality checks during & after update of adblock lists to ensure a reliable dnsmasq service
57 * basic adblock statistics via iptables packet counters
58 * list states, (overall) list counts & last update time will be stored in uci config
59 * status & error logging to stdout and syslog
60 * use a dynamic uhttpd instance as an adblock pixel server
61 * use dynamic iptables rulesets for adblock related redirects/rejects
62 * openwrt init system support (start/stop/restart/reload)
63 * hotplug support, the adblock start will be triggered by wan 'ifup' event
64 * optional: automatic adblock list backup/restore, backups will be (de-)compressed on the fly (disabled by default)
65 * optional: add new adblock sources via uci config (see example below)
66
67 ## Prerequisites
68 * [openwrt](https://openwrt.org), tested with latest stable release (Chaos Calmer) and with current trunk (Designated Driver)
69 * [LEDE project](https://www.lede-project.org), tested with trunk > r98
70 * usual setup with enabled 'iptables', 'dnsmasq' and 'uhttpd' - dump AP modes without these basics are _not_ supported!
71 * additional required software packages:
72 * wget
73 * optional: 'kmod-ipt-nat6' for IPv6 support
74 * the above dependencies and requirements will be checked during package installation & script runtime
75
76 ## OpenWrt / LEDE trunk Installation & Usage
77 * install 'adblock' (_opkg install adblock_)
78 * adblock starts automatically during boot, triggered by wan-ifup event, check _logread -e "adblock"_ for adblock related information
79 * optional: start/restart/stop the adblock service manually with _/etc/init.d/adblock_
80 * optional: enable/disable your required adblock list sources in _/etc/config/adblock_ - 'adaway', 'disconnect' and 'yoyo' are enabled by default
81 * optional: maintain the adblock service in luci under 'System => Startup'
82
83 ## LuCI adblock companion package
84 * for easy management of the various blocklist sources and adblock options there is also a nice & efficient LuCI frontend available
85 * install 'luci-app-adblock' (_opkg install luci-app-adblock_)
86 * the application is located in LuCI under 'Services' menu
87 * _Thanks to Hannu Nyman for this great adblock LuCI frontend!_
88
89 ## Chaos Calmer installation notes
90 * 'adblock' and 'luci-app-adblock' are _not_ available as .ipk packages in the Chaos Calmer download repository
91 * download both packages from a development snapshot package directory:
92 * for 'adblock' look [here](https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/packages/)
93 * for 'luci-app-adblock' look [here](https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/luci/)
94 * manually transfer the packages to your routers temp directory (with tools like _sshfs_ or _winscp_)
95 * install the packages with _opkg install <...>_ as described above
96
97 ## Tweaks
98 * **storage:** to process & store all blocklist sources at once it might helpful to enlarge your temp directory with a swap partition => see [openwrt wiki](https://wiki.openwrt.org/doc/uci/fstab) for further details
99 * **white-/blacklist:** add domain white- or blacklist entries to always-allow or -deny certain (sub) domains, by default both lists are located in _/etc/adblock_. Please add one domain per line - ip addresses, wildcards & regex are _not_ allowed (see example below)
100 * **backup/restore:** enable the backup/restore feature, to restore automatically the latest compressed backup of your adblock lists in case of any processing error (i.e. a single blocklist source is down). Please use an (external) solid partition and _not_ your volatile router temp directory for this
101 * **list updates:** for a scheduled call of the adblock service add an appropriate crontab entry (see example below)
102 * **new list sources:** you could add new blocklist sources on your own via uci config, all you need is a source url and an awk one-liner (see example below)
103 * **AP mode:** in AP mode adblock uses automatically the local router ip as nullip address. To make sure that your LuCI interface will be still accessible, please change the local uhttpd instance to ports <> 80/443 (see example below)
104 * **debugging:** for script debugging please change the 'DEBUG' variable in the header of _/usr/bin/adblock-update.sh_ from '0' to '1' and start this script directly (without any parameters)
105 * **disable active dns probing in windows:** to prevent a possible yellow exclamation mark on your internet connection icon (which wrongly means connected, but no internet), please change the following registry key/value from "1" to "0" _HKLM\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\EnableActiveProbing_
106
107 ## Further adblock config options
108 * usually the adblock autodetection works quite well and no manual config overrides are needed, all options apply to the 'global' config section:
109 * adb\_enabled => main switch to enable/disable adblock service (default: '1', enabled)
110 * adb\_cfgver => config version string (do not change!) - adblock will check this entry during startup
111 * adb\_lanif => name of the logical lan interface (default: 'lan')
112 * adb\_nullport => port of the adblock uhttpd instance (default: '65535')
113 * adb\_nullipv4 => IPv4 blackhole ip address (default: '192.0.2.1', in AP mode: local router ip)
114 * adb\_nullipv6 => IPv6 blackhole ip address (default: '::ffff:c000:0201', in AP mode: local router ip)
115 * adb\_forcedns => redirect all DNS queries to local dnsmasq resolver (default: '1', enabled)
116
117 ## Examples
118
119 **example cronjob for a regular block list update:**
120 <pre><code>
121 # configuration found in /etc/crontabs/root
122 # start adblock script once a day at 6 a.m.
123 #
124 0 06 * * * /etc/init.d/adblock start
125 </code></pre>
126
127 **example blacklist entry (/etc/adblock/adblock.blacklist):**
128 <pre><code>
129 ads.example.com
130
131 This rule blocks:
132 http://ads.example.com/foo.gif
133 http://server1.ads.example.com/foo.gif
134 https://ads.example.com:8000/
135
136 This rule doesn't block:
137 http://ads.example.com.ua/foo.gif
138 http://example.com/
139 </code></pre>
140
141 **example whitelist entry (/etc/adblock/adblock.whitelist):**
142 <pre><code>
143 analytics.com
144
145 This rule removes _all_ domains from the blocklists with this string in it, i.e.:
146 google-analytics.com
147 ssl.google-analytics.com
148 api.gameanalytics.com
149 photos.daily-deals.analoganalytics.com
150 adblockanalytics.com
151 </code></pre>
152
153 **example uhttpd configuration in AP mode:**
154 <pre><code>
155 # configuration found in /etc/config/uhttpd
156 # change default http/https ports <> 80/443
157 #
158 config uhttpd 'main'
159 list listen_http '0.0.0.0:88'
160 list listen_https '0.0.0.0:445'
161 </code></pre>
162
163 **example grep for blocked (sub-)domains in adblock source files:**
164 <pre><code>
165 grep "google-analytics.com" "/tmp/dnsmasq.d/adb_list"*
166
167 This will output all matches with corresponding source files:
168 /tmp/dnsmasq.d/adb_list.winhelp:address=/ssl.google-analytics.com/192.0.2.1
169 /tmp/dnsmasq.d/adb_list.winhelp:address=/www.google-analytics.com/192.0.2.1
170 /tmp/dnsmasq.d/adb_list.yoyo:address=/google-analytics.com/192.0.2.1
171 </code></pre>
172
173 **example to find blocked domains on certain sites for whitelisting:**
174 <pre><code>
175 1. the easy way ...
176 enable the network analysis builtins in chrome or firefox to identify domains
177 which are redirected to the adblock null-ip (default 192.0.2.1), add these domains to your whitelist
178
179 2. a bit harder ...
180 enable 'Log queries' in the dnsmasq configuration (via LuCI Network => DHCP/DNS),
181 ssh to your router and start tracing with 'logread -f -e "dnsmasq" -e "192.0.2.1"'
182 switch to your client, access the relevant site and check all domains
183 that are blocked/listed in logread, add these domains to your whitelist
184
185 => finally restart the adblock service (/etc/init.d/adblock restart) in both variants
186 </code></pre>
187
188 **example to add a new blocklist source:**
189 <pre><code>
190 1. the easy way ...
191 example: https://easylist-downloads.adblockplus.org/rolist+easylist.txt
192 adblock already supports an easylist source, called 'ruadlist'. To add the additional local easylist
193 as a new source, copy the existing config source 'ruadlist' section and change only
194 the source name, the url and the description - that's all!
195
196 config source 'rolist'
197 option enabled '0'
198 option adb_src 'https://easylist-downloads.adblockplus.org/rolist+easylist.txt'
199 option adb_src_rset '{FS=\"[|^]\"} \$0 ~/^\|\|([A-Za-z0-9_-]+\.){1,}[A-Za-z]+\^$/{print tolower(\$3)}'
200 option adb_src_desc 'focus on romanian ad related domains plus generic easylist additions, weekly updates, approx. 600 entries'
201
202 2. a bit harder ...
203 to add a really new source with different domain/host format you have to write a suitable
204 awk one-liner on your own, so basic awk skills are needed. As a starting point check the already
205 existing awk strings (adb_src_rset) in adblock config, maybe you need only small changes for your individual list.
206 Download the desired list and test your new awk string locally with:
207 cat new.list | awk 'fs__individual search__search core__result'
208 'fs' => field separator (optional)
209 'individual search' => individual search part to filter out needless list information
210 'search core' => always '([A-Za-z0-9_-]+\.){1,}[A-Za-z]+', this is part of all list sources and should be unchanged
211 'result' => always '{print tolower(\$n)}', only the output column 'n' may vary
212 the output result should be a sequential list with one domain/host per line - nothing more.
213
214 If your awk one-liner works quite well, add a new source section in adblock config and test your new source
215 </code></pre>
216
217 ## Background
218 This adblock package is a dns/dnsmasq based adblock solution.
219 Queries to ad/abuse domains are never forwarded and always replied with a local IP address which may be IPv4 or IPv6.
220 For that purpose adblock uses an ip address from the private 'TEST-NET-1' subnet (192.0.2.1 / ::ffff:c000:0201) by default (in AP mode the local router ip address will be used).
221 Furthermore all ad/abuse queries will be filtered by ip(6)tables and redirected to internal adblock pixel server (in PREROUTING chain) or rejected (in FORWARD or OUTPUT chain).
222 All iptables and uhttpd related adblock additions are non-destructive, no hard-coded changes in 'firewall.user', 'uhttpd' config or any other openwrt related config files. There is _no_ adblock background daemon running, the (scheduled) start of the adblock service keeps only the adblock lists up-to-date.
223
224 ## Support
225 Please join the adblock discussion in this [openwrt forum thread](https://forum.openwrt.org/viewtopic.php?id=59803) or contact me by mail <dev@brenken.org>
226
227 ## Removal
228 * stop all adblock related services with _/etc/init.d/adblock stop_
229 * optional: remove the adblock package (_opkg remove adblock_)
230
231 Have fun!
232 Dirk