Jump to content

Detect Container Drift with Microsoft Defender for Containers


Recommended Posts

Guest Vasavi_Pasula
Posted

[JUSTIFY]Introduction

 

In cloud-native Kubernetes environments, Containers are often treated as immutable resources, meaning they shouldn’t change after deployment. Immutable containers minimize the attack surface because they do not allow modifications during runtime. This limits the potential for attackers to make unauthorized changes, install malware, or create backdoors within a running container.

 

Container drift refers to unintended or unauthorized manual changes, updates, patches, or other modifications made during its runtime. When containers drift, they may incorporate untested and unverified changes, such as software updates, configuration modifications, or new libraries. These changes can introduce new vulnerabilities that were not present in the original, vetted container image. Drift might introduce changes that grant elevated privileges to processes or users within the container, which can be exploited to gain broader access to the system or network. Changes caused by drift can alter or disable security monitoring tools within the container, making it harder to detect and respond to security incidents promptly.

 

 

 

Microsoft Defender for Containers introduces the binary drift detection feature in public preview, to detect execution of files in a running container drifting from original Container Image which was scanned, tested, and validated. It's available for the Azure (AKS) V1.29, Amazon (EKS), and Google (GKE) clouds.

 

 

 

Defender for Containers Binary Drift Detection helps organizations:

 

Early Detection of Breaches: Drift detection serves as an early warning system for potential security breaches. If an attacker compromises a container and makes unauthorized changes, drift detection can immediately alert security teams, enabling them to respond quickly and mitigate the impact.

 

Monitor for Insider Activity: Drift detection helps mitigate insider threats by monitoring for unauthorized changes that could indicate malicious activity by an insider. This includes unauthorized changes to configurations, deployment scripts, or access controls within containers.

 

Reduce Human Error: Human error is a common cause of security breaches. Drift detection reduces the risk of human error by ensuring that any unintended changes made by administrators or developers are quickly detected and corrected.

 

Ensure Compliance with Security Standards: Many regulatory standards require organizations to maintain secure configurations and prevent unauthorized changes. Drift detection helps ensure compliance by continuously monitoring and documenting the state of containers, providing evidence that configurations remain consistent with regulatory requirements.

 

 

 

Prerequisites to enable Binary drift detection:

 

 

[ATTACH type=full" alt="Vasavi_Pasula_0-1724933061717.png]64050[/ATTACH]

 

 

 

  • Security Admin or higher permissions on the tenant to create and modify drift policies

 

 

 

Configure Binary Drift Detection

 

Security Admins can configure drift detection policies at Azure Subscription, AWS Connector or GCP Connector and on Resources at Cluster level, Name space, Pod, or individual container level.

 

For details on how to configure drift detection Rules, refer : Binary drift detection (preview) - Microsoft Defender for Cloud | Microsoft Learn

 

Rules are evaluated in ascending order of priority. First rule 1 is evaluated, if it's a match the evaluation stops. If no match is found, the next rule is evaluated. If there's no match for any rule, the out of the box Default binary drift rule with default Ignore drift detection applies.

 

 

 

Best practices for Drift Detection:

 

  • Kubernetes Administrators should ensure that all container images are regularly updated and patched to include the latest security fixes.
  • Detecting drift at the cluster level helps prevent unauthorized changes that could compromise the security and stability of the entire cluster. For example, an attacker gaining access to the Kubernetes API server might change cluster-wide settings to escalate privileges or disable security features.

 

[ATTACH type=full" alt="Vasavi_Pasula_1-1724933061719.png]64051[/ATTACH]

 

 

 

  • In multi-tenant environments, where different teams or customers share the same Kubernetes cluster but operate within their own namespaces, organizations can apply drift detection at namespace level monitoring only the areas of the cluster that are relevant to particular applications or teams.

 

[ATTACH type=full" alt="Vasavi_Pasula_2-1724933061720.png]64052[/ATTACH]

 

 

 

  • In development or testing environments, developers might need to make ad-hoc changes to containers to test new features, configurations, or debug issues, without the overhead of redeploying containers. Apply the ruleset only to the specific labelled Kubernetes pods.

 

[ATTACH type=full" alt="Vasavi_Pasula_3-1724933061723.png]64053[/ATTACH]

 

 

 

 

 

  • During scheduled maintenance windows, organizations might need to apply emergency patches or make quick operational changes directly to running containers to address critical security vulnerabilities or fix urgent issues. In this scenario, modify the rule action to Ignore Drift detection to avoid false positives.
  • Allow list for processes - Organizations might define specific processes like monitoring agents, logging agents to be exempt from drift detection to avoid false positives.

 

 

Test / Simulate a binary drift alert

 

To test the binary drift feature and generate alerts (only in situations you defined in the binary drift policy that you’d like to get an alerts) you can execute any binary process in the container (not part of the original image). You can also use this script to create binary drift scenario:

kubectl run ubuntu-pod --image=ubuntu --restart=Never -- /bin/bash -c “cp /bin/echo /bin/echod; /bin/echod This is a binary drift execution”

 

 

 

Below you can observe the drift detection alert generated in a threat scenario:

 

[ATTACH type=full" alt="Vasavi_Pasula_4-1724933061730.png]64054[/ATTACH]

 

 

 

Click on Open Logs to further examine the activities performed on this resource around the time of the alert. The attempt to list the Cluster admin credentials succeeded.

 

[ATTACH type=full" alt="Vasavi_Pasula_5-1724933061735.png]64055[/ATTACH]

 

 

 

The alert also indicates there are 42 more alerts on the affected resource

 

[ATTACH type=full" alt="Vasavi_Pasula_6-1724933061741.png]64056[/ATTACH]

 

 

 

This incident indicates that suspicious activity has been detected on the Kubernetes cluster. Multiple alerts from different Defender for Cloud plans have been triggered on the same cluster, which increases the fidelity of malicious activity. The suspicious activity might indicate that a threat actor has gained unauthorized access to your environment and is attempting to compromise it.

 

[ATTACH type=full" alt="Vasavi_Pasula_7-1724933061750.png]64057[/ATTACH]

 

 

 

 

 

[ATTACH type=full" alt="Vasavi_Pasula_8-1724933061756.png]64058[/ATTACH]

 

 

 

 

 

Advanced Hunting with XDR

 

Security teams can now access Defender for Cloud alerts and incidents within the Microsoft Defender portal, get the complete picture of an attack, including suspicious and malicious events that happen in their cloud environment, through immediate correlations of alerts and incidents.

 

By combining drift detection data with other security event information, SOC teams can build a more comprehensive understanding of potential incidents. A multi-stage incident involving multiple alerts can be observed in the XDR portal.

 

 

 

[ATTACH type=full" alt="Vasavi_Pasula_9-1724933061764.png]64059[/ATTACH]

 

 

 

The alert evidence pane shows there has been suspicious activity with “ubuntu-pod”

 

[ATTACH type=full" alt="Vasavi_Pasula_10-1724933061767.png]64060[/ATTACH]

 

 

 

The SOC team can further investigate the commands executed on the affected pod, and the user who executed the commands using the below query:

 

CloudAuditEvents

 

| where Timestamp > ago(1d)

 

| where DataSource == "Azure Kubernetes Service"

 

| where OperationName == "create"

 

| where RawEventData.ObjectRef.resource == "pods" and RawEventData.ResponseStatus.code == 101

 

| where RawEventData.ObjectRef.namespace == "kube-system"

 

| where RawEventData.ObjectRef.subresource == "exec"

 

| where RawEventData.ResponseStatus.code == 101

 

| extend RequestURI = tostring(RawEventData.RequestURI)

 

| extend PodName = tostring(RawEventData.ObjectRef.name)

 

| extend PodNamespace = tostring(RawEventData.ObjectRef.namespace)

 

| extend Username = tostring(RawEventData.User.username)

 

| where PodName == "ubuntu-pod"

 

| extend Commands = extract_all(@"command=([^\&]*)", RequestURI)

 

| extend ParsedCommand = url_decode(strcat_array(Commands, " "))

 

| project Timestamp, AzureResourceId , OperationName, IPAddress, UserAgent, PodName, PodNamespace, Username, ParsedCommand

 

 

 

For more information on how to Investigate suspicious Kubernetes (Kubeaudit) control plane activities in XDR advanced hunting refer: Kubeaudit events in advanced hunting - Microsoft Defender for Cloud | Microsoft Learn

 

 

 

 

 

[ATTACH type=full" alt="Vasavi_Pasula_11-1724933061772.png]64061[/ATTACH]

 

 

 

SOC team can assign incidents from the Manage incident pane for mitigating the attack

 

[ATTACH type=full" alt="Vasavi_Pasula_12-1724933061774.png]64062[/ATTACH]

 

 

 

Kubernetes Cluster administrators can configure automated workflows to handle common drift scenarios, such as reverting unauthorized changes, notifying relevant teams, or trigger response actions automatically.

 

[/JUSTIFY]

 

[HEADING=2]Additional Resources[/HEADING]

 

You can also use the resources below to learn more about these capabilities:

 

[HEADING=2]Reviewers[/HEADING]

 

Eyal Gur, Principal Product Manager, Defender for Cloud

 

[JUSTIFY]

 

 

 

[/JUSTIFY]

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...