|
4 | 4 | import json
|
5 | 5 | import logging
|
6 | 6 | import os
|
7 |
| -import re |
8 | 7 | import subprocess
|
9 | 8 | import sys
|
10 | 9 | import time
|
|
29 | 28 | from requests.exceptions import RequestException
|
30 | 29 | from staticconf.loader import yaml_loader
|
31 | 30 | from texttable import Texttable
|
32 |
| -from thehive4py.api import TheHiveApi |
33 |
| -from thehive4py.models import Alert |
34 |
| -from thehive4py.models import AlertArtifact |
35 |
| -from thehive4py.models import CustomFieldHelper |
36 | 31 | from twilio.base.exceptions import TwilioRestException
|
37 | 32 | from twilio.rest import Client as TwilioClient
|
38 | 33 |
|
@@ -2109,79 +2104,3 @@ def alert(self, matches):
|
2109 | 2104 |
|
2110 | 2105 | def get_info(self):
|
2111 | 2106 | return {"type": "linenotify", "linenotify_access_token": self.linenotify_access_token}
|
2112 |
| - |
2113 |
| - |
2114 |
| -class HiveAlerter(Alerter): |
2115 |
| - """ |
2116 |
| - Use matched data to create alerts containing observables in an instance of TheHive |
2117 |
| - """ |
2118 |
| - |
2119 |
| - required_options = set(['hive_connection', 'hive_alert_config']) |
2120 |
| - |
2121 |
| - def alert(self, matches): |
2122 |
| - |
2123 |
| - connection_details = self.rule['hive_connection'] |
2124 |
| - |
2125 |
| - api = TheHiveApi( |
2126 |
| - connection_details.get('hive_host'), |
2127 |
| - connection_details.get('hive_apikey', ''), |
2128 |
| - proxies=connection_details.get('hive_proxies', {'http': '', 'https': ''}), |
2129 |
| - cert=connection_details.get('hive_verify', False)) |
2130 |
| - |
2131 |
| - for match in matches: |
2132 |
| - context = {'rule': self.rule, 'match': match} |
2133 |
| - |
2134 |
| - artifacts = [] |
2135 |
| - for mapping in self.rule.get('hive_observable_data_mapping', []): |
2136 |
| - for observable_type, match_data_key in mapping.items(): |
2137 |
| - try: |
2138 |
| - match_data_keys = re.findall(r'\{match\[([^\]]*)\]', match_data_key) |
2139 |
| - rule_data_keys = re.findall(r'\{rule\[([^\]]*)\]', match_data_key) |
2140 |
| - data_keys = match_data_keys + rule_data_keys |
2141 |
| - context_keys = list(context['match'].keys()) + list(context['rule'].keys()) |
2142 |
| - if all([True if k in context_keys else False for k in data_keys]): |
2143 |
| - artifacts.append(AlertArtifact(dataType=observable_type, data=match_data_key.format(**context))) |
2144 |
| - except KeyError: |
2145 |
| - raise KeyError('\nformat string\n{}\nmatch data\n{}'.format(match_data_key, context)) |
2146 |
| - |
2147 |
| - alert_config = { |
2148 |
| - 'artifacts': artifacts, |
2149 |
| - 'sourceRef': str(uuid.uuid4())[0:6], |
2150 |
| - 'title': '{rule[index]}_{rule[name]}'.format(**context) |
2151 |
| - } |
2152 |
| - alert_config.update(self.rule.get('hive_alert_config', {})) |
2153 |
| - |
2154 |
| - for alert_config_field, alert_config_value in alert_config.items(): |
2155 |
| - if alert_config_field == 'customFields': |
2156 |
| - custom_fields = CustomFieldHelper() |
2157 |
| - for cf_key, cf_value in alert_config_value.items(): |
2158 |
| - try: |
2159 |
| - func = getattr(custom_fields, 'add_{}'.format(cf_value['type'])) |
2160 |
| - except AttributeError: |
2161 |
| - raise Exception('unsupported custom field type {}'.format(cf_value['type'])) |
2162 |
| - value = cf_value['value'].format(**context) |
2163 |
| - func(cf_key, value) |
2164 |
| - alert_config[alert_config_field] = custom_fields.build() |
2165 |
| - elif isinstance(alert_config_value, str): |
2166 |
| - alert_config[alert_config_field] = alert_config_value.format(**context) |
2167 |
| - elif isinstance(alert_config_value, (list, tuple)): |
2168 |
| - formatted_list = [] |
2169 |
| - for element in alert_config_value: |
2170 |
| - try: |
2171 |
| - formatted_list.append(element.format(**context)) |
2172 |
| - except (AttributeError, KeyError, IndexError): |
2173 |
| - formatted_list.append(element) |
2174 |
| - alert_config[alert_config_field] = formatted_list |
2175 |
| - |
2176 |
| - alert = Alert(**alert_config) |
2177 |
| - response = api.create_alert(alert) |
2178 |
| - |
2179 |
| - if response.status_code != 201: |
2180 |
| - raise Exception('alert not successfully created in TheHive\n{}'.format(response.text)) |
2181 |
| - |
2182 |
| - def get_info(self): |
2183 |
| - |
2184 |
| - return { |
2185 |
| - 'type': 'hivealerter', |
2186 |
| - 'hive_host': self.rule.get('hive_connection', {}).get('hive_host', '') |
2187 |
| - } |
0 commit comments