mcpField
D
detecting-s3-data-exfiltration-attempts

detecting-s3-data-exfiltration-attempts

github.com/mukul975安全35.2k79 次安装8 周前更新
代码仓库

关于 detecting-s3-data-exfiltration-attempts

用于安全团队调查 S3 数据外泄迹象的技能,涵盖日志分析、威胁发现关联和检测规则构建。它侧重识别与调查,不用于阻止外泄或数据分类。

主要功能

  1. 01分析 CloudTrail S3 访问日志
  2. 02检查 GuardDuty S3 发现
  3. 03关联 Macie 敏感数据发现
  4. 04创建实时检测规则

适用场景

  1. 01调查异常来源的批量下载
  2. 02评估敏感对象访问风险
  3. 03构建 S3 数据丢失检测

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill detecting-s3-data-exfiltration-attempts

安装后在 Claude Code 中输入/detecting-s3-data-exfiltration-attempts确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

检测 S3 数据外泄尝试

何时使用

  • 当 GuardDuty 检测到异常的 S3 访问模式,例如来自异常 IP 的大量下载时
  • 当调查涉及 S3 存储的敏感数据的疑似数据泄露时
  • 当为 S3 数据丢失防护监控构建检测规则时
  • 当响应有关敏感数据被访问或移动的 Macie 告警时
  • 当合规要求对所有机密数据存储的访问进行监控和记录时

请勿使用于防止数据外泄(请使用 S3 存储桶策略、VPC 终端节点和 SCP),用于数据分类(请使用 Amazon Macie 发现任务),或用于网络层面的外泄检测(请使用 VPC Flow Logs 配合网络分析工具)。

先决条件

  • 已配置 CloudTrail 并启用 S3 数据事件日志记录(GetObject、PutObject、CopyObject)
  • 已启用 GuardDuty 并激活 S3 Protection 功能
  • 已启用 Amazon Macie,用于目标存储桶中的敏感数据发现
  • 已配置 CloudWatch Logs 或 Athena,用于大规模查询 CloudTrail 日志
  • 已为 S3 访问监控配置 VPC 终端节点策略

工作流

步骤 1:在 CloudTrail 中启用 S3 数据事件日志记录

配置 CloudTrail 以捕获所有 S3 对象级操作,用于取证分析。

# Enable S3 data events on an existing trail
aws cloudtrail put-event-selectors \
  --trail-name management-trail \
  --event-selectors '[{
    "ReadWriteType": "All",
    "IncludeManagementEvents": true,
    "DataResources": [{
      "Type": "AWS::S3::Object",
      "Values": ["arn:aws:s3:::sensitive-data-bucket/", "arn:aws:s3:::customer-records/"]
    }]
  }]'

# Verify data event configuration
aws cloudtrail get-event-selectors --trail-name management-trail \
  --query 'EventSelectors[*].DataResources' --output json

# Enable GuardDuty S3 Protection
aws guardduty update-detector \
  --detector-id $(aws guardduty list-detectors --query 'DetectorIds[0]' --output text) \
  --data-sources '{"S3Logs":{"Enable":true}}'
步骤 2:在 CloudTrail 中查询异常的 S3 访问模式

分析 CloudTrail 日志中的大量下载活动、异常访问时间和不熟悉的源 IP。

# Athena query: Top S3 downloaders by volume in last 24 hours
cat << 'EOF'
SELECT
  useridentity.arn as principal,
  sourceipaddress,
  COUNT(*) as request_count,
  SUM(CAST(json_extract_scalar(requestparameters, '$.bytesTransferredOut') AS bigint)) as bytes_downloaded
FROM cloudtrail_logs
WHERE eventname = 'GetObject'
  AND eventsource = 's3.amazonaws.com'
  AND eventtime > date_add('hour', -24, now())
GROUP BY useridentity.arn, sourceipaddress
ORDER BY request_count DESC
LIMIT 50
EOF

# CloudWatch Logs Insights: S3 GetObject requests from unusual IPs
aws logs start-query \
  --log-group-name cloudtrail-logs \
  --start-time $(date -d "24 hours ago" +%s) \
  --end-time $(date +%s) \
  --query-string '
    fields @timestamp, userIdentity.arn, sourceIPAddress, requestParameters.bucketName, requestParameters.key
    | filter eventName = "GetObject"
    | stats count() as requestCount by sourceIPAddress, userIdentity.arn
    | sort requestCount desc
    | limit 25
  '

# Detect cross-account copies (potential exfiltration)
aws logs start-query \
  --log-group-name cloudtrail-logs \
  --start-time $(date -d "7 days ago" +%s) \
  --end-time $(date +%s) \
  --query-string '
    fields @timestamp, userIdentity.arn, sourceIPAddress, requestParameters.bucketName
    | filter eventName in ["CopyObject", "ReplicateObject", "UploadPart"]
    | filter userIdentity.accountId != "OUR_ACCOUNT_ID"
    | sort @timestamp desc
    | limit 100
  '
步骤 3:查看 GuardDuty S3 发现结果

检查是否存在表明外泄活动的 GuardDuty S3 特定发现类型。

# List active S3 exfiltration-related findings
aws guardduty list-findings \
  --detector-id $(aws guardduty list-detectors --query 'DetectorIds[0]' --output text) \
  --finding-criteria '{
    "Criterion": {
      "type": {
        "Eq": [
          "Exfiltration:S3/MaliciousIPCaller",
          "Exfiltration:S3/ObjectRead.Unusual",
          "Discovery:S3/MaliciousIPCaller.Custom",
          "Discovery:S3/BucketEnumeration.Unusual",
          "UnauthorizedAccess:S3/MaliciousIPCaller.Custom",
          "UnauthorizedAccess:S3/TorIPCaller",
          "Impact:S3/AnomalousBehavior.Delete"
        ]
      }
    }
  }' --output json

# Get detailed finding information
aws guardduty get-findings \
  --detector-id $(aws guardduty list-detectors --query 'DetectorIds[0]' --output text) \
  --finding-ids FINDING_IDS \
  --query 'Findings[*].{Type:Type,Severity:Severity,Resource:Resource.S3BucketDetails[0].Name,Action:Service.Action}' \
  --output table
步骤 4:分析 Macie 发现结果中的敏感数据访问

查看 Macie 发现结果,将数据敏感性与访问异常关联起来。

# List Macie findings for sensitive data exposure
aws macie2 list-findings \
  --finding-criteria '{
    "criterion": {
      "category": {"eq": ["CLASSIFICATION"]},
      "severity.description": {"eq": ["High", "Critical"]}
    }
  }' \
  --sort-criteria '{"attributeName": "updatedAt", "orderBy": "DESC"}' \
  --max-results 25

# Get detailed finding with data classification
aws macie2 get-findings \
  --finding-ids FINDING_IDS \
  --query 'findings[*].{Type:type,Severity:severity.description,Bucket:resourcesAffected.s3Bucket.name,SensitiveDataTypes:classificationDetails.result.sensitiveData[*].category}' \
  --output table

# Run a sensitive data discovery job on target bucket
aws macie2 create-classification-job \
  --job-type ONE_TIME \
  --name "exfiltration-investigation" \
  --s3-job-definition '{
    "bucketDefinitions": [{
      "accountId": "ACCOUNT_ID",
      "buckets": ["sensitive-data-bucket"]
    }]
  }'
步骤 5:构建自动化检测规则

创建 CloudWatch 告警和 EventBridge 规则,用于实时外泄检测。

# CloudWatch metric filter for high-volume S3 downloads
aws logs put-metric-filter \
  --log-group-name cloudtrail-logs \
  --filter-name s3-bulk-download \
  --filter-pattern '{$.eventName = "GetObject" && $.eventSource = "s3.amazonaws.com"}' \
  --metric-transformations '[{
    "metricName": "S3GetObjectCount",
    "metricNamespace": "SecurityMetrics",
    "metricValue": "1",
    "defaultValue": 0
  }]'

# Alarm for anomalous download volume (>1000 objects/hour)
aws cloudwatch put-metric-alarm \
  --alarm-name s3-exfiltration-alert \
  --metric-name S3GetObjectCount \
  --namespace SecurityMetrics \
  --statistic Sum \
  --period 3600 \
  --threshold 1000 \
  --comparison-operator GreaterThanThreshold \
  --evaluation-periods 1 \
  --alarm-actions arn:aws:sns:us-east-1:ACCOUNT:security-alerts

# EventBridge rule for GuardDuty S3 findings
aws events put-rule \
  --name guardduty-s3-exfiltration \
  --event-pattern '{
    "source": ["aws.guardduty"],
    "detail-type": ["GuardDuty Finding"],
    "detail": {
      "type": [{"prefix": "Exfiltration:S3/"}]
    }
  }'
步骤 6:实施预防性控制措施

部署存储桶策略和 VPC 终端节点策略,以限制数据移动路径。

# VPC endpoint policy restricting S3 access to specific buckets
aws ec2 modify-vpc-endpoint \
  --vpc-endpoint-id vpce-ENDPOINT_ID \
  --policy-document '{
    "Statement": [{
      "Sid": "RestrictToOwnBuckets",
      "Effect": "Allow",
      "Principal": "*",
      "Action": ["s3:GetObject", "s3:PutObject"],
      "Resource": ["arn:aws:s3:::approved-bucket-1/*", "arn:aws:s3:::approved-bucket-2/*"]
    }]
  }'

# Bucket policy denying access from outside the VPC
aws s3api put-bucket-policy --bucket sensitive-data-bucket --policy '{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "DenyNonVpcAccess",
    "Effect": "Deny",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::sensitive-data-bucket/*",
    "Condition": {
      "StringNotEquals": {
        "aws:sourceVpce": "vpce-ENDPOINT_ID"
      }
    }
  }]
}'

关键概念

术语定义
S3 数据事件CloudTrail 对象级日志记录,捕获 GetObject、PutObject、DeleteObject 和 CopyObject API 调用及其请求详细信息
GuardDuty S3 Protection威胁检测功能,分析 CloudTrail S3 数据事件以识别异常访问模式和外泄尝试
Amazon Macie数据安全服务,发现并分类 S3 中的敏感数据,并针对数据暴露风险生成发现结果
VPC 终端节点策略S3 VPC 终端节点上的访问控制策略,限制可通过该终端节点访问的存储桶和操作
数据外泄将数据从组织的 S3 存储未经授权地传输到由攻击者控制的外部位置
异常行为检测基于机器学习的识别,用于发现某主体偏离既定基线的 S3 访问模式

工具与系统

  • AWS CloudTrail:对 S3 对象级操作进行审计日志记录,用于取证分析和异常检测
  • Amazon GuardDuty:基于机器学习的威胁检测,具有针对外泄和未授权访问的 S3 特定发现类型
  • Amazon Macie:敏感数据发现与分类,用于将访问异常与数据敏感性关联起来
  • Amazon Athena:SQL 查询引擎,用于大规模分析 CloudTrail 日志以识别大量下载模式
  • CloudWatch Logs Insights:实时日志分析,用于针对 CloudTrail 数据构建检测查询

常见场景

场景:被攻陷的 IAM 凭证被用于批量下载 S3 数据

背景:GuardDuty 报告了一个 Exfiltration:S3/ObjectRead.Unusual 发现项,表明某开发者的访问密钥在凌晨 3 点从境外 IP 地址下载了敏感数据桶中的数千个对象。

处置方法:

  1. 立即停用被攻陷的访问密钥
  2. 在 CloudTrail 中查询过去 72 小时内该被攻陷主体执行的所有 S3 操作
  3. 使用 Athena 查询确定访问了哪些桶和对象
  4. 将访问过的对象与 Macie 分类进行交叉比对,评估数据敏感度
  5. 检查是否存在向外部账户发起的 CopyObject 调用(跨账户数据外泄)
  6. 审查凭证是如何被攻陷的(TruffleHog 扫描、钓鱼调查)
  7. 实施 VPC 端点策略,将未来的 S3 访问限制在已批准的网络路径内

注意事项:CloudTrail 的 S3 数据事件可能产生海量日志。对于超过 24 小时的查询,应使用带分区表的 Athena,而非 CloudWatch Logs Insights。GuardDuty 的基线学习需要 7-14 天,因此新账户可能会对正常访问模式产生误报。

输出格式

S3 Data Exfiltration Investigation Report
============================================
Account: 123456789012
Detection Source: GuardDuty Exfiltration:S3/ObjectRead.Unusual
Investigation Date: 2026-02-23

INCIDENT TIMELINE:
  2026-02-23 02:47 UTC - First anomalous GetObject from 185.x.x.x
  2026-02-23 02:47-04:12 UTC - 12,847 GetObject requests
  2026-02-23 04:15 UTC - GuardDuty finding generated
  2026-02-23 04:20 UTC - PagerDuty alert received by SOC
  2026-02-23 04:25 UTC - Access key deactivated

COMPROMISED PRINCIPAL:
  ARN: arn:aws:iam::123456789012:user/developer-jane
  Access Key: AKIA...WXYZ
  Source IP: 185.x.x.x (Tor exit node)

DATA IMPACT ASSESSMENT:
  Buckets accessed: 3
  Objects downloaded: 12,847
  Total data volume: 4.7 GB
  Sensitive data types: PII (SSN, email), Financial (credit card)
  Macie severity: CRITICAL

CONTAINMENT ACTIONS:
  [x] Access key deactivated
  [x] User password reset and MFA re-enrolled
  [x] VPC endpoint policy applied to sensitive buckets
  [x] Bucket policy restricting to VPC-only access
  [x] TruffleHog scan initiated on developer repositories

评论

支持 Markdown