Traffic to blocked address still succeeds. Why? A bug?

I have the address "android.clients.google.com" in the address-lists "deny" and "deny_nolog",
and two firewall rules to drop all packets to all the IPs behind that address.
Still, occassionally it happens that the blocking isn't working! Why? What's the reason?

Btw. how can I in CLI print only the IPs belonging to this address-list item?
Update: found it: print where list=deny comment="android.clients.google.com"
.

[admin3@AP1] /ip/firewall/address-list> print where list=deny address=android.clients.google.com
Columns: LIST, ADDRESS, CREATION-TIME

LIST ADDRESS CREATION-TIME

33 deny android.clients.google.com jul/15/2020 09:32:51

[admin3@AP1] /ip/firewall/address-list> print where list=deny_nolog address=android.clients.google.com
Columns: LIST, ADDRESS, CREATION-TIME

LIST ADDRESS CREATION-TIME

1 deny_nolog android.clients.google.com jul/16/2020 20:20:01

[admin3@AP1] /ip/firewall/filter> print
20 ;;; deny_nolog
chain=forward action=drop dst-address-list=deny_nolog

44 ;;; deny
chain=forward action=reject dst-address-list=deny log=yes log-prefix="DENY"

Log file of PC application (a web proxy server):
127.0.0.1 - - [17/Jul/2020:01:25:14 +0200] "CONNECT android.clients.google.com:443 HTTP/1.1" 503 7705
127.0.0.1 - - [17/Jul/2020:01:27:41 +0200] "CONNECT android.clients.google.com:443 HTTP/1.1" 200 0
127.0.0.1 - - [17/Jul/2020:01:28:05 +0200] "CONNECT android.clients.google.com:443 HTTP/1.1" 503 7706

Ie. the connect in the middle was successful (HTTP status code 200), the others were blocked (HTTP status code 503)

>

.
Environment: RouterOS 7.0beta8 on router hAP ac^2.

That’s the problem with this kind of blocking. Hostname can resolve to different IP addresses, they can change any time, and (which is the main problem) they can be different for different clients.

For this one I get:

  • from local resolver #1: 216.58.201.110, 172.217.23.206, 172.217.23.238, 216.58.201.78
  • from local resolver #2: 172.217.23.206, 172.217.23.238
  • from 8.8.8.8: 216.58.201.78, 216.58.201.110, 172.217.23.206
  • from 1.1.1.1: 172.217.22.238, 172.217.23.46, 172.217.22.206, 216.58.207.142, 172.217.23.14

You see the problem. These results are fine when you want to connect to android.clients.google.com, because server is available on all of them. But they are not good for blocking, because client can use address that router doesn’t know about. Only way how to make it work reliably (well, mostly *) is to force client to use same router as resolver. Problem is, you can’t really do that anymore with things like DNS over HTTPS, if client uses that, you’re out of luck.

(*) There could still be timing issues. If addresses change when TTL runs out, and client doesn’t respect TTL exactly, router may have different addresses for a while.

@Sob, thanks for the explanation. I now see the underlying problem.
You said “That’s the problem with this kind of blocking.”
So, does this statement imply that there is (or even are) some other blocking methods possible for this problem case?
I can force all clients to use the same one DNS server on this router (actually already doing this),
and DOH is not in use here, as far as I can say (no experience yet with DOH).
What else would you recommend to do?

I think for such cases one needs to filter by the very hostname itself, not by the underlying IP(s). But this is unfortunately not possible with ROS :

/ip/firewall/filter> add action=drop chain=forward dst-address=android.clients.google.com
value of range expects range of ip addresses

Thx.

Force the DNS resolver to a server you have under control and null the blocked domains out there.

I’m pretty sure the smart android clients in the very near future then revert to some DoH lookup mechanism if they feel something is “off”, go out on the Internet on port 443 and still perform the lookup and obtain some IP you missed and then can connect to it without a problem.

Your suggestion for sure is the next best thing to do indeed!
It is very hard to tightly control these data-flows, especially with a device like Mikrotik.

What about the proxies “privoxy” (http/https proxy) and “Pi-hole” (DNS proxy): can these be used for this problem?
Privoxy I’m already using since a few days now, but haven’t studied it’s capabilities fully yet :
https://en.wikipedia.org/wiki/Privoxy
https://en.wikipedia.org/wiki/Pi-hole

any proxy is generally very powerful because it actually processes the request (therefore it understands exactly what is being requested and returned) but https proxies are also serious security threat - for HTTPS or generally SSL encrypted traffic (nowadays majority of internet traffic) you need to install proxy’s root certificate into every device which will use it. That means, if private key of that certificate leaks in any way, all your devices will be susceptible to MITM even on encrypted traffic.

DNS proxy is generally fine and you can practically do it within RouterOS.

I’m already using the DNS server in RouterOS as DNS resolver for all clients, but as you said ROS has some more DNS capabilities as this document shows:

Btw, I encountered a new problem: an IP gets blocked, but I cannot locate it in address-list as the IP seems to match one inside a block-entry of the form network/mask.
Is it possible to locate the record of a single IP if most of the records in the list are of the form network/mask? Can regex be used with address-list?

You will have to live with the fact that makers of systems are moving more and more towards setups where a network administrator cannot filter or block the traffic!
In the past, you could filter on port numbers, redirect traffic to some ports to other destinations (DNS port 53), peek in traffic to filter URLs or to block traffic based on protocol, etc etc etc.
But these possibilities are taken away from you one by one, because everything is becoming encrypted and all services (including DNS) are moving to using only https (TCP port 443).

So even when you can now trick your users into using only the DNS of your router, and in the same router do the DNS-based address list blocking, hoping that it will block the same addresses that the clients also receive, and doing things with wildcard matches etc, these possibilities will be gone within a year.

Your best defense is to move yourself out of the position where you “need to block things”. It is a lost battle.

Man, up until a few weeks ago I was in the same camp as you: nearly resignating :slight_smile: But then I found THE SOLUTION TO PRIVACY AND SECURITY!
The key is: block everything for both inbound AND outbound and allow only on demand and only some select addresses among all the URLs the HTML page of the site tries to connect to.

I’m very confident this is the true solution. I now have full control over all connections (TCP) and UDP packets in both inbound AND, most importantly(!), outbound connections.
An HTML page in the browser means: it can do everything it can do in its environment (browser, sandbox, environment (home dir and other dirs etc.) of the user account that started the browser), ie. by default it can connect to any other sites it wishes to, and also spy the local system as much as it can and transfer to and from the local system as much data as it can.
So, IMO that kind of outbound traffic from inside the HTML page is the biggest threat to security and privacy, which most people don’t realize at all.
I’m confident this nasty problem can be solved with some advanced address-list functions, more advanced than in current ROS.
Ie. firewall, regex (also on hostnames), address-lists, and a HTML washer like privoxy (s. link above) are the ingredients to solve this privacy and security problem, IMO best done on a per site basis.

I am already experimenting with this approach, and can say it works! Most of the addresses are blocked by default as only select ones are allowed. Ie. I’ve inversed the normal/default/usual logic from “allow everything to outbound” to “block everything to outbound except only some select user defined addresses”.
But this is of course laborious, but IMO worth the extra effort, and I’m hopeful that most of this can be automated by some clever programming, and by the power of the user crowd of such a solution.
Of course this concept at this stage is only a solution for a single user only, not for a company (or family) as a whole yet.

The next best idea I came up is this: let the web browser run on a dedicated machine, just connect to it via RDP (or similar protocol). In this case no HTML page ever comes onto the local user machine, so consequently nothing can happen on the local machine. The (minor) problem with this approach is that saving web pages, PDFs etc. happens on the remote machine (though that problem is solvable). With this solution nothing of the above complicated tasks needs to be done, except after each RDP session (that should not last more than a day) one should clean the temp data on the remote machine (cookies (very important!), history etc.) so not to leave any traces there…

A closed system is what you are describing .. a concept that has been in effect in Enterprise computing for a very long time … BUT with the advent of the Internet which by definition is an OPEN system of COMMUNICATION — enterprise systems are now utilizing 3rd generation mechanisms that inspect everything in the payload and only allow [from the Internet] what security policies are in place. CISCO has been doing this for a long time as has Juniper, Microsoft ForeFront plus some others in the Enterprise security game. MikroTik is not in this game as its layer 7 mechanism is a toy [because it cannot do decryption] so all https traffic cannot be inspected. Perhaps in the near future MikroTik will have a 3rd gen engine — this is not a cheap en devour.

That problem of encrypted traffic (https) is IMO easily solvable by using a (transparent) proxy like the said privoxy (ie. as a proxy it can easily decrypt the https traffic, it even doesn’t need to do anything special for decryption as https does the decryption implicitly as well)…

Decrypting traffic on an inspection device can only be done in a setting where you can install malicious certificates on the client’s device.
That is possible in many “business settings” (where the business manages the user’s computers can can deploy software and certificates by central management methods like “group policy”).
However, in a more open network like a BYOD situation, a guest WiFi network, or an ISP that supplies paying customers with internet access, this method is not possible.
No matter if the equipment is made by CIsco, Juniper, or MikroTik.
Even in business settings, local law may prevent the business from spying on the employee’s traffic in this way.

Furthermore, this method will cease to work once the browser makers validate the correspondence between site and certificate issuer.

@pe1chl, correct me, but I think you are talking of two-way authentication via certs.
But I know of no public site where this is used, in 99+% only the server side is authenticated by the certs, but not the user side.

No, I am talking about the certificate validation in the browser on the user’s computer.
Of course you can decrypt the content a site sends in a proxy, but you will not be able to re-encrypt it before you send it to the browser, at least not with the same certificate.
So the browser will issue an error message about the authenticity of the site.
For now, you can make your own certificate that issues fake certificates that the browser will accept, but first you must install that certificate as trusted on the user’s computer.
You cannot do that unless you manage the user’s computer.

And it will stop working once the browser not only checks if the certificate is trusted, but also if it has been issued by the issuer that the website normally uses for its certificates.
Google Chrome already does that for some sites.

@pe1chl, maybe we are talking of different things. I just mean for example the said proxy server privoxy. Do you mean it can’t decrypt https?
As I’m new to it, I really don’t know; I just am thinking that it very well can decrypt HTML pages it gets via https.
There are several forms of proxy methods, ie. whether transparent or not. I think this proxy is not transparent. If that makes a difference in this context, and I think it indeed does.

I mean: everything is normal in my web browser, eventhough it uses that proxy server and https-URLs are used.
There is no warning in the browser, and nobody would expect one, IMO.
For example doing login to my bank is working very normal as before w/o the web proxy.
Even the green keylock sign for secure traffic appears in the addressbar.

Unless you mean the use of client-side certificates.

Privoxy cannot decrypt https, no. It cannot look in your HTML or in your URL.
The only thing a proxy can do (and it is only possible with a configured proxy, not a transparent proxy) is look at the hostnames and portnumbers you are trying to connect.
That is a very limited capability because hostnames do not map 1:1 to services you would want to block.
It could be used to implement the request in this topic (“block android.clients.google.com”) but it would still not be useful because it would be required to configure the proxy in all client machines, and also because not all software running on client computers can be configured to use a proxy.
Remember, unlike for plain http, you CANNOT make a transparent https proxy unless you have installed malicious certificates on the client machine.

But then I wonder how this is then technically working.
The proxy is in the middle, it is the one that connects to the remote. That’s at least what I was assuming.
So, then I wonder what happens next. Can you elaborate? Thx.

Update: you are right, the confirmation is here: https://www.privoxy.org/faq/misc.html

4.15. How can Privoxy filter Secure (HTTPS) URLs?
Since secure HTTP connections are encrypted SSL sessions between your browser and the secure site, and are meant to be reliably secure, there is little that Privoxy can do but hand the raw gibberish data though from one end to the other unprocessed.

So, then this means one needs to use an open-source web browser ( https://opensource.com/article/19/7/open-source-browsers ), modify the source code so that a copy of the decrypted HTML page is processed by an own filter processor, and somehow the traffic blocked until the own processor has processed the page…
Hmm. this is much work… :frowning:

Oh yes, Chrome is doing this HSTS for many sites, and the number is growing.
If the certificate is something not in the list, or different from what was seen before on another (direct?) connection , then the MitM is detected, and the page in the browser is blocked.
This can be a problem for automatic portal/hotspot login pages that maintain the URL but show the local login page first.

You do not want to learn the “danger/badidea/thisisunsafe” workaround to everyone, or one of those might one day also use it when blocked for on-line banking transactions on a malicious site.

And it might be or become illegal … https://security.stackexchange.com/questions/207309/is-a-company-decrypting-all-ssl-traffic-through-a-root-ca-gdpr-compliant

As was already suggested by others, popular way for HTTPS is some kind of MITM. But it breaks end-to-end security, which will be increasingly more problematic. And it’s only usable for devices under your control, because nobody else will trust your fake CA. Plain HTTP can be filtered using transparent proxy, but that’s going away, being replaced by HTTPS. Other protocols, hard to say, either you’ll have same problem with encryption, or they may not contain hostnames at all, unlike HTTP(S).

It’s not just RouterOS. DNS resolution and following connection are two independent things. You start with hostname, ask DNS server for IP address, and then connect to that IP adddress. But when you do that, the connection itself doesn’t contain any reference to original hostname. Some protocol may have it (Host header in HTTP(S), SNI in TLS, …), but it’s on different level, which IP firewall doesn’t see (not counting ugly hacks like L7 filters).

Pi-hole no, it’s just DNS. Privoxy maybe, I don’t know what exact features it has, but if there’s some filtering, it should be good enough for HTTP (without S, so not good enough).

IMHO the problem is not when you want to lock down your own network (devices managed by you), disable everything by default and allow only selected stuff. In that case, address-list based method is almost there. Make sure that devices use router as DNS resolver (use dstnat to redirect all connections to port 53 to router, in case something tries to access different DNS server). Don’t enable (or disable) DoH, DoT or any other ways how to resolve hostnames elsewhere (if you fail here, it’s no big deal for security, because if it’s not in router’s whitelist, connection to it won’t be allowed).

This solution won’t work for dynamic stuff, e.g. if something would use addresses like <something_random>.somecdn.tld, because there’s no way how router can resolve in advance all possible variations of <something_random>. That could be done with proxy. The idea I like is simple SOCKS proxy. If it’s for own devices, you can configure them to use it, many programs support it. Disable requests for connections to numeric IP addresses, allow only hostnames (so client device won’t be doing any DNS resolution at all). Set up ACL to allow access to selected hostnames. Since proxy will see them, it can easily allow even <something_random>.somecdn.tld as any subdomain of somecdn.tld. I can’t recommend any ready to use solution, I assume something exists that can be configured like this. I’m hoping for SOCKS proxy in RouterOS, after they recently added SOCKS5 and someone from MikroTik wrote that they plan to improve it further. And this would not be difficult. But currently it’s not there yet.

Same approach with proxy can be used for blocking something. Again, for your own devices, because you can configure them to use it. If it’s some company network, devices like workstations probably don’t need direct internet access, proxy is enough. And it can be useful not only for filtering, but also for accounting.

The main problem is when you need to do this for devices that are not yours. You can’t force them to use proxy. You can’t force them to use your DNS. If the goal is to block something, then for HTTPS (which is most popular protocol), you can look at SNI (so far, but in future it will be encrypted too). If it contains bad hostname, block it. But the reverse, to allow only something, would be difficult (the part where you need to block everything else), at least in current RouterOS.