0Pricing
Cloud & IT Cert Prep · 课时

GuardDuty、Inspector 与 Macie

启用 GuardDuty 进行威胁检测,运行 Inspector 扫描 EC2 和 Lambda 中的漏洞,并使用 Macie 发现 S3 中的敏感数据

GuardDuty、Inspector 与 Macie 是 CoddyKit 上的免费 Cloud & IT Cert Prep 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Cloud & IT Cert Prep 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Cloud & IT Cert Prep 课程共包含 4 节课。

威胁检测层

纵深防御安全不仅要求阻止攻击,还要求检测未被阻止的威胁。AWS 提供了三个相互协作的托管安全检测服务:Amazon GuardDuty 通过分析 AWS 账户行为和网络流量来检测威胁;Amazon Inspector 查找计算资源中的软件漏洞;Amazon Macie 发现 S3 中的敏感数据(PII、财务记录),并在数据暴露时发出提醒。这三个服务都完全托管,使用机器学习,并可与 AWS Security Hub 集成,以实现集中查看。

# Detective controls overview:
# GuardDuty:  Who is behaving suspiciously? (threat detection)
# Inspector:  What vulnerabilities exist in my compute? (CVE scanning)
# Macie:      Where is my sensitive data? (PII/PCI discovery)

# All three:
# - Fully managed (no agents for most features)
# - Machine learning-based analysis
# - Send findings to Security Hub
# - Integrate with EventBridge for automated response

Amazon GuardDuty:智能威胁检测

Amazon GuardDuty 是一项持续威胁检测服务,使用机器学习、异常检测和集成的威胁情报源(IP 信誉列表、已知恶意域名)分析 VPC Flow Logs、DNS logs、CloudTrail management events 和 S3 data events。GuardDuty 无需安装代理,您只需在账户中启用它,它便会立即开始分析现有日志。您无需管理基础设施,也无需承担日志存储费用(GuardDuty 直接从 AWS 使用这些日志)。它会按照威胁类型对发现结果进行分类,例如 UnauthorizedAccess、CryptoCurrency、Backdoor、Trojan 等。

# Enable GuardDuty
aws guardduty create-detector \
  --enable \
  --finding-publishing-frequency FIFTEEN_MINUTES

# List GuardDuty findings
aws guardduty list-findings \
  --detector-id <detector-id> \
  --finding-criteria '{
    "Criterion": {
      "severity": {"Gte": 7}
    }
  }'

# High severity (7-10) examples:
# UnauthorizedAccess:EC2/MaliciousIPCaller.Custom
# CryptoCurrency:EC2/BitcoinTool.B
# Backdoor:EC2/C&CActivity.B

GuardDuty 发现结果类型

GuardDuty 会根据威胁目的、资源类型和威胁名称对发现结果进行分类。常见的发现结果类别包括:UnauthorizedAccess——来自异常位置或 Tor 出口节点的 API 调用;Recon——端口扫描或 API 枚举;PrivilegeEscalation——暗示权限提升的 IAM policy 更改;Exfiltration——从 S3 或 RDS 异常大量检索数据;CryptoCurrency——EC2 实例与已知加密货币挖矿池通信;Stealth——CloudTrail 日志记录被禁用,S3 访问日志记录被禁用。每个发现结果都包含受影响的资源、执行者 IP/用户以及建议的操作。

# Get GuardDuty finding details
aws guardduty get-findings \
  --detector-id <detector-id> \
  --finding-ids finding-id-1 finding-id-2

# Finding structure:
# {
#   'type': 'CryptoCurrency:EC2/BitcoinTool.B!DNS',
#   'severity': 8.0,
#   'title': 'EC2 instance querying domain for cryptocurrency mining',
#   'resource': {'instanceDetails': {'instanceId': 'i-12345'}},
#   'service': {'action': {'networkConnectionAction': {'remoteIpDetails': {...}}}}
# }

GuardDuty 自动响应

GuardDuty 发现结果可与 Amazon EventBridge 集成,从而触发自动响应工作流。一种常见模式是:GuardDuty 检测到 EC2 实例遭到入侵 → EventBridge 规则触发 → Lambda 函数被调用 → Lambda 隔离该实例(将其从 ASG 中移除,并应用阻止所有流量的限制性安全组),为取证保存其 EBS 卷的快照,然后通过 SNS 通知安全团队。这种自动响应可在检测到威胁后的几秒内完成,远快于人工响应。

# EventBridge rule for high-severity GuardDuty findings
aws events put-rule \
  --name guardduty-high-severity \
  --event-pattern '{
    "source": ["aws.guardduty"],
    "detail-type": ["GuardDuty Finding"],
    "detail": {
      "severity": [{"numeric": [">", 6.9]}]
    }
  }'

