Advertisement
Guest User

Host Blocking With Acrylic

a guest
Oct 18th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.91 KB | None | 0 0
  1. Title Hosts Blocklist Updater
  2. SETLOCAL ENABLEEXTENSIONS
  3. @echo off
  4. e:
  5.  
  6. cd e:\Squid\etc\squid\hosts
  7.  
  8. IF EXIST e:\Squid\etc\squid\hosts\AcrylicHosts.txt (mv e:\Squid\etc\squid\hosts\AcrylicHosts.txt e:\Squid\etc\squid\hosts\AcrylicHosts-old.txt) ELSE echo[
  9.  
  10. rem Count how many domains were in original hosts file it can be displayed later in comparison to new entries
  11. for /f "delims=" %%i in ('cat AcrylicHosts-old.txt ^| wc -l ^| sed -e "s/^[ \t]*//"') do @set oldnumber=%%i
  12.  
  13. IF EXIST e:\Squid\etc\squid\hosts\hosts.txt (mv e:\Squid\etc\squid\hosts\hosts.txt e:\Squid\etc\squid\hosts\hosts-old.txt) ELSE echo[
  14.  
  15. rem Count how many domains were in original hosts file it can be displayed later in comparison to new entries
  16. for /f "delims=" %%i in ('cat hosts-old.txt ^| wc -l ^| sed -e "s/^[ \t]*//"') do @set oldnumber2=%%i
  17.  
  18.  
  19. rem First do MS telemtry domains.....
  20. echo Download Ancile MS Spyware Hosts
  21. curl --insecure https://bitbucket.org/ancile_development/ancileplugin_networking/raw/4d47fc58ab43fedec6119261fa6ade14dab0975e/data/modify_Hosts/modify_hosts.lst | grep -v "#" | sed -e "/^$/d" | sed -e "s/^/0.0.0.0 /" | sed -e "$a\ " > tempacrylichosts.txt
  22.  
  23. echo Download Blackbird hosts file - Microsoft Telemetry
  24. curl http://www.getblackbird.net/documentation/Blackbird_Blacklist.txt | grep -v "#" | sed -e "/^$/d" | sed -e "s/^/0.0.0.0 /" | sed -e "$a\ " >> tempacrylichosts.txt
  25.  
  26. rem Grab the telemtry domains, sort and remove duplicates
  27. cat tempacrylichosts.txt | sort | uniq -i > tempwindowshosts.txt
  28. cat windowshostsheader.txt tempwindowshosts.txt > windowshosts.txt
  29.  
  30. rem backup and then overwrite the current windows hosts file - sending telemtry domains to windows hosts file just in case something bypasses Acrylic DNS...
  31. attrib -r -h "%WinDir%\System32\drivers\etc\hosts"
  32. IF EXIST "%WinDir%\System32\drivers\etc\hosts.orig" (del "%WinDir%\System32\drivers\etc\hosts.orig") ELSE echo[
  33. copy "%WinDir%\System32\drivers\etc\hosts" "%WinDir%\System32\drivers\etc\hosts.orig"
  34. copy "windowshosts.txt" "%WinDir%\System32\drivers\etc\hosts"
  35. attrib +r +h "%WinDir%\System32\drivers\etc\hosts"
  36.  
  37. rem On with the main show for Acrylic and squid....
  38.  
  39. rem Add shallalist advertising/spyware and tracker domains to hosts list
  40.  
  41. IF EXIST e:\Squid\etc\squid\hosts\shallalist*.* (del e:\Squid\etc\squid\hosts\shallalist*.*) ELSE echo[
  42. IF EXIST e:\Squid\etc\squid\hosts\hosts.txt (del e:\Squid\etc\squid\hosts\hosts.txt) ELSE echo[
  43.  
  44. echo Delete old shallalist databases...
  45. del e:\Squid\etc\squid\hosts\BL\*.* /S /F /Q
  46.  
  47. echo "Download new shalllist block lists..."
  48. curl -s http://www.shallalist.de/Downloads/shallalist.tar.gz -o shallalist.tar.gz
  49. echo "Uncompressing block lists..."
  50. 7za x shallalist.tar.gz
  51. 7za x shallalist1.tar -y
  52.  
  53. echo Processing shallalist blocklist domains...
  54. cat .\BL\adv\domains | sed -e "s/^/0.0.0.0 /" >> tempacrylichosts.txt
  55. cat .\BL\spyware\domains | sed -e "s/^/0.0.0.0 /" >> tempacrylichosts.txt
  56. cat .\BL\tracker\domains | sed -e "s/^/0.0.0.0 /" >> tempacrylichosts.txt
  57.  
  58. rem Quick sort and uniq as most of the domains are in the hosts file by now, this will save time later
  59. cat tempacrylichosts.txt | sort | uniq -i > tempacrylichosts.tmp
  60. mv tempacrylichosts.tmp tempacrylichosts.txt
  61.  
  62. echo Processing own blocklist domains...
  63. cat blacklist.txt | sort | uniq -i > blacklist.tmp
  64. mv blacklist.tmp blacklist.txt
  65.  
  66. echo Processing own whitelist domains...
  67. cat whitelist.txt | sort | uniq -i > whitelist.tmp
  68. mv whitelist.tmp whitelist.txt
  69.  
  70. rem continue grabbing and creating a hosts file for acrylic from various sources
  71. echo Getting fanboy malware hosts list...
  72. curl -s http://www.fanboy.co.nz/malwaredomains_full.txt | sed -e "/^!/d" | sed -e "/^\[/d" | sed -e "s/\^$//g" | sed -e "s/||//g" | sed -e "s/^/0.0.0.0 /" | sed -e "$a\ " >> tempacrylichosts.txt
  73.  
  74. echo Getting yoyo ad hosts list...
  75. curl -s "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext&useip=0.0.0.0" | grep -v "#" | sed -e "$a\ " >> tempacrylichosts.txt
  76.  
  77. echo Getting winhelp2002 hosts list...
  78. curl -s http://winhelp2002.mvps.org/hosts.txt | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  79.  
  80. echo Getting adaway ad hosts list...
  81. curl -k https://adaway.org/hosts.txt | grep -v "#" | sed -e "/^$/d" | sed -e "s/127.0.0.1/0.0.0.0/" | sed -e "$a\ " >> tempacrylichosts.txt
  82.  
  83. echo Getting hosts-file ad hosts list...
  84. curl -s http://hosts-file.net/.%5Cad_servers.txt | grep -v "#" | sed -e "s/\t//g" | sed -e "s/127.0.0.1/0.0.0.0 /" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  85.  
  86. echo Getting malwaredomainlist malware hosts list...
  87. curl -s http://www.malwaredomainlist.com/hostslist/hosts.txt | grep -v "#" | sed -e "s/127.0.0.1 /0.0.0.0 /" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  88.  
  89. echo Getting malwaredomains malware hosts list...
  90. curl -s http://mirror1.malwaredomains.com/files/justdomains | sed -e "s/^/0.0.0.0 /" | sed -e "$a\ " >> tempacrylichosts.txt
  91.  
  92. echo Getting blocklist.de hosts list..."
  93. curl -s https://lists.blocklist.de/lists/all.txt | sed -e "$a\ " >> tempacrylichosts.txt
  94.  
  95. echo Getting disconnectme malvertising list...
  96. curl -k https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt | sed -e "1d" | grep -v "#" | sed -e "/^$/d" | sed -e "s/^/0.0.0.0 /" | sed -e "$a\ " >> tempacrylichosts.txt
  97.  
  98. echo Getting disconnectme malware list...
  99. curl -k https://s3.amazonaws.com/lists.disconnect.me/simple_malware.txt | sed -e "1d" |grep -v "#" | sed -e "/^$/d" | sed -e "s/^/0.0.0.0 /" | sed -e "$a\ " >> tempacrylichosts.txt
  100.  
  101. echo Getting someone who cares hosts list...
  102. curl -s http://someonewhocares.org/hosts/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "s/127.0.0.1/0.0.0.0/" | sed -e "$a\ " >> tempacrylichosts.txt
  103.  
  104. echo Getting Mother of All Ad Blocks hosts list...
  105. curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0" -e http://forum.xda-developers.com/ http://adblock.mahakala.is/ | grep -v "#" | sed -e "$a\ " >> tempacrylichosts.txt
  106.  
  107. echo Getting add.2o7Net hosts list...
  108. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  109.  
  110. echo Getting add.Dead hosts list...
  111. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Dead/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  112.  
  113. echo Getting add.Risk hosts list...
  114. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  115.  
  116. echo Getting add.Spam hosts list...
  117. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  118.  
  119. echo Getting Badd Boyz hosts list...
  120. curl --insecure https://raw.githubusercontent.com/mitchellkrogza/Badd-Boyz-Hosts/master/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  121.  
  122. echo Getting KAD hosts list...
  123. curl --insecure https://raw.githubusercontent.com/azet12/KADhosts/master/KADhosts.txt | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  124.  
  125. echo Getting Steven Blacks hosts list...
  126. curl --insecure https://raw.githubusercontent.com/StevenBlack/hosts/master/data/StevenBlack/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  127.  
  128. echo Getting Unchecky hosts list...
  129. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  130.  
  131. rem remove some common lines in some of the above hosts lists that arent needed, are duplicates of static lines in hosts file header or break DNS...
  132. cat tempacrylichosts.txt | sed -e "/0.0.0.0 * localhost.localdomain/d;/0.0.0.0 * localhost/d;s/\<0\.0\.0\.0 android\>//g;s/\<0\.0\.0\.0 test\>//g;/255.255.255.255/d;/^0.0.0.0 -/d" | sed -e "/::1/d;/\t/d;/:/d;/@/d" | grep -e "^0.0.0.0" > tempacrylichosts2.txt
  133.  
  134. rem combine tempacrylichosts and facebookdomains, then remove any lone 0.0.0.0 <blank> lines, then remove any domains in whitelist, then sort and remove duplicates...
  135. cat tempacrylichosts2.txt facebook.txt | awk "NF>=2" | grep -v -f whitelist.txt | sort | uniq -i > tempacrylichosts3.txt
  136.  
  137. rem will extract domains from 0.0.0.0 domain entries
  138. echo Extracting IP entries and sending to squids host blocklist...
  139. grep -Eo "([0-9]{1,3}\.){3}[0-9]{1,3}" tempacrylichosts3.txt | sort | uniq -i | sed -e "s/^/0.0.0.0 /" > hostips.txt
  140.  
  141. rem remove leading 0.0.0.0 from ip's
  142. cat hostips.txt | sed -e "s/0.0.0.0 //g" | sed -e "s/0.0.0.0//g" | sed -e "/^$/d" > hoststmp.txt
  143. rem validate xxx.xxx.xxx.xxx and remove and ip's with .00x
  144. cat hoststmp.txt | grep -E "\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" | sed -e "s/\.00/\./g" | sed -e "/127.0.0.1/d" | sort | uniq -i > hosts.txt
  145. echo Removing the IP entries and sending the remaining domains to Acrylic...
  146. comm -23 tempacrylichosts3.txt hostips.txt > tempacrylichosts4.txt
  147.  
  148. rem for ipv4 only
  149. cat acrylichostsheader.txt tempacrylichosts4.txt | sed -e "$a\#End Of Hosts File" > AcrylicHosts.txt
  150.  
  151. rem For ipv4 & ipv6
  152. rem cat acrylichostsheader.txt tempacrylichosts4.txt tempacrylichosts5.txt | sed -e "$a\#End Of Hosts File" > AcrylicHosts.txt
  153.  
  154. rem Count how many domains were added so it can be displayed to the user
  155. for /f "delims=" %%i in ('cat AcrylicHosts.txt ^| wc -l ^| sed -e "s/^[ \t]*//"') do @set newnumber=%%i
  156. echo[
  157. echo ______________________________
  158. echo %oldnumber% domains originally blocked
  159. echo %newnumber% domains now blocked
  160. echo ______________________________
  161. echo[
  162. if %newnumber% leq %oldnumber% (set /a new=%oldnumber% - %newnumber%) else (set /a new=%newnumber% - %oldnumber%)
  163. if %newnumber% leq %oldnumber% (echo %new% domains removed) else (echo %new% domains added)
  164.  
  165. rem Count how many domains were added so it can be displayed to the user
  166. for /f "delims=" %%i in ('cat hosts.txt ^| wc -l ^| sed -e "s/^[ \t]*//"') do @set newnumber2=%%i
  167. echo[
  168. echo ______________________________
  169. echo %oldnumber2% ips originally blocked
  170. echo %newnumber2% ips now blocked
  171. echo ______________________________
  172. echo[
  173. if %newnumber2% leq %oldnumber2% (set /a new2=%oldnumber2% - %newnumber2%) else (set /a new2=%newnumber2% - %oldnumber2%)
  174. if %newnumber2% leq %oldnumber2% (echo %new2% ips removed) else (echo %new2% ips added)
  175.  
  176. rem backup and copy acrylichosts.txt to acrylic dns folder
  177. copy /y "C:\Program Files (x86)\Acrylic DNS Proxy\AcrylicHosts.txt" "C:\Program Files (x86)\Acrylic DNS Proxy\AcrylicHosts.orig"
  178. Copy /y AcrylicHosts.txt "C:\Program Files (x86)\Acrylic DNS Proxy\"
  179.  
  180. rem remove working temp files
  181. del /q tempacrylichosts*.txt
  182.  
  183. rem restart acrylic
  184. sc stop AcrylicServiceController
  185. PING 1.1.1.1 -n 1 -w 1000 >NUL
  186. sc start AcrylicServiceController
  187.  
  188. rem restart squid
  189. sc stop squidsrv
  190. PING 1.1.1.1 -n 1 -w 3000 >NUL
  191. sc start squidsrv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement