False Positive In SID 2072593, SID 2072598 (ET HUNTING * Header Set to localhost)

Hello,

wanted to report about:

  • ET HUNTING X-Forward-For Header Set to localhost
  • ET HUNTING X-Real-IP Header Set to localhost

expected rules should match when IP is 127.*.*.*,
actual rules match when IP contains 127, e.g. 172.71.127.87

cannot make heads and tails out of rule’s pcre, which is:

pcre:“/^.*(?:127(?:(\x2e0){1,}?\x2e1|(\x2e[0-9]{1,3}){1,3})|0177.?0000.?0000.?0001|7f000001|2130706433|01111111.?00000000.?00000000.?00000001|\x3a\x3a1|169\x2e254\x2e169\x2e254|ec2\x3a\x3a254|localhost)/Ri”;

but possible fix with minimal side effects, could be:
pcre:“/^.*(?:(?<![0-9.])127(?:(\x2e0){1,}?\x2e1|(\x2e[0-9]{1,3}){1,3})|0177.?0000.?0000.?0001|7f000001|2130706433|01111111.?00000000.?00000000.?00000001|\x3a\x3a1|169\x2e254\x2e169\x2e254|ec2\x3a\x3a254|localhost)/Ri”;

Best Regards,
Jurgis

Your lookbehind fixes the reported substring case, but it only guards the literal 127 branch. The other alternatives (0177…, 7f000001, ::1, etc.) are still unanchored, so similar false positives could remain for those forms. Consider adding a common delimiter/start boundary around the entire alternation and an end boundary after it, rather than only before 127. Also test comma-separated X-Forwarded-For values, since matching any occurrence in a list can produce unexpected hits.

Hello! This rule is one of mine. I ended up modifying the regex to this:

pcre:"/^[^\x2e]*(?:127(?:(\x2e0){1,}?\x2e1|(\x2e[0-9]{1,3}){1,3})|0177.?0000.?0000.?0001|7f000001|2130706433|01111111.?00000000.?00000000.?00000001|\x3a\x3a1|169\x2e254\x2e169\x2e254|ec2\x3a\x3a254|localhost)/Ri";

The purpose of this regex is to catch a bunch of different funky ways that different servers can parse 127.0.0.1.

for example:

127.1
127.0.1
127.0.0.1 

are all valid notations for the IP address 127.0.0.1

but also, I’m trying to capture other IP address in 127.0.0.0/8 as well in a somewhat quick and dirty manner. the other formats you see are decimal, octal, hex, and binary notations for 127.0.0.1. Additionally we’re looking for 169.254.169.254 (or the equivalent ipv6 address containing the string ec2::254) to capture strange CSRF requests for AWS metadata. We’re also looking for the literal string localhost, case-insensitive.

Some might notice that I’m using the period wildcard character for some of the other notation types (hex, binary, octal, etc.) that is because sometimes these address can specify periods, spaces or NO separation characters at all for the different octets, and different web applications can and WILL honor those weird notations. That’s why .? is present in so many of them and not something like \x2e?

The regular expression change I made should be going live in tonight’s rule release and should help to relieve the false positives you’re experiencing. Should this continue to be a problem, please let me know and I’ll try to address any problems from there.

Note: this new modification probably won’t work for XFF headers that have multiple comma separated values. so keep that in mind.

Thanks,

-Tony