-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #837 from yeti-platform/investigation
Investigations
- Loading branch information
Showing
9 changed files
with
418 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from datetime import timedelta, datetime | ||
from time import sleep | ||
import logging | ||
|
||
from core.schemas import observable | ||
from core.schemas.observables import ipv4, hostname, url, sha1, md5, sha256, path | ||
from core.schemas.entity import Investigation | ||
from core.schemas import task | ||
from core import taskmanager | ||
from core.config.config import yeti_config | ||
|
||
from timesketch_api_client import client | ||
|
||
|
||
TIMESKETCH_TYPE_MAPPING = { | ||
'ipv4': ipv4.IPv4, | ||
'hostname': hostname.Hostname, | ||
'hash_sha1': sha1.SHA1, | ||
'hash_md5': md5.MD5, | ||
'hash_sha256': sha256.SHA256, | ||
'url': url.Url, | ||
'fs_path': path.Path, | ||
} | ||
|
||
class Timesketch(task.FeedTask): | ||
|
||
_defaults = { | ||
"name": "Timesketch", | ||
"frequency": timedelta(hours=1), | ||
"type": "feed", | ||
"description": "This feed creates Investigations from a Timesketch server.", | ||
} | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._endpoint = yeti_config.get("timesketch", "endpoint") | ||
if not self._endpoint: | ||
logging.error("Timesketch cannot proceed without an endpoint.") | ||
return | ||
username = yeti_config.get("timesketch", "username") | ||
password = yeti_config.get("timesketch", "password") | ||
|
||
self._ts_client = client.TimesketchApi(self._endpoint, username, password) | ||
|
||
|
||
def run(self): | ||
if not self._endpoint: | ||
logging.error("Timesketch cannot proceed without an endpoint.") | ||
return | ||
|
||
sketches = self._ts_client.list_sketches() | ||
|
||
for sketch in sketches: | ||
description = "# Timelines\n\n" | ||
for timeline in sketch.list_timelines(): | ||
description += f"- {timeline.name}\n" | ||
|
||
created_at = datetime.strptime(sketch.resource_data['objects'][0]['created_at'], "%Y-%m-%dT%H:%M:%S.%f") | ||
|
||
investigation = Investigation( | ||
name=sketch.name, | ||
created=created_at, | ||
reference=f'{self._endpoint}/sketch/{sketch.id}', | ||
description=description, | ||
).save() | ||
for intel in sketch.get_intelligence_attribute(): | ||
observable_type = TIMESKETCH_TYPE_MAPPING.get(intel['type']) | ||
if observable_type: | ||
obs = observable_type(value=intel['ioc']).save() | ||
else: | ||
try: | ||
obs = observable.Observable.add_text(intel['ioc']) | ||
except ValueError as error: | ||
logging.error('Error adding observable %s from Timesketch: %s', intel['ioc'], error) | ||
continue | ||
|
||
obs.tag(intel['tags']) | ||
obs.add_context("timesketch", {'sketch_link': intel['externalURI'], 'sketch_tags': intel['tags']}) | ||
obs.link_to(investigation, "seen in", f"Observable seen in {investigation.name}") | ||
|
||
|
||
taskmanager.TaskManager.register_task(Timesketch) |
Oops, something went wrong.