Az - Azure App Service & Function Apps

Az - Azure App Service & Function Apps

Impara l'hacking di AWS da zero a eroe con htARTE (HackTricks AWS Red Team Expert)!

Altri modi per supportare HackTricks:

Informazioni di base su App Service

Dalla documentazione: Azure App Service è un servizio basato su HTTP per l'hosting di applicazioni web, API REST e backend mobili. Puoi sviluppare nel tuo linguaggio preferito, che sia .NET, .NET Core, Java, Ruby, Node.js, PHP o Python. Le applicazioni vengono eseguite e scalate facilmente sia su ambienti basati su Windows che su Linux.

Ogni app viene eseguita all'interno di un sandbox, ma l'isolamento dipende dai piani di App Service

  • Le app nei livelli Free e Shared vengono eseguite su VM condivise

  • Le app nei livelli Standard e Premium vengono eseguite su VM dedicate

Nota che nessuno di questi isolamenti impedisce altre comuni vulnerabilità web (come l'upload di file o le iniezioni). E se viene utilizzata un'identità di gestione, potrebbe essere in grado di comprometterne i permessi.

Enumerazione

# List webapps
az webapp list

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

# Get access restrictions
az webapp config access-restriction show --resource-group <res-group> -n <name>

# Remove access restrictions
az webapp config access-restriction remove --resource-group <res-group> -n <name> --rule-name <rule-name>

# 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

# Restart webapp
az webapp restart --name <name> --resource-group <res-group>
# Get App Services and Function Apps
Get-AzWebApp
# Get only App Services
Get-AzWebApp | ?{$_.Kind -notmatch "functionapp"}

```bash #!/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

#### Ottenere le credenziali e accedere al codice dell'applicazione web

To obtain credentials and gain access to the code of the web application, you can follow these steps:

1. Utilize techniques like reconnaissance and enumeration to gather information about the target Azure App Service.

2. Identify potential vulnerabilities or misconfigurations that could lead to unauthorized access.

3. Exploit any discovered vulnerabilities or misconfigurations to gain access to the Azure App Service.

4. Once access is obtained, navigate to the web application's code repository or file system.

5. Analyze the code to understand its structure and functionality.

By following these steps, you can obtain the necessary credentials and gain access to the code of the Azure App Service.
```bash
# 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

Accesso al container Docker con l'app web tramite ssh:

# Get ssh session
az webapp create-remote-connection --subscription <SUBSCRIPTION-ID> --resource-group <RG-NAME> -n <APP-SERVICE-NAME>

## If successfull you will get a message such as:
#Verifying if app is running....
#App is running. Trying to establish tunnel connection...
#Opening tunnel on port: 39895
#SSH is available { username: root, password: Docker! }

## So from that machine ssh into that port (you might need generate a new ssh session to the jump host)
ssh root@127.0.0.1 -p 39895

Informazioni di base sulle Function Apps

Azure Functions è una soluzione serverless che ti permette di scrivere meno codice, mantenere meno infrastrutture e risparmiare sui costi. Invece di preoccuparti di distribuire e mantenere server, l'infrastruttura cloud fornisce tutte le risorse aggiornate necessarie per far funzionare le tue applicazioni.

Nel portale di Azure, l'integrazione tra Azure Functions e Azure API Management è facilitata, consentendo di esporre gli endpoint delle funzioni di trigger HTTP come API REST. Le API esposte in questo modo sono descritte utilizzando una definizione OpenAPI, fornendo un'interfaccia standard e indipendente dal linguaggio per le API RESTful.

Le Function Apps supportano le Identità Gestite.

Inoltre, la Function App potrebbe avere determinati endpoint che richiedono un certo livello di autenticazione, come "admin" o "anonymous". Un attaccante potrebbe cercare di accedere agli endpoint consentiti per gli utenti anonimi per eludere le restrizioni e ottenere accesso a dati o funzionalità sensibili.

Enumerazione

# Get only Function Apps
Get-AzFunctionApp

Riferimenti

Impara l'hacking di AWS da zero a eroe con htARTE (HackTricks AWS Red Team Expert)!

Altri modi per supportare HackTricks:

Last updated