Best solution for blocking certain websites in Windows?

Hey experts,

I have a task to write a parental control application for blocking certain black list websites.

I guess two solution that came to my mind was either using a NDIS or WFP to check DNS requests and block if the dns request matches one of the black listed websites.

So which of them is better for this task? or is there any easier solution than this?

Also note that there are situations such as DNSsec, is this possible to do in case an application uses DNssec?

A proxy is even easier. It runs in user mode, and runs no risk of blue screens.

Easier yet is to add the domains to \windows\system32\drivers\etc\hosts with fake IP addresses.

1 Like

@Tim_Roberts said:
A proxy is even easier. It runs in user mode, and runs no risk of blue screens.

Easier yet is to add the domains to \windows\system32\drivers\etc\hosts with fake IP addresses.

Doesnā€™t that require the user to manually import certificates because of ssl issues? And Is there any provided API for this task?

And I donā€™t think adding domains to hosts will not block them in the case of DNSsec, not sure about the proxy solution tho.

@brad_H said:
Hey experts,

I have a task to write a parental control application for blocking certain black list websites.

I guess two solution that came to my mind was either using a NDIS or WFP to check DNS requests and block if the dns request matches one of the black listed websites.

So which of them is better for this task? or is there any easier solution than this?

Also note that there are situations such as DNSsec, is this possible to do in case an application uses DNssec?

Itā€™s going to be exceptionally difficult, IMHO ā€¦ were it me I would simply purchase an off the shelf solution like NetNanny and be done with it. Hereā€™s why ā€¦ (and you likely already know this, this is just for the benefit of others who might find this on a search) ā€¦ other than the most trivial websites, everyone uses essentially a front facing well known IP address and a slew of servers that the actual connection is made to ā€¦ so you surf to ā€œyoutube.comā€ [142.250.189.174] but when you pick a video to watch and you look at a connection viewer youā€™ll find a different address actually serving the content. That means if you ā€œblackholeā€ the ā€œyoutube.comā€ address in ā€œhostsā€ or by blocking that connection in WFP or in an NDIS handler unless you ā€œblackholeā€ the actual service address sending the content all youā€™re doing is forcing someone to use a different front facing address (which will change based on region, the content provider using a DDOS blocker like CloudFlare or even due to load balancing, as itā€™s just a DNS entry). Thatā€™s a reverse of the problem that content providers like NetFlix face, where they want to restrict certain regions from getting content and people simply use a VPN to change their address ā€¦

Youā€™re going to be playing an eternal ā€œwhack-a-moleā€ game if you go down the ā€œblock the IP addressā€ route other than for the guy with a WordPress app running on his computer in the basement connected to a ComCast router, essentially, which is what the commercial applications have to do and why they issue daily updates ā€¦ itā€™s going to be easier to simply acknowledge that and go drop the $30 for the subscription ā€¦

Make them use the right browser. The good Microsoft will take care of the rest.
Filter websites and searches in Microsoft Edge

Tragically (not), Edge is slated to be taken out back, told to look at the sunset and dispatched like Cortana, Clippy and IoT Core [ https://9to5google.com/2020/08/18/microsoft-edge-legacy-replaced-chromium/ ] ā€¦ Microsoft is indeed taking care of the rest ā€¦

@craig_howard said:

@brad_H said:
Hey experts,

I have a task to write a parental control application for blocking certain black list websites.

I guess two solution that came to my mind was either using a NDIS or WFP to check DNS requests and block if the dns request matches one of the black listed websites.

So which of them is better for this task? or is there any easier solution than this?

Also note that there are situations such as DNSsec, is this possible to do in case an application uses DNssec?

Itā€™s going to be exceptionally difficult, IMHO ā€¦ were it me I would simply purchase an off the shelf solution like NetNanny and be done with it. Hereā€™s why ā€¦ (and you likely already know this, this is just for the benefit of others who might find this on a search) ā€¦ other than the most trivial websites, everyone uses essentially a front facing well known IP address and a slew of servers that the actual connection is made to ā€¦ so you surf to ā€œyoutube.comā€ [142.250.189.174] but when you pick a video to watch and you look at a connection viewer youā€™ll find a different address actually serving the content. That means if you ā€œblackholeā€ the ā€œyoutube.comā€ address in ā€œhostsā€ or by blocking that connection in WFP or in an NDIS handler unless you ā€œblackholeā€ the actual service address sending the content all youā€™re doing is forcing someone to use a different front facing address (which will change based on region, the content provider using a DDOS blocker like CloudFlare or even due to load balancing, as itā€™s just a DNS entry). Thatā€™s a reverse of the problem that content providers like NetFlix face, where they want to restrict certain regions from getting content and people simply use a VPN to change their address ā€¦

Youā€™re going to be playing an eternal ā€œwhack-a-moleā€ game if you go down the ā€œblock the IP addressā€ route other than for the guy with a WordPress app running on his computer in the basement connected to a ComCast router, essentially, which is what the commercial applications have to do and why they issue daily updates ā€¦ itā€™s going to be easier to simply acknowledge that and go drop the $30 for the subscription ā€¦

unfortunately, using off the shelf solutions is not an option for me.
So if you HAD to write an application that blocks certain website (written as a kernel driver or user mode app), and no matter which process is trying to resolve that host address (so not just by certain browsers), what would you do?

@Pavel_A said:
Make them use the right browser. The good Microsoft will take care of the rest.
Filter websites and searches in Microsoft Edge

In my case, i need to block any process that tries to connect to blacklisted URLs, so just blocking it in certain browsers is not enough.

@brad_H said:
unfortunately, using off the shelf solutions is not an option for me.
So if you HAD to write an application that blocks certain website (written as a kernel driver or user mode app), and no matter which process is trying to resolve that host address (so not just by certain browsers), what would you do?

Start with the ā€œinspectā€ WPF sample, have it check the connection IP against a blacklisted list maintained as a binary hash table in the registry. Have a usermode application update the hash table as needed, and play ā€œwhack a moleā€ adding IPā€™s to the hash table ā€¦

So if you HAD to write an application that blocks certain website
ā€¦ Iā€™d start from understanding what is a website. As craig_howard noted above, this is not trivial. If you are lucky, the user (ā€œparentā€) will provide you a ready list of IPs. Otherwise, you will have to resolve (changing) IPs from domain names.
And hope that smart kids donā€™t use other devices or Tor to access banned sites.

@craig_howard yes, the poor Spartan is dead (as so many things that Microsoft tried to make themselvesā€¦ sigh) but the Chromium Edge is a dandy.
On my newer win10 PCs I donā€™t even install other browsers. Only latest ā€œdevā€ Edge. It works great with everything, even with Google mail and other apps. And IT HAS DISTRACTION-FREE MODE like Safari! Absolutely cool.

@craig_howard said:

@brad_H said:
unfortunately, using off the shelf solutions is not an option for me.
So if you HAD to write an application that blocks certain website (written as a kernel driver or user mode app), and no matter which process is trying to resolve that host address (so not just by certain browsers), what would you do?

Start with the ā€œinspectā€ WPF sample, have it check the connection IP against a blacklisted list maintained as a binary hash table in the registry. Have a usermode application update the hash table as needed, and play ā€œwhack a moleā€ adding IPā€™s to the hash table ā€¦

Yes i have worked with that, but the problem with solutions such as WFP or NDIS is that they fail to detect domains when they are resolved using DNssec, what is the solution for this?

@Pavel_A said:

So if you HAD to write an application that blocks certain website
ā€¦ Iā€™d start from understanding what is a website. As craig_howard noted above, this is not trivial. If you are lucky, the user (ā€œparentā€) will provide you a ready list of IPs. Otherwise, you will have to resolve (changing) IPs from domain names.
And hope that smart kids donā€™t use other devices or Tor to access banned sites.

@craig_howard yes, the poor Spartan is dead (as so many things that Microsoft tried to make themselvesā€¦ sigh) but the Chromium Edge is a dandy.
On my newer win10 PCs I donā€™t even install other browsers. Only latest ā€œdevā€ Edge. It works great with everything, even with Google mail and other apps. And IT HAS DISTRACTION-FREE MODE like Safari! Absolutely cool.

Unfortunately i need to block URLs, not IP addresses.

Protection at the ā€œDNS53 layerā€ is trivial and can be achieved by redirecting the DNS packets into user mode using WFP at either the ALE_CONNECT_REDIRECT or DATAGRAM_DATA layers. You can then make a decision after parsing the packet.

I am not familiar with DNSSEC but a quick look over the RFC suggests to me that if your application was running as Admin then you could probably MITM it by controlling the keys it uses for validating. (Note: I could be very, very wrong on this)

DoH will require you to intercept and process traffic as mentioned below, but look for the ā€œapplication/dns-messageā€ content-type header.

If your goal is to block certain URLā€™s then you will need a local transparent HTTP/S proxy. You could then redirect outbound TCP 80,443, XXX into this local proxy using WFP. For decrypting the HTTPS stream youā€™ll need to generate certificates on the fly, signed by a locally generated CA that youā€™ve put into the Trusted Certificate Store (manually or programmatically).

If you want to support machines that could be behind a corporate proxy then things are a bit more awkward.
Jason

@brad_H said:

Unfortunately i need to block URLs, not IP addresses.

Hmm ā€¦ there might be a gap in understanding how internet connections are made and resolved ā€¦ Iā€™m going to be vastly, vastly simplifying things here, bear with me ā€¦

When youā€™re sitting at the browser (or other application) and type ā€œwww.youtube.comā€, that itself is just a string of letters. Thatā€™s like describing your address as ā€œthe blue house in the middle of the blockā€, descriptive and memorable but useless.

Anything on the internet is given an address (through a variety of methods) which is the IP address, looking like 123.456.789.abc which is like your house at ā€œ123 Main Stā€ ā€¦ itā€™s how the location is actually found.

The ā€œwww.youtube.comā€ is converted into the IP address ā€œ123.456.789.abcā€ by using either a local hosts table (uncommon) or by communicating with another program called a ā€œdomain name serverā€ which is usually (but not always) run by your ISP. The IP address of the DNS is listed in your network properties tab (and itā€™s obtained through a variety of ways), and the browser first connects to the DNS and says ā€œwhat is the IP address of this ā€œwww.youtube.comā€ thingā€ and the DNS responds ā€œ123.456.789.abcā€. The browser then says ā€œcool!ā€ and connects to that address to actually access ā€œyoutube.comā€

Thatā€™s why we are referring to IP addresses; other than something descriptive to put into the bookmarks file or bar, URLā€™s donā€™t exist ā€¦ itā€™s all about the IP address ā€¦

Thatā€™s why we are referring to IP addresses; other than something descriptive to put into the bookmarks file or bar, URLā€™s donā€™t exist ā€¦ itā€™s all about the IP address

Well, yes and no. Thereā€™s more to the URL than just conversion to an IP address. It is extremely common for many web sites to share the same IP addressā€¦ such as on shared hosting providers. So when the URL is passed to the web server, the web server determines (using the URL) which specific web site it serves up.

I suspect that what Mr. @brad_H meant when he said he needs to block URLs, not IPs. I suspect that he needs to see and evaluate the URL, not JUST the target IP address.

I mean, what do I know about networking in 2021 (nuthinā€™)ā€¦ but isnā€™t the only way to do this 100% a proxy?

Peter

1 Like

Correct, shared hosting providers like ā€˜godaddy.comā€™ as well as DDOS shield services like ā€˜cloudflare.comā€™ use the URL portion of the HTTP header of an inbound connection to identify an ultimate destination, so that ā€˜mysite.comā€™ and ā€˜yoursite.comā€™ and ā€˜thissite.comā€™ can all share the same IP address of ā€˜godaddy.comā€™ ā€¦ the machine hosting that specific IP on ā€˜godaddy.comā€™ or ā€˜cloudflare.comā€™ will decode the header portion of the connection packet and forward it on to the host for ā€˜yoursite.comā€™ and that host will determine from the header the browser type (for loading the right webpage), the originating IP (for blocking) and other stuff ā€¦

IMHO the WPF sample ā€œinspectā€ [ https://docs.microsoft.com/en-us/samples/microsoft/windows-driver-samples/windows-filtering-platform-traffic-inspection-sample/ ] is still the right place to start ā€¦ I would do an initial scan for a blacklisted IP (or range, as anything hosted on a bulletproof server canā€™t be good), then do examination of the connection packet header for more info (like the URL that the OP apparently wants to look at) ā€¦ ā€œinspectā€ will let you get at all that and more importantly lets you fail the connection attempt rather than attempt to interfere with it ā€¦

A proxy solution Iā€™m not familiar with, so Iā€™ll defer to the domain experts for that ā€¦ :smile:

@craig_howard said:

@brad_H said:

Unfortunately i need to block URLs, not IP addresses.

Hmm ā€¦ there might be a gap in understanding how internet connections are made and resolved ā€¦ Iā€™m going to be vastly, vastly simplifying things here, bear with me ā€¦

Although i appreciate the explanation, I do understand how it works. As Peter said, i meant that i need to block URLs, not IP addresses, because for example the IP address that URL x resolves to might change a 100 times a day, and get updated frequently too, not to mention cloud services that cause the same IP address to be assigned to many URLsā€¦

Thatā€™s why i need to block only based on the URL address that process x tries to resolve to IP, whether its a browser or any other application. And obviously this means that if the user types the IP manually this will get bypassed, but weā€™re talking about parental control here so the user is not advanced.

Thatā€™s why i need to block only based on the URL address that process x tries to resolve to IP

Your terminology is causing the confusion here. You want to conditionally block DNS.

Start with using WFP to process DNS as described above, you can then worry about DNSSEC, DoH and DoT when you have a better grip on things.
Jason

Your terminology is causing the confusion here.

Iā€™m sorry, but I disagree. His was a problem statement, but thisā€¦

You want to conditionally block DNS.

ā€¦ is a suggested solution. And, with all due respect, thisā€¦

you can then worry about DNSSEC, DoH and DoT

ā€¦effectively means ā€œyou can go down the road to blocking DNS queries, and then discover that it doesnā€™t work in an increasingly large number of situations and therefore have to find another way to meet your requirements. ā€œ

With the ever-proliferating number of EP Defense products being developed, it shouldnā€™t surprise you that our team has looked at this very problem. I was not deeply involved, but IIRC the outcome was that the only solution in the encrypted cases was to use a proxy. Otherwise, you see encrypted data, and thatā€™s not going to help.

Peter

@ā€œPeter_Viscarola_(OSR)ā€ said:
With the ever-proliferating number of EP Defense products being developed, it shouldnā€™t surprise you that our team has looked at this very problem. I was not deeply involved, but IIRC the outcome was that the only solution in the encrypted cases was to use a proxy. Otherwise, you see encrypted data, and thatā€™s not going to help.

Peter

If i recall correctly Kaspersky basically does a MiTM, it imports its own certificate into cert store, and this way it intercepts DNSsec and other encrypted traffic, so i guess this is one way of doing it. But seems like a messy solution.