# Lambda response function actions:
# 1. Stop instance from ASG
# 2. Replace security group with deny-all SG
# 3. Create EBS snapshot for forensics
# 4. Send SNS alert to security team
# 5. Create Jira ticket via API

Amazon Inspector:漏洞评估

Amazon Inspector 会自动发现并扫描您的工作负载,以查找软件漏洞和意外的网络暴露。Inspector v2(现代版本)涵盖EC2 实例(通过 Systems Manager Agent)、Amazon ECR 容器映像(推送时扫描)和 AWS Lambda 函数(扫描软件包依赖项)。它会将发现结果与 CVE 数据库(Common Vulnerabilities and Exposures)关联,并分配风险分数。当发布新的漏洞时,Inspector 会持续重新扫描资源,您无需手动启动扫描。

# Enable Amazon Inspector
aws inspector2 enable \
  --resource-types EC2 ECR LAMBDA

# List Inspector findings for critical vulnerabilities
aws inspector2 list-findings \
  --filter-criteria '{
    "severity": [{"comparison":"EQUALS","value":"CRITICAL"}]
  }' \
  --query 'findings[].{Resource:resources[0].id,CVE:packageVulnerabilityDetails.vulnerabilityId,CVSS:packageVulnerabilityDetails.cvss[0].baseScore}'

# Inspector integrates with ECR lifecycle policies
# to prevent deploying critically vulnerable images

Inspector 网络可达性

除了 CVE 扫描之外,Inspector 还会分析网络可达性,即哪些 EC2 实例由于安全组配置而可从互联网访问。它会映射您的 VPC 安全组、NACL、路由表和互联网网关,以确定互联网可以访问哪些实例上的哪些端口。例如,互联网可以访问 i-12345 上的端口 22(SSH)这一发现结果,表示安全组配置错误,允许直接进行 SSH 访问,这是常见的安全风险。这种网络分析无需安装代理,而是使用 VPC 配置数据运行。

# Inspector network findings example:
# Finding type: NETWORK_REACHABILITY
# Title: Port 22 is reachable from 0.0.0.0/0
# Resource: ec2-instance i-12345 (prod-web-01)
# Details: Security group sg-abc allows 0.0.0.0/0:22
# Recommendation: Restrict SSH to corporate IP range
#   or use Systems Manager Session Manager instead

# Fix: update security group
aws ec2 revoke-security-group-ingress \
  --group-id sg-abc \
  --protocol tcp --port 22 --cidr 0.0.0.0/0

Amazon Macie:敏感数据发现

Amazon Macie 使用机器学习和模式匹配,自动发现并保护 Amazon S3 中的敏感数据。Macie 可识别个人身份信息(PII)(姓名、社会保障号、信用卡号、护照)、财务数据、健康信息以及凭证(密码、API 密钥)。它还会检测公开的 S3 存储桶和未加密的存储桶。Macie 生成的发现结果可与 Security Hub 和 EventBridge 集成,以便在发现或暴露敏感数据时自动修复或发出提醒。

# Enable Macie
aws macie2 enable-macie

# Create a classification job to scan S3 buckets
aws macie2 create-classification-job \
  --name 'Scan-All-S3-Buckets' \
  --job-type ONE_TIME \
  --s3-job-definition '{
    "bucketDefinitions": [{
      "accountId": "123456789012",
      "buckets": ["customer-uploads","financial-reports"]
    }]
  }' \
  --managed-data-identifier-selector ALL

# Macie scans objects and reports:
# - SSN found in financial-reports/2026-q1.csv
# - Bucket customer-uploads is publicly readable

Macie 发现结果与合规性

对于要求定位和保护敏感数据的合规框架,Macie 尤其有价值:GDPR(EU 个人数据)、HIPAA(健康信息)和 PCI DSS(支付卡数据)。Macie 发现结果会显示哪些 S3 对象包含敏感数据、发现的数据类型以及存储桶上的访问控制。您可以利用这些信息验证所有包含敏感数据的存储桶都已加密、保持私有,并受适当的存储桶策略管理。Macie不会修改数据或存储桶访问权限,只负责检测和报告。修复工作由安全团队完成。

# Get Macie findings
aws macie2 list-findings \
  --finding-criteria '{
    "criterion": {
      "category": {"eqExactMatch": ["CLASSIFICATION"]}
    }
  }'

# Findings example output:
# sensitiveDataCategories: [FINANCIAL_INFORMATION, PERSONAL_HEALTH_INFORMATION]
# resourcesAffected:
#   s3Object:
#     bucketName: healthcare-records
#     key: patients/2026/march.csv
#     publicAccess: false  (good)
#     serverSideEncryption: null (BAD - not encrypted!)

AWS Security Hub:集中管理发现结果

