Skip to content

Malicious Code Execution and Compromised Containers: KCSA practice questions

Malicious code execution in a container is usually where a Kubernetes attack begins rather than where it ends.

By Ibrahim Yesilay · Published · Updated

Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.

What Malicious Code Execution and Compromised Containers covers in KCSA

Malicious code execution in a container is usually where a Kubernetes attack begins rather than where it ends. The CNCF Financial Services User Group attack tree for this goal describes the initial foothold as primarily a compromised application that gives access to the container, reached through a NodePort on a node or, more likely, directly from the external network, and calls it perhaps the most likely way into the environment. From there the attacker tries to load more code, using whatever the container's privilege level allows.

The companion scenario, a compromised application that leads to a foothold in a container, singles out the mounted and insecure service account token as one of the most exploited paths. A token is mounted into each Pod by default, so a compromised container hands the attacker API credentials. The threat model names strict RBAC policies and disabling automatic token mounting as key mitigations; automountServiceAccountToken: false can be set on the ServiceAccount, and a Pod-level value overrides it. The same work warns about the default network exposure of the control plane to every running container, which is why NetworkPolicies that limit what a compromised Pod can reach matter.

Malicious code can also arrive through the supply chain. If an image pull secret is obtained, the attacker may be able to poison the repository and distribute malicious code from there, and the attack tree calls compromised images a major source of exploitation. NIST SP 800-190 makes the same point about embedded malware: an image is a collection of files, so malicious files can be included intentionally or by accident, and base layers or third-party images whose full provenance is unknown are one source. It also warns against clear-text secrets embedded in images.

What a compromised container can do next depends on isolation. NIST SP 800-190 notes that a shared kernel gives a larger inter-object attack surface than hypervisors, that runtime vulnerabilities allowing container escape let malicious software attack other containers and the host, and that in most runtimes containers can reach each other and the host over the network by default, so a compromised one can scan for further weaknesses. Kubernetes documents an especially direct route: a container with access to the node's container runtime socket can launch new containers or interact with running ones, so hostPath mounts that include the socket or a parent directory should be restricted or forbidden.

Detection and containment complete the picture. NIST recommends container-aware runtime tools that flag unexpected process execution and system calls, changes to protected files and binaries, writes to unexpected locations, new network listeners, traffic to unexpected destinations and malware. It also recommends read-only root filesystems, which confine writes to defined directories that are easy to monitor and isolate any tampering; in Kubernetes that is readOnlyRootFilesystem: true. Running as non-root, dropping capabilities and disallowing privilege escalation, as the Restricted Pod Security Standard requires, further limit what injected code can do.

Key points

  • A compromised application is the most common entry point into a container.
  • The default-mounted ServiceAccount token is one of the most exploited follow-on paths.
  • A stolen image pull secret can be used to poison the registry for other workloads.
  • Containers share the host kernel, so escape vulnerabilities reach other containers and the node.

Three sample questions

8 KCSA questions on Malicious Code Execution and Compromised Containers, 8 with explanations. How practice works

Question 1

In the STRIDE threat model, which category best describes a Trojan horse that compromises a build server?
  1. A.Spoofing
  2. B.Repudiation
  3. C.Information Disclosure
  4. D.Tampering

Correct answer: D

A Trojan horse compromising a build server is an example of tampering because it involves unauthorized modification of system components or data. Tampering refers to malicious alterations that can affect the integrity of software or systems. Spoofing involves impersonation, repudiation relates to denial of actions, and information disclosure concerns unauthorized data exposure, none of which precisely describe this scenario.

Sources: Microsoft STRIDE Threat Model, OWASP Threat Modeling

Question 2

Which STRIDE threat category primarily addresses threats related to data integrity?
  1. A.Spoofing
  2. B.Tampering
  3. C.Repudiation
  4. D.Information Disclosure

Correct answer: B

The 'Tampering' category in STRIDE focuses on threats that compromise data integrity by unauthorized modification of data. Spoofing relates to identity, repudiation to denial of actions, and information disclosure to confidentiality breaches.

Sources: Microsoft STRIDE Threat Model, OWASP Threat Modeling

Question 3

What is a common mitigation strategy for 'Tampering' threats in Kubernetes?
  1. A.Implementing strong authentication
  2. B.Using digital signatures and checksums
  3. C.Applying redundant servers
  4. D.Enforcing password complexity

Correct answer: B

Using digital signatures and checksums is an effective way to mitigate Tampering threats. These mechanisms ensure data integrity by verifying that data has not been altered during transmission or storage.

Sources: Kubernetes Security Best Practices, OWASP Secure Coding Practices

Practice this topic

Focus mode keeps every question on Malicious Code Execution and Compromised Containers until you leave it. 10 free guest answers, then a free account; no credit card.

Or open KCSA practice across all topics.

Sources

The explanation above was checked against these official documents.