Wrong host match for subdomains
cc4ceb88a06f600fd7a0b44473dd4d2b2d364402 doesn't seem to completely fix the problem introduced in #143.
There is a global host match issue found both in DNS:
$ curl not.google.example.com
and HTTP (plus DNS):
$ curl not.google.github.io
Note that in the former case the lookup fails since there is no DNS record matching not.google.example.com while in the latter case the host not.google.github.io is resolved to github.io (yet it gives 404).
Through these examples, you may notice that we have other false positives which continues to match with Google.
@backer-and Fell free to provide a fix for the problem,
In my opinion, is probably necessary a general re-check of the http dissector.
@lucaderi I'm thinking about, it doesn't appear to be so simple rewriting all the hosts matching parts used in DNS, HTTP and maybe in other dissectors.
I closed the issue but I'll work on these protocols to find a good solution.
honestly I don't see the problem. We need to implement a better matcher.
Yes, is not a bug, just do a better matching for http payload imho
Gentlemen,
We've run in to the same issue. Our current solution was to borrow the ^ and $ regex characters and implement explicit head/tail matching. Depending on the number of permutations (or levels) enabled (head & tail, head-only, tail-only), it can add up to 3 additional radix/ptree lookups per hostname. That being said, we haven't seen a notable CPU usage increase when testing traffic up to 1Gbps...
In our application we override all of the built-in (content_match.c.inc) "application protocols" with our own definitions via a custom configuration file. Where we find overmatching occurring, we use explicit string head/tail matching.
For example, the twitter domain "t.co" was often matching for domains like: content.com, etc... now we define "t.co" as "^t.co$" and the expected results are returned.
The relevant commit is below if anyone is interested in looking at it: dsokoloski/nDPI@95e0fe4b6cba90849c4bcb7c766ee906cef8560c
Also I think this and #268 are duplicate issues.
@dsokoloski, thanks for this great work . is there a way to apply the regex to the middle of string for example : videos.XXXX.facebook.com where XXXX is a variable string . please help thanks again.
@NatashaR4in Unfortunately I can't think of a way to implement that. The reason why is due to the way that these strings are stored and how they are subsequently matched on lookups (nDPI uses Radix Trees for speed: https://en.wikipedia.org/wiki/Radix_tree)
My solution works only because I insert characters (^ and $) at the beginning and end of strings. This allows for explicit head/tail matching. Unfortunately this trick can not be extended to explicitly match a sub-string due to how Radix Trees work. You would have to use something far less efficient to support true regex matching.
@dsokoloski I have to study your commit and try to update on dev branch
@kYroL01 If you merge this in to nDPI, I would recommend making it an option that's disabled by default simply because it will add a minimal amount of additional processing for each look-up and some users of the engine may be already pushing their hardware to the max. If someone needs the additional matching flexibility, they can turn it on. For users of ndpiReader, a new command-line switch could be added to enable the various modes (head only, tail only, or both).
Just a suggestion...
This issue does not exist in recent nDPI versions.