Skip to content

Commit 779c076

Browse files
Merge branch 'main' into terrancedejesus/issue5361
2 parents b4cacd4 + 9b26cd2 commit 779c076

File tree

8 files changed

+178
-113
lines changed

8 files changed

+178
-113
lines changed

detection_rules/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def parse_rules_config(path: Path | None = None) -> RulesConfig: # noqa: PLR091
227227
raise ValueError(f"rules config file does not exist: {path}")
228228
loaded = yaml.safe_load(path.read_text())
229229
elif CUSTOM_RULES_DIR:
230-
path = Path(CUSTOM_RULES_DIR) / "_config.yaml"
230+
path = Path(CUSTOM_RULES_DIR).expanduser() / "_config.yaml"
231231
if not path.exists():
232232
raise FileNotFoundError(
233233
"""

detection_rules/schemas/definitions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def validator_wrapper(value: Any) -> Any:
7676
CONDITION_VERSION_PATTERN = re.compile(rf"^\^{_version}$")
7777
VERSION_PATTERN = f"^{_version}$"
7878
MINOR_SEMVER = re.compile(r"^\d+\.\d+$")
79-
FROM_SOURCES_REGEX = re.compile(r"^\s*FROM\s+(?P<sources>.+?)\s*(?:\||\bmetadata\b|//|$)", re.IGNORECASE | re.MULTILINE)
79+
FROM_SOURCES_REGEX = re.compile(
80+
r"^\s*FROM\s+(?P<sources>(?:.+?(?:,\s*)?\n?)+?)\s*(?:\||\bmetadata\b|//|$)", re.IGNORECASE | re.MULTILINE
81+
)
8082
BRANCH_PATTERN = f"{VERSION_PATTERN}|^master$"
8183
ELASTICSEARCH_EQL_FEATURES = {
8284
"allow_negation": (Version.parse("8.9.0"), None),

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "1.5.17"
3+
version = "1.5.19"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

rules/integrations/aws/credential_access_aws_iam_assume_role_brute_force.toml

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
[metadata]
2+
creation_date = "2020/07/16"
3+
integration = ["aws"]
4+
maturity = "production"
5+
updated_date = "2025/11/25"
6+
7+
[rule]
8+
author = ["Elastic"]
9+
description = """
10+
Detects repeated failed attempts to update an IAM role’s trust policy in an AWS account, consistent with role and user
11+
enumeration techniques. In this technique, an attacker who controls credentials in the current account repeatedly calls
12+
UpdateAssumeRolePolicy on a single role, cycling through guessed cross-account role or user ARNs as the principal. When
13+
those principals are invalid, IAM returns MalformedPolicyDocumentException, producing a burst of failed
14+
UpdateAssumeRolePolicy events. This rule alerts on that brute-force pattern originating from this account, which may
15+
indicate that the account is being used as attack infrastructure or that offensive tooling (such as Pacu) is running
16+
here. Note: this rule does not detect other accounts enumerating roles, because those API calls are logged in the
17+
caller’s account, not the target account.
18+
"""
19+
from = "now-6m"
20+
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
21+
language = "kuery"
22+
license = "Elastic License v2"
23+
name = "AWS IAM Principal Enumeration via UpdateAssumeRolePolicy"
24+
note = """## Triage and analysis
25+
26+
> **Disclaimer**:
27+
> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
28+
29+
### Investigating AWS IAM Principal Enumeration via UpdateAssumeRolePolicy
30+
31+
This rule detects bursts of failed attempts to update an IAM role’s trust policy — typically resulting in `MalformedPolicyDocumentException` errors — which can indicate enumeration of IAM principals.
32+
Adversaries who have obtained valid AWS credentials may attempt to identify roles or accounts that can be assumed by repeatedly modifying a role’s trust relationship using guessed `Principal` ARNs.
33+
When these principals are invalid, IAM rejects the request, creating a recognizable sequence of failed `UpdateAssumeRolePolicy` events.
34+
35+
Because this is a threshold rule, it triggers when the number of failures exceeds a defined count within a short period. This pattern suggests brute-force-style enumeration rather than normal misconfiguration.
36+
37+
#### Possible investigation steps
38+
39+
- **Validate the context of the threshold trigger**
40+
- Review the `@timestamp` range for when the burst occurred and the number of failed attempts in the threshold window.
41+
- Identify whether all failures targeted the same `RoleName` or multiple roles — targeting a single role is often indicative of brute-force enumeration.
42+
- Confirm the source identity and IP address (`aws.cloudtrail.user_identity.arn`, `source.ip`, `user_agent.original`) to determine whether these calls originated from a known automation process or an unexpected host.
43+
44+
- **Correlate with other IAM activity**
45+
- Look for any subsequent successful `UpdateAssumeRolePolicy` or `AssumeRole` calls, which may indicate the attacker eventually discovered a valid principal.
46+
- Search for reconnaissance-related API calls (`ListRoles`, `ListUsers`, `GetCallerIdentity`) before the threshold event — these often precede enumeration bursts.
47+
- Investigate whether other suspicious role- or identity-related actions occurred near the same timeframe, such as `CreateRole`, `PutRolePolicy`, or `AttachRolePolicy`.
48+
49+
- **Identify infrastructure patterns**
50+
- Examine the `user_agent.original` field — the presence of automation frameworks or penetration tools (e.g., “Boto3”, “Pacu”) may signal offensive tooling.
51+
- Review the `source.ip` or `cloud.account.id` fields to see whether this account may be acting as attacker-controlled infrastructure attempting to enumerate roles in other environments.
52+
53+
- **Validate authorization**
54+
- Confirm with your DevOps or Cloud IAM teams whether any expected testing, migration, or cross-account role configuration changes were planned for this time period.
55+
- If the identity performing these actions does not typically manage IAM roles or trust relationships, escalate for investigation as a possible credential compromise.
56+
57+
### False positive analysis
58+
59+
- **Legitimate automation retries**
60+
- Continuous integration or configuration management systems may retry failed IAM API calls during deployment rollouts.
61+
If the same IAM role was being updated as part of a known change, validate the timing and source identity before closing as benign.
62+
- **Misconfigured scripts or infrastructure drift**
63+
- Scripts that deploy trust policies using outdated or invalid ARNs can cause repetitive failures that mimic brute-force patterns.
64+
Review the `RoleName` and `Principal` ARNs included in the failed requests to confirm if they correspond to known but outdated configurations.
65+
66+
### Response and remediation
67+
68+
- **Immediate review and containment**
69+
- Investigate whether the source account is being used for offensive operations or compromised automation.
70+
- Disable or suspend the IAM user or access key responsible for the enumeration burst.
71+
- If activity originated from a workload or CI/CD system, audit its access keys and environment variables for compromise.
72+
73+
- **Investigation and scoping**
74+
- Review CloudTrail logs for other IAM or STS actions from the same source in the preceding and following 24 hours.
75+
- Check for any successful privilege changes (`PutRolePolicy`, `AttachRolePolicy`, or `AssumeRole`) by the same identity.
76+
- Determine if other roles in the same account experienced similar failed updates or bursts.
77+
78+
- **Recovery and hardening**
79+
- Rotate credentials for any identities involved.
80+
- Limit permissions to modify trust policies (`iam:UpdateAssumeRolePolicy`) to a small set of administrative roles.
81+
- Enable AWS Config rule `iam-role-trust-policy-check` to detect overly permissive or unusual trust relationships.
82+
- Use AWS GuardDuty or Security Hub to monitor for subsequent privilege escalation or reconnaissance findings.
83+
- Review the event against AWS Incident Response Playbook guidance (containment > investigation > recovery > hardening).
84+
85+
### Additional information
86+
- **[AWS IR Playbooks](https://github.com/aws-samples/aws-incident-response-playbooks/blob/c151b0dc091755fffd4d662a8f29e2f6794da52c/playbooks/)**
87+
- **[AWS Customer Playbook Framework](https://github.com/aws-samples/aws-customer-playbook-framework/tree/a8c7b313636b406a375952ac00b2d68e89a991f2/docs)**
88+
- **Security Best Practices:** [AWS Knowledge Center – Security Best Practices](https://aws.amazon.com/premiumsupport/knowledge-center/security-best-practices/)
89+
"""
90+
references = [
91+
"https://www.praetorian.com/blog/aws-iam-assume-role-vulnerabilities",
92+
"https://rhinosecuritylabs.com/aws/assume-worst-aws-assume-role-enumeration/",
93+
]
94+
risk_score = 47
95+
rule_id = "ea248a02-bc47-4043-8e94-2885b19b2636"
96+
severity = "medium"
97+
tags = [
98+
"Domain: Cloud",
99+
"Data Source: AWS",
100+
"Data Source: Amazon Web Services",
101+
"Data Source: AWS IAM",
102+
"Use Case: Identity and Access Audit",
103+
"Resources: Investigation Guide",
104+
"Tactic: Discovery",
105+
"Tactic: Credential Access",
106+
]
107+
timestamp_override = "event.ingested"
108+
type = "threshold"
109+
110+
query = '''
111+
event.dataset: "aws.cloudtrail"
112+
and event.provider: "iam.amazonaws.com"
113+
and event.action: "UpdateAssumeRolePolicy"
114+
and aws.cloudtrail.error_code: "MalformedPolicyDocumentException"
115+
and event.outcome: "failure"
116+
'''
117+
118+
119+
[[rule.threat]]
120+
framework = "MITRE ATT&CK"
121+
[[rule.threat.technique]]
122+
id = "T1087"
123+
name = "Account Discovery"
124+
reference = "https://attack.mitre.org/techniques/T1087/"
125+
[[rule.threat.technique.subtechnique]]
126+
id = "T1087.004"
127+
name = "Cloud Account"
128+
reference = "https://attack.mitre.org/techniques/T1087/004/"
129+
130+
131+
132+
[rule.threat.tactic]
133+
id = "TA0007"
134+
name = "Discovery"
135+
reference = "https://attack.mitre.org/tactics/TA0007/"
136+
[[rule.threat]]
137+
framework = "MITRE ATT&CK"
138+
[[rule.threat.technique]]
139+
id = "T1110"
140+
name = "Brute Force"
141+
reference = "https://attack.mitre.org/techniques/T1110/"
142+
143+
144+
[rule.threat.tactic]
145+
id = "TA0006"
146+
name = "Credential Access"
147+
reference = "https://attack.mitre.org/tactics/TA0006/"
148+
149+
[rule.threshold]
150+
field = ["cloud.account.id", "user.name", "source.ip"]
151+
value = 25
152+

rules/integrations/aws/persistence_redshift_instance_creation.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
creation_date = "2022/04/12"
33
integration = ["aws"]
44
maturity = "production"
5-
updated_date = "2025/01/15"
5+
updated_date = "2025/11/25"
66

77
[rule]
88
author = ["Elastic"]
@@ -23,13 +23,13 @@ index = ["filebeat-*", "logs-aws.cloudtrail-*"]
2323
interval = "10m"
2424
language = "kuery"
2525
license = "Elastic License v2"
26-
name = "AWS Redshift Cluster Creation"
26+
name = "Deprecated - AWS Redshift Cluster Creation"
2727
note = """## Triage and analysis
2828
2929
> **Disclaimer**:
3030
> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
3131
32-
### Investigating AWS Redshift Cluster Creation
32+
### Investigating Deprecated - AWS Redshift Cluster Creation
3333
3434
Amazon Redshift is a data warehousing service that allows for scalable data storage and analysis. In a secure environment, only authorized users should create Redshift clusters. Adversaries might exploit misconfigured permissions to create clusters, potentially leading to data exfiltration or unauthorized data processing. The detection rule monitors for successful cluster creation events, especially by non-admin users, to identify potential misuse or misconfigurations.
3535

tests/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
def load_rules() -> RuleCollection:
2727
if CUSTOM_RULES_DIR:
2828
rc = RuleCollection()
29-
path = Path(CUSTOM_RULES_DIR)
29+
path = Path(CUSTOM_RULES_DIR).expanduser()
3030
assert path.exists(), f"Custom rules directory {path} does not exist"
3131
rc.load_directories(directories=RULES_CONFIG.rule_dirs)
3232
rc.freeze()
@@ -62,7 +62,7 @@ def setUpClass(cls):
6262
RULE_LOADER_FAIL = True
6363
RULE_LOADER_FAIL_MSG = str(e)
6464

65-
cls.custom_dir = Path(CUSTOM_RULES_DIR).resolve() if CUSTOM_RULES_DIR else None
65+
cls.custom_dir = Path(CUSTOM_RULES_DIR).expanduser().resolve() if CUSTOM_RULES_DIR else None
6666
cls.rules_config = RULES_CONFIG
6767

6868
@staticmethod

tests/test_rules_remote.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ def test_esql_filtered_index_error(self):
155155
with pytest.raises(EsqlSchemaError):
156156
_ = RuleCollection().load_dict(production_rule)
157157

158+
def test_new_line_split_index(self):
159+
"""Test an ESQL rule's index validation to ensure that it can handle new line split indices."""
160+
file_path = get_path(["tests", "data", "command_control_dummy_production_rule.toml"])
161+
original_production_rule = load_rule_contents(file_path)
162+
production_rule = deepcopy(original_production_rule)[0]
163+
production_rule["metadata"]["integration"] = ["aws"]
164+
production_rule["rule"]["query"] = """
165+
from logs-aws.cloud*, logs-network_traffic.http-*,
166+
logs-nginx.access-* metadata _id, _version, _index
167+
| where @timestamp > now() - 30 minutes
168+
and aws.cloudtrail.user_identity.type == "IAMUser"
169+
| keep
170+
aws.*
171+
"""
172+
_ = RuleCollection().load_dict(production_rule)
173+
158174
def test_esql_endpoint_alerts_index(self):
159175
"""Test an ESQL rule's schema validation using ecs fields in the alerts index."""
160176
file_path = get_path(["tests", "data", "command_control_dummy_production_rule.toml"])

0 commit comments

Comments
 (0)