Skip to content

Commit 857d3f3

Browse files
authored
Merge branch 'main' into crwd_6
2 parents 3069ed6 + d2dfd46 commit 857d3f3

File tree

58 files changed

+1845
-314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1845
-314
lines changed

.github/PULL_REQUEST_GUIDELINES/bug_guidelines.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ These guidelines serve as a reminder set of considerations when addressing a bug
3131
- [ ] Ensure that the bug fix does not break existing functionality.
3232
- [ ] Review the bug fix with a peer or team member for additional insights.
3333
- [ ] Verify that the bug fix works across all relevant environments (e.g., different OS versions).
34-
- [ ] Confirm that all dependencies are up-to-date and compatible with the changes.
34+
- [ ] Confirm that all dependencies are up-to-date and compatible with the changes.
35+
- [ ] Confirm that the proper version label is applied to the PR `patch`, `minor`, `major`.

.github/PULL_REQUEST_GUIDELINES/enhancement_guidelines.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ These guidelines serve as a reminder set of considerations when addressing addin
3232
- [ ] Review the enhancement with a peer or team member for additional insights.
3333
- [ ] Verify that the enhancement works across all relevant environments (e.g., different OS versions).
3434
- [ ] Confirm that all dependencies are up-to-date and compatible with the changes.
35+
- [ ] Confirm that the proper version label is applied to the PR `patch`, `minor`, `major`.

.github/PULL_REQUEST_GUIDELINES/hunt_tuning_guidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ These guidelines serve as a reminder set of considerations when tuning an existi
2727
- [ ] Evidence of testing and valid query usage.
2828
- [ ] Markdown Generated: Run `python -m hunting generate-markdown` with specific parameters to ensure a markdown version of the hunting TOML files is created.
2929
- [ ] Index Refreshed: Run `python -m hunting refresh-index` to refresh indexes.
30-
- [ ] Run Unit Tests: Run `pytest tests/test_hunt_data.py` to run unit tests.
30+
- [ ] Run Unit Tests: Run `pytest tests/test_hunt_data.py` to run unit tests.

.github/PULL_REQUEST_GUIDELINES/schema_enhancement_guidelines.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ These guidelines serve as a reminder set of considerations when addressing addin
4343
- [ ] Implemented requisite downgrade functionality
4444
- [ ] Cross-referenced the feature with product documentation for consistency
4545
- [ ] Incorporated a comprehensive test rule in unit tests for full schema coverage
46-
- [ ] Conducted system testing, including fleet, import, and create APIs (e.g., run `make test-remote-cli`)
46+
- [ ] Conducted system testing, including fleet, import, and create APIs (e.g., run `make test-remote-cli`)
47+
- [ ] Confirm that the proper version label is applied to the PR `patch`, `minor`, `major`.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ from your submission, but they are here to help bring them to your attention.
3636

3737
<!-- Delete any items that are not applicable to this PR. -->
3838

39-
- [ ] Added a label for the type of pr: `bug`, `enhancement`, `schema`, `Rule: New`, `Rule: Deprecation`, `Rule: Tuning`, `Hunt: New`, or `Hunt: Tuning` so guidelines can be generated
39+
- [ ] Added a label for the type of pr: `bug`, `enhancement`, `schema`, `maintenance`, `Rule: New`, `Rule: Deprecation`, `Rule: Tuning`, `Hunt: New`, or `Hunt: Tuning` so guidelines can be generated
4040
- [ ] Added the `meta:rapid-merge` label if planning to merge within 24 hours
4141
- [ ] Secret and sensitive material has been managed correctly
4242
- [ ] Automated testing was updated or added to match the most common scenarios

.github/release-drafter.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name-template: 'dev-v$RESOLVED_VERSION'
2+
tag-template: 'dev-v$RESOLVED_VERSION'
3+
tag-prefix: 'dev-v'
4+
5+
categories:
6+
- title: 🚀 Features
7+
label: 'enhancement'
8+
- title: 🐛 Bug Fixes
9+
label: 'bug'
10+
- title: 🛠 Internal Changes
11+
labels:
12+
- 'maintenance'
13+
- 'schema'
14+
- 'documentation'
15+
- 'python'
16+
- title: 🔍 Hunting Updates
17+
label: 'Hunting'
18+
19+
change-template: '- $TITLE (#$NUMBER) @$AUTHOR'
20+
exclude-labels:
21+
- 'skip-changelog'
22+
23+
version-resolver:
24+
major:
25+
labels:
26+
- 'major'
27+
minor:
28+
labels:
29+
- 'minor'
30+
patch:
31+
labels:
32+
- 'patch'
33+
default: patch
34+
35+
template: |
36+
## Changes
37+
$CHANGES
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Version Code Check and Draft Release
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'lib/**'
7+
- 'hunting/**/*.py'
8+
- 'pyproject.toml'
9+
- 'Makefile'
10+
- 'docs/**'
11+
- 'detection_rules/**'
12+
- 'tests/**'
13+
- '**/*.md'
14+
types: [opened, reopened, synchronize, labeled, closed]
15+
16+
permissions:
17+
contents: read
18+
pull-requests: read
19+
20+
jobs:
21+
label_check:
22+
if: github.event_name == 'pull_request'
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Ensure PR has Version Bump Label
26+
uses: actions/github-script@v6
27+
with:
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
script: |
30+
const labels = ['major', 'minor', 'patch'];
31+
const prLabels = context.payload.pull_request.labels.map(label => label.name);
32+
const hasVersionLabel = labels.some(label => prLabels.includes(label));
33+
if (!hasVersionLabel) {
34+
throw new Error("PR must have one of the following labels: major, minor, or patch.");
35+
}
36+
37+
version_check:
38+
if: github.event_name == 'pull_request'
39+
needs: label_check
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
47+
- name: Check if core pyproject.toml was updated
48+
run: |
49+
BASE_COMMIT="${{ github.event.pull_request.base.sha }}"
50+
51+
if ! git diff --name-only "$BASE_COMMIT" "$GITHUB_SHA" | grep '^pyproject.toml$'; then
52+
echo "Code changes detected in core, but pyproject.toml was not updated."
53+
exit 1
54+
fi
55+
56+
- name: Check if lib pyproject.toml files were updated
57+
run: |
58+
BASE_COMMIT="${{ github.event.pull_request.base.sha }}"
59+
60+
if git diff --name-only "$BASE_COMMIT" "$GITHUB_SHA" | grep -E 'lib/kql/|lib/kibana/'; then
61+
if ! git diff --name-only "$BASE_COMMIT" "$GITHUB_SHA" | grep -E 'lib/kql/pyproject.toml|lib/kibana/pyproject.toml'; then
62+
echo "Changes detected in kql or kibana library, but respective pyproject.toml was not updated."
63+
exit 1
64+
fi
65+
fi
66+
67+
release_drafter:
68+
if: github.event.pull_request.merged == true
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: write
72+
steps:
73+
- name: Checkout repository
74+
uses: actions/checkout@v4
75+
76+
- name: Run Release Drafter
77+
uses: release-drafter/release-drafter@v6
78+
with:
79+
config-name: release-drafter.yml
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

detection_rules/etc/non-ecs-schema.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@
151151
"aws.cloudtrail.flattened.request_parameters.cidrIp": "keyword",
152152
"aws.cloudtrail.flattened.request_parameters.fromPort": "keyword",
153153
"aws.cloudtrail.flattened.request_parameters.roleArn": "keyword",
154+
"aws.cloudtrail.flattened.request_parameters.roleName": "keyword",
155+
"aws.cloudtrail.flattened.request_paramters.policyArn": "keyword",
154156
"aws.cloudtrail.flattened.request_parameters.serialNumber": "keyword"
155157
},
156158
"logs-azure.signinlogs-*": {

docs/versioning.md

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Supported Versions and Releases
1+
# Rule Supported Versions and Releases
22

33
This document provides detailed information about the different versions that are supported and released for prebuilt detection rules.
44

@@ -24,3 +24,138 @@ The following version(s) are maintained along with the current version.
2424
## End of Life Policy
2525

2626
Our policy is to support and provide public releases for `Current`, `Current-1`, `Current-2`, `Current-3` versions. We maintain and do not release `Current-4` and `Current-5` versions.
27+
28+
29+
# Code Supported Versions and Releases
30+
31+
This outlines the versioning strategy and release process for the [detection-rules](https://github.com/elastic/detection-rules) repository, covering the core code, `kql` and `kibana` libraries, configuration files, and the `hunting` folder. The strategy follows semantic versioning to ensure clear communication of changes to users and compatibility with different Elastic Stack versions.
32+
33+
> [!IMPORTANT]
34+
> This versioning process **excludes** the detection rules themselves. Detection rules are released separately and are not tied to the following process.
35+
36+
---
37+
38+
## Versioning Strategy
39+
40+
### Components Covered by Versioning:
41+
- **Core Detection-Rules Code**: Handles logic for rule management, CLI, etc.
42+
- **Libraries**:
43+
- **`kql`**: Manages Kibana Query Language parsing and operations.
44+
- **`kibana`**: Handles integrations and API interactions with Kibana.
45+
- **Configuration Files**: Under the `etc/` folder that impact schema and DAC.
46+
- **Hunting Logic**: The `hunting/` folder, which manages hunting rules.
47+
48+
49+
### Semantic Versioning Approach:
50+
We will use **Semantic Versioning** with the format `MAJOR.MINOR.PATCH`:
51+
- **MAJOR version (`X.0.0`)**: For backward-incompatible changes.
52+
- **MINOR version (`0.Y.0`)**: For backward-compatible new features.
53+
- **PATCH version (`0.0.Z`)**: For backward-compatible bug fixes or small improvements.
54+
55+
> [!NOTE]
56+
> The GitHub labels `patch`, `minor`, or `major` will be used in PRs to indicate the type of change being made.
57+
58+
---
59+
60+
## Versioning Guidelines
61+
62+
### Patch Version (`0.0.Z`):
63+
Increment the patch version when making bug fixes, performance improvements, or small enhancements that do not break backward compatibility. Open a PR to ensure the proper `pyproject.toml` files and any other `version` related files are bumped.
64+
65+
<details><summary>Expand for Examples</summary>
66+
<p>
67+
68+
**Examples**:
69+
- **Kibana Library**:
70+
- Minor fixes to API calls to ensure correct data retrieval.
71+
- Updates to the `kibana` lib without adding new features.
72+
- **KQL Library**:
73+
- Small bug fixes in the query parsing logic.
74+
- Optimizations that don't alter functionality.
75+
- **Core Detection-Rules Code**:
76+
- Fixes for CLI bugs or performance tweaks.
77+
- Minor enhancements to rule management that don’t require users to change workflows.
78+
- **Hunting Folder**:
79+
- Bug fixes in hunting rules logic.
80+
- Small performance tweaks for the hunting rule management.
81+
- **Docs Folder**:
82+
- Updates to documentation.
83+
84+
</p>
85+
</details>
86+
87+
---
88+
89+
### Minor Version (`0.Y.0`):
90+
Increment the minor version when adding backward-compatible new features, enhancements, or functionality.
91+
92+
<details><summary>Expand for Examples</summary>
93+
<p>
94+
95+
**Examples**:
96+
- **Kibana Library**:
97+
- Adding a new API endpoint to interact with Elastic Kibana X.Y while maintaining backward compatibility with older versions.
98+
- **KQL Library**:
99+
- Adding new query parsing functionality that is backward-compatible with previous Elastic Stack versions.
100+
- **Core Detection-Rules Code**:
101+
- New CLI commands or functionality for managing detection rules.
102+
- New optional fields in rule schemas that have minimum compatibility requirements. (e.g adding `alert_suppression` with `min_compat=8.14`).
103+
- **Hunting Folder**:
104+
- Adding new hunting rule management features that are optional and backward-compatible.
105+
- Enhancements in generating hunting rule markdown or CLI features.
106+
107+
</p>
108+
</details>
109+
110+
> [!NOTE]
111+
> When bumping this version, the patch version should be reset to `0` and the major version should remain the same.
112+
113+
---
114+
115+
### Major Version (`X.0.0`):
116+
Increment the major version when introducing backward-incompatible changes that require users to update workflows, Elastic Stack versions, or rule management strategies.
117+
118+
<details><summary>Expand for Examples</summary>
119+
<p>
120+
121+
**Examples**:
122+
- **Kibana Library**:
123+
- Replacing or removing an existing API endpoint that forces users to upgrade to Elastic X.Y
124+
- **KQL Library**:
125+
- Structural changes to query parsing logic that break compatibility with previous Elastic Stack versions.
126+
- **Core Detection-Rules Code**:
127+
- Breaking changes to rule schema definitions or CLI workflows that require user updates.
128+
- Forcing users to migrate to a newer Elastic Stack version due to changes in core code or schema compatibility.
129+
- **Hunting Folder**:
130+
- Major refactors of the hunting logic that break existing workflows.
131+
- Changes to how hunting rules are defined or managed, requiring users to adjust configurations.
132+
133+
</p>
134+
</details>
135+
136+
> [!NOTE]
137+
> When bumping this version, the minor version and patch version should be reset to `0`.
138+
139+
---
140+
141+
## Tagging Process
142+
143+
Each release will be tagged using the following format:
144+
- **Tag Format**: `dev-vX.Y.Z` (e.g., `dev-v1.2.0`).
145+
- **Single Tag for Combined Releases**: If there are changes to the core detection-rules code or libraries (`kql`, `kibana`), they will be tagged together as a single release with the core detection-rules versioning.
146+
- **Hunting Folder**: Changes to the hunting logic will be included in the combined release.
147+
148+
> [!CAUTION]
149+
> When a version is bumped in a lib, we need to also bump the core `pyproject.toml` file *(e.g A version bump in `kql` will also require a similar version bump in the core detection-rules versioning)*.
150+
---
151+
152+
## When to Trigger a GitHub Release
153+
154+
A draft release will be triggered in the following cases:
155+
- **New Feature or Bug Fix**: Once a feature or bug fix is merged into `main`, a version bump is made according to the semantic versioning rules.
156+
- **Version Bump**: After the version bump, a GitHub release will be created using **release-drafter** CI workflow to automate draft release generation.
157+
158+
As pull requests are merged, a draft release is kept up-to-date listing the changes, ready to publish quarterly.
159+
160+
> [!IMPORTANT]
161+
> Proper PR labels need to be added for this to properly be labeled and added to the draft.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AWS IAM Customer-Managed Policy Attachment for Privilege Escalation
2+
3+
---
4+
5+
## Metadata
6+
7+
- **Author:** Elastic
8+
- **Description:** This hunting query identifies instances where customer-managed IAM policies are attached to existing roles, potentially indicating a privilege escalation attempt. By detecting unexpected actors attaching customer-managed policies with elevated permissions to roles, this query helps identify potential abuse or misuse within AWS. Adversaries may attach these policies to gain unauthorized permissions or enable lateral movement and persistence within the environment.
9+
10+
- **UUID:** `418baaf2-9ae1-11ef-be63-f661ea17fbcd`
11+
- **Integration:** [aws.cloudtrail](https://docs.elastic.co/integrations/aws/cloudtrail)
12+
- **Language:** `[ES|QL]`
13+
- **Source File:** [AWS IAM Customer-Managed Policy Attachment for Privilege Escalation](../queries/iam_customer_managed_policies_attached_to_existing_roles.toml)
14+
15+
## Query
16+
17+
```sql
18+
from logs-aws.cloudtrail*
19+
| where
20+
event.dataset == "aws.cloudtrail"
21+
and event.provider == "iam.amazonaws.com"
22+
and event.action == "AttachRolePolicy"
23+
and event.outcome == "success"
24+
| dissect aws.cloudtrail.request_parameters "{%{}::%{owner}:%{?policy_key}/%{attached_policy_name}, %{?role_name_key}=%{target_role_name}}"
25+
| where owner != "aws"
26+
| stats
27+
actor_attaching_role_count = count(*) by aws.cloudtrail.user_identity.arn, attached_policy_name, target_role_name
28+
```
29+
30+
## Notes
31+
32+
- Review the `target_account_id` field to verify the AWS account in which the role is being modified, especially if this account is outside of your organization’s typical accounts.
33+
- Examine `aws.cloudtrail.request_parameters` for details on the role and attached policy. Customer-managed policies granting overly permissive access, such as `AdministratorAccess`, may signal unauthorized privilege escalation.
34+
- Cross-reference `event.action` values where `AttachRolePolicy` appears to further investigate attached policies that could enable lateral movement or persistence.
35+
- Evaluate `aws.cloudtrail.user_identity.arn` to confirm if the actor attaching the policy has legitimate permissions for this action. Anomalous or unauthorized actors may indicate privilege abuse.
36+
- Look for patterns of multiple `AttachRolePolicy` actions across roles by the same user or entity. High frequency of these actions could suggest an attempt to establish persistent control across roles within your AWS environment.
37+
38+
## MITRE ATT&CK Techniques
39+
40+
- [T1548.005](https://attack.mitre.org/techniques/T1548/005)
41+
42+
## License
43+
44+
- `Elastic License v2`

0 commit comments

Comments
 (0)