Anthropic-Cybersecurity-Skills 实战:使用 azure-mgmt-storage 检测 Azure 存储账户错误配置并生成风险评分报告

发布时间:2026/9/12 9:08:34
Anthropic-Cybersecurity-Skills 实战:使用 azure-mgmt-storage 检测 Azure 存储账户错误配置并生成风险评分报告
Anthropic-Cybersecurity-Skills 实战使用 azure-mgmt-storage 检测 Azure 存储账户错误配置并生成风险评分报告【免费下载链接】Anthropic-Cybersecurity-Skills817 structured cybersecurity skills for AI agents · Mapped to 6 frameworks: MITRE ATTCK, NIST CSF 2.0, MITRE ATLAS, D3FEND, NIST AI RMF MITRE F3 (Fight Fraud) · agentskills.io standard · Works with Claude Code, GitHub Copilot, Codex CLI, Cursor, Gemini CLI 20 platforms · 29 security domains · Apache 2.0项目地址: https://gitcode.com/GitHub_Trending/an/Anthropic-Cybersecurity-SkillsAzure 存储账户因其错误配置如公共 Blob 访问、长期有效的 SAS 令牌、缺失静态加密、未启用 HTTPS-only 流量、TLS 版本过旧而成为攻击者的高频目标。本文基于 Anthropic-Cybersecurity-Skills 仓库中的detecting-azure-storage-account-misconfigurations技能系统讲解如何使用azure-mgmt-storagePython SDK 枚举订阅内的全部存储账户、审计其安全属性、检查 Blob 容器的公共访问级别并输出符合 CIS Azure Benchmark 的按严重级别评分的审计报告。读完本文你将掌握一套可直接运行的存储账户安全态势评估方案可用于云安全基线检查与疑似数据泄露调查。技能概览与适用场景该技能由三部分构成技能描述文档 SKILL.md、Python 审计脚本 scripts/agent.py 以及本文所依托的 API 参考文档 references/api-reference.md。根据 SKILL.md 的定义该技能version 1.0Apache-2.0 许可适用于以下场景调查安全事件时需要检测 Azure 存储账户错误配置为这一领域构建检测规则或威胁狩猎查询SOC 分析师需要结构化的分析流程验证相关攻击技术如 T1530 从云存储账户收集数据、T1580 云基础设施发现的安全监控覆盖。技能聚焦六类关键检测领域公共 Blob 访问— 存储账户层面allow_blob_public_access被启用或单个容器被设置为 Blob/Container 访问级别HTTPS 强制—enable_https_traffic_only被禁用允许明文 HTTP 流量最低 TLS 版本— 账户仍接受 TLS 1.0 / TLS 1.1 而非 TLS 1.2静态加密— 存储服务加密未启用或缺少客户管理密钥网络规则— 默认操作default action为 Allow 而非 Deny导致存储对所有网络开放SAS 令牌风险— 账户级 SAS 权限过宽或生命周期过长。技能输出为 JSON 格式报告按账户列出发现项、严重级别Critical / High / Medium / Low以及对齐 CIS Azure Benchmark 的修复建议。环境准备与 SDK 安装安装依赖依据 api-reference.md 的 SDK 安装章节运行pip install azure-mgmt-storage azure-identity前置要求来自 SKILL.mdPython 3.9安装azure-mgmt-storage、azure-identity目标订阅上具有Reader角色的 Azure 服务主体Service Principal配置四个环境变量。配置环境变量审计脚本通过DefaultAzureCredential完成认证因此必须先在环境中注入身份信息。参考 api-reference.md 的环境变量表变量说明AZURE_SUBSCRIPTION_ID目标 Azure 订阅 IDAZURE_CLIENT_ID服务主体的应用程序客户端IDAZURE_TENANT_IDAzure AD / Entra ID 租户 IDAZURE_CLIENT_SECRET服务主体客户端密钥以 bash 为例export AZURE_SUBSCRIPTION_IDsubscription-id export AZURE_CLIENT_IDclient-id export AZURE_TENANT_IDtenant-id export AZURE_CLIENT_SECRETclient-secret在 scripts/agent.py 中脚本会首先校验AZURE_SUBSCRIPTION_ID是否已设置缺失时直接报错退出subscription_id os.environ.get(AZURE_SUBSCRIPTION_ID) if not subscription_id: print(Set AZURE_SUBSCRIPTION_ID environment variable, filesys.stderr) sys.exit(1)初始化 StorageManagementClientazure-mgmt-storage的核心入口是StorageManagementClient配合DefaultAzureCredential使用即可实现从环境变量、托管身份到 Azure CLI 登录态等多种身份来源的自动切换from azure.identity import DefaultAzureCredential from azure.mgmt.storage import StorageManagementClient client StorageManagementClient( credentialDefaultAzureCredential(), subscription_idsubscription-id )核心操作枚举、取属性、列容器参考 api-reference.md 的 Key Operations 章节审计过程依赖三个关键 API 调用。列出订阅内全部存储账户for account in client.storage_accounts.list(): print(account.name, account.location, account.kind)该调用返回订阅级所有存储账户的轻量元数据名称、区域、账户类型 kind。在 scripts/agent.py 中run_audit将其转为列表并计入总数accounts list(client.storage_accounts.list()) results[summary][total_accounts] len(accounts)获取单个存储账户属性当需要针对特定账户深入检查时account client.storage_accounts.get_properties( resource_group_namemyResourceGroup, account_namemystorageaccount )注意get_properties的返回对象包含完整的安全属性集allow_blob_public_access、enable_https_traffic_only、minimum_tls_version、encryption、network_rule_set等是审计判断的核心数据源。列出 Blob 容器及公共访问级别containers client.blob_containers.list( resource_group_namemyResourceGroup, account_namemystorageaccount ) for container in containers: print(container.name, container.public_access)public_access字段直接反映容器级暴露面。在 scripts/agent.py 中容器级检查仅在--check-containers开关开启时执行任何非None的访问级别都会触发 Critical 级别告警containers client.blob_containers.list( resource_group_nameresource_group, account_nameaccount.name ) for container in containers: public_access getattr(container, public_access, None) if public_access and public_access ! None: container_findings.append({ container_name: container.name, public_access_level: str(public_access), severity: Critical, message: fContainer {container.name} has public access level: {public_access}, remediation: Set container public access level to None (private) })安全属性审计清单逐项解析api-reference.md 提供了核心的Security Properties to Audit表格这是整个审计逻辑的骨架属性安全值错误配置风险allow_blob_public_accessFalse严重 — 数据暴露到互联网enable_https_traffic_onlyTrue高 — 凭据以明文传输minimum_tls_versionTLS1_2高 — 易受降级攻击encryption.services.blob.enabledTrue高 — 静态数据未加密encryption.key_sourceMicrosoft.Keyvault低 — 微软管理密钥控制力较弱network_rule_set.default_actionDeny高 — 存储对所有网络开放encryption.require_infrastructure_encryptionTrue低 — 缺少双重加密源码中的逐项检查实现scripts/agent.py 的audit_storage_account函数将上述每项属性翻译为具体的检查分支与审计表一一对应。1. 公共 Blob 访问Criticalif account.allow_blob_public_access is True: findings.append({ check: public_blob_access, severity: Critical, message: fStorage account {account_name} allows public blob access, remediation: Set allow_blob_public_access to false on the storage account })2. HTTPS-only 流量强制High— 对应 CIS 3.1 Secure transfer requiredif account.enable_https_traffic_only is False: findings.append({ check: https_enforcement, severity: High, message: fStorage account {account_name} allows HTTP traffic, remediation: Enable Secure transfer required in storage account settings })3. 最低 TLS 版本High— 允许 TLS 1.0/1.1 的账户直接判为 High并要求提升到 TLS1_2min_tls getattr(account, minimum_tls_version, None) if min_tls and min_tls in (TLS1_0, TLS1_1): findings.append({ check: minimum_tls_version, severity: High, message: fStorage account {account_name} allows {min_tls} (should be TLS1_2), remediation: Set minimum TLS version to TLS1_2 })4. 静态加密Blob 为 HighFile 为 Medium缺失配置为 Criticalencryption account.encryption if encryption: if not getattr(encryption.services, blob, None) or not encryption.services.blob.enabled: findings.append({check: blob_encryption, severity: High, ...}) if not getattr(encryption.services, file, None) or not encryption.services.file.enabled: findings.append({check: file_encryption, severity: Medium, ...}) else: findings.append({check: encryption_missing, severity: Critical, ...})从实现可见一个细节加密对象整体缺失encryption is None被判定为Critical而仅仅 Blob 服务未加密为 High、File 服务未加密为 Medium说明脚本对完全无加密配置给予了最严厉的评分。5. 网络默认规则High— 对应 CIS 3.7 Ensure default network access rule is set to denynetwork_rules account.network_rule_set if network_rules and network_rules.default_action Allow: findings.append({ check: network_default_allow, severity: High, message: fStorage account {account_name} allows access from all networks, remediation: Set network default action to Deny and add specific virtual network/IP rules })6. 基础设施加密 / 双重加密Lowif encryption and not getattr(encryption, require_infrastructure_encryption, False): findings.append({ check: infrastructure_encryption, severity: Low, message: fStorage account {account_name} does not use infrastructure encryption (double encryption), ... })7. 密钥来源Low— 仅当密钥来源为Microsoft.Storage微软托管密钥时提示建议改用 Azure Key Vault 客户管理密钥if encryption and getattr(encryption, key_source, None) Microsoft.Storage: findings.append({ check: customer_managed_keys, severity: Low, message: fStorage account {account_name} uses Microsoft-managed keys instead of customer-managed keys, remediation: Configure customer-managed keys via Azure Key Vault for enhanced control })此外audit_storage_account还会在结果中附带账户的资源组、区域、SKU 与 kind便于报告定位return { account_name: account_name, resource_group: resource_group, location: account.location, sku: account.sku.name if account.sku else unknown, kind: account.kind, findings: findings, finding_count: len(findings) }其中资源组通过解析账户 ID 字符串获得account.id.split(/)[4]这保证了后续容器枚举无需额外查询即可复用。容器公共访问级别三种状态api-reference.md 将容器公共访问级别归纳为三个档位级别描述风险None私有无公共访问安全Blob仅 Blob 可匿名读取高Container容器及其内 Blob 均可匿名读取严重对应到审计实现scripts/agent.py任何不等于None的public_access都会被标记为 Critical。audit_blob_containers对容器枚举做了异常兜底——若因权限不足等原因无法列出容器会将错误信息写入该账户的container_findings而不是让整个审计中断except Exception as e: container_findings.append({ error: fCould not list containers for {account.name}: {str(e)} })运行审计脚本与风险评分报告命令行用法scripts/agent.py 的main提供三个参数# 基础审计只检查账户级属性 python scripts/agent.py # 同时检查每个容器的公共访问级别 python scripts/agent.py --check-containers # 输出到文件 python scripts/agent.py --output audit_report.json # 只保留某级别及以上的发现项如只保留 High 及以上 python scripts/agent.py --severity-filter high参数说明参数作用默认值--check-containers额外检查单个 Blob 容器的公共访问设置不启用--output/-o报告输出路径-标准输出--severity-filter仅显示达到该严重级别critical/high/medium/low及以上的发现项不启用严重级别过滤采用权重映射实现scripts/agent.py{critical: 4, high: 3, medium: 2, low: 1}低于阈值的 finding 从结果中剔除并重算finding_count。报告结构run_auditscripts/agent.py生成 JSON 报告顶层包含scan_time扫描时间UTC ISO 8601subscription_id被扫描的订阅 IDaccounts每个账户的完整审计结果summary汇总统计包括total_accounts、accounts_with_findings以及按critical/high/medium/low计数的发现项总数。{ scan_time: 2026-09-11T15:00:00.000000Z, subscription_id: ..., accounts: [ { account_name: mystorageaccount, resource_group: myResourceGroup, location: eastus, sku: Standard_LRS, kind: StorageV2, findings: [ { check: public_blob_access, severity: Critical, message: ..., remediation: Set allow_blob_public_access to false on the storage account } ], finding_count: 1 } ], summary: { total_accounts: 1, accounts_with_findings: 1, critical: 1, high: 0, medium: 0, low: 0 } }每条 finding 均携带check检查项标识、severity严重级别、message发现描述与remediation修复建议可直接导入 SOC 工作流或票务系统。Azure CLI 等价操作若不便运行 Python 脚本api-reference.md 提供了完整的 Azure CLI 等价命令适合快速抽查与人工验证# 列出存储账户含关键安全属性 az storage account list --query [].{name:name, publicAccess:allowBlobPublicAccess, httpsOnly:enableHttpsTrafficOnly, minTls:minimumTlsVersion} -o table # 查看特定账户详情 az storage account show -n mystorageaccount -g myResourceGroup # 列出容器及其访问级别 az storage container list --account-name mystorageaccount --query [].{name:name, publicAccess:properties.publicAccess} -o table # 禁用公共 Blob 访问 az storage account update -n mystorageaccount -g myResourceGroup --allow-blob-public-access false # 设置最低 TLS 版本 az storage account update -n mystorageaccount -g myResourceGroup --min-tls-version TLS1_2SDK 路径与 CLI 路径是一一对应的az storage account list对应client.storage_accounts.list()az storage account update --allow-blob-public-access false对应审计发现后建议的修复动作。这意味着既可以用 CLI 快速复核脚本结论也可以在发现 Critical 问题时立即用 CLI 完成修复。对齐 CIS Azure Benchmark 控制项api-reference.md 明确列出了审计项与 CIS Azure Benchmark 的映射关系控制项描述对应检查3.1确保启用 Secure transfer requiredenable_https_traffic_only3.7确保默认网络访问规则设为拒绝network_rule_set.default_action Deny3.8确保启用 Trusted Microsoft Services网络规则白名单配置3.10确保为 Blob 服务启用存储日志诊断设置检查3.12确保定期轮换存储账户访问密钥密钥生命周期检查其中 3.1 与 3.7 已在audit_storage_account中落地为可执行检查3.8、3.10、3.12 作为报告对齐的合规参考项可用于将脚本输出与组织合规基线对接作为审计发现项的补充背景。威胁框架映射从检测到防御闭环该技能在仓库的统一框架映射体系中占据明确位置可作为威胁知情防御Threat-Informed Defense的一部分。MITRE ATTCK技能 YAML 头SKILL.md声明了T1530Data from Cloud Storage Object、T1078.004Valid Accounts: Cloud Accounts、T1619Cloud Storage Object Discovery与T1580Cloud Infrastructure Discovery。其中 T1580 在 mappings/mitre-attack/coverage-summary.md 中被归类到 cloud-security 资产发现技能组完整的技能矩阵可参考 mappings/mitre-attack/README.md 与 mappings/attack-navigator-layer.jsonATTCK Navigator layer 文件可直接导入 MITRE ATTCK Navigator 可视化覆盖情况。NIST CSF 2.0技能映射了PR.IR-01技术基础设施弹性、ID.AM-08资产管理、GV.SC-06供应链风险、DE.CM-01持续监控。这与 mappings/nist-csf/csf-alignment.md 中 cloud-security 领域 Identify (ID) / Protect (PR) 功能定位一致——存储账户配置审计既是资产管理ID.AM也是持续监控DE.CM的落地动作。MITRE ATLAS / NIST AI RMF技能同时标注了AML.T0070、AML.T0066、AML.T0082及MEASURE-2.7、MAP-5.1、MANAGE-2.4说明该审计能力也可用于 AI 工作负载所依赖的云存储基础设施的风险度量与治理。将检测技能与 ATTCK 技术 ID 关联后红蓝队可以针对同一技术如 T1530 从云存储收集数据分别执行攻击模拟与检测验证这正是仓库 mappings/mitre-attack/README.md 所倡导的 purple team 工作方式。局限性与使用前提基于仓库实际内容使用本方案时需注意需要读权限服务主体需对目标订阅具备 Reader 及以上角色容器级检查--check-containers还需要对存储账户的读取权限否则容器枚举会进入异常分支并记录错误SAS 令牌检查不在脚本内SKILL.md 将 SAS 令牌列为关键检测领域之一但当前 scripts/agent.py 的检查逻辑聚焦账户与容器属性SAS 生命周期与权限审计需要结合门户诊断或额外的数据平面查询完成只读审计本文与脚本仅做检测与报告生成不执行任何修复修复动作如禁用公共访问、提升 TLS 版本应通过 Azure CLI 或门户在变更流程中单独执行。这套方案完全基于仓库内提供的脚本与文档可作为 Agent 直接可复用的云安全技能包克隆仓库后配置好服务主体环境变量即可在数秒内输出一份订阅级、可追溯、可直接分诊的 Azure 存储安全态势报告。【免费下载链接】Anthropic-Cybersecurity-Skills817 structured cybersecurity skills for AI agents · Mapped to 6 frameworks: MITRE ATTCK, NIST CSF 2.0, MITRE ATLAS, D3FEND, NIST AI RMF MITRE F3 (Fight Fraud) · agentskills.io standard · Works with Claude Code, GitHub Copilot, Codex CLI, Cursor, Gemini CLI 20 platforms · 29 security domains · Apache 2.0项目地址: https://gitcode.com/GitHub_Trending/an/Anthropic-Cybersecurity-Skills创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考