How to block a website using c++ other than "hosts file"???

closed account (3hMz8vqX)
Hi All,

There are many tutorials on the internet about blocking websites using
C++ by modifying the C:\
Windows\System32\hosts file . . .

This method is not that powerful and does not
block sub domains . . .

Is there another way to block websites using c++ . . .
I mean, how do antivirus software like Avast do that . . .

Thankyou everyone in advance!!!
They install a plugin or an add-on into your browser. C++ doesn't know or care about the internet, so you would have to go through the OS/browser and it's methods.
You could also hook some of the windows api functions that the browsers use, and check the urls before making a http request.

It seems a bit "sketchy" that you seem to be asking these security related questions too often, that too they tend to ask for practical questions. I sincerely hope it is not Malwares you are programming.

On topic, there are several DNS\Internet related functions you can hijack\hook in order to redirect\block websites. There are several functions you need to hook in order to succeed with your criteria, are LSP based hooks, they stand for Layered Socket Providers and are much more lower than most functions such as the ones most Website-Re-directors\Blockers hooks, therefore it will provide more ease of usage and will reduce the chances of it being unhooked and competing. The LSP functions are WSPSend(),WSPRecv() and more and hooking these functions will perform at lower level.
The most common and easiest based hook to create is DnsQuery_W() (Unicode) although this will only work on one browser, not telling because I wish you do a bit of research on you own.
There are many Internet-based functions you need to hook before all of the web-browsers will be at your proper control.
Do be aware that Browsers like Google Chrome are extremely protected and will deny and access to its components and it makes it ever so hard to hook into it, every time I do an Ring3 level injection (obvious) the Google Chrome's Sand Box is triggered instantaneously and it is almost impossible to do it but some have managed.

How AV's such as Avast managed to block are by it hooking networking function at kernel level therefore it does not need any injecting into foreign processes therefore its hooks it places are system-wide.
I am guessing you are working at User-mode, therefore you need to inject the hook into foreign processes via usage of DLL (Dynamic Link Libraries) files, Code Injection , Windows Hook function which forces all processes to load a DLL.

Using HOST files is a very bad idea keeping in mind almost every "good" AV, always protect it and monitor it, and making changes to it is going to end up in termination of your software besides it will be detected before even running.

MSDN Documentation:




Last edited on
Topic archived. No new replies allowed.