Skip to content

Cymru Expert: Wrong Cache-Key Calculation #1592

Closed
@daniwb

Description

The Cymru Expert creates a Key from an IP-Address in the following manner:
IP to Int
Int to bin
f.e.:
8.39.215.10 => 136828682 => '0b1000001001111101011100001010'

When the first octet is smaller than 128 (ipv4), the resulting binary is < 32 Chars.
For the Key Calculation in the Cache you strip the IP address to 24 Chards (in ipv4), this leads to wrong information in the cache.

The upper IP leads to a key: 100110010110110101111100

When you check the same algorithm for 130.125.112.0 you will end up with the same key.
[130.125.112.0 => 2189258752 => '0b10000010011111010111000000000000']

This will lead to wrong information when the Cache is hit.

Suggestion:
(Line 55, intelmq/bots/experts/cymru_whois/expert.py)
cache_key = bin(ip_integer)[2: minimum + 2]

        ip_bin = bin(ip_integer)[2:]
        if(ip_version == '4' and len(ip_bin) < 32) # check if lenght is smaller than 32, so shorten minimum
            minimum = minimum - (32 - len(ip_bin))
        cache_key = ip_bin[0:minimum]

But maybe you have a better Idea.

This will lead, that the Key is shorter than 24 Characters if the first octet of the ip is smaller than 128.

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorcomponent: bots

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions