Skip to content

Conversation

@Aegrah
Copy link
Contributor

@Aegrah Aegrah commented Jan 21, 2026

Summary

This PR introduces 11 new detection rules for detecting suspicious activity within containers, leveraging Elastic Defend for Containers (D4C) and Kubernetes audit logs.

Standalone D4C Rules (7 rules)

Process and file-based detection rules using Defend for Containers telemetry:

Credential Access & K8s API:

  • Service Account Token/Certificate Read - Detects interactive access to /var/run/secrets/kubernetes.io/serviceaccount/token or ca.crt
  • Direct Interactive K8s API Request - Detects common utilities (curl, wget, kubectl, openssl, socat, ncat) making K8s API requests with bearer token authentication

Discovery:

  • Service Account Namespace Read - Detects interactive access to the service account namespace file
  • DNS Enumeration - Detects DNS lookup tools (nslookup, dig, host, getent) querying Kubernetes-related domains (e.g., kubernetes.default, *.svc.cluster.local)
  • Environment Variable Enumeration - Detects env and printenv execution to enumerate container environment variables
  • Tool Enumeration - Detects which command probing for networking, container management, compilation, and scanning tools

Execution:

  • Tool Installation - Detects package managers (apt, yum, apk, dnf, etc.) installing common offensive tools (curl, wget, netcat, python, etc.)

Multi-Data Source Correlation Rules (4 rules)

EQL sequence rules correlating D4C process/file events with Kubernetes audit logs:

  • Service Account Token Access → K8s API Request - Correlates credential file access followed by an API request from the same pod
  • Direct Interactive K8s API Request by Common Utilities - Correlates process execution of common HTTP/CLI tools with matching K8s audit log events
  • Direct Interactive K8s API Request by Unusual Utilities - Same correlation but for non-standard/unexpected utilities
  • Forbidden Direct Interactive K8s API Request - Correlates process execution with K8s audit logs showing forbid authorization decisions

Key Details

  • Stack Version: 9.3.0+ (when D4C integration was re-introduced)
  • MITRE Coverage: Execution (T1059.004, T1072), Credential Access (T1552.001), Discovery (T1613, T1082, T1018, T1016, T1049, T1518)
  • Target: Linux containers with interactive process activity

Rule Summary

Kubernetes User Exec into Pod

Hit a FN where ResponseComplete did not log the exec event, but ResponseStarted did. Adding the ResponseStarted stage to kubernetes.audit.stage to address this FN.

Environment Variable Enumeration Detected via Defend for Containers

This rule detects the execution of the "env" or "printenv" commands inside a container. The "env" command is used to display all the environment variables for the current shell, and the "printenv" command is used to print the values of environment variables. These commands are used to enumerate the environment variables of the container, which can be used by an adversary to gain information about the container and the services running inside it.

{2B3F1920-93FC-4B29-984C-58DD64916D7B}

Tested this rule across telemetry, and over the last 365 days, only 37 hits returned. Once D4C is reintroduced, this will increase; however, I expect this behavior to be limited by interactive processes within a container.

DNS Enumeration Detected via Defend for Containers

This rule detects the execution of DNS enumeration tools inside a container. DNS enumeration tools are used to enumerate the DNS servers and domains of the container, which can be used by an adversary to gain information about the network configuration of the container and the services running inside it.

{0909D784-50AE-41DB-AFCF-E0F55BE05DA6}

Across all of telemetry last 365 days only 9 hits on Suspicious Network Tool Launched Inside A Container. However, this rule is very broad; the one proposed in this PR is way more specific. This may allow to further reduce the noise from the Suspicious Network Tool Launched Inside A Container rule.

Tool Enumeration Detected via Defend for Containers

This rule detects the enumeration of tools by the "which" command inside a container. The "which" command is used to list what tools are installed on a system, and may be used by an adversary to gain information about the container and the services running inside it.

{66FA9592-5C09-444D-B115-52AC27E1E342}

0 hits in telemetry last 365 days when filtered on containers.

Tool Installation Detected via Defend for Containers

This rule detects the installation of tools inside a container. An adversary may need to install additional software to enumerate the container, its environment, and move laterally within the environment.

{B27774CE-4361-4E30-AD13-2B6F0CDDFC1B}

Last 365 days, 11 hits via Unusual Interactive Process Launched in a Container were detected within Telemetry.

Service Account Namespace Read Detected via Defend for Containers

This rule detects the reading of the service account namespace file inside a container. The service account namespace file is used to identify the namespace of the container in which it is running, and may be used by an adversary to get a better understanding of the container and the services running inside it.

0 hits in telemetry last 365 days.

Service Account Token or Certificate Read Detected via Defend for Containers

This rule detects the reading of the service account token or certificate inside a container. The service account token or certificate is used to authenticate the container to the Kubernetes API server, and may be used by an adversary to gain access to the Kubernetes API server or other resources within the cluster. These files are a common target for adversaries to gain access to the cluster.

0 hits in telemetry last 365 days.

Direct Interactive Kubernetes API Request Detected via Defend for Containers

This rule detects the execution of direct interactive Kubernetes API requests inside a container. An adversary may need to execute direct interactive Kubernetes API requests to gain access to the Kubernetes API server or other resources within the cluster. These requests are often used to enumerate the Kubernetes API server or other resources within the cluster, and may indicate an attempt to move laterally within the cluster. Note that this rule may not trigger if the token is expanded within the process argument list, as the length of the "process.args" field may lead to the field being ignored.

{58D40979-DBF4-449F-B8BD-9BAAB2CB1119}

Last 365 days, quite a lot of hits in telemetry, however, this is expected. I created this as low severity, because this activity may also occur within benign infrastructure. I will create a similar rule to this, chaining K8s audit logs to this API hitting activity from an MDA perspective, which I will assign a higher severity.

Direct Interactive Kubernetes API Request by Common Utilities

This rule leverages a combination of Defend for Containers and Kubernetes audit logs to detect the execution of direct interactive Kubernetes API requests. An adversary may need to execute direct interactive Kubernetes API requests to gain access to the Kubernetes API server or other resources within the cluster. These requests are often used to enumerate the Kubernetes API server or other resources within the cluster, and may indicate an attempt to move laterally within the cluster. Note that this rule may not trigger if the authorization token of the request is expanded within the process argument list, as the length of the "process.args" field may lead to the field being ignored.

{8A301331-15FD-472D-BD5A-2742940DB96D}

Forbidden Direct Interactive Kubernetes API Request

This rule leverages a combination of Defend for Containers and Kubernetes audit logs to detect the execution of direct interactive Kubernetes API requests, that are forbidden by the Kubernetes API. An adversary may need to execute direct interactive Kubernetes API requests to gain access to the Kubernetes API server or other resources within the cluster. These requests are often used to enumerate the Kubernetes API server or other resources within the cluster, and may indicate an attempt to move laterally within the cluster. Note that this rule may not trigger if the authorization token of the request is expanded within the process argument list, as the length of the "process.args" field may lead to the field being ignored.

{E8DDBE74-C2EC-4360-9112-9B52B943BFB9}

Direct Interactive Kubernetes API Request by Unusual Utilities

This rule leverages a combination of Defend for Containers and Kubernetes audit logs to detect the execution of direct interactive Kubernetes API requests via unusual utilities. An adversary may need to execute direct interactive Kubernetes API requests to gain access to the Kubernetes API server or other resources within the cluster. These requests are often used to enumerate the Kubernetes API server or other resources within the cluster, and may indicate an attempt to move laterally within the cluster.

{2CFC7B78-4639-4E68-AA7E-B44A5FB6099D}

Service Account Token or Certificate Access Followed by Kubernetes API Request

This rule leverages a combination of Defend for Containers and Kubernetes audit logs to detect the access to the service account token or certificate followed by the execution of a direct interactive Kubernetes API request. An adversary may need to access the service account token or certificate to gain access to the Kubernetes API server or other resources within the cluster. These requests are often used to enumerate the Kubernetes API server or other resources within the cluster, and may indicate an attempt to move laterally within the cluster.

@Aegrah Aegrah self-assigned this Jan 21, 2026
@Aegrah Aegrah added OS: Linux Rule: New Proposal for new rule Rule: Tuning tweaking or tuning an existing rule Integration: Kubernetes Kubernetes Integration container Integration: Cloud Defend Cloud Defend Integration Team: TRADE labels Jan 21, 2026
@github-actions
Copy link
Contributor

Rule: New - Guidelines

These guidelines serve as a reminder set of considerations when proposing a new rule.

Documentation and Context

  • Detailed description of the rule.
  • List any new fields required in ECS/data sources.
  • Link related issues or PRs.
  • Include references.

Rule Metadata Checks

  • creation_date matches the date of creation PR initially merged.
  • min_stack_version should support the widest stack versions.
  • name and description should be descriptive and not include typos.
  • query should be inclusive, not overly exclusive, considering performance for diverse environments. Non ecs fields should be added to non-ecs-schema.json if not available in an integration.
  • min_stack_comments and min_stack_version should be included if the rule is only compatible starting from a specific stack version.
  • index pattern should be neither too specific nor too vague, ensuring it accurately matches the relevant data stream (e.g., use logs-endpoint.process-* for process data).
  • integration should align with the index. If the integration is newly introduced, ensure the manifest, schemas, and new_rule.yaml template are updated.
  • setup should include the necessary steps to configure the integration.
  • note should include any additional information (e.g. Triage and analysis investigation guides, timeline templates).
  • tags should be relevant to the threat and align/added to the EXPECTED_RULE_TAGS in the definitions.py file.
  • threat, techniques, and subtechniques should map to ATT&CK always if possible.

New BBR Rules

  • building_block_type should be included if the rule is a building block and the rule should be located in the rules_building_block folder.
  • bypass_bbr_timing should be included if adding custom lookback timing to the rule.

Testing and Validation

  • Provide evidence of testing and detecting the expected threat.
  • Check for existence of coverage to prevent duplication.

1 similar comment
@github-actions
Copy link
Contributor

Rule: New - Guidelines

These guidelines serve as a reminder set of considerations when proposing a new rule.

Documentation and Context

  • Detailed description of the rule.
  • List any new fields required in ECS/data sources.
  • Link related issues or PRs.
  • Include references.

Rule Metadata Checks

  • creation_date matches the date of creation PR initially merged.
  • min_stack_version should support the widest stack versions.
  • name and description should be descriptive and not include typos.
  • query should be inclusive, not overly exclusive, considering performance for diverse environments. Non ecs fields should be added to non-ecs-schema.json if not available in an integration.
  • min_stack_comments and min_stack_version should be included if the rule is only compatible starting from a specific stack version.
  • index pattern should be neither too specific nor too vague, ensuring it accurately matches the relevant data stream (e.g., use logs-endpoint.process-* for process data).
  • integration should align with the index. If the integration is newly introduced, ensure the manifest, schemas, and new_rule.yaml template are updated.
  • setup should include the necessary steps to configure the integration.
  • note should include any additional information (e.g. Triage and analysis investigation guides, timeline templates).
  • tags should be relevant to the threat and align/added to the EXPECTED_RULE_TAGS in the definitions.py file.
  • threat, techniques, and subtechniques should map to ATT&CK always if possible.

New BBR Rules

  • building_block_type should be included if the rule is a building block and the rule should be located in the rules_building_block folder.
  • bypass_bbr_timing should be included if adding custom lookback timing to the rule.

Testing and Validation

  • Provide evidence of testing and detecting the expected threat.
  • Check for existence of coverage to prevent duplication.

@tradebot-elastic
Copy link

tradebot-elastic commented Jan 21, 2026

⛔️ Test failed

Results
  • ❌ Direct Interactive Kubernetes API Request by Unusual Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Kubernetes User Exec into Pod (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Access Followed by Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Installation Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Forbidden Direct Interactive Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ DNS Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request by Common Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Environment Variable Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Namespace Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta

any where host.os.type == "linux" and event.dataset == "kubernetes.audit_logs" and
kubernetes.audit.verb in ("get", "create") and kubernetes.audit.objectRef.subresource == "exec" and
kubernetes.audit.stage == "ResponseComplete" and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted") and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aegrah host.os.type == linux is not reported in AKS. Not to mention, I don't think we should limit exec'ing into Linux only. We should consider this for all K8s/D4C rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I left this here because that update is added in #5577; I left it out because I will merge the other PR first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted") and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted") and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
and kubernetes.audit.level == "Request"

When testing this rule I noticed duplicate alerts for audit level Request and RequestResponse. May want to consider only including Request level here.

@tradebot-elastic
Copy link

tradebot-elastic commented Jan 21, 2026

⛔️ Test failed

Results
  • ❌ Direct Interactive Kubernetes API Request by Unusual Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Kubernetes User Exec into Pod (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Access Followed by Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Installation Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Forbidden Direct Interactive Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ DNS Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request by Common Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Environment Variable Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Namespace Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta

@tradebot-elastic
Copy link

tradebot-elastic commented Jan 22, 2026

⛔️ Test failed

Results
  • ❌ Direct Interactive Kubernetes API Request by Unusual Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Kubernetes User Exec into Pod (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Access Followed by Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Installation Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Forbidden Direct Interactive Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ DNS Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request by Common Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Environment Variable Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Namespace Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta

@tradebot-elastic
Copy link

tradebot-elastic commented Jan 23, 2026

⛔️ Test failed

Results
  • ❌ Direct Interactive Kubernetes API Request by Unusual Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Kubernetes User Exec into Pod (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Access Followed by Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Installation Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Forbidden Direct Interactive Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ DNS Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request by Common Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Environment Variable Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Namespace Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta

@tradebot-elastic
Copy link

tradebot-elastic commented Jan 23, 2026

⛔️ Test failed

Results
  • ❌ Direct Interactive Kubernetes API Request by Unusual Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Kubernetes User Exec into Pod (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Access Followed by Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Installation Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Forbidden Direct Interactive Kubernetes API Request (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Token or Certificate Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ DNS Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Direct Interactive Kubernetes API Request by Common Utilities (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Tool Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Environment Variable Enumeration Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta
  • ❌ Service Account Namespace Read Detected via Defend for Containers (eql)
    • coverage_issue: no_rta
    • stack_validation_failed: no_rta

)
) and process.interactive == true and container.id like "*"
] by orchestrator.resource.name
[any where event.dataset == "kubernetes.audit_logs" and kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted")] by `kubernetes.audit.user.extra.authentication.kubernetes.io/pod-name`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[any where event.dataset == "kubernetes.audit_logs" and kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted")] by `kubernetes.audit.user.extra.authentication.kubernetes.io/pod-name`
[any where event.dataset == "kubernetes.audit_logs" and kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted") and event.outcome == "success"] by `kubernetes.audit.user.extra.authentication.kubernetes.io/pod-name`

may want to filter out failed requests

Comment on lines +12 to +17
This rule leverages a combination of Defend for Containers and Kubernetes audit logs to detect the execution of direct
interactive Kubernetes API requests. An adversary may need to execute direct interactive Kubernetes API requests to gain
access to the Kubernetes API server or other resources within the cluster. These requests are often used to enumerate
the Kubernetes API server or other resources within the cluster, and may indicate an attempt to move laterally within
the cluster. Note that this rule may not trigger if the authorization token of the request is expanded within the process
argument list, as the length of the "process.args" field may lead to the field being ignored.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should make this description a bit more distinct from the last rule, clearer that this is looking for forbidden calls and why that's relevant from a security perspective

Comment on lines +96 to +97
)
] by `kubernetes.audit.user.extra.authentication.kubernetes.io/pod-name`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)
] by `kubernetes.audit.user.extra.authentication.kubernetes.io/pod-name`
)
and event.outcome == "success"
] by `kubernetes.audit.user.extra.authentication.kubernetes.io/pod-name`

may want to consider excluding failed requests

Comment on lines +52 to +56
sequence with maxspan=60s
[file where host.os.type == "linux" and event.type == "change" and event.action == "open" and
file.path in ("/var/run/secrets/kubernetes.io/serviceaccount/token", "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") and
process.interactive == true and container.id like "*"] by orchestrator.resource.name
[any where event.dataset == "kubernetes.audit_logs" and kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted")] by `kubernetes.audit.user.extra.authentication.kubernetes.io/pod-name`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to figure out why this doesn't capture the following behavior I executed from inside a container, is it meant to?

  # Get the service account token
    TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
    
    # API server endpoint
    API=https://kubernetes.default.svc

    # === Make requests with unusual user agents (triggers detection) ===
    
    # Custom attack tool user agent
    curl -sk -H "Authorization: Bearer $TOKEN" \
      -A 'hacker-tool/1.0' \
      $API/api/v1/secrets

file where host.os.type == "linux" and event.type == "change" and event.action == "open" and file.path in (
"/var/run/secrets/kubernetes.io/serviceaccount/token", "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
) and
process.interactive == true and container.id like "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above, is it because I'm adding token to env variables?

query = '''
file where host.os.type == "linux" and event.type == "change" and event.action == "open" and
file.path == "/var/run/secrets/kubernetes.io/serviceaccount/namespace" and
process.interactive == true and container.id like "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat this file is showing up as a process event for me. As a file event it's showing as file.path /home/curl_user/.ash_history with no field to distinguish the specific file being read. Is this a known variation?

(process.name == "ncat" and process.args like "--ssl*") or
(process.name == "kubectl" and process.args in ("get", "list", "watch", "create", "patch", "update"))
) and
process.interactive == true and container.id like "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule captures the service token read I mentioned earlier 👍🏾

any where host.os.type == "linux" and event.dataset == "kubernetes.audit_logs" and
kubernetes.audit.verb in ("get", "create") and kubernetes.audit.objectRef.subresource == "exec" and
kubernetes.audit.stage == "ResponseComplete" and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted") and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted") and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
kubernetes.audit.stage in ("ResponseComplete", "ResponseStarted") and `kubernetes.audit.annotations.authorization_k8s_io/decision` == "allow"
and kubernetes.audit.level == "Request"

When testing this rule I noticed duplicate alerts for audit level Request and RequestResponse. May want to consider only including Request level here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport: auto container Integration: Cloud Defend Cloud Defend Integration Integration: Kubernetes Kubernetes Integration OS: Linux Rule: New Proposal for new rule Rule: Tuning tweaking or tuning an existing rule Team: TRADE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants