Skip to content

Commit

Permalink
Merge branch 'develop' into revert-1429-panos/revert-noisy-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
arielkr256 authored Dec 4, 2024
2 parents d587c90 + ea063d5 commit b1059e2
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-deprecated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: block
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-mitre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: block
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-packs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: block
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Build Dockerfile
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: block
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: block
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
API_HOST: ${{ secrets.GA_API_HOST }}
API_TOKEN: ${{ secrets.GA_API_TOKEN }}
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.PANTHER_BOT_AUTOMATION_TOKEN }}
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: audit
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
API_HOST: ${{ secrets.API_HOST }}
API_TOKEN: ${{ secrets.API_TOKEN }}
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
disable-sudo: true
egress-policy: audit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
API_HOST: ${{ secrets.API_HOST }}
API_TOKEN: ${{ secrets.API_TOKEN }}
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
API_HOST: ${{ secrets.API_HOST }}
API_TOKEN: ${{ secrets.API_TOKEN }}
steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
- uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- name: Validate Secrets
Expand Down
48 changes: 48 additions & 0 deletions global_helpers/global_helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2391,5 +2391,53 @@ def test_change_filed_is_empty_on_update_context(self):
)


class TestPantherFlowInvestigation(unittest.TestCase):
def test_pantherflow_investigation(self):
# pylint: disable=line-too-long
event = {
"p_any_ip_addresses": ["12.34.56.78"],
"p_source_file": {
"aws_s3_bucket": "threat-research-trail-trail-bucket-0ipb5nzxam",
"aws_s3_key": "AWSLogs/123456789123/CloudTrail/us-east-1/2024/11/25/123456789123_CloudTrail_us-east-1_20241125T1505Z_XLixf09QqBSOD7c4.json.gz",
},
"p_any_trace_ids": ["ASIAQWERTYUIOPASDFGH"],
"p_any_actor_ids": ["AROAQWERTYUIOPASDFGH", "AROAQWERTYUIOPASDFGH:bob.ross"],
"p_any_aws_account_ids": ["123456789123"],
"p_any_aws_arns": [
"arn:aws:iam::123456789123:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_DevAdmin",
"arn:aws:sts::123456789123:assumed-role/AWSReservedSSO_DevAdmin/bob.ross",
"arn:aws:iam::123456789123:role/aws-reserved/sso.amazonaws.com/us-west-2/AWSReservedSSO_DevAdmin",
],
"p_any_usernames": ["AWSReservedSSO_DevAdmin", "bob.ross"],
"p_event_time": "2024-11-25 15:00:21.000000",
"p_log_type": "AWS.CloudTrail",
"p_parse_time": "2024-11-25 15:05:54.123385",
"p_row_id": "d66379c617d1f7b3b2e7ce9623c104",
"p_schema_version": 0,
"p_source_id": "d0a1e235-6548-4e7f-952a-35063b304007",
"p_source_label": "threat-research-trail-us-east-1",
"p_udm": {
"source": {"address": "12.34.56.78", "ip": "12.34.56.78"},
"user": {
"arns": [
"arn:aws:iam::123456789123:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_DevAdmin",
"arn:aws:sts::123456789123:assumed-role/AWSReservedSSO_DevAdmin/bob.ross",
]
},
},
}
event = ImmutableCaseInsensitiveDict(event)
query = """union panther_signals.public.correlation_signals
, panther_logs.public.aws_cloudtrail
| where p_event_time between datetime('2024-11-25 15:00:21.000000') - time.parse_timespan('30m') .. datetime('2024-11-25 15:00:21.000000') + time.parse_timespan('30m')
| where arrays.overlap(p_any_ip_addresses, ['12.34.56.78'])
or arrays.overlap(p_any_trace_ids, ['ASIAQWERTYUIOPASDFGH'])
or arrays.overlap(p_any_actor_ids, ['AROAQWERTYUIOPASDFGH', 'AROAQWERTYUIOPASDFGH:bob.ross'])
or arrays.overlap(p_any_aws_arns, ['arn:aws:iam::123456789123:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_DevAdmin', 'arn:aws:sts::123456789123:assumed-role/AWSReservedSSO_DevAdmin/bob.ross', 'arn:aws:iam::123456789123:role/aws-reserved/sso.amazonaws.com/us-west-2/AWSReservedSSO_DevAdmin'])
or arrays.overlap(p_any_usernames, ['AWSReservedSSO_DevAdmin', 'bob.ross'])
| sort p_event_time"""
self.assertEqual(p_b_h.pantherflow_investigation(event), query)


if __name__ == "__main__":
unittest.main()
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
23 changes: 23 additions & 0 deletions global_helpers/panther_base_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,26 @@ 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.copy()})\n"
first = False
else:
query += f" or arrays.overlap({key}, {value.copy()})\n"
query += "| sort p_event_time"

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),
}
9 changes: 7 additions & 2 deletions rules/wiz_rules/wiz_alert_passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ def title(event):


def severity(event):
# if event.get("severity") == "INFORMATIONAL":
# return "INFO"
return event.get("severity")


def dedup(event):
# For lower-severity events, dedup based on specific source rule to reduce overall alert volume
if event.get("severity") in ("INFO", "LOW"):
dedup_str = str(event.deep_get("sourceRule", "id"))
if dedup_str:
return dedup_str
# If the severity is higher, or for some reason we couldn't generate a dedup string based on
# the source rule, then use the alert severity + the resource ID itself.
return event.deep_get(
"entitySnapshot", "externalId", default="<RESOURCE_NOT_FOUND>"
) + event.get("severity", "<SEVERITY_NOT_FOUND>")
Expand Down
66 changes: 66 additions & 0 deletions rules/wiz_rules/wiz_alert_passthrough.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,72 @@ Tests:
"type": "TOXIC_COMBINATION",
"updatedAt": "2024-06-04 02:28:06.763277000"
}
- Name: Low-Severity Open Alert
ExpectedResult: true
Log:
{
"createdAt": "2024-06-04 02:28:06.763277000",
"entitySnapshot": {
"cloudProviderURL": "",
"externalId": "someExternalId",
"id": "12345",
"name": "someName",
"nativeType": "",
"providerId": "someProviderId",
"region": "",
"resourceGroupExternalId": "",
"subscriptionExternalId": "",
"subscriptionName": "",
"tags": { },
"type": "DATA_FINDING"
},
"id": "54321",
"notes": [ ],
"projects": [
{
"businessUnit": "",
"id": "45678",
"name": "Project 2",
"riskProfile": {
"businessImpact": "MBI"
},
"slug": "project-2"
},
],
"serviceTickets": [ ],
"severity": "LOW",
"sourceRule": {
"__typename": "Control",
"controlDescription": "Alert Description",
"id": "12345",
"name": "Alert Name",
"resolutionRecommendation": "Alert Resolution Recommendation",
"securitySubCategories": [
{
"category": {
"framework": {
"name": "Wiz for Risk Assessment"
},
"name": "High Profile Threats"
},
"title": "High-profile vulnerability exploited in the wild"
},
{
"category": {
"framework": {
"name": "MITRE ATT&CK Matrix"
},
"name": "TA0001 Initial Access"
},
"title": "T1190 Exploit Public-Facing Application"
},
]
},
"status": "OPEN",
"statusChangedAt": "2024-06-04 02:28:06.597355000",
"type": "TOXIC_COMBINATION",
"updatedAt": "2024-06-04 02:28:06.763277000"
}
- Name: Resolved Alert
ExpectedResult: false
Log:
Expand Down

0 comments on commit b1059e2

Please sign in to comment.