elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Whitelists doesn't seems to work

Open arall opened this issue 10 years ago • 13 comments

Here is my rule:

name: Security - Apache Access events frequency
type: frequency
index: logstash-access-apache
num_events: 600
timeframe:
  minutes: 1
alert:
- hipchat
use_terms_query: true
doc_type: apache_access
query_key: clientip.raw

fields:
- clientip.raw
- geoip.country_name

top_count_keys:
- beat.hostname
- app
- request

compare_key: clientip.raw
whitelist: ["1.2.3.4", "5.6.7.8"]

hipchat_auth_token: XXX
hipchat_room_id: XXX

Logs with the IPs 1.2.3.4 and 5.6.7.8 are triggered as well, and as I understood, it should not work like that.

arall avatar Jul 22 '16 13:07 arall

whitelist as a config option only works with type: whitelist. You can achieve this same affect by adding

filter:
  - not:
       terms:
         clientip.raw: ["1.2.3.4", "5.6.7.8"]

Qmando avatar Jul 22 '16 16:07 Qmando

@Qmando thanks for your reply. I've tried that already with no success. Stressing from the IP 1.2.3.4 triggers the alert.

Any idea why?

arall avatar Jul 26 '16 08:07 arall

The filter did not affect the results at all? That seems surprising to me. I've tested a very similar set up to confirm this. When using use_terms_query + somefield.raw as the query_key, adding that filter filtered out the results as I expected.

What version of Elasticsearch are you using? I tested it using < 2.0 and it's possible aggregation filters are not working. Can you verify that you would get no results if you add a garbage filter like

filter:
  - term:
       clientip.raw: "dlfghkjdfhgdjfkhg"

which should give 0 results at all.

Qmando avatar Jul 26 '16 22:07 Qmando

Thanks, it worked.

arall avatar Aug 05 '16 08:08 arall

@arall @Qmando

I'm using the below rule to whitelist few IP address and its working as expected. How do I achieve the same for subnet range/IP address range example /24, /16, OR 192.168.1.1-192.168.1.100 etc ...Not sure, if this can be achieved with ElastAlert?

filter:
  - not:
       terms:
         src_ip: ["10.10.10.10", "20.20.20.20", "30.30.30.30"]

sathishdsgithub avatar Jul 04 '17 17:07 sathishdsgithub

Use these https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-query-string-query.html#_regular_expressions in a filter plus type: any

Qmando avatar Jul 06 '17 20:07 Qmando

@Qmando

  • Can we use whitelist by setting the type as any ?type: any

  • Is it possible to mention two fields in compare_key ? example: compare_key: [src_ip, dst_ip] ?

sathishdsgithub avatar Jul 13 '17 06:07 sathishdsgithub

  1. I just told you you can use type: any with a filter to achieve the same effect. http://elastalert.readthedocs.io/en/latest/ruletypes.html#any

  2. http://elastalert.readthedocs.io/en/latest/ruletypes.html?highlight=compare_key#change compare_key: The names of the field to monitor for changes. Since this is list of strings, we can have multiple keys. An alert will trigger if any of the fields change.

Qmando avatar Jul 13 '17 17:07 Qmando

@Qmando Thanks, I tried different options to achieve whitelist but it's not working.

I'm trying to achieve the below working rule with whitelist but it's not matching.

Working rule with term condition

filter:
 - not:
      terms:
         srx-source-zone-name: ["EXTERNAL"]

My whitelist condition which is not working

type: any
compare_key: srx-source-zone-name
ignore_null: true

whitelist:
    - "EXTERNAL"   ==> tried with "" and without "" 

Am I missing something here?

sathishdsgithub avatar Jul 13 '17 17:07 sathishdsgithub

You can't use the whitelist option with type: any. You can use type: any plus filters to achieve that same effect.

Qmando avatar Jul 13 '17 17:07 Qmando

type: any
filter:
 - not:
      terms:
         srx-source-zone-name: ["EXTERNAL"]

is equivalent to

type: whitelist
compare_key: srx-source-zone-name
whitelist:
 - EXTERNAL

Qmando avatar Jul 13 '17 17:07 Qmando

@Qmando

If I understood correctly I cannot use both cardinality type and whitelist in same YAML rule.

Is it possible to create a separate rule with type: whitelist rule 2and the mention my file list(- "!file /tmp/whitelist1.txt" ) and call the rule 2 to my rule 1 ? if possible let me know how to call the rule 2 to my rule 1? will it work?

sathishdsgithub avatar Jul 13 '17 17:07 sathishdsgithub

@Qmando

Can I use something like below?

type: cardinality filter:

  • terms: rule_name: rule -- > whitelist rule yaml

sathishdsgithub avatar Jul 13 '17 18:07 sathishdsgithub