Skip to content

Conversation

arthurzenika
Copy link
Contributor

No description provided.

#- evt.Meta.source_ip in LookupHost("server-130-176-186-238.cdg52.r.cloudfront.net")
- IpInRange(evt.Meta.source_ip, "130.176.128.0/18")
- any(File("aws-ip-ranges.json"), { IpInRange(evt.Meta.source_ip, JsonExtract(#, "ip_prefix")) })
#- any(File("aws-ip-ranges.json"), { IpInRange(evt.Meta.source_ip, JsonExtractSlice(#, "prefixes.ip_prefix")) })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two expressions don't work yet. Looking for a way to check an IP against multiple ranges extracted from a JSON file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File will read a file line by line, and return an array with the content of each line, the only way to reconstruct the JSON object I can think of would be to something like this, which is really not great :

let ip_json = Join(File("aws-ip-ranges.json"), '');
let jsonObject = JsonExtractSlice(ip_json, "prefixes");
...

@blotus
Copy link
Member

blotus commented Sep 17, 2025

Hello,

Unless I'm mistaken, this effectively allowlist all the AWS IPs ? (including EC2).

While allowing cloudfront is probably a good idea, allowing any EC2 IP seems kinda dangerous: even if AWS responds to abuse, some of their servers have malicious behaviours (AWS is in the top 5 AS in the community blocklist).

From a performance perspective, I'd expect this parser to be extremely slow: JsonExtract will reparse the JSON each time it is called, and there are about 15k ranges in the JSON file:

  • Each log line will trigger parsing of a not-so-small JSON file
  • In the worst case, the IP in the log line will be checked against 15k ranges, which will take some time.

Ideally, this file should be pre-processed and have a single range per line, which would allow to just use File and any without any parsing.
This is actually part of a larger subject: currently we have some scenarios that fetch datafiles from 3rd parties (eg, cloudflare ip ranges), I'd like to centralize everything in a repo we own (for example, https://github.com/crowdsecurity/sec-lists/) and have a CI job update everything automatically. This would allow for easy pre-processing if needed (and ideally, make sure crowdsec can use the same whitelists we use server-side for the consensus)

Additionally, this kind of resource-intensive match should be instead performed in a postoverflow: they will only be checked after a scenario was triggered, which should happen much less often.

@blotus blotus added the waiting-for-user Waiting for submitter answer regarding specific points in the PR label Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-user Waiting for submitter answer regarding specific points in the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants