通过有意触发检测器并检查发现结果,验证 Container Threat Detection 是否正常运行。Container Threat Detection 是 Security Command Center 付费级的内置服务。如要查看 Container Threat Detection 结果,您必须在 Security Command Center 服务设置中启用该服务。
准备工作
如需检测容器的潜在威胁,您需要确保集群位于受支持的 Google Kubernetes Engine (GKE) 版本上。如需了解详情,请参阅使用受支持的 GKE 版本。
已执行添加的二进制文件
要触发已执行添加的二进制文件发现结果,请在容器中放入二进制文件并执行该文件。此示例将部署最新的 Ubuntu 18.04 映像,将 /bin/ls
复制到其他位置,然后执行。二进制文件的执行是出乎意料的,因为二进制文件的副本不是原始容器映像的一部分,即使该映像位于 Ubuntu 18.04 中,而且容器也是不可变的。
- 转到 Google Cloud Console。
转到 Google Cloud Console - 选择包含要用来测试的容器的项目。
- 点击激活 Cloud Shell。
在 Cloud Shell 中,设置环境变量。
您的服务帐号电子邮件:
export SERVICE_ACCOUNT_EMAIL=service-account-address@iam.gserviceaccount.com
您的集群所在的区域:
export ZONE=cluster-zone
您的容器所在的项目:
export CONSUMER_PROJECT=project-name
您的集群名称:
export CLUSTER_NAME=cluster-name
访问集群控制方案:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $CONSUMER_PROJECT
放入二进制文件并执行该文件:
tag="dropped-binary-$(date +%Y-%m-%d-%H-%M-%S)" kubectl run --restart=Never --rm=true --wait=true -i \ --image marketplace.gcr.io/google/ubuntu1804:latest \ "$tag" -- bash -c "cp /bin/ls /tmp/$tag; /tmp/$tag"
此测试过程会创建一个已添加的二进制文件执行的发现结果,您可以在 Security Command Center 和 Cloud Logging(如果您为 Container Threat Detection 配置了 Logging)中查看该发现结果。
已加载添加的库
要触发已加载添加的库发现结果,请将库放入容器中并加载该库。此示例将部署最新的 Ubuntu 18.04 映像,将 /lib/x86_64-linux-gnu/libc.so.6
复制到其他位置,然后使用 ld
加载。已加载的库是出乎意料的,因为库的副本不是原始容器映像的一部分,即使该映像位于 Ubuntu 18.04 中,而且容器是不可变的。
- 转到 Google Cloud Console。
转到 Google Cloud Console - 选择包含要用来测试的容器的项目。
- 点击激活 Cloud Shell。
在 Cloud Shell 中,设置环境变量。
您的服务帐号电子邮件:
export SERVICE_ACCOUNT_EMAIL=service-account-address@iam.gserviceaccount.com
您的集群所在的区域:
export ZONE=cluster-zone
您的容器所在的项目:
export CONSUMER_PROJECT=project-name
您的集群名称:
export CLUSTER_NAME=cluster-name
访问集群控制方案:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $CONSUMER_PROJECT
放入一个库并使用
ld
加载它:tag="dropped-library-$(date +%Y-%m-%d-%H-%M-%S)" kubectl run --restart=Never --rm=true --wait=true -i \ --image marketplace.gcr.io/google/ubuntu1804:latest \ "$tag" -- bash -c "cp /lib/x86_64-linux-gnu/libc.so.6 /tmp/$tag; /lib64/ld-linux-x86-64.so.2 /tmp/$tag"
此测试过程会创建一个已加载添加的库发现结果,您可以在 Security Command Center 和 Cloud Logging(如果您为 Container Threat Detection 配置了 Logging)中查看该发现结果。
反向 shell
要触发反向 shell 查找,请使用 stdin
启动二进制文件,并重定向到 TCP 连接的套接字。此示例启动 /bin/echo
重定向到 DNS 端口上的 Google 公共 DNS 8.8.8.8
。运行此示例时,不会打印任何内容。为防止通过中间人 (MITM) 攻击注入任何外部代码,此示例未使用 /bin/bash binary
。
- 转到 Google Cloud Console。
转到 Google Cloud Console - 选择包含要用来测试的容器的项目。
- 点击激活 Cloud Shell。
在 Cloud Shell 中,设置环境变量。
您的服务帐号电子邮件:
export SERVICE_ACCOUNT_EMAIL=service-account-address@iam.gserviceaccount.com
您的集群所在的区域:
export ZONE=cluster-zone
您的容器所在的项目:
export CONSUMER_PROJECT=project-name
您的集群名称:
export CLUSTER_NAME=cluster-name
访问集群控制方案:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $CONSUMER_PROJECT
使用
/bin/echo
启动二进制文件重定向至 Google 公共 DNS:tag="reverse-shell-$(date +%Y-%m-%d-%H-%M-%S)" kubectl run --restart=Never --rm=true --wait=true -i \ --image marketplace.gcr.io/google/ubuntu1804:latest \ "$tag" -- bash -c "/bin/echo >& /dev/tcp/8.8.8.8/53 0>&1"
如果您已为 Container Threat Detection 配置了日志记录,则此测试过程会创建一个反向 shell 发现结果,您可在 Security Command Center 和 Cloud Logging 中查看该结果。
后续步骤
- 了解如何使用 。