AWS CloudTrail Password Spraying
Description
Detects password spraying attacks by alerting when more than 9 distinct usernames fail to authenticate to the AWS console from the same account and region within 60 minutes.
Query · python
from panther_aws_helpers import aws_rule_context
def rule(event):
if event.get("eventType") != "AwsConsoleSignIn":
return False
return event.deep_get("responseElements", "ConsoleLogin", default="") == "Failure"
def title(event):
account = event.get("recipientAccountId", "Unknown Account")
region = event.get("awsRegion", "Unknown Region")
return f"Password Spraying Detected in AWS Account [{account}] Region [{region}]"
def dedup(event):
account = event.get("recipientAccountId", "")
region = event.get("awsRegion", "")
return f"{account}:{region}"
def unique(event):
return event.deep_get("userIdentity", "userName") or None
def severity(event):
if event.deep_get("userIdentity", "type", default="") == "Root":
return "HIGH"
return "DEFAULT"
def alert_context(event):
return aws_rule_context(event)
Analyst notes
- Query CloudTrail for all ConsoleLogin events in the 2 hours around this alert grouped by sourceIPAddress to identify the origin of the spray targeting recipientAccountId
- Check if any of the targeted usernames subsequently had a successful ConsoleLogin from any sourceIPAddress in the 6 hours after the alert
- Find other alerts for this recipientAccountId or any of the targeted usernames in the past 7 days to determine if this is part of a broader campaign