{"id":14647,"date":"2022-11-02T23:06:55","date_gmt":"2022-11-02T20:06:55","guid":{"rendered":"https:\/\/kifarunix.com\/?p=14647"},"modified":"2024-03-09T23:27:49","modified_gmt":"2024-03-09T20:27:49","slug":"how-to-integrate-elk-stack-with-thehive","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-integrate-elk-stack-with-thehive\/","title":{"rendered":"How to Integrate ELK Stack with TheHive"},"content":{"rendered":"\n
In this tutorial, we are going to learn how to integrate ELK stack with TheHive. ELK Stack can be configured to sent event alerts to TheHive<\/a> case management system. This enables security personnel to create, investigate and follow up on various incidents or cases.<\/p>\n\n\n\n In order to integrate ELK stack with TheHive, proceed as follows;<\/p>\n\n\n\n Follow the link below to learn how t install ELK Stack;<\/p>\n\n\n\n Install and Configure ELK Stack<\/a><\/p>\n\n\n\n You can check the guide below on how to install TheHive;<\/p>\n\n\n\n Install TheHive on Ubuntu<\/a><\/p>\n\n\n\n “ElastAlert is a simple framework for alerting on anomalies, spikes, or other patterns of interest from data in Elasticsearch”.<\/em><\/p>\n\n\n\n In our previous guide, we learnt how to Configure ELK Stack Alerting with ElastAlert<\/a>.<\/p>\n\n\n\n Based on the guide above on how to configure ELK stack alerting with ElastAlert, you need to configure ElastAlert to sent alerts to TheHive.<\/p>\n\n\n\n ElastAlert can be configured to read specific Elasticsearch indices and check for specific events based on the defined query conditions. When those conditions are true, it can sent alerts, via the theHive alert type, to TheHive.<\/p>\n\n\n\n To begin with, login to TheHive web interface as admin user and create your organization and an administrative user for that account, if you have not done so already.<\/p>\n\n\n\n Follow the links below to learn how to create TheHive organization and an administrative user for that organization.<\/p>\n\n\n\n Creating an Organization on TheHive<\/a><\/p>\n\n\n\n Create TheHive Organization Administrative User<\/a><\/p>\n\n\n\n Login as the administrative user to your TheHive organization and add another less privileged user with permissions to create alerts via API. Remember, ElastAlert will be configured to sent alerts to TheHive via API. Hence, we will use the profile analyst<\/strong> for the API user.<\/p>\n\n\n\n Hence, under your specific Organization > click Users > +. Enter the login username, the name and choose the privileges (analyst<\/strong>).<\/p>\n\n\n\n Click Confirm<\/strong> to add the user.<\/p>\n\n\n\n Next, you need to generate the API key for the API user.<\/p>\n\n\n\n Note that we are using ElastAlert2<\/a> in our demo setup.<\/p>\n\n\n\n Define ElastAlert configuration options;<\/p>\n\n\n\n This is my sample Elastalert config for thehive;<\/p>\n\n\n\n Update your configuration accordingly;<\/p>\n\n\n\n Create ElastAlert alerting rules for TheHive;<\/p>\n\n\n\n For this, you will need to get the API key generated above.<\/p>\n\n\n\n This is our sample rules file;<\/p>\n\n\n\n Test the rule;<\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n As you can see from the test above, four events found related to failed SSH authentications within one minute.<\/p>\n\n\n\n To check if alerts can be sent to TheHive, let’s run the rule;<\/p>\n\n\n\n Now, simulate failed events to one your systems that are already collecting and sending logs to ELK stack;<\/p>\n\n\n\n Sample rule output;<\/p>\n\n\n\n As you can see, an alert has been sent to TheHive based on the alert query event match.<\/p>\n\n\n\n Login to TheHive and verify the alerts;<\/p>\n\n\n\n Hover the mouse over alert and click preview<\/strong> > Go to details<\/strong> to see more details;<\/p>\n\n\n\nIntegrating ELK Stack with TheHive<\/h2>\n\n\n\n
Install ELK Stack<\/h3>\n\n\n\n
Install TheHive<\/h3>\n\n\n\n
Configure ELK Stack Alerting Via ElastAlert<\/h3>\n\n\n\n
Configure ELK Stack to Sent Alerts to TheHive<\/h3>\n\n\n\n
Create Organization and Administrative User on TheHive<\/h4>\n\n\n\n
Create TheHive API User<\/h4>\n\n\n\n
<\/figure><\/a><\/div>\n\n\n\n
Generate TheHive Alerts API Key for the API User<\/h4>\n\n\n\n
\n
<\/figure><\/a><\/div>\n\n\n\n
\n
<\/figure><\/a><\/div>\n\n\n\n
Configure ElastAlert to Sent Alerts to TheHive<\/h4>\n\n\n\n
cat \/opt\/elastalert\/config-thehive.yaml<\/code><\/pre>\n\n\n\n
rules_folder: example_rules\nrun_every:\n minutes: 5\nbuffer_time:\n minutes: 15\nes_host: 192.168.58.22\nes_port: 9200\nwriteback_index: elastalert_status\nwriteback_alias: elastalert_alerts\nalert_time_limit:\n days: 2\n<\/code><\/pre>\n\n\n\n
cat \/opt\/elastalert\/example_rules\/thehive.yaml<\/code><\/pre>\n\n\n\n
\nname: Sample SSH Rule\ntype: frequency\nnum_events: 3\ntimeframe:\n minutes: 1\nfilter:\n- query:\n query_string:\n query: \"event.type:authentication_failure\"\nindex: filebeat-*\nrealert:\n minutes: 1\nquery_key:\n - source.ip\ninclude:\n - source.ip\n - host.hostname\n - user.name\n\nalert: hivealerter\nhive_connection:\n hive_host: http:\/\/thehive.kifarunix-demo.com\n hive_port: 9000\n hive_apikey: Uf0W20Mf9UTYrLuI\/hyn74ni9UzFZJvb\n hive_proxies:\n http: ''\n https: ''\n\nhive_alert_config:\n title: 'SSH Bruteforce Attacks'\n type: 'external'\n source: 'elastalert'\n description: 'SSH Bruteforce Attacks'\n severity: 2\n tags: ['ssh', 'bruteforce', 'authentications']\n tlp: 3\n status: 'New'\n follow: True\n\nhive_observable_data_mapping:\n - ip: source.ip\n - hostname: host.hostname\n<\/code><\/pre>\n\n\n\n
elastalert-test-rule --config \/opt\/elastalert\/config-thehive.yaml \/opt\/elastalert\/example_rules\/thehive.yaml<\/code><\/pre>\n\n\n\n
\nINFO:elastalert:Note: In debug mode, alerts will be logged to console but NOT actually sent.\n To send them but remain verbose, use --verbose instead.\nGot 155 hits from the last 0 day\n\nAvailable terms in first hit:\n\tagent.hostname\n\tagent.name\n\tagent.id\n\tagent.ephemeral_id\n\tagent.type\n\tagent.version\n\tprocess.name\n\tprocess.pid\n\tlog.file.path\n\tlog.offset\n\tsource.port\n\tsource.ip\n\tfileset.name\n\tinput.type\n\t@timestamp\n\tsystem.auth.ssh.method\n\tsystem.auth.ssh.event\n\tecs.version\n\trelated.hosts\n\trelated.ip\n\trelated.user\n\tservice.type\n\thost.hostname\n\thost.os.kernel\n\thost.os.codename\n\thost.os.name\n\thost.os.type\n\thost.os.family\n\thost.os.version\n\thost.os.platform\n\thost.containerized\n\thost.ip\n\thost.name\n\thost.id\n\thost.mac\n\thost.architecture\n\tevent.ingested\n\tevent.timezone\n\tevent.kind\n\tevent.module\n\tevent.action\n\tevent.type\n\tevent.category\n\tevent.dataset\n\tevent.outcome\n\tuser.name\n\nINFO:elastalert:Note: In debug mode, alerts will be logged to console but NOT actually sent.\n To send them but remain verbose, use --verbose instead.\nINFO:elastalert:1 rules loaded\nINFO:apscheduler.scheduler:Adding job tentatively -- it will be properly scheduled when the scheduler starts\nINFO:elastalert:Queried rule Sample SSH Rule from 2022-11-02 22:30 EAT to 2022-11-02 22:31 EAT: 4 \/ 4 hits\nINFO:elastalert:Alert for Sample SSH Rule at 2022-11-02T22:31:17+03:00:\nINFO:elastalert:Sample SSH Rule\n\nAt least 3 events occurred between 2022-11-02 22:30 EAT and 2022-11-02 22:31 EAT\n\n@timestamp: 2022-11-02T22:31:17+03:00\n_id: HK3TOYQBtG6LAFezqKdP\n_index: filebeat-7.17.0-2022.10.20-000001\n_type: _doc\nhost: {\n \"hostname\": \"debian11\"\n}\nnum_hits: 4\nnum_matches: 1\nsource: {\n \"ip\": \"192.168.58.50\"\n}\nuser: {\n \"name\": \"socadmin\"\n}\n\n\nWould have written the following documents to writeback index (default is elastalert_status):\n\nsilence - {'exponent': 0, 'rule_name': 'Sample SSH Rule.192.168.58.50', '@timestamp': datetime.datetime(2022, 11, 2, 19, 31, 29, 378481, tzinfo=tzutc()), 'until': datetime.datetime(2022, 11, 2, 19, 36, 29, 378473, tzinfo=tzutc())}\n\nelastalert_status - {'rule_name': 'Sample SSH Rule', 'endtime': datetime.datetime(2022, 11, 2, 19, 31, 29, 222934, tzinfo=tzutc()), 'starttime': datetime.datetime(2022, 11, 2, 19, 30, 28, 622934, tzinfo=tzutc()), 'matches': 1, 'hits': 4, '@timestamp': datetime.datetime(2022, 11, 2, 19, 31, 29, 379893, tzinfo=tzutc()), 'time_taken': 0.008604764938354492}\n<\/code><\/pre>\n\n\n\n
Run ElastAlert Against the TheHive Rule<\/h4>\n\n\n\n
\/usr\/local\/bin\/elastalert --verbose --config \/opt\/elastalert\/config-thehive.yaml --rule \/opt\/elastalert\/example_rules\/thehive.yaml<\/code><\/pre>\n\n\n\n
\nINFO:elastalert:1 rules loaded\nINFO:elastalert:Starting up\nINFO:elastalert:Disabled rules are: []\nINFO:elastalert:Sleeping for 299.999836 seconds\nINFO:elastalert:Queried rule Sample SSH Rule from 2022-11-02 22:27 EAT to 2022-11-02 22:32 EAT: 16 \/ 16 hits\nINFO:elastalert:Alert sent to TheHive\nINFO:elastalert:Ran Sample SSH Rule from 2022-11-02 22:27 EAT to 2022-11-02 22:32 EAT: 16 query hits (0 already seen), 5 matches, 1 alerts sent\nINFO:elastalert:Sample SSH Rule range 337\n<\/code><\/pre>\n\n\n\n
<\/figure><\/a><\/div>\n\n\n\n