Skip to content

Latest commit

 

History

History
141 lines (97 loc) · 6.79 KB

File metadata and controls

141 lines (97 loc) · 6.79 KB

Az - Key Vault

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks:

Basic Information

From the docs: Azure Key Vault is a cloud service for securely storing and accessing secrets. A secret is anything that you want to tightly control access to, such as API keys, passwords, certificates, or cryptographic keys. Key Vault service supports two types of containers: vaults and managed hardware security module(HSM) pools. Vaults support storing software and HSM-backed keys, secrets, and certificates. Managed HSM pools only support HSM-backed keys. See Azure Key Vault REST API overview for complete details.

The URL format is https://{vault-name}.vault.azure.net/{object-type}/{object-name}/{object-version} Where:

  • vault-name is the globally unique name of the key vault
  • object-type can be "keys", "secrets" or "certificates"
  • object-name is unique name of the object within the key vault
  • object-version is system generated and optionally used to address a unique version of an object.

In order to access to the secrets stored in the vault 2 permissions models can be used:

  • Vault access policy
  • Azure RBAC

Access Control

Access to a Key Vault resource is controlled by two planes:

  • The management plane, whose target is management.azure.com.
    • It's used to manage the key vault and access policies. Only Azure role based access control (RBAC) is supported.
  • The data plane, whose target is <vault-name>.vault.azure.com.
    • It's used to manage and access the data (keys, secrets and certificates) in the key vault. This supports key vault access policies or Azure RBAC.

A role like Contributor that has permissions in the management place to manage access policies can get access to the secrets by modifying the access policies.

Key Vault RBAC Built-In Roles

Network Access

In Azure Key Vault, firewall rules can be set up to allow data plane operations only from specified virtual networks or IPv4 address ranges. This restriction also affects access through the Azure administration portal; users will not be able to list keys, secrets, or certificates in a key vault if their login IP address is not within the authorized range.

For analyzing and managing these settings, you can use the Azure CLI:

az keyvault show --name name-vault --query networkAcls

The previous command will display the firewall settings of name-vault, including enabled IP ranges and policies for denied traffic.

Enumeration

{% tabs %} {% tab title="Az Powershell" %} {% code overflow="wrap" %}

# Get keyvault token
curl "$IDENTITY_ENDPOINT?resource=https://vault.azure.net&api-version=2017-09-01" -H secret:$IDENTITY_HEADER

# Connect with PS AzureAD
## $token from management API
Connect-AzAccount -AccessToken $token -AccountId 1937ea5938eb-10eb-a365-10abede52387 -KeyVaultAccessToken $keyvaulttoken

# List vaults
Get-AzKeyVault
# Get secrets names from the vault
Get-AzKeyVaultSecret -VaultName <vault_name>
# Get secret values
Get-AzKeyVaultSecret -VaultName <vault_name> -Name <secret_name> –AsPlainText

{% endcode %} {% endtab %}

{% tab title="az" %}

#!/bin/bash

# Dump all keyvaults from the subscription

# Define Azure subscription ID
AZ_SUBSCRIPTION_ID="your-subscription-id"

# Specify the filename for output
CSV_OUTPUT="vault-names-list.csv"

# Login to Azure account
az login

# Select the desired subscription
az account set --subscription $AZ_SUBSCRIPTION_ID

# Retrieve all resource groups within the subscription
AZ_RESOURCE_GROUPS=$(az group list --query "[].name" -o tsv)

# Initialize the CSV file with headers
echo "Vault Name,Associated Resource Group" > $CSV_OUTPUT

# Iterate over each resource group
for GROUP in $AZ_RESOURCE_GROUPS
do
  # Fetch key vaults within the current resource group
  VAULT_LIST=$(az keyvault list --resource-group $GROUP --query "[].name" -o tsv)

  # Process each key vault
  for VAULT in $VAULT_LIST
  do
    # Extract the key vault's name
    VAULT_NAME=$(az keyvault show --name $VAULT --resource-group $GROUP --query "name" -o tsv)

    # Append the key vault name and its resource group to the file
    echo "$VAULT_NAME,$GROUP" >> $CSV_OUTPUT
  done
done

{% endtab %} {% endtabs %}

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks: