Files
hacktricks-cloud/src/pentesting-cloud/azure-security/az-services/az-app-service.md

7.7 KiB

Az - App Services

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

App Service Grundinformationen

Azure App Services ermöglicht Entwicklern, Webanwendungen, mobile App-Backends und APIs nahtlos zu erstellen, bereitzustellen und zu skalieren. Es unterstützt mehrere Programmiersprachen und integriert sich mit verschiedenen Azure-Tools und -Diensten für verbesserte Funktionalität und Verwaltung.

Jede App läuft in einer Sandbox, aber die Isolation hängt von den App Service-Plänen ab.

  • Apps in den kostenlosen und gemeinsamen Stufen laufen auf gemeinsamen VMs.
  • Apps in den Standard- und Premium-Stufen laufen auf dedizierten VMs.

Warning

Beachten Sie, dass keine dieser Isolierungen andere gängige Webanfälligkeiten (wie Datei-Uploads oder Injektionen) verhindert. Und wenn eine Verwaltungsidentität verwendet wird, könnte sie in der Lage sein, Berechtigungen zu ihnen zu eskalieren.

Azure Function Apps

Im Grunde sind Azure Function Apps eine Untergruppe von Azure App Service im Web, und wenn Sie zur Webkonsole gehen und alle App-Dienste auflisten oder az webapp list im az cli ausführen, werden Sie auch die Function Apps hier aufgelistet sehen.

Tatsächlich werden einige der sicherheitsbezogenen Funktionen, die App Services verwenden (webapp im az cli), auch von Function Apps verwendet.

Basisauthentifizierung

Beim Erstellen einer Webanwendung (und einer Azure-Funktion normalerweise) ist es möglich anzugeben, ob die Basisauthentifizierung aktiviert werden soll. Dies aktiviert im Grunde SCM und FTP für die Anwendung, sodass es möglich ist, die Anwendung mit diesen Technologien bereitzustellen.
Darüber hinaus stellt Azure eine API zur Verfügung, die es ermöglicht, den Benutzernamen, das Passwort und die URL zum Verbinden mit den SCM- und FTP-Servern abzurufen.

  • Authentifizierung: az webapp auth show --name lol --resource-group lol_group

SSH

Immer aktiv

Debugging

Aufzählung

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

# List webapps
az webapp list

## Less information
az webapp list --query "[].{hostName: defaultHostName, state: state, name: name, resourcegroup: resourceGroup}"

# Get info about 1 app
az webapp show --name <name> --resource-group <res-group>

# Get instances of a webapp
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 appsettings of an app
az webapp config appsettings list --name <name> --resource-group <res-group>

# Get backups of a webapp
az webapp config backup list --webapp-name <name> --resource-group <res-group>

# Get backups scheduled for a webapp
az webapp config backup show --webapp-name <name> --resource-group <res-group>

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




# List all the functions
az functionapp list

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

{{#endtab }}

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

# Get App Services and Function Apps
Get-AzWebApp
# Get only App Services
Get-AzWebApp | ?{$_.Kind -notmatch "functionapp"}

{{#endtab }}

{{#tab name="az get all" }}

#!/bin/bash

# Get all App Service and Function Apps

# Define Azure subscription ID
azure_subscription="your_subscription_id"

# Log in to Azure
az login

# Select Azure subscription
az account set --subscription $azure_subscription

# Get all App Services in the specified subscription
list_app_services=$(az appservice list --query "[].{appServiceName: name, group: resourceGroup}" -o tsv)

# Iterate over each App Service
echo "$list_app_services" | while IFS=$'\t' read -r appServiceName group; do
# Get the type of the App Service
service_type=$(az appservice show --name $appServiceName --resource-group $group --query "kind" -o tsv)

# Check if it is a Function App and print its name
if [ "$service_type" == "functionapp" ]; then
echo "Function App Name: $appServiceName"
fi
done

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

Anmeldeinformationen erhalten & Zugriff auf den Webanwendungscode erhalten

# Get connection strings that could contain credentials (with DBs for example)
az webapp config connection-string list --name <name> --resource-group <res-group>
## Check how to use the DBs connection strings in the SQL page

# Get credentials to access the code and DB credentials if configured.
az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>


# Get git URL to access the code
az webapp deployment source config-local-git --resource-group <res-group> -n <name>

# Access/Modify the code via git
git clone 'https://<username>:<password>@name.scm.azurewebsites.net/repo-name.git'
## In my case the username was: $nameofthewebapp and the password some random chars
## If you change the code and do a push, the app is automatically redeployed

{{#ref}} ../az-privilege-escalation/az-app-services-privesc.md {{#endref}}

Referenzen

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