ad-blocking with DD-WRT revisited (simple)

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Author Message
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Feb 16, 2009 18:39    Post subject: ad-blocking with DD-WRT revisited (simple) Reply with quote
I've been asked to start a new thread to get this add-blocking to work.

I will make 2 seperate threads. One thread is a simple one. It will resolve all those nasty domains to an IP of your choice. In my example I will use 0.0.0.0 but you can also change that to an ip on which you have pixelserv running.

First enable local dns and add the line
Code:
addn-hosts=/tmp/dlhosts

And put this in startup code.
Code:
_rogue=0.0.0.0
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

or this one (which gives the possibility to add some custom hosts in either /opt/etc/hosts or /jffs/hosts):
Code:
_rogue=0.0.0.0
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\n[ -e /jffs/hosts ] && cat /jffs/hosts >>/tmp/dlhosts\n[ -e /opt/etc/hosts ] && cat /opt/etc/hosts >>/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &


I will later make another thread where I'll be using the onboard webserver to answer the webcalls.



sshot-61.png
 Description:
 Filesize:  8.89 KB
 Viewed:  43045 Time(s)

sshot-61.png



_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)


Last edited by frater on Thu Feb 26, 2009 10:44; edited 3 times in total
Sponsor
Donny
DD-WRT Guru


Joined: 13 Nov 2008
Posts: 5266
Location: CENTRAL Midnowhere

PostPosted: Mon Feb 16, 2009 21:02    Post subject: Reply with quote
Any limitations to running this? (Will it run on all builds?) What, in idjits terms, does this do? (How does it work?)
_________________
Warning: I'm "out of my element!"
http://www.youtube.com/watch?v=MjYJ7zZ9BRw&NR=1

Peacock Thread Sticky- Just read it! (Anyone using SP1 will be taken out back and shot)
http://www.dd-wrt.com/phpBB2/viewtopic.php?t=51486
freonchill
DD-WRT Guru


Joined: 17 Jul 2006
Posts: 2056

PostPosted: Mon Feb 16, 2009 21:18    Post subject: Reply with quote
how often does this download the hosts file from the internet?

will it reduce the life of the nvram? (e.g. writing to it with a file every x hours/days/etc)

_________________
2x WRT54G v5, 2x WRT54G v2
1x WRT54G-TM
1x WRT54GL
2x BUFFALO WHR-G54S
1x La Fonera
FON Client Bridge tutorial
MKruer
DD-WRT Novice


Joined: 15 Feb 2009
Posts: 18

PostPosted: Sat Feb 21, 2009 8:47    Post subject: Reply with quote
Donny:
This should run on all builds.
What is does is takes any request from a system and checks it against the list of URLS. If the URL matches, it returns the IP 0.0.0.0 instead of passing it though and getting the ad.

Freonchill:
If i am reading the code correctly its runs only upon a restart.

Now that those have been answered. The one missing component is getting pixelserv running, unless you like IE telling you the page could not be found. IMO i would rather place a message like blocked by DDWRT, but thats just me.

Edit: Is there anyway or reason why we couldn't configure the DD-WRT web service to use a second IP and link that IP to a different web page other then default, instead have to go through the entire port renaming.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sat Feb 21, 2009 9:38    Post subject: Reply with quote
I investigated this already. The http server on DD-WRT binds to all IP-addresses.
_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
MKruer
DD-WRT Novice


Joined: 15 Feb 2009
Posts: 18

PostPosted: Sun Feb 22, 2009 6:24    Post subject: Reply with quote
frater wrote:
I investigated this already. The http server on DD-WRT binds to all IP-addresses.

Is there a way to get this changed? One could make the case that if you could have two web services running at the same time, you could make main internal page accessible by LAN only as another level of protection or at least making anyone trying to get access to the router from the outside, have a false lead.

Reported as a possible tweak in the tracking software
http://www.dd-wrt.com/dd-wrtv2/bugtracker/view.php?id=3577
gaganwalia
DD-WRT User


Joined: 24 Dec 2007
Posts: 447

PostPosted: Sun Feb 22, 2009 17:46    Post subject: Reply with quote
this didnt work for me. no space on router

