Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3 rule added to monitor potential defacement attempts #563

Closed
wants to merge 8 commits into from

Conversation

nkulig
Copy link
Contributor

@nkulig nkulig commented Nov 23, 2022

Background

As part of Project Odin, we are looking to provide more out-of-the-box coverage against MITRE ATT&CK. Using Ed's findings in this Asana task, I put together this rule. Please let me know how it could be improved!

Changes

  • Adding a AWS S3 Rule that could potentially cover MITRE ATT&CK - TA0040:T1491

Testing

  • Pulled a log event that matched Ed's query here. Used a row from that query as my unit test to build the detection.

@nkulig nkulig requested review from a team November 23, 2022 23:17
def rule(event):

# Quick exit if event contains ignored value
if event.get("operation") in OPERATIONS:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is doing what you want.

>>> OPERATIONS = ["REST.GET.", "REST.HEAD.", "S3.EXPIRE.OBJECT"]
>>> "REST.GET.POLICY_STATUS" in OPERATIONS
False

@@ -0,0 +1,44 @@
# Ignore certain operations, users, user agents and specifc iam roles
OPERATIONS = ["REST.GET.", "REST.HEAD.", "S3.EXPIRE.OBJECT"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest marking these as EXCLUDE_OPERATIONS, etc

Copy link
Contributor

@edyesed edyesed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that these exclude/include rules aren't behaving as intended. I suggest checking out this detection as a cross-reference.

I believe you'll want to implement both the looping for the constants and to bring in fnmatch to do the matching.

Additionally, this detection should bring a positive and negative test case for each of the early-exit/exclusion checks to demonstrate how those evaluations behave.

@nkulig
Copy link
Contributor Author

nkulig commented Nov 28, 2022

Thank you for the suggestions, Ed! I am working on improving the logic now.

@nkulig
Copy link
Contributor Author

nkulig commented Nov 28, 2022

Let me know your thoughts when you have a moment Ed! Im sure there is a way to simplify this detection but its not immediately obvious to me at the moment.

@nkulig
Copy link
Contributor Author

nkulig commented Dec 5, 2022

@edyesed - any suggestions for this rule?

if fnmatch(event.get("key"), item):
return True

return True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default should return False . When the default is True, lines 31-39 are unnecessary processing

- TA0040:T1491
Severity: Low
Tests:
- ExpectedResult: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This detection should include test cases that show

  1. S3 Get operation which does not match the EXCLUDE_* rules -> false
  2. At least one test case demonstrating that the EXCLUDE_* functions -> false
  3. a s3 put operation which returns -> true. You'll need to mock the INCLUDED_BUCKET_NAMES object. I'm happy to help with that if you would like 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey hey! I made some changes and pushed them. However, it doesn't appear to pass linting:

rules/aws_s3_rules/aws_s3_bucket_defacement_attempt.py:22:0: R1260: 'rule' is too complex. The McCabe rating is 15 (too-complex)
rules/aws_s3_rules/aws_s3_bucket_defacement_attempt.py:22:0: R0911: Too many return statements (7/6) (too-many-return-statements)
rules/aws_s3_rules/aws_s3_bucket_defacement_attempt.py:22:0: R0912: Too many branches (14/12) (too-many-branches)

Are those thresholds arbitrary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those thresholds are intentional ( arbitrary is a word that might be universally applied to any style/lint guidelines ). There's ~1 detection that's disabling these by intention. I can take a look in here and see if there's a way to logically simplify the detection

Nicholas Kuligoski and others added 2 commits January 6, 2023 11:47
Copy link
Contributor

@edyesed edyesed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creates an alert when the contents of user-defined high-priority buckets change.

rules/aws_s3_rules/aws_s3_bucket_defacement_attempt.py Outdated Show resolved Hide resolved
@zacbrown zacbrown removed the request for review from a team May 31, 2023 20:24
@arielkr256 arielkr256 closed this Oct 22, 2024
@le4ker le4ker deleted the nkulig-mitre-attack-TA0040-T1491 branch December 4, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants