sigma icon indicating copy to clipboard operation
sigma copied to clipboard

Direct IP Request detection rule

Open SpeedyFireCyclone opened this issue 4 years ago • 13 comments

Rule to detect webrequests directly to an IP in your proxy logs.

SpeedyFireCyclone avatar Mar 27 '20 14:03 SpeedyFireCyclone

nice. i would recommend tweaking this to be accomplished with just ends in an integer. a domain never ends in an integer and so this is a more efficient way

neu5ron avatar Mar 28 '20 22:03 neu5ron

Yes, please use a regex that is simpler. We could even use strings, don't we?

cs-host|endswith: 
    - '1'
    - '2'
    - '3'
    - '4'
    - '5'
    - '6'
    - '7'
    - '8'
    - '9'
    - '0'

Neo23x0 avatar Mar 29 '20 09:03 Neo23x0

i would recommend tweaking this to be accomplished with just ends in an integer.

I think this could introduce false positives as same-domain hosts can end with numbers (i.e. https://PROXY01) if the local DNS can resolve them. I am hence more in favor of a regex which detects either (digits and dots) or (hexadecimal and colons) (i.e. ^([\d.]+|[\da-fA-F:]+)$) this would also support the alternate IP notations such as those observed in this sample.

0xThiebaut avatar Mar 29 '20 19:03 0xThiebaut

@0xThiebaut are you referring to how a domain would look browser side? where the possibilities are endless, the browser/client side converts it to a reasonable HTTP HOST/domain - so browser side https://proxy01 gets converted to HTTP HOST field of whatever proxy01 resolves to. You bring up a point though about IPv6, how about writing it as:

detection:
  ip_v4:
    cs-host|endswith: 
      - '1'
      - '2'
      - '3'
      - '4'
      - '5'
      - '6'
      - '7'
      - '8'
      - '9'
      - '0'
  ip_v6:
    cs-host|contains: ':'
  condition: ip_v4 or ip_v6

neu5ron avatar Mar 30 '20 03:03 neu5ron

So I changed the regex to be more readable, and supporting the alternate notations that @0xThiebaut brought up. There's also the matching for IPv6 now.

I also noticed that Elasticsearch doesn't do the anchor symbols (^, %) and always expects a full match, but I'll create an issue for that one later today.

SpeedyFireCyclone avatar Mar 30 '20 06:03 SpeedyFireCyclone

sounds good, can you cc me if you create an issue? yeah (Elasticsearch) lucene regex is not pcre 😩

neu5ron avatar Mar 30 '20 06:03 neu5ron

Why not

detection:
  ip_v4_end:
    cs-host|endswith: 
      - '1'
      - '2'
      - '3'
      - '4'
      - '5'
      - '6'
      - '7'
      - '8'
      - '9'
      - '0'
  ip_v4_dot:
    cs-host|contains: 
      - '.'
  ip_v6:
    cs-host|contains: ':'
  condition: ( ip_v4_end and ip_v4_dot) or ip_v6

Is the search for a dot . too expensive?

Neo23x0 avatar Mar 30 '20 07:03 Neo23x0

I thing this is indeed a less-expensive approach than relying on regex matches, however this wouldn't match decimal-noted IPv4 addresses as just a number is valid too.

0xThiebaut avatar Mar 30 '20 07:03 0xThiebaut

But then again, there can be a balance between performances and matches.

0xThiebaut avatar Mar 30 '20 07:03 0xThiebaut

I just encountered a case that would give a false positive with the proposed (regex-less) rule: <redacted>.router_w_921v_1_46_000.

Having said that; It's rare for naming schemes to end with a number, much less have those show up frequently. Is it worth the performance loss by using a regex to avoid these special cases? I don't know yet. The IPv6 part of the rule I've not encountered any possible issues with yet, thanks for the suggestion. I've change the rule to use that instead, commenting out the regex.

I'll see if I get any more examples during the week, otherwise I may concede and accept the occasional FP caused by exotic internal DNS/hostname schemes.

SpeedyFireCyclone avatar Apr 15 '20 11:04 SpeedyFireCyclone

I think the rule is best kept as it currently is; The search for "ending with a number and containing a dot" doesn't seem as semantically correct as having an expression that requires the whole destination to be numbers and dots. It may only give false positives in rare cases, but it still doesn't sit very right with me.

SpeedyFireCyclone avatar May 07 '20 05:05 SpeedyFireCyclone

just to double check and confirm here, we are talking about HTTP Host Header correct?

neu5ron avatar May 07 '20 07:05 neu5ron

Yes indeed, that's what this rule does its check on.

SpeedyFireCyclone avatar May 07 '20 17:05 SpeedyFireCyclone

Closed because no more activity since 1 year

frack113 avatar Dec 19 '22 15:12 frack113