Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new modifier: CIDR #969

Closed
malvidin opened this issue Aug 5, 2020 · 3 comments
Closed

Add new modifier: CIDR #969

malvidin opened this issue Aug 5, 2020 · 3 comments

Comments

@malvidin
Copy link

malvidin commented Aug 5, 2020

A modifier for IPv4/IPv6 addresses for CIDR matching would be useful, especially for classless addresses.

Based on sysmon_dllhost_net_connections.yml, the filter is much simpler to read:

    filter:
        DestinationIp|cidr:
            - '10.0.0.0/8'
            - '172.16.0.0/12'
            - '192.168.0.0/16'
            - '127.0.0.0/8'
            - 'fe80::/16'

If the backend does not support CIDR natively, it can decompose the address into multiple wildcards with the ipaddress library.

For an IPv4 example:

net = ipaddress.IPv4Network("172.16.0.0/12")
wc_mask = (1 + net.prefixlen // 8) * 8
wc_trail_chars = -2 * ((32-wc_mask) // 8)

if net.prefixlen % 8 == 0:
    if wc_trail_chars < 0:
        print(net.network_address.exploded[:wc_trail_chars] + ".*")
    else:
        print(net.network_address.exploded)
else:
    for subnet in net.subnets(new_prefix=wc_mask):
        if wc_trail_chars < 0:
            print(subnet.network_address.exploded[:wc_trail_chars] + ".*")
        else:
            print(subnet.network_address.exploded)

For IPv6, the resulting string would need to validated against the IPv6 output from the Windows Event Log.

@krsbr
Copy link

krsbr commented Aug 11, 2020

This would be extremely useful

@frack113
Copy link
Member

Hello,
I put #1563 to add a ipv4 modifiers

@frack113
Copy link
Member

Hi, it is in PySigma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants