Skip to content

Instantly share code, notes, and snippets.

@RooieRakkert
Last active April 19, 2021 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RooieRakkert/ac52b85004a1bf9fdef1635ef7497d09 to your computer and use it in GitHub Desktop.
Save RooieRakkert/ac52b85004a1bf9fdef1635ef7497d09 to your computer and use it in GitHub Desktop.
from python_rules import Rule, deep_get
import rapidjson
def original_get(e, key='event.original', default=None):
# used to return event.original field, deserialized into dictionary
# if key not found, we return empty dict
nested = deep_get(e, *key.split('.'))
if nested is None:
return default
try:
# deserialize, for example a field with '.flattened.' or 'event.original'
return rapidjson.loads(nested)
except: # couldn't be deseralized
return nested
class ConsoleLoginFailed(Rule):
# src: https://bit.ly/3e1LeoG
id = "1c6ab561-932f-4ca9-93ff-95a72a99a5be"
title = "Console login failed"
description = "AWS console login failed"
author = "Bouke Hendriks"
date = "2021/04/08"
tags = []
status = "experimental"
level = "medium"
def rule(self, e):
event = original_get(e)
accountid = deep_get(event, 'recipientAccountId')
self.description = f"AWS logins failed in account [{accountid}]"
event_name = deep_get(event, 'eventName')
if event_name != 'ConsoleLogin':
return False
user_type = deep_get(event, 'userIdentity', 'type')
response = deep_get(event, 'responseElements')
return (event_name == 'ConsoleLogin'
and user_type == 'IAMUser'
and deep_get(response, 'ConsoleLogin') == 'Failure')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment