|
| 1 | +[[prebuilt-rule-8-17-13-aws-access-token-used-from-multiple-addresses]] |
| 2 | +=== AWS Access Token Used from Multiple Addresses |
| 3 | + |
| 4 | +This rule identifies potentially suspicious activity by detecting instances where a single IAM user's temporary session token is accessed from multiple IP addresses within a short time frame. Such behavior may suggest that an adversary has compromised temporary credentials and is utilizing them from various locations. To enhance detection accuracy and minimize false positives, the rule incorporates criteria that evaluate unique IP addresses, user agents, cities, and networks. These additional checks help distinguish between legitimate distributed access patterns and potential credential misuse. Detected activities are classified into different types based on the combination of unique indicators, with each classification assigned a fidelity score reflecting the likelihood of malicious behavior. High fidelity scores are given to patterns most indicative of threats, such as multiple unique IPs, networks, cities, and user agents. Medium and low fidelity scores correspond to less severe patterns, enabling security teams to effectively prioritize alerts. |
| 5 | + |
| 6 | +*Rule type*: esql |
| 7 | + |
| 8 | +*Rule indices*: None |
| 9 | + |
| 10 | +*Severity*: medium |
| 11 | + |
| 12 | +*Risk score*: 47 |
| 13 | + |
| 14 | +*Runs every*: 5m |
| 15 | + |
| 16 | +*Searches indices from*: now-32m ({ref}/common-options.html#date-math[Date Math format], see also <<rule-schedule, `Additional look-back time`>>) |
| 17 | + |
| 18 | +*Maximum alerts per execution*: 100 |
| 19 | + |
| 20 | +*References*: |
| 21 | + |
| 22 | +* https://www.sygnia.co/blog/sygnia-investigation-bybit-hack/ |
| 23 | + |
| 24 | +*Tags*: |
| 25 | + |
| 26 | +* Domain: Cloud |
| 27 | +* Data Source: AWS |
| 28 | +* Data Source: Amazon Web Services |
| 29 | +* Data Source: AWS IAM |
| 30 | +* Data Source: AWS CloudTrail |
| 31 | +* Tactic: Initial Access |
| 32 | +* Use Case: Identity and Access Audit |
| 33 | +* Resources: Investigation Guide |
| 34 | + |
| 35 | +*Version*: 101 |
| 36 | + |
| 37 | +*Rule authors*: |
| 38 | + |
| 39 | +* Elastic |
| 40 | + |
| 41 | +*Rule license*: Elastic License v2 |
| 42 | + |
| 43 | + |
| 44 | +==== Investigation guide |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +*Triage and Analysis* |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +*Investigating AWS Access Token Used from Multiple Addresses* |
| 53 | + |
| 54 | + |
| 55 | +Access tokens are bound to a single user. Usage from multiple IP addresses may indicate the token was stolen and used elsewhere. By correlating this with additional detection criteria like multiple user agents, different cities, and different networks, we can improve the fidelity of the rule and help to eliminate false positives associated with expected behavior, like dual-stack IPV4/IPV6 usage. |
| 56 | + |
| 57 | + |
| 58 | +*Possible Investigation Steps* |
| 59 | + |
| 60 | + |
| 61 | +- **Identify the IAM User**: Examine the `aws.cloudtrail.user_identity.arn` stored in `user_id` and correlate with the `source.ips` stored in `ip_list` and `unique_ips` count to determine how widely the token was used. |
| 62 | +- **Correlate Additional Detection Context**: Examine `activity_type` and `fidelity_score` to determine additional cities, networks or user agents associated with the token usage. |
| 63 | +- **Determine Access Key Type**: Examine the `access_key_id` to determine whether the token is short-term (beginning with ASIA) or long-term (beginning with AKIA). |
| 64 | +- **Check Recent MFA Events**: Determine whether the user recently enabled MFA, registered devices, or assumed a role using this token. |
| 65 | +- **Review Workload Context**: Confirm whether the user was expected to be active across multiple cities, networks or user agent environments. |
| 66 | +- **Trace Adversary Movement**: Pivot to related actions (e.g., `s3:ListBuckets`, `iam:ListUsers`, `sts:GetCallerIdentity`) to track further enumeration. |
| 67 | + |
| 68 | + |
| 69 | +*False Positive Analysis* |
| 70 | + |
| 71 | + |
| 72 | +- Automation frameworks that rotate through multiple IPs or cloud functions with dynamic egress IPs may cause this alert to fire. |
| 73 | +- Confirm geolocation and workload context before escalating. |
| 74 | + |
| 75 | + |
| 76 | +*Response and Remediation* |
| 77 | + |
| 78 | + |
| 79 | +- **Revoke the Token**: Disable or rotate the IAM credentials and invalidate the temporary session token. |
| 80 | +- **Audit the Environment**: Look for signs of lateral movement or data access during the token's validity. |
| 81 | +- **Strengthen Controls**: Require MFA for high-privilege actions, restrict access via policy conditions (e.g., IP range or device). |
| 82 | + |
| 83 | + |
| 84 | +*References* |
| 85 | + |
| 86 | + |
| 87 | +- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html[IAM Long-Term Credentials] |
| 88 | +- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html[STS Temporary Credentials] |
| 89 | +- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html[Using MFA with Temporary Credentials] |
| 90 | +- https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-standards-fsbp-controls.html[AWS Threat Detection Use Cases] |
| 91 | + |
| 92 | + |
| 93 | +==== Rule query |
| 94 | + |
| 95 | + |
| 96 | +[source, js] |
| 97 | +---------------------------------- |
| 98 | +FROM logs-aws.cloudtrail* metadata _id, _version, _index |
| 99 | +| WHERE @timestamp > NOW() - 30 minutes |
| 100 | + // filter on CloudTrail logs for STS temporary session tokens used by IAM users |
| 101 | +
|
| 102 | + AND event.dataset == "aws.cloudtrail" |
| 103 | + AND aws.cloudtrail.user_identity.arn IS NOT NULL |
| 104 | + AND aws.cloudtrail.user_identity.type == "IAMUser" |
| 105 | + AND source.ip IS NOT NULL |
| 106 | + |
| 107 | + // exclude known benign IaC tools and Amazon Network |
| 108 | + AND NOT (user_agent.original LIKE "%Terraform%" OR user_agent.original LIKE "%Ansible%" OR user_agent.original LIKE "%Pulumni%") |
| 109 | + AND `source.as.organization.name` != "AMAZON-AES" |
| 110 | + |
| 111 | + // exclude noisy service APIs less indicative of malicous behavior |
| 112 | + AND event.provider NOT IN ("health.amazonaws.com", "monitoring.amazonaws.com", "notifications.amazonaws.com", "ce.amazonaws.com", "cost-optimization-hub.amazonaws.com", "servicecatalog-appregistry.amazonaws.com", "securityhub.amazonaws.com") |
| 113 | +
|
| 114 | +| EVAL |
| 115 | + // create a time window for aggregation |
| 116 | + time_window = DATE_TRUNC(30 minutes, @timestamp), |
| 117 | + // capture necessary fields for detection and investigation |
| 118 | + user_id = aws.cloudtrail.user_identity.arn, |
| 119 | + access_key_id = aws.cloudtrail.user_identity.access_key_id, |
| 120 | + ip = source.ip, |
| 121 | + user_agent = user_agent.original, |
| 122 | + ip_string = TO_STRING(source.ip), // Convert IP to string |
| 123 | + ip_user_agent_pair = CONCAT(ip_string, " - ", user_agent.original), // Combine IP and user agent |
| 124 | + ip_city_pair = CONCAT(ip_string, " - ", source.geo.city_name), // Combine IP and city |
| 125 | + city = source.geo.city_name, |
| 126 | + event_time = @timestamp, |
| 127 | + network_arn = `source.as.organization.name` |
| 128 | +
|
| 129 | +| STATS |
| 130 | + event_actions = VALUES(event.action), |
| 131 | + event_providers = VALUES(event.provider), |
| 132 | + access_key_id = VALUES(access_key_id), |
| 133 | + user_id = VALUES(user_id), |
| 134 | + ip_list = VALUES(ip), // Collect list of IPs |
| 135 | + user_agent_list = VALUES(user_agent), // Collect list of user agents |
| 136 | + ip_user_agent_pairs = VALUES(ip_user_agent_pair), // Collect list of IP - user agent pairs |
| 137 | + cities_list = VALUES(city), // Collect list of cities |
| 138 | + ip_city_pairs = VALUES(ip_city_pair), // Collect list of IP - city pairs |
| 139 | + networks_list = VALUES(network_arn), // Collect list of networks |
| 140 | + unique_ips = COUNT_DISTINCT(ip), |
| 141 | + unique_user_agents = COUNT_DISTINCT(user_agent), |
| 142 | + unique_cities = COUNT_DISTINCT(city), |
| 143 | + unique_networks = COUNT_DISTINCT(network_arn), |
| 144 | + first_seen = MIN(event_time), |
| 145 | + last_seen = MAX(event_time), |
| 146 | + total_events = COUNT() |
| 147 | + BY time_window, access_key_id |
| 148 | +
|
| 149 | +| EVAL |
| 150 | + // activity type based on combinations of detection criteria |
| 151 | + activity_type = CASE( |
| 152 | + unique_ips >= 2 AND unique_networks >= 2 AND unique_cities >= 2 AND unique_user_agents >= 2, "multiple_ip_network_city_user_agent", // high severity |
| 153 | + unique_ips >= 2 AND unique_networks >= 2 AND unique_cities >= 2, "multiple_ip_network_city", // high severity |
| 154 | + unique_ips >= 2 AND unique_cities >= 2, "multiple_ip_and_city", // medium severity |
| 155 | + unique_ips >= 2 AND unique_networks >= 2, "multiple_ip_and_network", // medium severity |
| 156 | + unique_ips >= 2 AND unique_user_agents >= 2, "multiple_ip_and_user_agent", // low severity |
| 157 | + "normal_activity" |
| 158 | + ), |
| 159 | + // likelihood of malicious activity based on activity type |
| 160 | + fidelity_score = CASE( |
| 161 | + activity_type == "multiple_ip_network_city_user_agent", "high", |
| 162 | + activity_type == "multiple_ip_network_city", "high", |
| 163 | + activity_type == "multiple_ip_and_city", "medium", |
| 164 | + activity_type == "multiple_ip_and_network", "medium", |
| 165 | + activity_type == "multiple_ip_and_user_agent", "low" |
| 166 | + ) |
| 167 | +
|
| 168 | +| KEEP |
| 169 | + time_window, activity_type, fidelity_score, total_events, first_seen, last_seen, |
| 170 | + user_id, access_key_id, event_actions, event_providers, ip_list, user_agent_list, ip_user_agent_pairs, cities_list, ip_city_pairs, networks_list, unique_ips, unique_user_agents, unique_cities, unique_networks |
| 171 | +
|
| 172 | +| WHERE activity_type != "normal_activity" |
| 173 | +
|
| 174 | +---------------------------------- |
| 175 | + |
| 176 | +*Framework*: MITRE ATT&CK^TM^ |
| 177 | + |
| 178 | +* Tactic: |
| 179 | +** Name: Initial Access |
| 180 | +** ID: TA0001 |
| 181 | +** Reference URL: https://attack.mitre.org/tactics/TA0001/ |
| 182 | +* Technique: |
| 183 | +** Name: Valid Accounts |
| 184 | +** ID: T1078 |
| 185 | +** Reference URL: https://attack.mitre.org/techniques/T1078/ |
| 186 | +* Sub-technique: |
| 187 | +** Name: Cloud Accounts |
| 188 | +** ID: T1078.004 |
| 189 | +** Reference URL: https://attack.mitre.org/techniques/T1078/004/ |
0 commit comments