can we somehow do this on jffs

also, i would like to use the hosts file to point to my lanip address port 83 so that i can host a warning page there telling the client that the site was blocked by the router.

i am running httpd on port
80 (normal web server)
81 (management GUI)
82 (accounts)
83 (warning for hosts.txt file)

please give detailed instruction as i am having trouble with this.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Feb 23, 2009 11:47    Post subject: Reply with quote
You can not use another port. It's merely DNS you are fiddling with. You supply a name to the DNS-server and it responds by giving you an IP. No ports involved.

That's also the reason we are changing the port of the normal webserver in the enhanced script.

It needs to run on port 80 because the websites have links to port 80.

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
gaganwalia
DD-WRT User


Joined: 24 Dec 2007
Posts: 447

PostPosted: Tue Feb 24, 2009 18:43    Post subject: Reply with quote
i tried this method, but it is not working. the /tmp/hosts file is populated with the websites from the hosts.txt file, but seems like the hosts file is not doing the job. i am still able to open all the banned sites

i am using eko build 11650 on wrt 600N router
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Tue Feb 24, 2009 19:19    Post subject: Reply with quote
Maybe you forgot to enable local dns, enable dnsmasq or the dnsmasq option addn-hosts=/tmp/dlhosts?
What happens when you login to your router with ssh or telnet and issue the command nslookup a.abnad.net?

Of course you should use your router as your DNS-server. Check this by doing an nslookup on your local machine or an ipconfig /all

Can someone confirm it does work when following my instructions to the letter?

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
gaganwalia
DD-WRT User


Joined: 24 Dec 2007
Posts: 447

PostPosted: Wed Feb 25, 2009 4:21    Post subject: Reply with quote
what i am thinking is that the router is already using the file /tmp/hosts (and /etc/hosts is a link to this file)

if i write all those hosts from hosts.txt to the /tmp/hosts file, shouldnt it work without setting the addn-hosts=/tmp/dlhosts and enabling localdns and without changing the filename to dlhosts.

please let me know if this is possible.

also, would it make a diff. if we are using static dns in the setup section. i am using opendns servers as my static dns servers on a static IP
MKruer
DD-WRT Novice


Joined: 15 Feb 2009
Posts: 18

PostPosted: Wed Feb 25, 2009 5:19    Post subject: Reply with quote
frater, I can confirm that your script does work on my LinkSys WRT54GSv4
gaganwalia
DD-WRT User


Joined: 24 Dec 2007
Posts: 447

PostPosted: Wed Feb 25, 2009 6:54    Post subject: Reply with quote
ok, all i did is this

code:
wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep "^127.0.0.1" | grep -v localhost | awk '{print "192.168.6.1\t"$2}' | tr -d '\015' >> /tmp/hosts

192.168.6.1 is my router IP running on port 80 where i have a page saying that the site was blocked by our router

i had to disable static dns on the setup page to get this to work. if i use a static dns then it does not work.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Feb 25, 2009 7:20    Post subject: Reply with quote
gaganwalia wrote:
ok, all i did is this

code:
wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep "^127.0.0.1" | grep -v localhost | awk '{print "192.168.6.1\t"$2}' | tr -d '\015' >> /tmp/hosts

192.168.6.1 is my router IP running on port 80 where i have a page saying that the site was blocked by our router

i had to disable static dns on the setup page to get this to work. if i use a static dns then it does not work.


You are doing something else and then tell me it isn't working?
I started a totally seperate thread because I totally didn't agree with the code as it was flawed.
Now you are introducing this code in my thread which I wanted to avoid because it confuses people.

Thanks Sad

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
gaganwalia
DD-WRT User


Joined: 24 Dec 2007
Posts: 447

PostPosted: Wed Feb 25, 2009 7:27    Post subject: Reply with quote
i was not doing something else. initially i did what you had told everyone in the thread, and that did not work for me.

so i changed stuff a bit and it worked. but if youdont like the comment then you can go ahead and delete it from the thread.
Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next Display posts from previous:    Page 1 of 10
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum