detecting-s3-data-exfiltration-attempts
通过分析 CloudTrail S3 数据事件、VPC Flow Logs、GuardDuty 发现、Amazon Macie 告警和 S3 访问模式,检测 AWS S3 存储桶的数据泄露企图,识别未授权的批量下载和跨账户数据传输。
Best use case
detecting-s3-data-exfiltration-attempts is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
通过分析 CloudTrail S3 数据事件、VPC Flow Logs、GuardDuty 发现、Amazon Macie 告警和 S3 访问模式,检测 AWS S3 存储桶的数据泄露企图,识别未授权的批量下载和跨账户数据传输。
Teams using detecting-s3-data-exfiltration-attempts should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/detecting-s3-data-exfiltration-attempts/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How detecting-s3-data-exfiltration-attempts Compares
| Feature / Agent | detecting-s3-data-exfiltration-attempts | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
通过分析 CloudTrail S3 数据事件、VPC Flow Logs、GuardDuty 发现、Amazon Macie 告警和 S3 访问模式,检测 AWS S3 存储桶的数据泄露企图,识别未授权的批量下载和跨账户数据传输。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 检测 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 日志
- 配置 VPC 端点策略用于 S3 访问监控
## 工作流程
### 步骤 1:在 CloudTrail 中启用 S3 数据事件日志记录
配置 CloudTrail 捕获所有 S3 对象级别操作,用于取证分析。
```bash
# 在现有跟踪上启用 S3 数据事件
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/"]
}]
}]'
# 验证数据事件配置
aws cloudtrail get-event-selectors --trail-name management-trail \
--query 'EventSelectors[*].DataResources' --output json
# 启用 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。
```bash
# Athena 查询:过去 24 小时内按下载量排名的 S3 用户
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:来自异常 IP 的 S3 GetObject 请求
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
'
# 检测跨账户复制(潜在数据泄露)
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 专项发现类型。
```bash
# 列出活跃的 S3 数据泄露相关发现
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
# 获取详细发现信息
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 发现,将数据敏感性与访问异常进行关联。
```bash
# 列出关于敏感数据暴露的 Macie 发现
aws macie2 list-findings \
--finding-criteria '{
"criterion": {
"category": {"eq": ["CLASSIFICATION"]},
"severity.description": {"eq": ["High", "Critical"]}
}
}' \
--sort-criteria '{"attributeName": "updatedAt", "orderBy": "DESC"}' \
--max-results 25
# 获取含数据分类的详细发现
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
# 对目标存储桶运行敏感数据发现作业
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 规则用于实时泄露检测。
```bash
# 高容量 S3 下载的 CloudWatch 指标过滤器
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
}]'
# 异常下载量告警(每小时超过 1000 个对象)
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
# GuardDuty S3 发现的 EventBridge 规则
aws events put-rule \
--name guardduty-s3-exfiltration \
--event-pattern '{
"source": ["aws.guardduty"],
"detail-type": ["GuardDuty Finding"],
"detail": {
"type": [{"prefix": "Exfiltration:S3/"}]
}
}'
```
### 步骤 6:实施预防性控制
部署存储桶策略和 VPC 端点策略,限制数据移动路径。
```bash
# 将 S3 访问限制为特定存储桶的 VPC 端点策略
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/*"]
}]
}'
# 拒绝来自 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 数据事件(S3 Data Events) | CloudTrail 对象级别日志记录,捕获 GetObject、PutObject、DeleteObject 和 CopyObject API 调用及请求详情 |
| GuardDuty S3 Protection | 威胁检测功能,分析 CloudTrail S3 数据事件以识别异常访问模式和泄露企图 |
| Amazon Macie | 数据安全服务,在 S3 中发现和分类敏感数据,并为数据暴露风险生成发现 |
| VPC 端点策略(VPC Endpoint Policy) | S3 VPC 端点上的访问控制策略,限制可通过端点访问哪些存储桶和操作 |
| 数据泄露(Data Exfiltration) | 未授权地将数据从组织的 S3 存储传输到攻击者控制的外部位置 |
| 异常行为检测(Anomalous Behavior Detection) | 基于机器学习识别主体 S3 访问模式中偏离既定基线的异常 |
## 工具与系统
- **AWS CloudTrail**:S3 对象级别操作的审计日志,用于取证分析和异常检测
- **Amazon GuardDuty**:基于 ML 的威胁检测,包含用于泄露和未授权访问的 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 数据泄露调查报告
============================================
账户: 123456789012
检测来源: GuardDuty Exfiltration:S3/ObjectRead.Unusual
调查日期: 2026-02-23
事件时间线:
2026-02-23 02:47 UTC - 首次来自 185.x.x.x 的异常 GetObject 请求
2026-02-23 02:47-04:12 UTC - 12,847 次 GetObject 请求
2026-02-23 04:15 UTC - GuardDuty 发现生成
2026-02-23 04:20 UTC - PagerDuty 告警发送至 SOC
2026-02-23 04:25 UTC - 访问密钥已停用
被入侵主体:
ARN: arn:aws:iam::123456789012:user/developer-jane
访问密钥: AKIA...WXYZ
来源 IP: 185.x.x.x(Tor 出口节点)
数据影响评估:
访问的存储桶: 3 个
下载的对象: 12,847 个
总数据量: 4.7 GB
敏感数据类型: PII(SSN、电子邮件)、金融数据(信用卡号)
Macie 严重级别: 严重
遏制操作:
[x] 访问密钥已停用
[x] 用户密码已重置,MFA 已重新注册
[x] VPC 端点策略已应用于敏感存储桶
[x] 存储桶策略已限制为仅 VPC 访问
[x] TruffleHog 扫描已对开发者仓库启动
```Related Skills
testing-for-sensitive-data-exposure
在安全评估中识别敏感数据暴露漏洞,包括 API 密钥泄露、响应中的 PII、不安全存储以及未受保护的数据传输。
performing-sqlite-database-forensics
对 SQLite 数据库执行取证分析,从空闲列表(Freelist)和 WAL 文件中恢复已删除记录,解码编码时间戳,并从浏览器历史、即时通讯应用和移动设备数据库中提取证据。
implementing-security-monitoring-with-datadog
使用 Datadog 的云安全信息和事件管理(Cloud SIEM)、日志分析和威胁检测能力实施安全监控,识别并响应整个云基础设施中的安全事件。
implementing-pam-for-database-access
为数据库系统(包括 Oracle、SQL Server、PostgreSQL 和 MySQL)部署特权访问管理。涵盖会话代理配置、凭据保管、查询审计、动态凭据生成和最小权限数据库角色。
implementing-gdpr-data-protection-controls
《通用数据保护条例》(EU)2016/679(GDPR)是欧盟关于个人数据收集、处理、存储和传输的综合数据保护法律。本技能涵盖实施 GDPR 要求的技术和组织措施。
implementing-cloud-dlp-for-data-protection
使用 Amazon Macie、Azure Information Protection 和 Google Cloud DLP API 实施云数据丢失预防(DLP),对云存储、数据库和数据管道中的敏感数据进行发现、分类和保护。
implementing-aws-macie-for-data-classification
实施 Amazon Macie,利用机器学习和模式匹配自动发现、分类并保护 S3 存储桶中的敏感数据,包括 PII、金融数据和凭据检测。
implementing-aes-encryption-for-data-at-rest
AES(高级加密标准)是由 NIST(FIPS 197)标准化的对称分组密码,用于保护机密和敏感数据。本技能涵盖在 GCM 模式下实现 AES-256 加密,用于加密静态文件和数据存储,包括正确的密钥派生、IV/nonce 管理和认证加密。
hunting-for-data-staging-before-exfiltration
通过监控 7-Zip/RAR 压缩文件创建、异常临时目录访问、大文件合并以及暂存目录模式,借助 EDR 和进程遥测检测数据外泄前的暂存活动。
hunting-for-data-exfiltration-indicators
通过网络流量分析狩猎数据外泄行为,检测异常数据流、DNS 隧道、云存储上传以及加密通道滥用。
exploiting-excessive-data-exposure-in-api
测试 API 是否存在过度数据暴露,即端点返回的数据超出客户端应用程序实际需要的量,依赖前端过滤敏感字段。测试人员拦截 API 响应并分析其中泄露的 PII、内部标识符、调试信息或 UI 不显示但 API 传输的敏感业务数据。对应 OWASP API3:2023 对象属性级授权破坏。适用于 API 数据泄露测试、过度数据暴露、响应过滤绕过或 API 过度获取等请求场景。
detecting-wmi-persistence
通过分析 Sysmon 事件 ID 19、20 和 21 中的恶意 EventFilter、EventConsumer 和 FilterToConsumerBinding 创建,检测 WMI 事件订阅持久化。