diff --git a/src/pentesting-cloud/azure-security/az-services/az-storage.md b/src/pentesting-cloud/azure-security/az-services/az-storage.md index 0d24f91da..60ed9ac34 100644 --- a/src/pentesting-cloud/azure-security/az-services/az-storage.md +++ b/src/pentesting-cloud/azure-security/az-services/az-storage.md @@ -4,24 +4,24 @@ ## 基本信息 -Azure Storage Accounts 是 Microsoft Azure 中的基础服务,提供可扩展、安全且高可用的云 **storage for various data types**,包括 blobs (binary large objects)、files、queues 和 tables。它们作为容器,将这些不同的存储服务在单一命名空间下分组以便管理。 +Azure Storage Accounts 是 Microsoft Azure 中的基础服务,提供可扩展、安全且高度可用的云 **用于多种数据类型的存储**,包括 blobs (binary large objects)、files、queues 和 tables。它们作为容器,将这些不同的存储服务在单一命名空间下分组以便于管理。 **主要配置选项**: -- 每个 storage account 必须在 **整个 Azure 中具有唯一名称**。 -- 每个 storage account 部署在一个 **region** 或 Azure extended zone 中。 +- 每个 storage account 必须有一个 **在整个 Azure 中唯一的名称**。 +- 每个 storage account 部署在一个 **region** 或在 Azure extended zone。 - 可以选择 storage account 的 **premium** 版本以获得更好的性能。 -- 可以在 **4 种冗余类型** 中选择以防止机架、磁盘和数据中心级别的 **故障**。 +- 可以在 **4 种冗余类型之间选择以防护** 机架、驱动器和数据中心 **故障**。 **安全配置选项**: -- **Require secure transfer for REST API operations**:要求与存储的所有通信使用 TLS。 -- **Allows enabling anonymous access on individual containers**:如果未启用,之后将无法对容器开启匿名访问。 -- **Enable storage account key access**:如果未启用,将禁止使用 Shared Keys 访问。 +- **Require secure transfer for REST API operations**:要求与 storage 的任何通信使用 TLS +- **Allows enabling anonymous access on individual containers**:如果不允许,将来无法为单独容器启用匿名访问 +- **Enable storage account key access**:如果未启用,将禁止使用 Shared Keys 访问 - **Minimum TLS version** -- **Permitted scope for copy operations**:允许来自任意 storage account,来自相同 Entra tenant 的任意 storage account,或来自具有私有端点且位于相同虚拟网络的 storage account。 +- **Permitted scope for copy operations**:允许来自任何 storage account、来自同一 Entra tenant 的任何 storage account,或来自在同一虚拟网络中具有 private endpoints 的 storage account。 -**Blob Storage options**: +**Blob Storage 选项**: - **Allow cross-tenant replication** - **Access tier**:Hot(频繁访问的数据)、Cool 和 Cold(很少访问的数据) @@ -29,57 +29,72 @@ Azure Storage Accounts 是 Microsoft Azure 中的基础服务,提供可扩展 **网络选项**: - **Network access**: -- 允许来自所有网络 -- 允许来自选定的虚拟网络和 IP 地址 -- 禁用公共访问并使用私有访问 + - 允许来自所有网络 + - 允许来自选定的虚拟网络和 IP 地址 + - 禁用公共访问并使用私有访问 - **Private endpoints**:允许从虚拟网络到 storage account 的私有连接 **数据保护选项**: -- **Point-in-time restore for containers**:允许将容器恢复到早期状态 -- 需要启用 versioning、change feed 和 blob soft delete。 -- **Enable soft delete for blobs**:为已删除(甚至被覆盖的)blob 启用按天计的保留期 -- **Enable soft delete for containers**:为已删除的容器启用按天计的保留期 -- **Enable soft delete for file shares**:为已删除的 file shares 启用按天计的保留期 +- **Point-in-time restore for containers**:允许将容器还原到较早的状态 +- 它需要启用 versioning、change feed 和 blob soft delete。 +- **Enable soft delete for blobs**:为已删除的 blobs(即使被覆盖)启用以天为单位的保留期 +- **Enable soft delete for containers**:为已删除的容器启用以天为单位的保留期 +- **Enable soft delete for file shares**:为已删除的 file shares 启用以天为单位的保留期 - **Enable versioning for blobs**:保留 blob 的历史版本 -- **Enable blob change feed**:记录对 blob 的创建、修改和删除变更日志 -- **Enable version-level immutability support**:允许在账户级别设置基于时间的保留策略,适用于所有 blob 版本。 +- **Enable blob change feed**:记录对 blobs 的创建、修改和删除变化日志 +- **Enable version-level immutability support**:允许在账户级别设置基于时间的保留策略,该策略将应用于所有 blob 版本。 - Version-level immutability support 和 point-in-time restore for containers 不能同时启用。 **加密配置选项**: - **Encryption type**:可以使用 Microsoft-managed keys (MMK) 或 Customer-managed keys (CMK) -- **Enable infrastructure encryption**:允许对数据进行双重加密以“提高安全性” +- **Enable infrastructure encryption**:允许对数据进行双重加密,以“增强安全性” ### 存储端点 -
存储服务端点
Blob storagehttps://.blob.core.windows.net

