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

9.6 KiB

Az - Statiese Web Apps

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

Statiese Web Apps Basiese Inligting

Azure Static Web Apps is 'n wolkdienste vir die aanbied van statiese web apps met outomatiese CI/CD vanaf repositories soos GitHub. Dit bied globale inhoudsaflewering, serverless agtergronde, en ingeboude HTTPS, wat dit veilig en skaalbaar maak. Tog, selfs al word die diens "staties" genoem, beteken dit nie dat dit heeltemal veilig is nie. Risiko's sluit verkeerd geconfigureerde CORS, onvoldoende verifikasie, en inhoudsmanipulasie in, wat apps aan aanvalle soos XSS en datalekke kan blootstel as dit nie behoorlik bestuur word nie.

Ontplooiing Verifikasie

Tip

Wanneer 'n Statiese App geskep word, kan jy die ontplooiing magtiging beleid tussen Ontplooiingstoken en GitHub Actions werksvloei kies.

  • Ontplooiingstoken: 'n Token word gegenereer en gebruik om die ontplooiingsproses te verifieer. Enigeen met hierdie token is genoeg om 'n nuwe weergawe van die app te ontplooi. 'n Github Action word outomaties ontplooi in die repo met die token in 'n geheim om 'n nuwe weergawe van die app te ontplooi elke keer as die repo opgedateer word.
  • GitHub Actions werksvloei: In hierdie geval word 'n baie soortgelyke Github Action ook in die repo ontplooi en die token word ook in 'n geheim gestoor. egter, hierdie Github Action het 'n verskil, dit gebruik die actions/github-script@v6 aksie om die IDToken van die repository te kry en dit te gebruik om die app te ontplooi.
  • Selfs al word in albei gevalle die aksie Azure/static-web-apps-deploy@v1 met 'n token in die azure_static_web_apps_api_token param gebruik, is 'n willekeurige token met 'n geldige formaat soos 12345cbb198a77a092ff885781a62a15d51ef5e3654ca11234509ab54547270704-4140ccee-e04f-424f-b4ca-3d4dd123459c00f0702071d12345 net genoeg om die app te ontplooi aangesien die magtiging met die IDToken in die github_id_token param gedoen word.

Web App Basiese Verifikasie

Dit is moontlik om 'n wagwoord te configure om toegang tot die Web App te verkry. Die webkonsol laat toe om dit te configure om slegs staging omgewings of beide staging en die produksie omgewing te beskerm.

So lyk 'n wagwoord beskermde web app op die tyd van skryf:

Dit is moontlik om te sien of enige wagwoord gebruik word en watter omgewings beskerm word met:

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"

However, this won't show the password in clear text, just something like: "password": "**********************".

Routes & Roles

Routes define hoe inkomende HTTP versoeke hanteer word within a static web app. Configured in the staticwebapp.config.json file, they control URL rewriting, redirections, access restrictions, and role-based authorization, ensuring proper resource handling and security.

Some example:

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

Let op hoe dit moontlik is om 'n pad met 'n rol te beskerm, dan sal gebruikers moet autentiseer by die app en daardie rol toegeken moet word om toegang tot die pad te verkry. Dit is ook moontlik om uitnodigings te skep wat spesifieke rolle aan spesifieke gebruikers toeken wat via EntraID, Facebook, GitHub, Google, Twitter aanmeld, wat nuttig kan wees om bevoegdhede binne die app te verhoog.

Tip

Let daarop dat dit moontlik is om die App so te konfigureer dat veranderings aan die staticwebapp.config.json lêer nie aanvaar word nie. In hierdie geval mag dit nie genoeg wees om net die lêer van Github te verander nie, maar ook om die instelling in die App te verander.

Die staging URL het hierdie formaat: https://<app-subdomain>-<PR-num>.<region>.<res-of-app-domain> soos: https://ambitious-plant-0f764e00f-2.eastus2.4.azurestaticapps.net

Gemanagte Identiteite

Azure Static Web Apps kan gekonfigureer word om gemanagte identiteite te gebruik, egter, soos genoem in hierdie FAQ, word hulle slegs ondersteun om geheime uit Azure Key Vault vir autentisering doeleindes te onttrek, nie om toegang tot ander Azure hulpbronne te verkry nie.

Vir meer inligting kan jy 'n Azure-gids vind oor hoe om 'n kluis geheim in 'n statiese app te gebruik by https://learn.microsoft.com/en-us/azure/static-web-apps/key-vault-secrets.

Enumerasie

{% tabs %} {% tab title="az cli" %} {% code overflow="wrap" %}

# 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 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>

{% endcode %} {% endtab %}

{% tab title="Az PowerShell" %} {% code overflow="wrap" %}

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>

{% endcode %} {% endtab %} {% endtabs %}

Voorbeelde om Web Apps te genereer

Jy kan 'n mooi voorbeeld vind om 'n web app te genereer in die volgende skakel: https://learn.microsoft.com/en-us/azure/static-web-apps/get-started-portal?tabs=react&pivots=github

  1. Fork die repository https://github.com/staticwebdev/react-basic/generate na jou GitHub-rekening en noem dit my-first-static-web-app
  2. Skep 'n Static Web App in die Azure-portaal deur die Github-toegang te konfigureer en die voorheen geforkte nuwe repository te kies
  3. Skep dit, en wag 'n paar minute, en kyk na jou nuwe bladsy!

Privilege Escalation en Post Exploitation

Alle inligting oor privilege escalation en post exploitation in Azure Static Web Apps kan in die volgende skakel gevind word:

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

Verwysings

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