GreedyBear icon indicating copy to clipboard operation
GreedyBear copied to clipboard

bug : enrichment lookup is case-sensitive for domains but not for IPs

Open AdeshDeshmukh opened this issue 2 weeks ago • 3 comments

Description

/api/enrichment?query=MALICIOUS.EXAMPLE.COM returns found: false while malicious.example.com is in the database. and IPs don't have this problem — 2001:DB8::1 matches fine because EnrichmentRequestSerializer.validate() normalizes them (api/serializers/common.py:71-72). The domain branch only regex-checks the value (:66) and passes it through as typed, then the lookup is an exact get(name=query) (api/views/enrichment.py:50).

stored domains are always lowercase (they come from urlparse(...).hostname in the Cowrie and Tanner paths)... so any uppercase typed by the user misses the row. DNS is case-insensitive anyway (RFC 1035 §2.3.3), and the rest of the codebase already treats names that way: honeypots__name__iexact in feeds.py, Lower("name") unique on Honeypot.

Steps to reproduce

  1. Store a domain IOC, e.g. malicious.example.com.
  2. Request ?query=malicious.example.com → found: true.
  3. Request ?query=MALICIOUS.EXAMPLE.COM → found: false.
  4. For contrast: ?query=2001:DB8::1 → found: true, response echoes the normalized 2001:db8::1.

Expected behaviour

Domain queries match case-insensitively, like IPs already do.!

Possible fix

i think lowercasing the domain in validate() before the lookup (one line), or switching to __iexact like feeds.py:154 already does. Leaning toward the validate() one-liner, but open to normalizing on the write side too..!

would like to have ur opinion.!

AdeshDeshmukh avatar Nov 18 '26 19:11 AdeshDeshmukh

I verified this locally on develop (ebb649e). With malicious.example.com stored, the lowercase query returned found: true and the uppercase query returned found: false. The uppercase IPv6 query still matched.

I’d go with the proposed serializer fix and add a regression test. Lowercasing the validated domain keeps the indexed lookup and avoids the duplicate-match error that get(name__iexact=...) can raise when two stored names differ only by case.

Hey @regulartim could you assign this issue to me? I’d like to work on the fix.

Saurabh-1785 avatar Nov 20 '26 14:11 Saurabh-1785

Hey @AdeshDeshmukh ! Good find, thank you! I think you are right, we should normalize the domain names as well. Do you want to work on it yourself or should I assign @Saurabh-1785 ?

regulartim avatar Nov 23 '26 14:11 regulartim

Thanks for reproducing this, @Saurabh-1785. A good regression case would be an uppercase query against a domain stored in lowercase.

@regulartim I’m happy for you to assign this to Saurabh..!

AdeshDeshmukh avatar Nov 28 '26 17:11 AdeshDeshmukh