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

AWS Rule Tuning #66

Merged
merged 8 commits into from
Jun 12, 2020
Merged

AWS Rule Tuning #66

merged 8 commits into from
Jun 12, 2020

Conversation

jacknagz
Copy link
Contributor

Background

General cleanup, adding deduplication, add better titles, add some helpers.

Changes

  • Tune existing CloudTrail/S3 Rules
  • Add helper functions around common logic
  • Add a new rule around detecting recon

Testing

  • Panther Analysis Tool

elif event['eventName'] == 'StopLogging':
action = 'stopped'
return 'CloudTrail [{}] in account [{}] has been {}'.format(
trail_arn, lookup_aws_account_name(event['recipientAccountId']), action)
Copy link
Contributor

Choose a reason for hiding this comment

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

If neither condition is true, you will get a runtime exception:

UnboundLocalError: local variable 'action' referenced before assignment

I know this may not be possible right now with the rule, but still better to have a default value rather than risk an exception. Set action = '(unknown)' or some other default before the if statement on line 21


def rule(event):
# Filter events
if event['errorCode'] != 'AccessDenied':
Copy link
Contributor

Choose a reason for hiding this comment

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

Is errorCode always defined? if event.get('errorCode') != 'AccessDenied' to be safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call

Copy link
Contributor

Choose a reason for hiding this comment

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

errorCode is not a required field, should be a safe lookup.

aws_cloudtrail_rules/aws_iam_user_recon_denied.py Outdated Show resolved Hide resolved
@@ -258,6 +259,26 @@ def aws_strip_role_session_id(user_identity_arn):
return user_identity_arn


def check_threshold(key: str,
Copy link
Contributor

Choose a reason for hiding this comment

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

"Check threshold" makes it sound read-only, but you're changing the counter value. let's make that clear somehow. Maybe increment_and_threshold or increment_and_check



def pattern_match(string_to_match: str, pattern: str):
return fnmatch(string_to_match, pattern)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if from panther_oss_helpers import pattern_match is any better than from fnmatch import fnmatch

I'd vote to remove this one

jacknagz and others added 2 commits June 12, 2020 12:03
Co-authored-by: Austin Byers <austin.byers@runpanther.io>
def rule(event):
return (event['eventName'] == 'ConsoleLogin' and
event['userIdentity'].get('type') == 'IAMUser' and
event.get('responseElements', {}).get('ConsoleLogin') == 'Failure')


def dedup(event):
return event['userIdentity'].get('arn')
return event['recipientAccountId']
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a required field, this should be a safe lookup with .get

def rule(event):
return (event['eventName'] == 'ConsoleLogin' and
event['userIdentity'].get('type') == 'Root' and
event.get('responseElements', {}).get('ConsoleLogin') == 'Success')


def dedup(event):
return event.get('sourceIPAddress')
return '{ip}-{account}'.format(ip=event['sourceIPAddress'],
account=event['recipientAccountId'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about recipientAccountId.


def rule(event):
# Filter events
if event['errorCode'] != 'AccessDenied':
Copy link
Contributor

Choose a reason for hiding this comment

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

errorCode is not a required field, should be a safe lookup.

@jacknagz jacknagz requested a review from nhakmiller June 12, 2020 19:26
@jacknagz jacknagz merged commit 69893cf into master Jun 12, 2020
@jacknagz jacknagz deleted the jacknagz-update-cloudtrail-rules branch June 12, 2020 19:50
melenevskyi pushed a commit that referenced this pull request Dec 12, 2023
* add contains function

* add test & fix bug
egibs pushed a commit that referenced this pull request Feb 7, 2024
* Checking log keypath existence when using Expressions

* BugFix - GCP serviceusage.apiKeys.create Privilege Escalation
egibs pushed a commit that referenced this pull request Feb 7, 2024
…1089)

* BugFix - GCP serviceusage.apiKeys.create Privilege Escalation (#66)

* Checking log keypath existence when using Expressions

* BugFix - GCP serviceusage.apiKeys.create Privilege Escalation

* Appease the linter

---------

Co-authored-by: akozlovets098 <95437895+akozlovets098@users.noreply.github.com>
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