AnalysisType: rule
Filename: aws_iam_backdoor_role.py
RuleID: "AWS.IAM.BackdoorRole"
DisplayName: "IAM Role Policy Updated to Allow Internet Access"
Enabled: true
LogTypes:
- AWS.CloudTrail
Tags:
- AWS
- Security Control
- IAM
Reports:
CIS:
- 1.1
MITRE ATT&CK:
- TA0007:T1078
Severity: Medium
Description: >
An IAM role policy was updated to allow internet access, which could indicate a backdoor.
Runbook: Check if the action was authorized and if the policy was updated by a trusted user. If not, revert the policy and investigate the user
Reference: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html
Tests:
- Name: IAM Role Policy Updated to Allow Internet Access
ExpectedResult: true
Log:
{
"eventVersion": "1.05",
"userIdentity":
{
"type": "AssumedRole",
"principalId": "tester",
"arn": "arn:aws:sts::123456789012:assumed-role/tester",
"accountId": "123456789012",
"accessKeyId": "1",
"sessionContext":
{
"sessionIssuer":
{
"type": "Role",
"principalId": "1111",
"arn": "arn:aws:iam::123456789012:role/tester",
"accountId": "123456789012",
"userName": "Tester",
},
"webIdFederationData": {},
"attributes":
{
"mfaAuthenticated": "true",
"creationDate": "2019-01-01T00:00:00Z",
},
},
},
"eventTime": "2019-01-01T00:00:00Z",
"eventSource": "iam.amazonaws.com",
"eventName": "UpdateAssumeRolePolicy",
"awsRegion": "us-west-2",
"sourceIPAddress": "111.111.111.111",
"userAgent": "console.amazonaws.com",
"requestParameters":
{
"policyDocument": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"sts:AssumeRole\",\"Condition\":{\"StringEquals\":{\"sts:ExternalId\":\"12345\"}}}]}"
},
"responseElements": null,
"requestID": "1",
"eventID": "1",
"readOnly": false,
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012",
}
- Name: IAM Role Policy Updated Without Internet Access
ExpectedResult: false
Log:
{
"eventVersion": "1.05",
"userIdentity":
{
"type": "AssumedRole",
"principalId": "tester",
"arn": "arn:aws:sts::123456789012:assumed-role/tester",
"accountId": "123456789012",
"accessKeyId": "1",
"sessionContext":
{
"sessionIssuer":
{
"type": "Role",
"principalId": "1111",
"arn": "arn:aws:iam::123456789012:role/tester",
"accountId": "123456789012",
"userName": "Tester",
},
"webIdFederationData": {},
"attributes":
{
"mfaAuthenticated": "true",
"creationDate": "2019-01-01T00:00:00Z",
},
},
},
"eventTime": "2019-01-01T00:00:00Z",
"eventSource": "iam.amazonaws.com",
"eventName": "UpdateAssumeRolePolicy",
"awsRegion": "us-west-2",
"sourceIPAddress": "111.111.111.111",
"userAgent": "console.amazonaws.com",
"requestParameters":
{
"policyDocument": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
},
"responseElements": null,
"requestID": "1",
"eventID": "1",
"readOnly": false,
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012",
}
- Name: IAM Role Policy Updated With No Policy Document
ExpectedResult: false
Log:
{
"eventVersion": "1.05",
"userIdentity":
{
"type": "AssumedRole",
"principalId": "tester",
"arn": "arn:aws:sts::123456789012:assumed-role/tester",
"accountId": "123456789012",
"accessKeyId": "1",
"sessionContext":
{
"sessionIssuer":
{
"type": "Role",
"principalId": "1111",
"arn": "arn:aws:iam::123456789012:role/tester",
"accountId": "123456789012",
"userName": "Tester",
},
"webIdFederationData": { },
"attributes":
{
"mfaAuthenticated": "true",
"creationDate": "2019-01-01T00:00:00Z",
},
},
},
"eventTime": "2019-01-01T00:00:00Z",
"eventSource": "iam.amazonaws.com",
"eventName": "UpdateAssumeRolePolicy",
"awsRegion": "us-west-2",
"sourceIPAddress": "111.111.111.111",
"userAgent": "console.amazonaws.com",
"requestParameters":
{},
"responseElements": null,
"requestID": "1",
"eventID": "1",
"readOnly": false,
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012",
}
# ------ paired body: aws_iam_backdoor_role.py ------
import json
from panther_aws_helpers import aws_cloudtrail_success, aws_rule_context
from policyuniverse.policy import Policy
def rule(event):
if not aws_cloudtrail_success(event) or event.get("eventName") != "UpdateAssumeRolePolicy":
return False
policy = event.deep_get("requestParameters", "policyDocument", default="{}")
return Policy(json.loads(policy)).is_internet_accessible()
def alert_context(event):
return aws_rule_context(event)