You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

366 lines
22 KiB

  1. # dns based ad/abuse domain blocking
  2. ## Description
  3. 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 a simple 'NXDOMAIN'. This is nothing but **N**on-e**X**istent Internet or Intranet domain name, if domain name is unable to resolved using the dns server, a condition called the 'NXDOMAIN' occurred.
  4. ## Main Features
  5. * support of the following domain blocklist sources (free for private usage, for commercial use please check their individual licenses):
  6. * [adaway](https://adaway.org)
  7. * => infrequent updates, approx. 400 entries (enabled by default)
  8. * [adguard](https://adguard.com)
  9. * => numerous updates on the same day, approx. 12.000 entries
  10. * [bitcoin](https://github.com/hoshsadiq/adblock-nocoin-list)
  11. * => infrequent updates, approx. 15 entries
  12. * [blacklist]()
  13. * => static local blacklist, located by default in '/etc/adblock/adblock.blacklist'
  14. * [disconnect](https://disconnect.me)
  15. * => numerous updates on the same day, approx. 6.500 entries (enabled by default)
  16. * [dshield](http://dshield.org)
  17. * => daily updates, approx. 4.500 entries
  18. * [hphosts](https://hosts-file.net)
  19. * => monthly updates, approx. 50.000 entries
  20. * [malwaredomains](http://malwaredomains.com)
  21. * => daily updates, approx. 16.000 entries
  22. * [malwaredomainlist](http://www.malwaredomainlist.com)
  23. * => daily updates, approx. 1.500 entries
  24. * [openphish](https://openphish.com)
  25. * => numerous updates on the same day, approx. 1.800 entries
  26. * [ransomware tracker](https://ransomwaretracker.abuse.ch)
  27. * => daily updates, approx. 150 entries
  28. * [reg_cn](https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt)
  29. * => regional blocklist for China, daily updates, approx. 1.600 entries
  30. * [reg_cz](https://raw.githubusercontent.com/qxstyles/turris-hole-czech-block-list/master/turris-hole-czech-block-list)
  31. * => regional blocklist for Czechia, maintained by Turris Omnia Users, infrequent updates, approx. 100 entries
  32. * [reg_de](https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt)
  33. * => regional blocklist for Germany, daily updates, approx. 9.200 entries
  34. * [reg_id](https://easylist-downloads.adblockplus.org/abpindo+easylist.txt)
  35. * => regional blocklist for Indonesia, daily updates, approx. 800 entries
  36. * [reg_nl](https://easylist-downloads.adblockplus.org/easylistdutch+easylist.txt)
  37. * => regional blocklist for the Netherlands, weekly updates, approx. 1300 entries
  38. * [reg_pl](http://adblocklist.org)
  39. * => regional blocklist for Poland, daily updates, approx. 50 entries
  40. * [reg_ro](https://easylist-downloads.adblockplus.org/rolist+easylist.txt)
  41. * => regional blocklist for Romania, weekly updates, approx. 600 entries
  42. * [reg_ru](https://code.google.com/p/ruadlist)
  43. * => regional blocklist for Russia, weekly updates, approx. 2.000 entries
  44. * [shallalist](http://www.shallalist.de) (categories "adv" "costtraps" "spyware" "tracker" "warez" enabled by default)
  45. * => daily updates, approx. 32.000 entries (a short description of all categories can be found [online](http://www.shallalist.de/categories.html))
  46. * [spam404](http://www.spam404.com)
  47. * => infrequent updates, approx. 5.000 entries
  48. * [sysctl/cameleon](http://sysctl.org/cameleon)
  49. * => weekly updates, approx. 21.000 entries
  50. * [ut_capitole](https://dsi.ut-capitole.fr/blacklists) (categories "cryptojacking" "ddos" "malware" "phishing" "warez" enabled by default)
  51. * => daily updates, approx. 64.000 entries (a short description of all categories can be found [online](https://dsi.ut-capitole.fr/blacklists/index_en.php))
  52. * [urlhaus](https://urlhaus.abuse.ch)
  53. * => numerous updates on the same day, approx. 3.500 entries
  54. * [whocares](http://someonewhocares.org)
  55. * => weekly updates, approx. 12.000 entries
  56. * [winhelp](http://winhelp2002.mvps.org)
  57. * => infrequent updates, approx. 15.000 entries
  58. * [winspy](https://github.com/crazy-max/WindowsSpyBlocker)
  59. * => infrequent updates, approx. 120 entries
  60. * [youtube](https://api.hackertarget.com/hostsearch/?q=googlevideo.com)
  61. * => dynamic request API to filter "random" youtube ad domains (experimental!), approx. 150 entries
  62. * [yoyo](http://pgl.yoyo.org/adservers)
  63. * => weekly updates, approx. 2.500 entries (enabled by default)
  64. * [zeus tracker](https://zeustracker.abuse.ch)
  65. * => daily updates, approx. 440 entries
  66. * zero-conf like automatic installation & setup, usually no manual changes needed
  67. * simple but yet powerful adblock engine: adblock does not use error prone external iptables rulesets, http pixel server instances and things like that
  68. * supports five different dns backends / blocklist formats: dnsmasq, unbound, named (bind), kresd and dnscrypt-proxy
  69. * supports six different download utilities: uclient-fetch, wget, curl, aria2c, wget-nossl, busybox-wget
  70. * Really fast downloads & list processing as they are handled in parallel as background jobs in a configurable 'Download Queue'
  71. * provides 'http only' mode without installed ssl library for all non-SSL blocklist sources
  72. * supports a wide range of router modes, even AP modes are supported
  73. * full IPv4 and IPv6 support
  74. * provides top level domain compression ('tld compression'), this feature removes thousands of needless host entries from the blocklist and lowers the memory footprint for the dns backend
  75. * blocklist source parsing by fast & flexible regex rulesets
  76. * overall duplicate removal in central blocklist 'adb_list.overall'
  77. * additional whitelist for manual overrides, located by default in /etc/adblock/adblock.whitelist
  78. * quality checks during blocklist update to ensure a reliable dns backend service
  79. * minimal status & error logging to syslog, enable debug logging to receive more output
  80. * procd based init system support (start/stop/restart/reload/suspend/resume/query/status)
  81. * procd network interface trigger support or classic time based startup
  82. * keep the dns cache intact after adblock processing (currently supported by unbound, named and kresd)
  83. * conditional dns backend restarts by old/new blocklist comparison with sha256sum (default) or md5sum
  84. * suspend & resume adblock actions temporarily without blocklist reloading
  85. * provide comprehensive runtime information via LuCI or via 'status' init command
  86. * provide a detailed DNS Query Report with dns related information about client requests, top (blocked) domains and more
  87. * query function to quickly identify blocked (sub-)domains, e.g. for whitelisting
  88. * force dns requests to local resolver
  89. * force overall sort / duplicate removal for low memory devices (handle with care!)
  90. * automatic blocklist backup & restore, they will be used in case of download errors or during startup in backup mode
  91. * 'backup mode' to re-use blocklist backups during startup, get fresh lists only via reload or restart action
  92. * 'Jail' blocklist generation which builds an additional list (/tmp/adb_list.jail) to block access to all domains except those listed in the whitelist file. You can use this restrictive blocklist manually e.g. for guest wifi or kidsafe configurations
  93. * send notification emails in case of a processing error or if the overall domain count is ≤ 0
  94. * add new adblock sources on your own, see example below
  95. * strong LuCI support
  96. ## Prerequisites
  97. * [OpenWrt](https://openwrt.org), tested with the stable release series (18.06) and with the latest snapshot
  98. * a usual setup with an enabled dns backend at minimum - dump AP modes without a working dns backend are _not_ supported
  99. * a download utility:
  100. * to support all blocklist sources a full version (with ssl support) of 'wget', 'uclient-fetch' with one of the 'libustream-*' ssl libraries, 'aria2c' or 'curl' is required
  101. * for limited devices with real memory constraints, adblock provides also a 'http only' option and supports wget-nossl and uclient-fetch (without libustream-ssl) as well
  102. * for more configuration options see examples below
  103. * email notification (optional): for email notification support you need to install and configure the additional 'msmtp' package
  104. * DNS Query Report (optional): for this detailed report you need to install the additional package 'tcpdump-mini'
  105. ## Installation & Usage
  106. * install 'adblock' (_opkg install adblock_)
  107. * at minimum configure the appropriate dns backend ('dnsmasq' by default), the download utility and enable the adblock service in _/etc/config/adblock_
  108. * control the adblock service manually with _/etc/init.d/adblock_ start/stop/restart/reload/suspend/resume/status or use the LuCI frontend
  109. ## LuCI adblock companion package
  110. * it's strongly recommended to use the LuCI frontend to easily configure all powerful aspects of adblock
  111. * install 'luci-app-adblock' (_opkg install luci-app-adblock_)
  112. * the application is located in LuCI under 'Services' menu
  113. ## Tweaks
  114. * **runtime information:** the adblock status is available via _/etc/init.d/adblock status_ (see example below)
  115. * **debug logging:** for script debugging please set the config option 'adb\_debug' to '1' and check the runtime output with _logread -e "adblock"_
  116. * **storage expansion:** to process and 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
  117. * **add white- / blacklist entries:** add domain white- or blacklist entries to always-allow or -deny certain (sub) domains, by default both lists are empty and located in _/etc/adblock_. Please add one domain per line - ip addresses, wildcards & regex are _not_ allowed (see example below)
  118. * **backup & restore blocklists:** enable this feature, to restore automatically the latest compressed backup of your blocklists in case of any processing error (e.g. a single blocklist source is not available during update). Please use an (external) solid partition and _not_ your volatile router temp directory for this
  119. * **download queue size:** for further download & list processing performance improvements you can raise the 'adb\_maxqueue' value, e.g. '8' or '16' should be safe
  120. * **scheduled list updates:** for a scheduled call of the adblock service add an appropriate crontab entry (see example below)
  121. * **change startup behaviour:** by default the startup will be triggered by the 'wan' procd interface trigger. Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface
  122. * **suspend & resume adblocking:** to quickly switch the adblock service 'on' or 'off', simply use _/etc/init.d/adblock [suspend|resume]_
  123. * **domain query:** to query the active blocklist for a certain domain, please use the LuCI frontend or run _/etc/init.d/adblock query `<DOMAIN>`_ (see example below)
  124. * **add 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)
  125. * **disable active dns probing in windows 10:** to prevent a 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_
  126. ## Further adblock config options
  127. * usually the pre-configured adblock setup works quite well and no manual overrides are needed
  128. * the following options apply to the 'global' config section:
  129. * adb\_enabled => main switch to enable/disable adblock service (default: '0', disabled)
  130. * adb\_debug => enable/disable adblock debug output (default: '0', disabled)
  131. * adb\_fetchutil => name of the used download utility: 'uclient-fetch', 'wget', 'curl', 'aria2c', 'wget-nossl'. 'busybox' (default: 'uclient-fetch')
  132. * adb\_fetchparm => special config options for the download utility (default: not set)
  133. * adb\_dns => select the dns backend for your environment: 'dnsmasq', 'unbound', 'named', 'kresd' or 'dnscrypt-proxy' (default: 'dnsmasq')
  134. * adb\_dnsdir => target directory for the generated blocklist 'adb_list.overall' (default: not set, use dns backend default)
  135. * adb\_trigger => set the startup trigger to a certain interface, to 'timed' or to 'none' (default: 'wan')
  136. * the following options apply to the 'extra' config section:
  137. * adb\_nice => set the nice level of the adblock process and all sub-processes (int/default: '0', standard priority)
  138. * adb\_triggerdelay => additional trigger delay in seconds before adblock processing begins (int/default: '2')
  139. * adb\_forcedns => force dns requests to local resolver (bool/default: '0', disabled)
  140. * adb\_backup => create compressed blocklist backups, they will be used in case of download errors or during startup in backup mode (bool/default: '0', disabled)
  141. * adb\_backupdir => target directory for adblock backups (default: not set)
  142. * adb\_backup_mode => do not automatically update blocklists during startup, use backups instead (bool/default: '0', disabled)
  143. * adb\_report => enable the background tcpdump gathering process to provide a detailed DNS Query Report (bool/default: '0', disabled)
  144. * adb\_repdir => target directory for dns related report files generated by tcpdump (default: '/tmp')
  145. * adb\_repiface => reporting interface used by tcpdump, set to 'any' for multiple interfaces (default: 'br-lan')
  146. * adb\_replisten => space separated list of reporting port(s) used by tcpdump (default: '53')
  147. * adb\_repchunksize => report chunk size used by tcpdump in MB (int/default: '1')
  148. * adb\_repchunkcnt => report chunk count used by tcpdump (default: '5')
  149. * adb\_maxqueue => size of the download queue to handle downloads & list processing in parallel (int/default: '8')
  150. * adb\_jail => builds an additional 'Jail' list (/tmp/adb_list.jail) to block access to all domains except those listed in the whitelist file (bool/default: '0', disabled)
  151. * adb\_dnsflush => flush DNS cache after adblock processing, i.e. enable the old restart behavior (bool/default: '0', disabled)
  152. * adb\_notify => send notification emails in case of a processing error or if the overall domain count is &le; 0 (bool/default: '0', disabled)
  153. * adb\_notifycnt => Raise minimum domain count email notification trigger (int/default: '0')
  154. ## Examples
  155. **change default dns backend to 'unbound':**
  156. Adblock deposits the final blocklist 'adb_list.overall' in '/var/lib/unbound' where unbound can find them in its jail.
  157. To preserve the DNS cache after adblock processing you need to install 'unbound-control'.
  158. **change default dns backend to 'named' (bind):**
  159. Adblock deposits the final blocklist 'adb_list.overall' in '/var/lib/bind'.
  160. To preserve the DNS cache after adblock processing you need to install & configure 'bind-rdnc'.
  161. To use the blocklist please modify '/etc/bind/named.conf':
  162. <pre><code>
  163. in the 'options' namespace add:
  164. response-policy { zone "rpz"; };
  165. and at the end of the file add:
  166. zone "rpz" {
  167. type master;
  168. file "/var/lib/bind/adb_list.overall";
  169. allow-query { none; };
  170. allow-transfer { none; };
  171. };
  172. </code></pre>
  173. **change default dns backend to 'kresd':**
  174. The knot-resolver (kresd) is only available on Turris Omnia devices.
  175. Adblock deposits the final blocklist 'adb_list.overall' in '/etc/kresd', no further configuration needed.
  176. **change default dns backend to 'dnscrypt-proxy':**
  177. The required 'blacklist' option of dnscrypt-proxy is not enabled by default, because the package will be compiled without plugins support.
  178. Take a custom OpenWrt build with plugins support to use this feature. Adblock deposits the final blocklist 'adb_list.overall' in '/tmp'.
  179. To use the blocklist please modify '/etc/config/dnscrypt-proxy' per instance:
  180. <pre><code>
  181. list blacklist 'domains:/tmp/adb_list.overall'
  182. </code></pre>
  183. **enable email notification via msmtp:**
  184. To use the email notification you have to install & configure the package 'msmtp'.
  185. Modify the file '/etc/msmtprc':
  186. <pre><code>
  187. [...]
  188. defaults
  189. auth on
  190. tls on
  191. tls_certcheck off
  192. timeout 5
  193. syslog LOG_MAIL
  194. [...]
  195. account adb_notify
  196. host smtp.gmail.com
  197. port 587
  198. from dev.adblock@gmail.com
  199. user dev.adblock
  200. password xxx
  201. </code></pre>
  202. Edit the file '/etc/adblock/adblock.notify' and change at least the 'mail_receiver'.
  203. Finally make this file executable via 'chmod' and test it directly. If no more errors come up you can comment 'mail_debug', too.
  204. **receive adblock runtime information:**
  205. <pre><code>
  206. /etc/init.d/adblock status
  207. ::: adblock runtime information
  208. + adblock_status : enabled
  209. + adblock_version : 3.6.0
  210. + overall_domains : 30267 (backup mode)
  211. + fetch_utility : /bin/uclient-fetch (libustream-ssl)
  212. + dns_backend : dnsmasq (/tmp)
  213. + last_rundate : 19.12.2018 16:29:25
  214. + system_release : GL-AR750S, OpenWrt SNAPSHOT r8814-6835c13e5a
  215. </code></pre>
  216. **receive adblock DNS Query Report information:**
  217. <pre><code>
  218. /etc/init.d/adblock report
  219. :::
  220. ::: Adblock DNS-Query Report
  221. :::
  222. + Start ::: 2018-12-19, 16:29:40
  223. + End ::: 2018-12-19, 16:45:08
  224. + Total ::: 42
  225. + Blocked ::: 17 (40.48 %)
  226. :::
  227. ::: Top 10 Clients
  228. + 32 ::: 101.167.1.103
  229. + 10 ::: abc1:abc1:abc0:0:abc1:abcb:abc5:abc3
  230. :::
  231. ::: Top 10 Domains
  232. + 7 ::: dns.msftncsi.com
  233. + 4 ::: forum.openwrt.org
  234. + 2 ::: outlook.office365.com
  235. + 1 ::: www.google.com
  236. + 1 ::: www.deepl.com
  237. + 1 ::: safebrowsing.googleapis.com
  238. + 1 ::: play.googleapis.com
  239. + 1 ::: odc.officeapps.live.com
  240. + 1 ::: login.microsoftonline.com
  241. + 1 ::: test-my.sharepoint.com
  242. :::
  243. ::: Top 10 Blocked Domains
  244. + 4 ::: nexus.officeapps.live.com
  245. + 4 ::: mobile.pipe.aria.microsoft.com
  246. + 3 ::: watson.telemetry.microsoft.com
  247. + 2 ::: v10.events.data.microsoft.com
  248. + 2 ::: settings-win.data.microsoft.com
  249. + 2 ::: nexusrules.officeapps.live.com
  250. </code></pre>
  251. **cronjob for a regular block list update (/etc/crontabs/root):**
  252. <pre><code>
  253. 0 06 * * * /etc/init.d/adblock reload
  254. </code></pre>
  255. **blacklist entry (/etc/adblock/adblock.blacklist):**
  256. <pre><code>
  257. ads.example.com
  258. This entry blocks the following (sub)domains:
  259. http://ads.example.com/foo.gif
  260. http://server1.ads.example.com/foo.gif
  261. https://ads.example.com:8000/
  262. This entry does not block:
  263. http://ads.example.com.ua/foo.gif
  264. http://example.com/
  265. </code></pre>
  266. **whitelist entry (/etc/adblock/adblock.whitelist):**
  267. <pre><code>
  268. here.com
  269. This entry removes the following (sub)domains from the blocklist:
  270. maps.here.com
  271. here.com
  272. This entry does not remove:
  273. where.com
  274. www.adwhere.com
  275. </code></pre>
  276. **query the active blocklist for a certain (sub-)domain, e.g. for whitelisting:**
  277. The query function checks against the submitted (sub-)domain and recurses automatically to the upper top level domain. For every (sub-)domain it returns the first ten relevant results.
  278. <pre><code>
  279. /etc/init.d/adblock query google.com
  280. :::
  281. ::: results for domain 'google.com'
  282. :::
  283. + analytics.google.com
  284. + googleadapis.l.google.com
  285. + pagead.l.google.com
  286. + partnerad.l.google.com
  287. + ssl-google-analytics.l.google.com
  288. + www-google-analytics.l.google.com
  289. + video-stats.video.google.com
  290. :::
  291. ::: results for domain 'google.com' in backups
  292. :::
  293. + adb_list.adguard.gz partnerad.l.google.com
  294. + adb_list.adguard.gz googleadapis.l.google.com
  295. + adb_list.adguard.gz ssl-google-analytics.l.google.com
  296. + adb_list.adguard.gz [...]
  297. + adb_list.disconnect.gz pagead.l.google.com
  298. + adb_list.disconnect.gz partnerad.l.google.com
  299. + adb_list.disconnect.gz video-stats.video.google.com
  300. + adb_list.disconnect.gz [...]
  301. + adb_list.yoyo.gz analytics.google.com
  302. + adb_list.yoyo.gz pagead.l.google.com
  303. + adb_list.yoyo.gz partnerad.l.google.com
  304. + adb_list.yoyo.gz [...]
  305. </code></pre>
  306. **add a new blocklist source:**
  307. 1. the easy way ...
  308. example: https://easylist-downloads.adblockplus.org/rolist+easylist.txt
  309. Adblock already supports an easylist source, called 'reg_ru'. To add the additional local easylist as a new source, copy the existing config source section and change only
  310. the source name, the url and the description - that's all!
  311. <pre><code>
  312. config source 'reg_ro'
  313. option enabled '0'
  314. option adb_src 'https://easylist-downloads.adblockplus.org/rolist+easylist.txt'
  315. option adb_src_rset 'BEGIN{FS=\"[|^]\"}/^\|\|([^([:space:]|#|\*|\/).]+\.)+[[:alpha:]]+\^("\\\$third-party")?$/{print tolower(\$3)}'
  316. option adb_src_desc 'focus on romanian ads plus generic easylist additions, weekly updates, approx. 9.400 entries'
  317. </code></pre>
  318. 2. a bit harder ...
  319. To add a really new source with different domain/host format you have to write a suitable awk one-liner on your own, so basic awk skills are needed. As a starting point check the already existing awk rulesets 'adb_src_rset' in the config file, probably you need only small changes for your individual list. Download the desired list and test your new awk string locally. The output result should be a sequential list with one domain/host per line - nothing more. If your awk one-liner works quite well, add a new source section to the adblock config file and test the new source.
  320. ## Support
  321. Please join the adblock discussion in this [forum thread](https://forum.openwrt.org/t/adblock-support-thread/507) or contact me by mail <dev@brenken.org>
  322. ## Removal
  323. * stop all adblock related services with _/etc/init.d/adblock stop_
  324. * optional: remove the adblock package (_opkg remove adblock_)
  325. Have fun!
  326. Dirk