Files
hacktricks-cloud/src/pentesting-cloud/azure-security/az-services/az-static-web-apps.md

11 KiB
Raw Blame History

Az Static Web Apps

{{#include ../../../banners/hacktricks-training.md}}

Static Web Apps 基本情報

Azure Static Web Appsは、GitHubなどのリポジトリからの自動CI/CDを備えた静的Webアプリをホスティングするためのクラウドサービスです。グローバルなコンテンツ配信、サーバーレスバックエンド、組み込みのHTTPSを提供し、安全でスケーラブルです。しかし、サービスが「静的」と呼ばれていても、完全に安全であるとは限りません。リスクには、誤って構成されたCORS、不十分な認証、コンテンツの改ざんが含まれ、適切に管理されないとXSSやデータ漏洩などの攻撃にさらされる可能性があります。

デプロイ認証

Tip

Static Appが作成されると、デプロイ認証ポリシーとしてデプロイメントトークンGitHub Actionsワークフローの間で選択できます。

  • デプロイメントトークン: トークンが生成され、デプロイプロセスを認証するために使用されます。このトークンを持つ人は、新しいバージョンのアプリをデプロイするのに十分です。リポジトリにトークンを秘密として持つGithub Actionが自動的にデプロイされ、リポジトリが更新されるたびに新しいバージョンのアプリをデプロイします。
  • GitHub Actionsワークフロー: この場合、非常に似たGithub Actionもリポジトリにデプロイされ、トークンも秘密に保存されます。ただし、このGithub Actionには違いがあり、**actions/github-script@v6**アクションを使用してリポジトリのIDTokenを取得し、それを使用してアプリをデプロイします。
  • 両方のケースでアクション**Azure/static-web-apps-deploy@v1**がazure_static_web_apps_api_tokenパラメータのトークンと共に使用されますが、2番目のケースでは、github_id_tokenパラメータのIDTokenで認証が行われるため、12345cbb198a77a092ff885781a62a15d51ef5e3654ca11234509ab54547270704-4140ccee-e04f-424f-b4ca-3d4dd123459c00f0702071d12345のような有効な形式のランダムトークンだけでアプリをデプロイするのに十分です。

Webアプリ基本認証

Webアプリにアクセスするためのパスワードを設定することが可能です。Webコンソールでは、ステージング環境のみ、またはステージングと本番の両方を保護するように設定できます。

執筆時点でのパスワード保護されたWebアプリの外観は次のとおりです

どのパスワードが使用されているか、およびどの環境が保護されているかを確認することができます:

az rest --method GET \
--url "/subscriptions/<subscription-id>/resourceGroups/Resource_Group_1/providers/Microsoft.Web/staticSites/<app-name>/config/basicAuth?api-version=2024-04-01"

しかし、これはパスワードを平文で表示しません。代わりに、次のようなものが表示されます: "password": "**********************"

ルートとロール

ルートは、静的ウェブアプリ内で受信HTTPリクエストがどのように処理されるかを定義します。**staticwebapp.config.json**ファイルで構成されており、URLの書き換え、リダイレクト、アクセス制限、ロールベースの認証を制御し、適切なリソースの処理とセキュリティを確保します。

いくつかの例:

{
"routes": [
{
"route": "/",
"rewrite": "/index.html"
},
{
"route": "/about",
"rewrite": "/about.html"
},
{
"route": "/api/*",
"allowedRoles": ["authenticated"]
},
{
"route": "/admin",
"redirect": "/login",
"statusCode": 302
},
{
"route": "/google",
"redirect": "https://google.com",
"statusCode": 307
}
],
"navigationFallback": {
"rewrite": "/index.html",
"exclude": ["/api/*", "/assets/*"]
}
}

パスをロールで保護することが可能であることに注意してください。これにより、ユーザーはアプリに認証し、そのロールを付与されてパスにアクセスする必要があります。また、特定のユーザーに特定のロールを付与する招待を作成することも可能で、これはアプリ内で権限を昇格させるのに役立つかもしれません。

Tip

staticwebapp.config.jsonファイルへの変更が受け入れられないようにアプリを構成することが可能であることに注意してください。この場合、Githubからファイルを変更するだけでは不十分で、アプリ内の設定を変更する必要があります。

ステージングURLは次の形式です: https://<app-subdomain>-<PR-num>.<region>.<res-of-app-domain> 例えば: https://ambitious-plant-0f764e00f-2.eastus2.4.azurestaticapps.net

スニペット

静的ウェブアプリ内にHTMLスニペットを保存することが可能で、アプリ内で読み込まれます。これは、アプリに悪意のあるコードを注入するために使用でき、例えば資格情報を盗むためのJSコードキーロガーなどです。詳細は権限昇格のセクションにあります。

マネージドアイデンティティ

Azure Static Web Appsはマネージドアイデンティティを使用するように構成できますが、このFAQで述べられているように、認証目的でAzure Key Vaultからシークレットを抽出するためにのみサポートされています。他のAzureリソースにアクセスするためではありません

詳細については、静的アプリでボールトシークレットを使用するAzureガイドをhttps://learn.microsoft.com/en-us/azure/static-web-apps/key-vault-secretsで見つけることができます

列挙

{{#tabs }} {{#tab name="az cli" }}

# List Static Webapps
az staticwebapp list --output table

# Get Static Webapp details
az staticwebapp show --name <name> --resource-group <res-group> --output table

# Get appsettings
az staticwebapp appsettings list --name <name>

# Get env information
az staticwebapp environment list --name <name>
az staticwebapp environment functions --name <name>

# Get API key
az staticwebapp secrets list --name <name>

# Get invited users
az staticwebapp users list --name <name>

# Get current snippets
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/trainingdemo/snippets?api-version=2022-03-01"

# Get database connections
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/databaseConnections?api-version=2021-03-01"

## Once you have the database connection name ("default" by default) you can get the connection string with the credentials
az rest --method POST \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/databaseConnections/default/show?api-version=2021-03-01"

# Check connected backends
az staticwebapp backends show --name <name> --resource-group <res-group>

{{#endtab }}

{{#tab name="Az Powershell" }}

Get-Command -Module Az.Websites

# Retrieves details of a specific Static Web App in the specified resource group.
Get-AzStaticWebApp -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves the build details for a specific Static Web App.
Get-AzStaticWebAppBuild -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves the application settings for a specific build environment in a Static Web App.
Get-AzStaticWebAppBuildAppSetting -ResourceGroupName <ResourceGroupName> -Name <Name> -EnvironmentName <EnvironmentName>

# Retrieves functions for a specific build environment in a Static Web App.
Get-AzStaticWebAppBuildFunction -ResourceGroupName <ResourceGroupName> -Name <Name> -EnvironmentName <EnvironmentName>

# Retrieves function app settings for a specific build environment in a Static Web App.
Get-AzStaticWebAppBuildFunctionAppSetting -ResourceGroupName <ResourceGroupName> -Name <Name> -EnvironmentName <EnvironmentName>

# Retrieves the configured roles for a Static Web App.
Get-AzStaticWebAppConfiguredRole -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves the custom domains configured for a Static Web App.
Get-AzStaticWebAppCustomDomain -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves details of the functions associated with a Static Web App.
Get-AzStaticWebAppFunction -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves the app settings for the function app associated with a Static Web App.
Get-AzStaticWebAppFunctionAppSetting -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves the secrets for a Static Web App.
Get-AzStaticWebAppSecret -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves general app settings for a Static Web App.
Get-AzStaticWebAppSetting -ResourceGroupName <ResourceGroupName> -Name <Name>

# Retrieves user details for a Static Web App with a specified authentication provider.
Get-AzStaticWebAppUser -ResourceGroupName <ResourceGroupName> -Name <Name> -AuthProvider <AuthProvider>

# Retrieves user-provided function apps associated with a Static Web App.
Get-AzStaticWebAppUserProvidedFunctionApp -ResourceGroupName <ResourceGroupName> -Name <Name>

{{#endtab }} {{#endtabs }}

Webアプリを生成するための例

以下のリンクでウェブアプリを生成するための良い例を見つけることができます: https://learn.microsoft.com/en-us/azure/static-web-apps/get-started-portal?tabs=react&pivots=github

  1. リポジトリ https://github.com/staticwebdev/react-basic/generate をあなたのGitHubアカウントにフォークし、my-first-static-web-appという名前を付けます
  2. AzureポータルでStatic Web Appを作成し、GitHubアクセスを設定し、先にフォークした新しいリポジトリを選択します
  3. 作成し、数分待って、新しいページを確認してください!

権限昇格とポストエクスプロイト

Azure Static Web Appsにおける権限昇格とポストエクスプロイトに関するすべての情報は、以下のリンクで見つけることができます:

{{#ref}} ../az-privilege-escalation/az-static-web-apps-privesc.md {{#endref}}

参考文献

{{#include ../../../banners/hacktricks-training.md}}