AWS Security Hub 会将 GuardDuty、Inspector、Macie、IAM Access Analyzer、Firewall Manager 以及第三方工具的发现结果汇总到一个控制台中。它会将发现结果规范化为 AWS Security Finding Format (ASFF),从而支持跨来源进行一致的处理和分析。Security Hub 还会根据 CIS AWS Foundations、PCI DSS 和 NIST 等安全标准评估您的环境。请将 Security Hub 作为查看安全状况的统一入口,通过关联多个服务的相关发现结果,全面了解事件的范围。

# Enable Security Hub and all integrations
aws securityhub enable-security-hub \
  --enable-default-standards

# GuardDuty, Inspector, Macie automatically
# send findings to Security Hub when all are enabled

# Query aggregated findings
aws securityhub get-findings \
  --filters '{
    "SeverityLabel": [{"Value":"CRITICAL","Comparison":"EQUALS"}],
    "WorkflowStatus": [{"Value":"NEW","Comparison":"EQUALS"}]
  }' \
  --sort-criteria '[{"Field":"LastObservedAt","SortOrder":"desc"}]'

GuardDuty、Inspector 和 Macie 对比

SAA-C03 考试会测试您能否根据具体的安全要求选择正确的检测服务。主要区别如下:GuardDuty——检测运行时威胁和可疑行为(现在是谁在执行恶意操作);Inspector——查找软件和网络配置中已有的漏洞(我的资源有什么问题);Macie——发现 S3 中的敏感数据及其暴露风险(我的敏感数据在哪里,以及是否受到保护)。这三个服务相互补充,通常会在生产环境中一起部署,作为全面安全策略的一部分。

# Service selection guide:
# 'Detect if EC2 is mining cryptocurrency' -> GuardDuty
# 'Find unpatched Apache Log4j vulnerabilities' -> Inspector
# 'Discover PII stored in S3 buckets' -> Macie
# 'Alert if unusual API calls from foreign IP' -> GuardDuty
# 'Find publicly accessible EC2 ports' -> Inspector
# 'Detect unencrypted S3 buckets with credit card data' -> Macie
# 'Correlate findings from all three services' -> Security Hub

使用 AWS Organizations 扩展启用范围

在每个 AWS 账户中手动启用 GuardDuty、Inspector 和 Macie,在大规模环境中并不现实。AWS Organizations 集成允许您指定一个委托管理员账户(通常是 Security 账户),从一个位置为所有成员账户启用和管理这些服务。添加到组织的新账户会自动启用 GuardDuty、Inspector 和 Macie。所有账户的发现结果都会汇总到委托管理员账户中,供集中查看。这是多账户安全治理的推荐架构。

# Enable GuardDuty for entire AWS Organization
# Run from management account
aws guardduty enable-organization-admin-account \
  --admin-account-id 111111111111

# From security/delegated admin account:
aws guardduty update-organization-configuration \
  --detector-id <detector-id> \
  --auto-enable-organization-members NEW

# NEW accounts automatically get GuardDuty enabled
# All findings aggregate in the admin account

快速检查

请测试您对本课 AWS Solutions Architect(SAA-C03)概念的理解。

课程回顾

本课介绍了以下内容:GuardDuty 通过基于机器学习的 CloudTrail、VPC Flow Logs 和 DNS logs 分析来检测运行时威胁;Inspector 会自动扫描 EC2、ECR 和 Lambda,以发现 CVE 漏洞及网络可达性问题;Macie 通过托管数据标识符扫描来发现并保护 S3 中的敏感数据。Security Hub 会集中管理这三个服务的发现结果。接下来我们将学习 Secrets Manager 和 Parameter Store。

常见问题解答

「GuardDuty、Inspector 与 Macie」课时是免费的吗?

是的 — 「GuardDuty、Inspector 与 Macie」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Cloud & IT Cert Prep 课程的其余内容,请升级到 CoddyKit PRO。 Cloud & IT Cert Prep 课程共包含 4 节课。

「GuardDuty、Inspector 与 Macie」这节课中我会学到什么?

启用 GuardDuty 进行威胁检测,运行 Inspector 扫描 EC2 和 Lambda 中的漏洞,并使用 Macie 发现 S3 中的敏感数据 你通过在浏览器中直接运行的动手代码来练习 Cloud & IT Cert Prep,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Cloud & IT Cert Prep 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Cloud & IT Cert Prep 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「GuardDuty、Inspector 与 Macie」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Cloud & IT Cert Prep 课中编写并运行代码吗?

能。每节 Cloud & IT Cert Prep 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. KMS、ACM 与加密模式
  2. GuardDuty、Inspector 与 Macie
  3. Secrets Manager 与 Parameter Store
  4. WAF、Shield 与 Network Firewall
← 返回 Cloud & IT Cert Prep