Advertisement
Guest User

Hosts Blocking

a guest
Oct 18th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.01 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\tempacrylichosts.txt (del e:\Squid\etc\squid\hosts\tempacrylichosts*.*) ELSE echo[
  43. IF EXIST e:\Squid\etc\squid\hosts\hosts.txt (del e:\Squid\etc\squid\hosts\hosts.txt) ELSE echo[
  44.  
  45. echo Delete old shallalist databases...
  46. del e:\Squid\etc\squid\hosts\BL\*.* /S /F /Q
  47.  
  48. echo "Download new shalllist block lists..."
  49. curl -s http://www.shallalist.de/Downloads/shallalist.tar.gz -o shallalist.tar.gz
  50. echo "Uncompressing block lists..."
  51. 7za x shallalist.tar.gz
  52. 7za x shallalist1.tar -y
  53.  
  54. echo Processing shallalist blocklist domains...
  55. cat .\BL\adv\domains | sed -e "s/^/0.0.0.0 /" >> tempacrylichosts.txt
  56. cat .\BL\spyware\domains | sed -e "s/^/0.0.0.0 /" >> tempacrylichosts.txt
  57. cat .\BL\tracker\domains | sed -e "s/^/0.0.0.0 /" >> tempacrylichosts.txt
  58.  
  59. rem Quick sort and uniq as most of the domains are in the hosts file by now, this will save time later
  60. cat tempacrylichosts.txt | sort | uniq -i > tempacrylichosts.tmp
  61. mv tempacrylichosts.tmp tempacrylichosts.txt
  62.  
  63. echo Processing own blocklist domains...
  64. cat blacklist.txt | sort | uniq -i > blacklist.tmp
  65. mv blacklist.tmp blacklist.txt
  66.  
  67. echo Processing own whitelist domains...
  68. cat whitelist.txt | sort | uniq -i > whitelist.tmp
  69. mv whitelist.tmp whitelist.txt
  70.  
  71. rem continue grabbing and creating a hosts file for acrylic from various sources
  72. echo Getting fanboy malware hosts list...
  73. 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
  74.  
  75. echo Getting yoyo ad hosts list...
  76. 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
  77.  
  78. echo Getting winhelp2002 hosts list...
  79. curl -s http://winhelp2002.mvps.org/hosts.txt | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  80.  
  81. echo Getting adaway ad hosts list...
  82. 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
  83.  
  84. echo Getting hosts-file ad hosts list...
  85. 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
  86.  
  87. echo Getting malwaredomainlist malware hosts list...
  88. 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
  89.  
  90. echo Getting malwaredomains malware hosts list...
  91. curl -s http://mirror1.malwaredomains.com/files/justdomains | sed -e "s/^/0.0.0.0 /" | sed -e "$a\ " >> tempacrylichosts.txt
  92.  
  93. echo Getting blocklist.de hosts list..."
  94. curl -s https://lists.blocklist.de/lists/all.txt | sed -e "$a\ " >> tempacrylichosts.txt
  95.  
  96. echo Getting disconnectme malvertising list...
  97. 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
  98.  
  99. echo Getting disconnectme malware list...
  100. 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
  101.  
  102. echo Getting someone who cares hosts list...
  103. 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
  104.  
  105. echo Getting Mother of All Ad Blocks hosts list...
  106. 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
  107.  
  108. echo Getting add.2o7Net hosts list...
  109. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  110.  
  111. echo Getting add.Dead hosts list...
  112. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Dead/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  113.  
  114. echo Getting add.Risk hosts list...
  115. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  116.  
  117. echo Getting add.Spam hosts list...
  118. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  119.  
  120. echo Getting Badd Boyz hosts list...
  121. curl --insecure https://raw.githubusercontent.com/mitchellkrogza/Badd-Boyz-Hosts/master/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  122.  
  123. echo Getting KAD hosts list...
  124. curl --insecure https://raw.githubusercontent.com/azet12/KADhosts/master/KADhosts.txt | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  125.  
  126. echo Getting Steven Blacks hosts list...
  127. curl --insecure https://raw.githubusercontent.com/StevenBlack/hosts/master/data/StevenBlack/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  128.  
  129. echo Getting Unchecky hosts list...
  130. curl --insecure https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts | grep -v "#" | sed -e "/^$/d" | sed -e "$a\ " >> tempacrylichosts.txt
  131.  
  132. 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...
  133. 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
  134.  
  135. 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...
  136. cat tempacrylichosts2.txt facebook.txt | awk "NF>=2" | grep -v -f whitelist.txt | sort | uniq -i > tempacrylichosts3.txt
  137.  
  138. rem will extract domains from 0.0.0.0 domain entries
  139. echo Extracting IP entries and sending to squids host blocklist...
  140. 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
  141.  
  142. rem remove leading 0.0.0.0 from ip's
  143. cat hostips.txt | sed -e "s/0.0.0.0 //g" | sed -e "s/0.0.0.0//g" | sed -e "/^$/d" > hoststmp.txt
  144. rem validate xxx.xxx.xxx.xxx and remove and ip's with .00x
  145. 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
  146. echo Removing the IP entries and sending the remaining domains to Acrylic...
  147. comm -23 tempacrylichosts3.txt hostips.txt > tempacrylichosts4.txt
  148.  
  149. rem for ipv4 only
  150. cat acrylichostsheader.txt tempacrylichosts4.txt | sed -e "$a\#End Of Hosts File" > AcrylicHosts.txt
  151.  
  152. rem For ipv4 & ipv6
  153. rem cat acrylichostsheader.txt tempacrylichosts4.txt tempacrylichosts5.txt | sed -e "$a\#End Of Hosts File" > AcrylicHosts.txt
  154.  
  155. rem Count how many domains were added so it can be displayed to the user
  156. for /f "delims=" %%i in ('cat AcrylicHosts.txt ^| wc -l ^| sed -e "s/^[ \t]*//"') do @set newnumber=%%i
  157. echo[
  158. echo ______________________________
  159. echo %oldnumber% domains originally blocked
  160. echo %newnumber% domains now blocked
  161. echo ______________________________
  162. echo[
  163. if %newnumber% leq %oldnumber% (set /a new=%oldnumber% - %newnumber%) else (set /a new=%newnumber% - %oldnumber%)
  164. if %newnumber% leq %oldnumber% (echo %new% domains removed) else (echo %new% domains added)
  165.  
  166. rem Count how many domains were added so it can be displayed to the user
  167. for /f "delims=" %%i in ('cat hosts.txt ^| wc -l ^| sed -e "s/^[ \t]*//"') do @set newnumber2=%%i
  168. echo[
  169. echo ______________________________
  170. echo %oldnumber2% ips originally blocked
  171. echo %newnumber2% ips now blocked
  172. echo ______________________________
  173. echo[
  174. if %newnumber2% leq %oldnumber2% (set /a new2=%oldnumber2% - %newnumber2%) else (set /a new2=%newnumber2% - %oldnumber2%)
  175. if %newnumber2% leq %oldnumber2% (echo %new2% ips removed) else (echo %new2% ips added)
  176.  
  177. rem backup and copy acrylichosts.txt to acrylic dns folder
  178. copy /y "C:\Program Files (x86)\Acrylic DNS Proxy\AcrylicHosts.txt" "C:\Program Files (x86)\Acrylic DNS Proxy\AcrylicHosts.orig"
  179. Copy /y AcrylicHosts.txt "C:\Program Files (x86)\Acrylic DNS Proxy\"
  180.  
  181. rem remove working temp files
  182. del /q tempacrylichosts*.txt
  183.  
  184. rem restart acrylic
  185. sc stop AcrylicServiceController
  186. PING 1.1.1.1 -n 1 -w 1000 >NUL
  187. sc start AcrylicServiceController
  188.  
  189. rem restart squid
  190. sc stop squidsrv
  191. PING 1.1.1.1 -n 1 -w 3000 >NUL
  192. sc start squidsrv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement