你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

高级搜寻中的 Kubeaudit 事件

Kubernetes Kubeaudit 事件(和 Azure 资源管理器云审核)可在 Microsoft Defender 门户中的高级搜寻中使用。

可以对 Kubernetes 控制平面攻击面和 Azure 资源管理上发生的事件进行会审和调查。 还可以使用高级搜寻主动搜寻威胁。

此外,还可以为可疑资源管理器和 Kubernetes (KubeAudit) 控制平面活动创建自定义检测

此功能包括:

  • 来自 Azure(Azure Kubernetes 服务)、Amazon Web Services(Amazon Elastic Kubernetes 服务)、Google Cloud Platform(Google Kubernetes 引擎)以及本地的 Kubernetes KubeAudit 事件

  • 资源管理器控制平面事件

首先,请查看高级搜寻“架构”选项卡中新增的名为“CloudAuditEvents”的新表

屏幕截图显示高级搜寻“架构”选项卡中的 CloudAuditEvents 表。

常见用例和场景

  • 调查 XDR 高级搜寻中的可疑资源管理器和 Kubernetes (Kubeaudit) 控制平面活动
  • 为可疑资源管理器和 Kubernetes (Kubeaudit) 控制平面活动创建自定义检测

先决条件

  • 对于 Kubernetes 事件:至少需要一个启用了 Defender for Containers 计划的订阅
  • 对于 Azure 资源管理器事件:至少需要一个启用了 Defender for Azure 资源管理器计划的订阅

示例查询

若要显示特权 Pod 的部署,请使用以下示例查询:

CloudAuditEvents
| where Timestamp > ago(1d)
| where DataSource == "Azure Kubernetes Service"
| where OperationName == "create"
| where RawEventData.ObjectRef.resource == "pods" and isnull(RawEventData.ObjectRef.subresource)
| where RawEventData.ResponseStatus.code startswith "20"
| extend PodName = RawEventData.RequestObject.metadata.name
| extend PodNamespace = RawEventData.ObjectRef.namespace
| mv-expand Container = RawEventData.RequestObject.spec.containers
| extend ContainerName = Container.name
| where Container.securityContext.privileged == "true"
| extend Username = RawEventData.User.username
| project Timestamp, AzureResourceId , OperationName, IPAddress, UserAgent, PodName, PodNamespace, ContainerName, Username

若要在 kube-system 命名空间中显示 exec 命令,请使用以下示例查询

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 !startswith "tunnelfront-" and PodName !startswith "konnectivity-" and PodName !startswith "aks-link"
| extend Commands =  extract_all(@"command=([^\&]*)", RequestURI)
| extend ParsedCommand = url_decode(strcat_array(Commands, " "))
| project Timestamp, AzureResourceId , OperationName, IPAddress, UserAgent, PodName, PodNamespace,  Username, ParsedCommand

若要标识 cluster-admin 角色绑定的创建,请使用以下示例查询

CloudAuditEvents
| where Timestamp > ago(1d)
| where OperationName == "create"
| where RawEventData.ObjectRef.resource == "clusterrolebindings"
| where RawEventData.ResponseStatus.code startswith "20"
| where RawEventData.RequestObject.roleRef.name == "cluster-admin"
| mv-expand Subject = RawEventData.RequestObject.subjects
| extend SubjectName = tostring(Subject.name)
| extend SubjectKind = tostring(Subject["kind"]) 
| extend BindingName = tostring(RawEventData.ObjectRef.name)
| extend ActionTakenBy = tostring(RawEventData.User.username)
| where ActionTakenBy != "acsService" //Remove FP
| project Timestamp, AzureResourceId , OperationName, ActionTakenBy, IPAddress, UserAgent, BindingName, SubjectName, SubjectKind