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:
+29
-29
@@ -19,11 +19,11 @@ Azure App 서비스에 대한 자세한 정보는 다음을 확인하세요:
|
||||
# Direct option
|
||||
az webapp ssh --name <name> --resource-group <res-group>
|
||||
```
|
||||
- **터널 생성 후 SSH에 연결**:
|
||||
- **터널을 생성한 후 SSH에 연결**:
|
||||
```bash
|
||||
az webapp create-remote-connection --name <name> --resource-group <res-group>
|
||||
|
||||
## If successfull you will get a message such as:
|
||||
## If successful you will get a message such as:
|
||||
#Verifying if app is running....
|
||||
#App is running. Trying to establish tunnel connection...
|
||||
#Opening tunnel on port: 39895
|
||||
@@ -36,7 +36,7 @@ ssh root@127.0.0.1 -p 39895
|
||||
1. VScode에 Azure 확장을 설치합니다.
|
||||
2. Azure 계정으로 확장에 로그인합니다.
|
||||
3. 구독 내 모든 앱 서비스를 나열합니다.
|
||||
4. 디버깅할 앱 서비스를 선택하고, 마우스 오른쪽 버튼을 클릭한 후 "디버깅 시작"을 선택합니다.
|
||||
4. 디버깅할 앱 서비스를 선택하고 마우스 오른쪽 버튼을 클릭한 후 "디버깅 시작"을 선택합니다.
|
||||
5. 앱에 디버깅이 활성화되어 있지 않으면, 확장이 이를 활성화하려고 시도하지만, 귀하의 계정은 이를 수행하기 위해 `Microsoft.Web/sites/config/write` 권한이 필요합니다.
|
||||
|
||||
### SCM 자격 증명 얻기 및 기본 인증 활성화
|
||||
@@ -132,7 +132,7 @@ az webapp deployment user set \
|
||||
> 모든 사용자가 이전 명령을 호출하여 자신의 자격 증명을 구성할 수 있지만, 사용자가 SCM 또는 FTP에 액세스할 수 있는 충분한 권한이 없으면 자격 증명이 작동하지 않습니다.
|
||||
|
||||
|
||||
- 이러한 자격 증명이 **REDACTED**로 표시되면, 이는 **SCM 기본 인증 옵션을 활성화해야 하기 때문이며**, 이를 위해 두 번째 권한(`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write):`이 필요합니다.
|
||||
- 이러한 자격 증명이 **REDACTED**로 표시되면, 이는 **SCM 기본 인증 옵션을 활성화해야 하기 때문이며**, 이를 위해 두 번째 권한(`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write`)이 필요합니다:
|
||||
```bash
|
||||
# Enable basic authentication for SCM
|
||||
az rest --method PUT \
|
||||
@@ -150,7 +150,7 @@ az rest --method PUT \
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
### SCM 자격 증명을 사용하여 코드 게시
|
||||
|
||||
@@ -158,11 +158,11 @@ az rest --method PUT \
|
||||
|
||||
이 파이썬 예제를 위해 https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart에서 리포를 다운로드하고 원하는 **변경**을 한 다음 **`zip -r app.zip .`**을 실행하여 압축할 수 있습니다.
|
||||
|
||||
그런 다음 다음 명령어로 **코드를 게시**할 수 있습니다:
|
||||
그런 다음 다음 명령어로 웹 앱에 **코드를 게시**할 수 있습니다:
|
||||
```bash
|
||||
curl -X POST "<SMC-URL>/api/publish?type=zip" --data-binary "@./app.zip" -u '<username>:<password>' -H "Content-Type: application/octet-stream"
|
||||
```
|
||||
### Microsoft.Web/sites/publish/Action | SCM 자격 증명
|
||||
### Webjobs: Microsoft.Web/sites/publish/Action | SCM 자격 증명
|
||||
|
||||
언급된 Azure 권한은 SCM 자격 증명으로 수행할 수 있는 여러 흥미로운 작업을 수행할 수 있습니다:
|
||||
|
||||
@@ -174,7 +174,7 @@ az rest --method GET --url "https://lol-b5fyaeceh4e9dce0.scm.canadacentral-01.az
|
||||
|
||||
# Using SCM username and password:
|
||||
curl "<SCM-URL>/vfs/data/jobs/continuous/job_name/job_log.txt" \
|
||||
--user '<username>:<password>>' -v
|
||||
--user '<username>:<password>' -v
|
||||
```
|
||||
- **Webjobs** 소스 코드 읽기:
|
||||
```bash
|
||||
@@ -204,6 +204,12 @@ curl -X PUT \
|
||||
--data-binary "@/Users/carlospolop/Downloads/rev.js" \
|
||||
--user '<username>:<password>'
|
||||
```
|
||||
### Microsoft.Web/sites/write, Microsoft.Web/sites/read, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action
|
||||
|
||||
이 권한은 **관리되는 ID**를 App 서비스에 할당할 수 있게 하므로, 이전에 App 서비스가 손상된 경우 공격자가 App 서비스에 새로운 관리되는 ID를 할당하고 **권한을 상승**시킬 수 있습니다.
|
||||
```bash
|
||||
az webapp identity assign --name <app-name> --resource-group <res-group> --identities /subscriptions/<subcripttion-id>/resourceGroups/<res_group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>
|
||||
```
|
||||
### Microsoft.Web/sites/config/list/action
|
||||
|
||||
이 권한은 데이터베이스 자격 증명과 같은 민감한 정보를 포함할 수 있는 App 서비스의 **connection strings** 및 **appsettings**를 나열할 수 있게 해줍니다.
|
||||
@@ -211,22 +217,16 @@ curl -X PUT \
|
||||
az webapp config connection-string list --name <name> --resource-group <res-group>
|
||||
az webapp config appsettings list --name <name> --resource-group <res-group>
|
||||
```
|
||||
### Microsoft.Web/sites/write, Microsoft.Web/sites/read, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action
|
||||
|
||||
이 권한은 **관리형 ID를 할당**할 수 있게 하여, 만약 App 서비스가 이전에 침해되었다면 공격자가 App 서비스에 새로운 관리형 ID를 할당하고 **권한을 상승**시킬 수 있게 합니다.
|
||||
```bash
|
||||
az webapp identity assign --name <app-name> --resource-group <res-group> --identities /subscriptions/<subcripttion-id>/resourceGroups/<res_group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>
|
||||
```
|
||||
### 구성된 제3자 자격 증명 읽기
|
||||
|
||||
다음 명령을 실행하면 현재 계정에 구성된 **제3자 자격 증명**을 읽을 수 있습니다. 예를 들어, 다른 사용자에 구성된 Github 자격 증명이 있는 경우, 다른 사용자에서 토큰에 접근할 수 없습니다.
|
||||
다음 명령을 실행하면 현재 계정에 구성된 **제3자 자격 증명**을 읽을 수 있습니다. 예를 들어, 다른 사용자에 구성된 Github 자격 증명이 있는 경우, 다른 사용자에서 토큰에 접근할 수 없음을 유의하십시오.
|
||||
```bash
|
||||
az rest --method GET \
|
||||
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
|
||||
```
|
||||
이 명령은 Github, Bitbucket, Dropbox 및 OneDrive에 대한 토큰을 반환합니다.
|
||||
|
||||
여기 토큰을 확인하기 위한 몇 가지 명령 예제가 있습니다:
|
||||
여기 토큰을 확인하기 위한 몇 가지 명령 예가 있습니다:
|
||||
```bash
|
||||
# GitHub – List Repositories
|
||||
curl -H "Authorization: token <token>" \
|
||||
@@ -249,29 +249,29 @@ curl -H "Authorization: Bearer <token>" \
|
||||
-H "Accept: application/json" \
|
||||
https://graph.microsoft.com/v1.0/me/drive/root/children
|
||||
```
|
||||
### 소스에서 앱 코드 업데이트
|
||||
### Update App Code from the source
|
||||
|
||||
- 구성된 소스가 Github, BitBucket 또는 Azure Repository와 같은 제3자 제공자인 경우, 리포지토리의 소스 코드를 손상시켜 **앱 서비스의 코드를 업데이트**할 수 있습니다.
|
||||
- 앱이 **원격 git 리포지토리**(사용자 이름 및 비밀번호 포함)를 사용하도록 구성된 경우, **URL 및 기본 인증 자격 증명**을 얻어 클론하고 변경 사항을 푸시할 수 있습니다:
|
||||
- 권한 **`Microsoft.Web/sites/sourcecontrols/read`** 사용: `az webapp deployment source show --name <app-name> --resource-group <res-group>`
|
||||
- 권한 **`Microsoft.Web/sites/config/list/action`** 사용:
|
||||
- If the configured source is a third-party provider like Github, BitBucket or an Azure Repository, you can **update the code** of the App service by compromising the source code in the repository.
|
||||
- If the app is configured using a **remote git repository** (with username and password), it's possible to get the **URL and basic auth credentials** to clone and push changes with:
|
||||
- Using the permission **`Microsoft.Web/sites/sourcecontrols/read`**: `az webapp deployment source show --name <app-name> --resource-group <res-group>`
|
||||
- Using the permission **`Microsoft.Web/sites/config/list/action`**:
|
||||
- `az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>`
|
||||
- `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`
|
||||
- 앱이 **로컬 git 리포지토리**를 사용하도록 구성된 경우, **리포지토리를 클론하고 변경 사항을 푸시**할 수 있습니다:
|
||||
- 권한 **`Microsoft.Web/sites/sourcecontrols/read`** 사용: `az webapp deployment source show --name <app-name> --resource-group <res-group>`로 git 리포지토리의 URL을 얻을 수 있지만, 이는 앱의 SCM URL과 동일하며 경로는 `/<app-name>.git`입니다 (예: `https://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git`).
|
||||
- SCM 자격 증명을 얻으려면 권한이 필요합니다:
|
||||
- **`Microsoft.Web/sites/publishxml/action`**: 그런 다음 `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`을 실행합니다.
|
||||
- **`Microsoft.Web/sites/config/list/action`**: 그런 다음 `az webapp deployment list-publishing-credentials --name <name> --resource-group <res-group>`을 실행합니다.
|
||||
- If the app is configured to use a **local git repository**, it's possible to **clone the repository** and **push changes** to it:
|
||||
- Using the permission **`Microsoft.Web/sites/sourcecontrols/read`**: You can get the URL of the git repo with `az webapp deployment source show --name <app-name> --resource-group <res-group>`, but it's going to be the same as the the SCM URL of the app with the path `/<app-name>.git` (e.g. `https://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git`).
|
||||
- To get the SCM credential you need the permission:
|
||||
- **`Microsoft.Web/sites/publishxml/action`**: Then run `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`.
|
||||
- **`Microsoft.Web/sites/config/list/action`**: Then run `az webapp deployment list-publishing-credentials --name <name> --resource-group <res-group>`
|
||||
|
||||
> [!WARNING]
|
||||
> 권한 `Microsoft.Web/sites/config/list/action`과 SCM 자격 증명이 있으면, 이전 섹션에서 언급한 바와 같이 웹앱에 배포하는 것이 항상 가능합니다 (제3자 제공자를 사용하도록 구성된 경우에도).
|
||||
> Note that having the permission `Microsoft.Web/sites/config/list/action` and the SCM credentials it's always possible to deploy into a webapp (even if it was configured to use a third-party provider) as mentioned in a previous section.
|
||||
|
||||
> [!WARNING]
|
||||
> 아래 권한이 있으면 웹앱이 다르게 구성되었더라도 **임의의 컨테이너를 실행하는 것도 가능합니다**.
|
||||
> Note that having the permissions below it's also **possible to execute an arbitrary container** even if the webapp was configured differently.
|
||||
|
||||
### `Microsoft.Web/sites/config/Write`, `Microsoft.Web/sites/config/Read`, `Microsoft.Web/sites/config/list/Action`, `Microsoft.Web/sites/Read`
|
||||
|
||||
이 권한 세트는 웹앱에서 사용되는 **컨테이너를 수정**할 수 있게 해줍니다. 공격자는 이를 악용하여 웹앱이 악성 컨테이너를 실행하도록 만들 수 있습니다.
|
||||
이것은 웹앱에서 사용되는 **컨테이너를 수정할 수 있는** 권한 세트입니다. 공격자는 이를 악용하여 웹앱이 악성 컨테이너를 실행하도록 만들 수 있습니다.
|
||||
```bash
|
||||
az webapp config container set \
|
||||
--name <app-name> \
|
||||
|
||||
@@ -28,7 +28,7 @@ Azure App Services는 개발자가 **웹 애플리케이션, 모바일 앱 백
|
||||
|
||||
## Basic Authentication
|
||||
|
||||
웹 앱(및 일반적으로 Azure 함수)을 생성할 때 **기본 인증을 활성화할지 여부**를 지정할 수 있습니다(기본적으로 비활성화됨). 이는 기본적으로 **SCM(소스 제어 관리자) 및 FTP(파일 전송 프로토콜)**를 애플리케이션에 대해 활성화하여 이러한 기술을 사용하여 애플리케이션을 배포할 수 있도록 합니다.
|
||||
웹 앱(및 일반적으로 Azure 함수)을 생성할 때 **기본 인증을 활성화할지 여부**를 지정할 수 있습니다(기본적으로 비활성화됨). 이는 기본적으로 **SCM(소스 제어 관리자) 및 FTP(파일 전송 프로토콜)**를 애플리케이션에 활성화하여 이러한 기술을 사용하여 애플리케이션을 배포할 수 있도록 합니다.
|
||||
|
||||
SCM 및 FTP 서버에 액세스하려면 **사용자 이름과 비밀번호**가 필요합니다. 따라서 Azure는 이러한 플랫폼에 대한 URL과 자격 증명을 얻기 위한 **API를 제공합니다**.
|
||||
|
||||
@@ -41,7 +41,7 @@ SCM
|
||||
|
||||
Kudu는 **SCM과 웹 및 API 인터페이스를 관리**하여 App Service를 관리하고 Git 기반 배포, 원격 디버깅 및 파일 관리 기능을 제공합니다. 웹 앱에 정의된 SCM URL을 통해 접근할 수 있습니다.
|
||||
|
||||
Kudu는 App Services와 Function Apps에서 사용되는 버전이 다르며, Function Apps의 버전은 훨씬 더 제한적입니다.
|
||||
Kudu는 App Services와 Function Apps에서 사용하는 버전이 다르며, Function Apps의 버전은 훨씬 더 제한적입니다.
|
||||
|
||||
Kudu에서 찾을 수 있는 몇 가지 흥미로운 엔드포인트는 다음과 같습니다:
|
||||
- `/BasicAuth`: Kudu에 **로그인하기 위해 이 경로에 접근해야 합니다**.
|
||||
@@ -56,17 +56,17 @@ Kudu에서 찾을 수 있는 몇 가지 흥미로운 엔드포인트는 다음
|
||||
|
||||
## Sources
|
||||
|
||||
App Services는 기본적으로 코드를 zip 파일로 업로드할 수 있도록 허용하지만, 타사 서비스에 연결하여 그곳에서 코드를 가져오는 것도 허용합니다.
|
||||
App Services는 기본적으로 코드를 zip 파일로 업로드할 수 있지만, 타사 서비스에 연결하여 그곳에서 코드를 가져올 수도 있습니다.
|
||||
|
||||
- 현재 지원되는 타사 소스는 **Github**와 **Bitbucket**입니다.
|
||||
- 인증 토큰을 얻으려면 `az rest --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"`을 실행하면 됩니다.
|
||||
- 인증 토큰을 얻으려면 `az rest --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"`을 실행할 수 있습니다.
|
||||
- Azure는 기본적으로 코드가 업데이트될 때마다 App Service에 코드를 배포하기 위해 **Github Action**을 설정합니다.
|
||||
- 또한, 그곳에서 코드를 가져오기 위해 **원격 git 저장소**(사용자 이름 및 비밀번호 포함)를 지정할 수 있습니다.
|
||||
- 원격 저장소에 대한 자격 증명을 얻으려면 `az webapp deployment source show --name <app-name> --resource-group <res-group>` 또는 `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`을 실행하면 됩니다.
|
||||
- 원격 저장소에 대한 자격 증명을 얻으려면 `az webapp deployment source show --name <app-name> --resource-group <res-group>` 또는 `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`을 실행할 수 있습니다.
|
||||
- **Azure Repository**를 사용할 수도 있습니다.
|
||||
- **로컬 git 저장소**를 구성할 수도 있습니다.
|
||||
- `az webapp deployment source show --name <app-name> --resource-group <res-group>`를 사용하여 git 저장소의 URL을 얻을 수 있으며, 이는 앱의 SCM URL이 될 것입니다.
|
||||
- 이를 클론하려면 `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`를 통해 얻은 SCM 자격 증명이 필요합니다.
|
||||
- `az webapp deployment source show --name <app-name> --resource-group <res-group>`로 git 저장소의 URL을 얻을 수 있으며, 이는 앱의 SCM URL이 될 것입니다.
|
||||
- 이를 클론하려면 `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`로 얻은 SCM 자격 증명이 필요합니다.
|
||||
|
||||
## Webjobs
|
||||
|
||||
@@ -77,7 +77,7 @@ Azure WebJobs는 **Azure App Service 환경에서 실행되는 백그라운드
|
||||
|
||||
웹잡은 환경에서 **코드를 실행**하고 연결된 관리 ID에 대한 **권한 상승**에 사용할 수 있기 때문에 공격자의 관점에서 매우 흥미롭습니다.
|
||||
|
||||
또한, 웹잡이 생성하는 **로그**를 확인하는 것도 항상 흥미롭습니다. 로그에는 **민감한 정보**가 포함될 수 있습니다.
|
||||
또한, 웹잡에서 생성된 **로그**를 확인하는 것도 항상 흥미롭습니다. 이 로그에는 **민감한 정보**가 포함될 수 있습니다.
|
||||
|
||||
## Slots
|
||||
|
||||
@@ -156,6 +156,9 @@ az webapp config storage-account list --name <name> --resource-group <res-group>
|
||||
# Get configured container (if any) in the webapp, it could contain credentials
|
||||
az webapp config container show --name <name> --resource-group <res-group>
|
||||
|
||||
# Get git URL to access the code
|
||||
az webapp deployment source config-local-git --resource-group <res-group> -n <name>
|
||||
|
||||
# Get Webjobs
|
||||
az webapp webjob continuous list --resource-group <res-group> --name <app-name>
|
||||
az webapp webjob triggered list --resource-group <res-group> --name <app-name>
|
||||
@@ -217,24 +220,7 @@ done
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
#### 자격 증명 얻기 및 웹앱 코드에 접근하기
|
||||
```bash
|
||||
# Get connection strings that could contain credentials (with DBs for example)
|
||||
az webapp config connection-string list --name <name> --resource-group <res-group>
|
||||
## Check how to use the DBs connection strings in the SQL page
|
||||
|
||||
# Get credentials to access the code and DB credentials if configured.
|
||||
az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>
|
||||
|
||||
|
||||
# Get git URL to access the code
|
||||
az webapp deployment source config-local-git --resource-group <res-group> -n <name>
|
||||
|
||||
# Access/Modify the code via git
|
||||
git clone 'https://<username>:<password>@name.scm.azurewebsites.net/repo-name.git'
|
||||
## In my case the username was: $nameofthewebapp and the password some random chars
|
||||
## If you change the code and do a push, the app is automatically redeployed
|
||||
```
|
||||
{{#ref}}
|
||||
../az-privilege-escalation/az-app-services-privesc.md
|
||||
{{#endref}}
|
||||
@@ -278,7 +264,7 @@ SCM 포털에 로그인하거나 FTP를 통해 로그인하면 `/wwwroot`에서
|
||||
../az-privilege-escalation/az-app-services-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## 참조
|
||||
## 참고자료
|
||||
|
||||
- [https://learn.microsoft.com/en-in/azure/app-service/overview](https://learn.microsoft.com/en-in/azure/app-service/overview)
|
||||
- [https://learn.microsoft.com/en-us/azure/app-service/overview-hosting-plans](https://learn.microsoft.com/en-us/azure/app-service/overview-hosting-plans)
|
||||
|
||||
Reference in New Issue
Block a user