simplewall icon indicating copy to clipboard operation
simplewall copied to clipboard

[Feature Request] When creating rules, add support for host-names , which are resolved by as soon as an application with such a rule tries to connect.

Open gettysburg opened this issue 3 years ago • 4 comments

Checklist

  • [X] I have used the search function to see if someone else has already submitted the same feature request.
  • [X] I will describe the problem with as much detail as possible.
  • [X] This issue only contains a request for one single feature, not multiple (related) features.

App version

3.6.7

Problem you are trying to solve

Right now, we can only add IP addresses to the "Remote Address" filter list, but due to CDN's and (D)DoS protection providers like Cloudflare, as well as websites using multiple back-ends / web-servers for reliability are annoying to whitelist, since you have to perform a DNS lookup and manually add all A records.

Suggested solution

If it is possible using the usermode WFP API, add support for host-name based filters instead of raw IP addresses - if the API does not support it, you'll have to fetch all A records, which might make these filters a bit slower (perhaps use a different thread that respects the TTL of the records, and then iterates all host-name based filters based on it, all while keeping the IP(s) invisible to the user.

You can also spawn a thread for each host-name based filter, which then looks up all A records and stores them in an allocated buffer along with the host-name at an interval defined by the TTL.

At least on my system - Windows Server 2019 LTSC, which is based on Windows 10 1809, all DNS lookups are handled by one single service named Dnscache, unless an application has built-in DNS resolving code, however I noticed that even applications with their own resolver somehow go through the service mentioned above, unless some flag is set.

I don't know when Microsoft changed this, however it should massively simplify implementing this, I believe the structures that Dnscache uses are documented on MSDN, all along with TTL and all the information you need.

On older Windows versions, where every program is / was still responsible for it's own host-name look-ups, I don't have a good idea except for writing your own DNS lookup code and checking at runtime if the service exists or what OS is in use, but I think Windows 8, 8.1, 10 and 11 all behave the same - redirecting programs DNS lookups to the service.

Screenshots / Drawings / Technical details

No response

gettysburg avatar Feb 27 '23 17:02 gettysburg

No, it's not a dns resorver.

henrypp avatar Feb 27 '23 21:02 henrypp

It most definitely is a DNS Resolver, with caching functionality as indicated by the services real name, don't get confused by the description which is clearly wrong and says "If the service is stopped, DNS names will continue to be resolved", allow me to demonstrate with a video:

https://www.youtube.com/watch?v=ija6u1d728U

It might not function that way on your system, but I have a very strict firewall policy (Incoming + Outgoing blocked by default) and all I needed for DNS queries system-wide was to create a user rule for the service Dnscache.

Ignore the lack of ICMP traffic, I don't need it so I disabled both the rules for ICMP and ICMPv6.

Now looking at the registry entry for the Dnscache service and analyzing it's respective shared library which get's loaded into svchost.exe with IDA64 and debug symbols shows definitive DNS resolving capability:

image

image

From the remarks section of that MSDN article:

When the DNS_QUERY_STANDARD option is set, DNS uses the resolver cache, queries first with UDP, then retries with TCP if the response is truncated, and requests that the server to perform recursive resolution on behalf of the client to resolve the query.

Going further down the rabbit hole, and taking a look at Query_Shim which essentially just calls Query_PrivateExW which is the function for actually establishing a connection with the DNS server(s) you configured in network settings (both functions are not exported or documented, and just used internally) and looking up different types of records.

"Minimum supported client: Windows 8" tells me this is a newer thing, on Windows 7 DNS resolving and caching is handled in a completely different manner, I could dissect and reverse-engineer the DNS API on Windows 7 as well, but I think I proved my point here.

Keep in mind that the MSDN documentation is for Dnsapi.dll, the same library the "Dnscache" / "DNS Client" service uses.

I also did not change anything DNS related on this Workstation running Windows Server 2019, it is and was always the default behavior, since Windows 8 I assume.

Since the most important functions are documented, my request should be easy to implement - just ask me if you need me to confirm / reverse engineer something specific.

gettysburg avatar Feb 28 '23 01:02 gettysburg

Sorry if you got multiple notification, I had to make a few changes.

gettysburg avatar Feb 28 '23 01:02 gettysburg

@henrypp I would like such functionality as well. The hostname often says enough to make a decision whether to allow or block it without having to look up all ip addresses.

KDAM71 avatar May 11 '23 01:05 KDAM71