What the Function: Decrypting Azure Function App Keys
Azure Function App access keys are stored encrypted in the supporting Storage Account's host.json file, and the decryption key sits in an environment variable inside the Function container. An attacker with read access to the Storage Account blobs and write access to the Function code File Share could deploy a trigger that decrypts the master key or returns the decryption key, then use it to take over the Function App.
Published on netspi.com
Technical / Cloud Pentesting
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the design stores the encrypted access keys in a Storage Account the attacker can read while the decryption key lives in the Function container the attacker can write to, so the two halves of the secret are reachable from one compromised Storage Account.
Impact
An attacker could obtain the master key and gain administrative access to the Function App, potentially leading to supply chain attacks and control of any managed identities assigned to the Function.
What the attacker needed
Read access to Storage Account blobs; write access to the Function code File Share; a Storage Account linked to the Function App
The fix
Microsoft closed the reports as expected and documented behaviour, so the guidance is to treat the supporting Storage Account as part of the Function App: restrict and rotate shared access keys, apply least privilege, use dedicated resource groups and storage accounts, store keys in Key Vault and…
How it was found
- Read the host.json blob in the azure-webjobs-secrets container to obtain the encrypted master key.
- Create a new function by adding folders under wwwroot in the SMB file share.
- Deploy trigger code that uses the Azure Data Protection library to decrypt the key, or that returns the decryption environment variable.
- Trigger the function and receive the decrypted master key or the decryption key.
- Use the master key against the Function App administrative REST APIs.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
An Azure Function App is a small piece of code that runs in the cloud, and it keeps its passwords (access keys) in a storage account next to it. Those passwords are scrambled, but the thing needed to unscramble them is kept inside the Function itself. If someone can read the storage account and also add code to the Function, they can unscramble the most powerful password and control the app.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.