https://.blob.core.windows.net/?restype=container&comp=list
Data Lake Storagehttps://.dfs.core.windows.net
Azure Fileshttps://.file.core.windows.net
Queue storagehttps://.queue.core.windows.net
Table storagehttps://.table.core.windows.net
+
存储服务Endpoint
Blob storagehttps://.blob.core.windows.net

https://.blob.core.windows.net/?restype=container&comp=list
Data Lake Storagehttps://.dfs.core.windows.net
Azure Fileshttps://.file.core.windows.net
Queue storagehttps://.queue.core.windows.net
Table storagehttps://.table.core.windows.net
-### 公开暴露 +### 公共暴露 -如果 "Allow Blob public access" 被**启用**(默认禁用),创建容器时可以: +如果 "Allow Blob public access" 被 **启用**(默认禁用),在创建容器时可以: -- 给予 **public access to read blobs**(需要知道 blob 名称)。 -- **List container blobs** 并 **读取** 它们。 -- 将其设置为完全 **private** +- 允许 **public access to read blobs**(需要知道容器名称)。 +- 列出容器中的 blobs 并读取它们。 +- 将其设置为完全 **私有**
-#### 审计匿名 blob 暴露 +### Static website (`$web`) 暴露 & leaked secrets -- **定位可能暴露数据的 storage accounts**:`az storage account list | jq -r '.[] | select(.properties.allowBlobPublicAccess==true) | .name'`。如果 `allowBlobPublicAccess` 为 `false`,则无法将容器设置为公开。 -- **检查风险账户** 以确认该标志和其他弱设置:`az storage account show --name --query '{allow:properties.allowBlobPublicAccess, minTls:properties.minimumTlsVersion}'`。 -- **枚举在该标志启用时的容器级别暴露**: +- **Static websites** 从特殊的 `$web` 容器通过区域特定的端点提供,例如 `https://.z13.web.core.windows.net/`。 +- 通过 blob API `$web` 容器可能会报告 `publicAccess: null`,但文件仍可通过静态站点端点访问,因此将配置/IaC 工件放在那里可能会 leak secrets。 +- 快速审计工作流程: +```bash +# Identify storage accounts with static website hosting enabled +az storage blob service-properties show --account-name --auth-mode login +# Enumerate containers (including $web) and their public flags +az storage container list --account-name --auth-mode login +# List files served by the static site even when publicAccess is null +az storage blob list --container-name '$web' --account-name --auth-mode login +# Pull suspicious files directly (e.g., IaC tfvars containing secrets/SAS) +az storage blob download -c '$web' --name iac/terraform.tfvars --file /dev/stdout --account-name --auth-mode login +``` +### 审计匿名 blob 暴露 + +- **定位可能暴露数据的 storage accounts**: `az storage account list | jq -r '.[] | select(.properties.allowBlobPublicAccess==true) | .name'`. 如果 `allowBlobPublicAccess` 是 `false`,你无法将 containers 设为 public. +- **检查存在风险的 storage accounts** 以确认 `allowBlobPublicAccess` 标志和其他弱配置: `az storage account show --name --query '{allow:properties.allowBlobPublicAccess, minTls:properties.minimumTlsVersion}'`. +- **枚举启用该标志的 containers 的暴露情况** where the flag is enabled: ```bash az storage container list --account-name \ --query '[].{name:name, access:properties.publicAccess}' ``` -- `"Blob"`: 允许匿名读取 **仅当已知 Blob 名称**(无法列出)。 -- `"Container"`: 允许匿名**列出 + 读取**所有 Blob。 -- `null`: 私有;需要身份验证。 -- **无需凭据即可证明访问**: -- 如果 `publicAccess` 为 `Container`,匿名列出有效: `curl "https://.blob.core.windows.net/?restype=container&comp=list"`. -- 对于 `Blob` 和 `Container`,当名称已知时,匿名 Blob 下载均可行: +- `"Blob"`: 匿名读取仅在已知 blob 名称时允许(不允许列出)。 +- `"Container"`: 匿名对每个 blob 的**列出 + 读取**。 +- `null`: 私有;需要认证。 +- **证明访问** 无需凭据: +- 如果 `publicAccess` 是 `Container`,匿名列出可行: `curl "https://.blob.core.windows.net/?restype=container&comp=list"`. +- 对于 `Blob` 和 `Container`,当名称已知时,匿名 blob 下载可行: ```bash az storage blob download -c -n --account-name --file /dev/stdout # or via raw HTTP @@ -87,31 +102,31 @@ curl "https://.blob.core.windows.net//" ``` ### 连接到存储 -如果你发现任何可以连接的 **存储**,可以使用工具 [**Microsoft Azure Storage Explorer**](https://azure.microsoft.com/es-es/products/storage/storage-explorer/) 来进行连接。 +如果发现可以连接的 **存储**,可以使用工具 [**Microsoft Azure Storage Explorer**](https://azure.microsoft.com/es-es/products/storage/storage-explorer/) 来连接。 ## 访问存储 ### RBAC -可以使用 Entra ID 主体结合 **RBAC roles** 来访问存储帐户,这是推荐的方式。 +可以使用 Entra ID 主体与 **RBAC roles** 来访问存储账户,这是推荐的方式。 ### 访问密钥 -存储帐户有可用于访问的访问密钥。这会提供对存储帐户的**完全访问权限**。 +存储账户有可用于访问的访问密钥。这会提供对存储账户的**完全访问权限**。
### **Shared Keys & Lite Shared Keys** -可以 [**generate Shared Keys**](https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key),使用访问密钥对其签名,以通过签名 URL 授权对某些资源的访问。 +可以使用访问密钥[**generate Shared Keys**](https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key) 签名,从而通过签名 URL 授权对特定资源的访问。 > [!NOTE] -> 请注意,`CanonicalizedResource` 部分表示存储服务的资源(URI)。如果 URL 中的任何部分被编码,则它也应在 `CanonicalizedResource` 中进行编码。 +> 注意 `CanonicalizedResource` 部分表示存储服务的资源 (URI)。如果 URL 的任何部分被编码,那么在 `CanonicalizedResource` 内也应进行相应编码。 > [!NOTE] -> 默认情况下 **`az` cli 使用此方法** 来对请求进行身份验证。要让它使用 Entra ID 主体凭据,请指定参数 `--auth-mode login`。 +> 这是 **默认被 `az` cli 使用** 来对请求进行认证。若要让其使用 Entra ID 主体凭据,请指定参数 `--auth-mode login`。 -- 可以通过签署以下信息来为 blob、queue 和 file services 生成**shared key**: +- 可以通过对以下信息进行签名来生成 **shared key for blob, queue and file services**: ```bash StringToSign = VERB + "\n" + Content-Encoding + "\n" + @@ -128,7 +143,7 @@ Range + "\n" + CanonicalizedHeaders + CanonicalizedResource; ``` -- 可以生成一个 **shared key for table services**,对以下信息进行签名: +- 可以通过对以下信息进行签名来生成 **shared key for table services**: ```bash StringToSign = VERB + "\n" + Content-MD5 + "\n" + @@ -150,7 +165,7 @@ CanonicalizedResource; StringToSign = Date + "\n" CanonicalizedResource ``` -然后,要使用该 key,可在 Authorization header 中按以下语法: +然后,要使用该密钥,可以在 Authorization header 中按以下语法进行: ```bash Authorization="[SharedKey|SharedKeyLite] :" #e.g. @@ -164,76 +179,76 @@ Content-Length: 0 ``` ### **共享访问签名** (SAS) -Shared Access Signatures (SAS) 是安全的、时限性的 URL,允许在不暴露存储帐户访问密钥的情况下授予对 Azure Storage 帐户中资源的特定访问权限。虽然访问密钥提供对所有资源的完整管理访问权限,SAS 通过指定权限(如 read 或 write)和设置到期时间来实现细粒度控制。 +Shared Access Signatures (SAS) 是安全的、时限性的 URL,允许在不暴露 Azure Storage 账户访问密钥的情况下向资源授予特定访问权限。访问密钥提供对所有资源的完整管理访问,而 SAS 通过指定权限(如读或写)并定义到期时间,允许更精细的控制。 #### SAS 类型 -- **User delegation SAS**: 由 **Entra ID principal** 创建,该 principal 将对 SAS 进行签名并将用户的权限委派给 SAS。它只能用于 **blob and data lake storage**([docs](https://learn.microsoft.com/en-us/rest/api/storageservices/create-user-delegation-sas))。可以**撤销**所有已生成的用户委派 SAS。 -- 即使可以生成比用户拥有更多权限的 delegation SAS,但如果该 principal 没有这些权限,SAS 将无法工作(no privesc)。 -- **Service SAS**: 使用存储帐户的某个 **access keys** 签名。可用于授予对单一存储服务中特定资源的访问。如果密钥被更新,SAS 将停止工作。 -- **Account SAS**: 同样使用存储帐户的某个 **access keys** 签名。它授予跨存储帐户服务(Blob、Queue、Table、File)的资源访问权限,并可以包含服务级别的操作。 +- **用户委派 SAS**: 由 **Entra ID 主体** 创建,主体会对 SAS 签名并将用户的权限委派给该 SAS。它只能用于 **blob and data lake storage** ([docs](https://learn.microsoft.com/en-us/rest/api/storageservices/create-user-delegation-sas))。可以 **撤销** 所有已生成的用户委派 SAS。 +- 即使可以生成权限“多于”用户实际拥有权限的委派 SAS,但如果该主体并不具备那些权限,SAS 将无法生效(no privesc)。 +- **服务 SAS**: 使用存储账户的某个 **访问密钥** 进行签名。可用于授予单个存储服务中特定资源的访问权限。如果该密钥被更新,SAS 将停止工作。 +- **账户 SAS**: 同样由存储账户的某个 **访问密钥** 签名。它授予跨存储账户服务(Blob、Queue、Table、File)的资源访问权限,并可包含服务级别操作。 -由 **access key** 签名的 SAS URL 如下: +由 **访问密钥** 签名的 SAS URL 如下所示: - `https://.blob.core.windows.net/newcontainer?sp=r&st=2021-09-26T18:15:21Z&se=2021-10-27T02:14:21Z&spr=https&sv=2021-07-08&sr=c&sig=7S%2BZySOgy4aA3Dk0V1cJyTSIf1cW%2Fu3WFkhHV32%2B4PE%3D` -作为 **user delegation** 签名的 SAS URL 如下: +以 **用户委派** 签名的 SAS URL 如下: - `https://.blob.core.windows.net/testing-container?sp=r&st=2024-11-22T15:07:40Z&se=2024-11-22T23:07:40Z&skoid=d77c71a1-96e7-483d-bd51-bd753aa66e62&sktid=fdd066e1-ee37-49bc-b08f-d0e152119b04&skt=2024-11-22T15:07:40Z&ske=2024-11-22T23:07:40Z&sks=b&skv=2022-11-02&spr=https&sv=2022-11-02&sr=c&sig=7s5dJyeE6klUNRulUj9TNL0tMj2K7mtxyRc97xbYDqs%3D` -注意一些 **http params**: +注意一些 **HTTP 参数**: -- The **`se`** param indicates the **expiration date** of the SAS -- The **`sp`** param indicates the **permissions** of the SAS -- The **`sig`** is the **signature** validating the SAS +- **`se`** 参数表示 SAS 的 **到期日期** +- **`sp`** 参数表示 SAS 的 **权限** +- **`sig`** 是用于验证 SAS 的 **签名** #### SAS 权限 -生成 SAS 时需要指定应授予的权限。根据 SAS 所针对的对象,可能包含不同的权限。例如: +生成 SAS 时需要指明它应授予的权限。根据所针对的对象不同,可能包含不同的权限。例如: - (a)dd, (c)reate, (d)elete, (e)xecute, (f)ilter_by_tags, (i)set_immutability_policy, (l)ist, (m)ove, (r)ead, (t)ag, (w)rite, (x)delete_previous_version, (y)permanent_delete -## SFTP Support for Azure Blob Storage +## SFTP 对 Azure Blob Storage 的支持 -Azure Blob Storage 现在支持 SSH File Transfer Protocol (SFTP),允许直接对 Blob Storage 进行安全的文件传输和管理,而无需自定义解决方案或第三方产品。 +Azure Blob Storage 现在支持 SSH 文件传输协议 (SFTP),使得可以直接对 Blob Storage 进行安全的文件传输和管理,而无需自定义解决方案或第三方产品。 -### Key Features +### 主要特性 -- Protocol Support: SFTP 可用于已启用 hierarchical namespace (HNS) 的 Blob Storage 帐户。该功能将 blobs 组织为目录和子目录,便于浏览。 -- Security: SFTP 使用本地用户身份进行认证,不与 RBAC 或 ABAC 集成。每个本地用户可以通过以下方式进行认证: -- Azure-generated passwords -- 公私 SSH 密钥对 -- Granular Permissions: 诸如 Read、Write、Delete 和 List 的权限可以分配给本地用户,最多适用于 100 个容器。 -- Networking Considerations: SFTP 连接通过端口 22 建立。Azure 支持防火墙、private endpoints 或虚拟网络等网络配置以保护 SFTP 流量。 +- 协议支持:SFTP 可用于启用了 分层命名空间 (HNS) 的 Blob Storage 账户。这样可以将 blobs 组织为目录和子目录,便于导航。 +- 安全:SFTP 使用本地用户身份进行认证,不与 RBAC 或 ABAC 集成。每个本地用户可以通过以下方式进行认证: + - Azure 生成的密码 + - 公/私 SSH 密钥对 +- 细粒度权限:可以为本地用户在最多 100 个容器上分配如读取、写入、删除和列出等权限。 +- 网络考虑:SFTP 通过端口 22 建立连接。Azure 支持防火墙、private endpoints 或虚拟网络等网络配置,以保护 SFTP 流量。 -### Setup Requirements +### 设置要求 -- Hierarchical Namespace: 在创建存储帐户时必须启用 HNS。 -- Supported Encryption: 需要 Microsoft Security Development Lifecycle (SDL) 批准的加密算法(例如 rsa-sha2-256、ecdsa-sha2-nistp256)。 -- SFTP Configuration: -- 在存储帐户上启用 SFTP。 -- 为本地用户创建具有适当权限的身份。 -- 为用户配置 home 目录,以定义他们在容器内的起始位置。 +- 分层命名空间:在创建存储账户时必须启用 HNS。 +- 支持的加密:需要 Microsoft Security Development Lifecycle (SDL) 批准的加密算法(例如 rsa-sha2-256、ecdsa-sha2-nistp256)。 +- SFTP 配置: + - 在存储账户上启用 SFTP。 + - 创建具有适当权限的本地用户身份。 + - 为用户配置主目录,以定义他们在容器内的起始位置。 -### Permissions +### 权限 -| 权限 | 符号 | 描述 | -| ---------------------- | ------ | -------------------------------------- | -| **Read** | `r` | 读取文件内容。 | -| **Write** | `w` | 上传文件并创建目录。 | -| **List** | `l` | 列出目录内容。 | -| **Delete** | `d` | 删除文件或目录。 | -| **Create** | `c` | 创建文件或目录。 | -| **Modify Ownership** | `o` | 更改所属用户或组。 | -| **Modify Permissions** | `p` | 更改文件或目录上的 ACL。 | +| 权限 | 符号 | 说明 | +| ---------------------- | ------ | ------------------------------------ | +| **读取** | `r` | 读取文件内容。 | +| **写入** | `w` | 上传文件并创建目录。 | +| **列出** | `l` | 列出目录内容。 | +| **删除** | `d` | 删除文件或目录。 | +| **创建** | `c` | 创建文件或目录。 | +| **修改所有权** | `o` | 更改所属用户或组。 | +| **修改权限** | `p` | 更改文件或目录的 ACL。 | -## Enumeration +## 枚举 {{#tabs }} {{#tab name="az cli" }}
-az cli enumeration +az cli 枚举 ```bash # Get storage accounts az storage account list #Get the account name from here @@ -426,19 +441,19 @@ New-AzStorageBlobSASToken ` az-file-shares.md {{#endref}} -## Privilege Escalation +## 权限提升 {{#ref}} ../az-privilege-escalation/az-storage-privesc.md {{#endref}} -## Post Exploitation +## 利用后活动 {{#ref}} ../az-post-exploitation/az-blob-storage-post-exploitation.md {{#endref}} -## Persistence +## 持久化 {{#ref}} ../az-persistence/az-storage-persistence.md @@ -449,6 +464,7 @@ az-file-shares.md - [https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction) - [https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview](https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview) - [https://learn.microsoft.com/en-us/azure/storage/blobs/secure-file-transfer-protocol-support](https://learn.microsoft.com/en-us/azure/storage/blobs/secure-file-transfer-protocol-support) +- [Holiday Hack Challenge 2025 – Spare Key (Azure static website SAS leak)](https://0xdf.gitlab.io/holidayhack2025/act1/spare-key) - [Holiday Hack Challenge 2025: Blob Storage (Storage Secrets)](https://0xdf.gitlab.io/holidayhack2025/act1/blob-storage) - [https://learn.microsoft.com/en-us/cli/azure/storage/account](https://learn.microsoft.com/en-us/cli/azure/storage/account) - [https://learn.microsoft.com/en-us/cli/azure/storage/container](https://learn.microsoft.com/en-us/cli/azure/storage/container)