Skip to content
Cloud Security

Key Vault 14 - Abusing Tags and an Old Key Version to Get the Flag

How a Key Vault access policy that blocks secrets but allows decrypt leads to a ciphertext hidden across two key version tags.

Introduction

This is Altered Security’s Key Vault 14 (Abuse Tag and Versioning) lab from their Red Labs platform, rated Hard. The scenario line is short on purpose: you’re told to abuse Key Vault features to get the flag, and you get two one-line hints pointing at tags and decryption. No diagram, no step list, just the vault.

You start with an Entra ID user and nothing else:

code
Username: [email protected]
Password: #jOgKfnYDIRX7p5A1!

That user drops into a resource group called AS-KV-121126-pooledLab-njemyw447, and that resource group has exactly one thing in it: a Key Vault named ASgecnpq447. That’s the whole attack surface.

The lab’s own attack path diagram lays out the two legs you need: enumerate the vault through the portal to find the key and the version to target, then hit it from PowerShell to actually decrypt.

Official attack path: enumerate the Key Vault key and version through the portal, then decrypt from PowerShell to get the flag

Enumeration

First instinct with any Key Vault is to just list the secrets and see what falls out.

bash
az login --tenant "redteamlabsus.onmicrosoft.com" --allow-no-subscriptions --use-device-code

az resource list -o table
code
Name         ResourceGroup                     Location    Type                       Status
-----------  --------------------------------  ----------  -------------------------  ---------
ASgecnpq447  AS-KV-121126-pooledLab-njemyw447  westindia   Microsoft.KeyVault/vaults  Succeeded

One vault, as expected. Then the obvious next command:

bash
az keyvault secret list --vault-name "ASgecnpq447"
code
(Forbidden) The user, group or application '...' does not have secrets list permission on key vault 'ASgecnpq447;location=westindia'.
Code: Forbidden
Inner error: {
    "code": "ForbiddenByPolicy"
}

ForbiddenByPolicy is more specific than a generic RBAC denial, so it was worth checking what model this vault was even using before assuming secrets were a dead end:

bash
az keyvault show --name ASgecnpq447 --query "properties.enableRbacAuthorization"
# false

RBAC is off, which means this vault runs on the old access-policy model, and the actual permission breakdown lives directly on the vault resource:

bash
az keyvault show --name ASgecnpq447 --query "properties.accessPolicies"

My identity’s entry had secrets as a flat-out empty array, no get, no list. But the same entry listed keys: ["get", "list", "decrypt"]. That decrypt permission is what caught my eye. It’s not something you’d normally hand out, and it’s a pretty clear signal the lab wants you working with a key directly instead of reading a secret value.

Access policy breakdown showing secrets blocked and keys allowed with decrypt

Finding the Key

bash
az keyvault key list --vault-name ASgecnpq447 -o table
code
KeySize    Kid                                                   Name
---------  ----------------------------------------------------  -----------
2048       https://asgecnpq447.vault.azure.net/keys/aspuoqek447  aspuoqek447

One RSA-2048 key, aspuoqek447. Before going further into the key itself, I tried pivoting sideways to see if there was an encrypted blob sitting somewhere else in the resource group:

bash
az resource list -g AS-KV-121126-pooledLab-njemyw447 -o table
code
(AuthorizationFailed) ... does not have authorization to perform action 'Microsoft.Resources/subscriptions/resourcegroups/read' ...

No resource-group-level read at all. My access was scoped tightly to the vault resource itself, so that pivot was a dead end. Whatever this lab wanted, it had to be sitting on the key.

Two Key Versions

At this point I was stuck for a bit, just staring at one key with get/list/decrypt and not much else to do with it. Then it clicked to check if the key had multiple versions, since that’s not something you’d normally think to look at.

bash
az keyvault key list-versions --vault-name ASgecnpq447 --name aspuoqek447 -o table
code
KeySize    Kid                                                                                    Name
---------  -------------------------------------------------------------------------------------  -----------
2048       https://asgecnpq447.vault.azure.net/keys/aspuoqek447/87c45533041d4c78aca6b0f0489285dd  aspuoqek447
2048       https://asgecnpq447.vault.azure.net/keys/aspuoqek447/de771c298140422d8d0660662f6054f4  aspuoqek447

Two versions of the same key. Pulled the full metadata on each one, not just keyOps, because tags turned out to be exactly where this challenge hides things.

The old version (de771c29...) just had a welcome tag:

json
"tags": { "flag": "Welcome to Azure Challenge" }

The new version (87c45533...) had the real payload, split across two tags. Azure caps how long a tag value can be, so whoever built this lab chunked the ciphertext in half to fit:

json
"tags": {
  "part1": "AurWeya3ONix/jA/BsJMWo7Xnpfp1k8nUGNK6MxnnDQ0lyIu/GUCJiCFtH9TE1oRpyrO8WXDNJRL4ZSqBlTuW5KwjNRKR9pcpALUBhSFbF4xVBSgGTEsaYl5dC6Xxzqpbwdk9fioCw4b9SZ3gzV0MGngJaRqgNhK/p2D0gFe38J6",
  "part2": "xFQLsLMBYeAbJCa+1TPM5cyoE5uh/eAs+1rMMUsca4R0vDV8bMdrvIFXHTWxepWi1RCCNncwtJyl+3QBlLE6n8pkA+EYE7+VEw6AoDiavzL7VZoMaW2+kxK+CTvL4Y8eSbQdNvpUDbrUX/Dqhg0YLfRztgMQ+e2n6zYfcRMnVg=="
}

Concatenating part1 + part2 gives a clean base64 blob that decodes to exactly 256 bytes, which is precisely what a ciphertext from a 2048-bit RSA key should be. That length match is what told me these two tags weren’t just junk data, they were a real ciphertext someone had split in half.

Decrypting It

Here’s where I almost second-guessed myself. The payload lives on the new key version, so it seemed reasonable that the new version might also be the one holding the matching key. I ran the decrypt against the new version’s ID first just to rule it out:

powershell
Invoke-AzKeyVaultKeyOperation -Operation Decrypt -Algorithm RSA1_5 -ByteArrayValue $cipherBytes `
  -VaultName "ASgecnpq447" -Name "aspuoqek447" -Version "87c45533041d4c78aca6b0f0489285dd"

That just errors out, the new version’s key material doesn’t match this ciphertext at all. Which makes sense once you think about it: the old version is the one that originally encrypted the data, the new version just got created afterward to carry the tags. So the old version is the one that has to do the decrypting:

powershell
$b64 = "AurWeya3ONix/jA/BsJMWo7Xnpfp1k8nUGNK6MxnnDQ0lyIu/GUCJiCFtH9TE1oRpyrO8WXDNJRL4ZSqBlTuW5KwjNRKR9pcpALUBhSFbF4xVBSgGTEsaYl5dC6Xxzqpbwdk9fioCw4b9SZ3gzV0MGngJaRqgNhK/p2D0gFe38J6xFQLsLMBYeAbJCa+1TPM5cyoE5uh/eAs+1rMMUsca4R0vDV8bMdrvIFXHTWxepWi1RCCNncwtJyl+3QBlLE6n8pkA+EYE7+VEw6AoDiavzL7VZoMaW2+kxK+CTvL4Y8eSbQdNvpUDbrUX/Dqhg0YLfRztgMQ+e2n6zYfcRMnVg=="
$cipherBytes = [Convert]::FromBase64String($b64)
$cipherBytes.Length   # 256, confirms we've got the right blob

$decrypted = Invoke-AzKeyVaultKeyOperation `
  -Operation Decrypt `
  -Algorithm RSA1_5 `
  -ByteArrayValue $cipherBytes `
  -VaultName "ASgecnpq447" `
  -Name "aspuoqek447" `
  -Version "de771c298140422d8d0660662f6054f4"

[System.Text.Encoding]::UTF8.GetString($decrypted.RawResult)

A few things tripped me up getting to that working command, worth flagging since they’re easy to hit:

  • The official lab writeup uses -Value (ConvertTo-SecureString ...), but the Az.KeyVault module version I had installed didn’t expose -Value at all, only -ByteArrayValue. So skip the SecureString step entirely and just hand it the raw byte array.
  • My first attempt used RSA-OAEP and got back "Error occurred while decoding OAEP padding". This key’s ciphertext was wrapped with PKCS#1 v1.5, so RSA1_5 is the algorithm you actually want here.
  • At one point I grabbed the wrong value entirely and tried decrypting the key’s own public modulus (the n field from the JSON) instead of the tag-derived ciphertext. It’s also exactly 256 bytes, so the length check alone won’t catch that mistake. Worth double-checking you’re pulling the concatenated tags and not key material.

Tags on the new version feed a concatenated ciphertext that the old key version decrypts into the flag

Once RSA1_5 runs against the old version, it comes back clean:

code
asawzidj447asnaeksj447

Flag

asawzidj447asnaeksj447

Mitigation

  • Don’t grant decrypt (or sign) on Key Vault keys to identities that only need to reference a key, not use it cryptographically.
  • Never stash ciphertext, secrets, or other sensitive blobs in tags. Tags aren’t access-controlled the way secret values are, so anyone with get/list on keys can read them straight off the metadata.
  • Disable or purge old key versions instead of leaving them active and still capable of decrypting.
  • Prefer RBAC role assignments over legacy access policies. It’s much easier to see exactly who can do what on a vault.

References