elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Comparing a list against one field

Open psymon101 opened this issue 9 years ago • 7 comments

Hi all,

I have an ELK stack which absorbs all router/fw/server logs. I also have using Logstash an indice that contains threat info from critical stack.

Can Elastalert compare all documents for a specific field within the threat info indice to another field with one value. with as the log data comes in. So if a field of the log data is called DEST_IPADDRESS it looks up that IP against all the documents in the threat indices.

I use Elastlert for everything else, but cant figure out how to lookup a one field value against a list of others.

Thanks!

psymon101 avatar Mar 22 '17 19:03 psymon101

You cannot do this out of the box. You would need to write an enhancement. If you are familiar with writing Python and want some tips on how this could work, I'd be happy to give you some pointers.

Qmando avatar Mar 22 '17 20:03 Qmando

Qmando , would appreciate any pointers! Thank you

psymon101 avatar Mar 22 '17 20:03 psymon101

Here's some terrible code to get you started. This will make a terms query on startup to get the list of bad IP addresses, and then drop each match if they don't match.

http://elastalert.readthedocs.io/en/latest/recipes/adding_enhancements.html

from elasticsearch.client import Elasticsearch
from elastalert.enhancements import BaseEnhancement, DropMatchException
class IsIPMalicious(BaseEnhancement):
    def __init__(self, *args):
        super(IsIPMalicious, self)
        query = {'aggs': {'ipaddrs': {'terms': {'field': 'ip address field here'}}}}
        es = Elasticsearch(host=self.rule['es_host'], port=self.rule['es_port'])
        res = es.search(index='index here', doc_type='_type here', body=query, search_type='count', size=0)
        self.bad_ips = [x['key'] for x in res['aggregations']['ipaddrs']['buckets']]

    def process(self, match):
        if match['ip_Address'] not in self.bad_ips:
            raise DropMatchException

You'd want your rule to have

type: any
match_enhancements: ["modules.ipaddrs.IsIPMalicious"]

obviously this code is not complete, nor does it update the list.

Qmando avatar Mar 22 '17 20:03 Qmando

Cheers Qmando , will give this a shot!

simonh101 avatar Mar 23 '17 19:03 simonh101

@simonh101

Hi, have you managed to achieve the above task..? comparing list against one field ? I'm also planning to achieve the same. Thanks

sathishdsgithub avatar Jul 30 '17 18:07 sathishdsgithub

I did, I didn't need to do the above. I have a formatted list that gets updated nightly, Using the Blacklist config option and comparing it to the field I initially mentioned . I don't think Elastalert sees the list update, so I have a script that restarts elastlert every time the list updates (Only IP`s that where not present on the previous updates).. Seems to work for me!

simonh101 avatar Jul 31 '17 12:07 simonh101

@simonh101

Just curious to know how are you updating the list automatically? are you using any Python script in the backend to update the blacklist ip address ?, If possible could you please share the example of the formatted blacklist file containing the IP address and the rule performing this task? , I would like to have it as a reference.

Appreciate your help !!!

sathishdsgithub avatar Jul 31 '17 14:07 sathishdsgithub