Az - Blob Storage

Support HackTricks

Basic Information

From the docs: Azure Blob storage 是微软的云对象存储解决方案。Blob 存储针对存储大量非结构化数据进行了优化。非结构化数据是指不遵循特定数据模型或定义的数据,例如文本或二进制数据。

Blob 存储提供三种类型的资源:

  • 存储账户(唯一名称)

  • 存储账户中的容器(文件夹)

  • 容器中的Blob

不同类型的存储

Blob storage

https://<storage-account>.blob.core.windows.net https://<stg-acc>.blob.core.windows.net/<container-name>?restype=container&comp=list

Azure Data Lake Storage Gen2

https://<storage-account>.dfs.core.windows.net

Azure Files

https://<storage-account>.file.core.windows.net

Queue storage

https://<storage-account>.queue.core.windows.net

Table storage

https://<storage-account>.table.core.windows.net

访问存储

  • 使用 Azure AD 主体通过支持的RBAC 角色

  • 访问密钥:使用存储账户的访问密钥。这提供了对存储账户的完全访问

  • 共享访问签名(SAS):时间****有限和特定权限。

  • 您可以使用访问密钥生成 SAS URL(更难检测)。

  • 由于 SAS 是从访问密钥生成的,如果它被更新,SAS 将停止工作。

公开暴露

如果“允许 Blob 公开访问”启用(默认禁用),则可以:

  • 给予读取 Blob 的公共访问权限(您需要知道名称)。

  • 列出容器 Blob读取它们。

连接到存储

如果您找到任何可以连接的存储,可以使用工具 Microsoft Azure Storage Explorer 进行连接。

SAS URLs

From the docs: 共享访问签名(SAS)为存储账户中的资源提供安全的委托访问。使用 SAS,您可以对客户端如何访问您的数据进行细粒度控制。例如:

  • 客户端可以访问哪些资源。

  • 他们对这些资源有什么权限。

  • SAS 有效的时间。

一个 SAS URL 看起来像这样:https://<container_name>.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

使用 Storage Explorer 访问数据或使用 python:

#pip3 install azure-storage-blob
from azure.storage.blob import BlobServiceClient

# List containers
conn_str="<SAS URL>"
svc = BlobServiceClient.from_connection_string(conn_str=conn_str)
for c in svc.list_containers():
print(c['name'])

# List blobs inside the containers
container = svc.get_container_client(container=c['name'])

for b in container.list_blobs():
print(b['name'])


# Download all the blobs
blob_name = b['name'].split("/")[::-1][0]
blob = svc.get_blob_client(container=c['name'],blob=b['name'])
with open(blob_name,"wb") as f:
f.write(blob.download_blob().readall())

User delegation SAS

你可以使用 Azure Active Directory (Azure AD) 凭证或账户密钥保护共享访问签名 (SAS) 令牌,以访问容器、目录或 blob。要创建用户委托 SAS,必须首先请求用户委托密钥,然后使用该密钥签署 SAS。

Azure Blob StorageAzure Data Lake Storage Gen2 中均支持用户委托共享访问签名 (SAS)。然而,重要的是要注意,存储访问策略与用户委托 SAS 不兼容。

请注意,用户委托 SAS 是使用 Azure AD 凭证而不是存储账户密钥来保护的。这防止了客户端/应用程序存储/检索存储密钥以创建 SAS。

Service SAS

服务 SAS 是用存储账户密钥保护的。服务 SAS 仅委托对 Azure 存储服务之一的资源的访问:Blob 存储、队列存储、表存储或 Azure 文件。服务级别 SAS 的 URI 由将委托访问的资源的 URI 以及 SAS 令牌组成。

要使用 Azure Active Directory (Azure AD) 凭证来保护容器blob的 SAS,请使用用户委托 SAS

Account SAS

账户 SAS 是用两个存储账户密钥中的一个保护的。账户 SAS 委托对一个或多个存储服务中的资源的访问。通过服务或用户委托 SAS 可用的所有操作也可以通过账户 SAS 进行。

来自文档: 通过创建账户 SAS,你可以:

  • 委托对当前无法通过特定服务 SAS 进行的服务级操作的访问,例如 Get/Set Service PropertiesGet Service Stats 操作。

  • 同时委托对存储账户中多个服务的访问。例如,你可以使用账户 SAS 委托对 Azure Blob Storage 和 Azure Files 中资源的访问。

  • 委托对容器、队列、表和文件共享的写入和删除操作的访问,这些操作无法通过特定对象 SAS 进行。

  • 指定接受请求的 IP 地址或 IP 地址范围。

  • 指定接受请求的 HTTP 协议(HTTPS 或 HTTP/HTTPS)。

Enumeration

# Get storage accounts
az storage account list #Get the account name from here

# Get keys to authenticate
az storage account keys list --account-name <name>

# Get shares
az storage share list --account-name <name> --account-key <key>

# Get dirs/files inside the share
az storage file list --account-name <name> --share-name <share-name> --account-key <key>
## If type is "dir", you can continue enumerationg files inside of it
az storage file list --account-name <name> --share-name <prev_dir/share-name> --account-key <key>

# Download a complete share (with directories and files inside of them)
az storage file download-batch -d . --source <share-name> --account-name <name> --account-key <key>

参考资料

支持 HackTricks

Last updated