nDPI icon indicating copy to clipboard operation
nDPI copied to clipboard

Wrong host match for subdomains

Open backer-and opened this issue 10 years ago • 12 comments

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 avatar Feb 13 '16 20:02 backer-and

@backer-and Fell free to provide a fix for the problem,

lucaderi avatar Feb 13 '16 23:02 lucaderi

In my opinion, is probably necessary a general re-check of the http dissector.

kYroL01 avatar Feb 14 '16 18:02 kYroL01

@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.

backer-and avatar Feb 15 '16 01:02 backer-and

I closed the issue but I'll work on these protocols to find a good solution.

kYroL01 avatar Feb 15 '16 09:02 kYroL01

honestly I don't see the problem. We need to implement a better matcher.

lucaderi avatar Feb 15 '16 10:02 lucaderi

Yes, is not a bug, just do a better matching for http payload imho

kYroL01 avatar Feb 15 '16 10:02 kYroL01

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 avatar Sep 24 '17 04:09 dsokoloski

@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 avatar Nov 22 '17 13:11 NatashaR4in

@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 avatar Dec 05 '17 03:12 dsokoloski

@dsokoloski I have to study your commit and try to update on dev branch

kYroL01 avatar Dec 05 '17 15:12 kYroL01

@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...

dsokoloski avatar Dec 07 '17 01:12 dsokoloski

This issue does not exist in recent nDPI versions.

utoni avatar Oct 06 '21 09:10 utoni