Skip to content

Commit

Permalink
PantherFlow Investigator Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
arielkr256 committed Nov 27, 2024
1 parent d02d3e7 commit f351fe3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions global_helpers/panther_aws_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Dict, List

import boto3
from panther_base_helpers import pantherflow_investigation
from panther_config import config


Expand Down Expand Up @@ -38,6 +39,7 @@ def aws_rule_context(event):
"sourceIPAddress": event.get("sourceIPAddress", "<MISSING_SOURCE_IP>"),
"userAgent": event.get("userAgent", "<MISSING_USER_AGENT>"),
"userIdentity": event.get("userIdentity", "<MISSING_USER_IDENTITY>"),
"PantherFlow Investigation": pantherflow_investigation(event),
}


Expand Down
24 changes: 24 additions & 0 deletions global_helpers/panther_base_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,27 @@ def add_parse_delay(event, context: dict) -> dict:
parsing_delay = time_delta(event.get("p_event_time"), event.get("p_parse_time"))
context["parseDelay"] = f"{parsing_delay}"
return context


# generate a PantherFlow investigation from an event
def pantherflow_investigation(event, interval="30m"):
logtype = event.get("p_log_type", "").lower().replace(".", "_")
timestamp = event.get("p_event_time", "")

query = f"""
union panther_signals.public.correlation_signals
, panther_logs.public.{logtype}
| where p_event_time between datetime('{timestamp}') - time.parse_timespan('{interval}') .. datetime('{timestamp}') + time.parse_timespan('{interval}')
"""

first = True
for key, value in event.items():
if key.startswith("p_any_") and key != "p_any_aws_account_ids":
if first:
query += f"| where arrays.overlap({key}, {value})\n"
first = False
else:
query += f" or arrays.overlap({key}, {value})\n"
query += "| sort p_event_time\n"

return query
4 changes: 4 additions & 0 deletions global_helpers/panther_okta_helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from panther_base_helpers import pantherflow_investigation


def okta_alert_context(event):
"""Returns common context for automation of Okta alerts"""
return {
Expand All @@ -12,4 +15,5 @@ def okta_alert_context(event):
"authentication_context": event.get("authenticationcontext", {}),
"security_context": event.get("securitycontext", {}),
"ips": event.get("p_any_ip_addresses", []),
"PantherFlow Investigation": pantherflow_investigation(event),
}

0 comments on commit f351fe3

Please sign in to comment.