detecting-cryptomining-in-cloud
本 skill 教导安全团队如何检测和响应云环境中未授权的加密货币挖矿活动。内容涵盖通过计算使用异常、挖矿池网络流量模式、GuardDuty 加密货币发现以及 EC2、ECS、EKS 和 Azure Automation 工作负载上的运行时进程监控来识别挖矿指标。
Best use case
detecting-cryptomining-in-cloud is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
本 skill 教导安全团队如何检测和响应云环境中未授权的加密货币挖矿活动。内容涵盖通过计算使用异常、挖矿池网络流量模式、GuardDuty 加密货币发现以及 EC2、ECS、EKS 和 Azure Automation 工作负载上的运行时进程监控来识别挖矿指标。
Teams using detecting-cryptomining-in-cloud 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-cryptomining-in-cloud/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How detecting-cryptomining-in-cloud Compares
| Feature / Agent | detecting-cryptomining-in-cloud | 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?
本 skill 教导安全团队如何检测和响应云环境中未授权的加密货币挖矿活动。内容涵盖通过计算使用异常、挖矿池网络流量模式、GuardDuty 加密货币发现以及 EC2、ECS、EKS 和 Azure Automation 工作负载上的运行时进程监控来识别挖矿指标。
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
# 检测云中的加密货币挖矿
## 适用场景
- 云账单告警显示意外计算成本激增时
- GuardDuty 生成 CryptoCurrency 或 Impact 类型发现时
- 调查可能用于启动挖矿实例的被入侵 IAM 凭据时
- 监控容器工作负载中的未授权进程执行时
- 针对资源劫持攻击建立主动检测控制时
**不适用于**:合法的加密货币挖矿操作、物理硬件上的非云环境挖矿检测,或与挖矿活动无关的通用恶意软件分析。
## 前置条件
- 为 EC2、ECS 和 EKS 启用 Runtime Monitoring 的 Amazon GuardDuty
- 配置 CloudWatch 或 Azure Monitor 用于计算资源利用率告警
- 启用 VPC Flow Logs 用于分析到挖矿池 IP 的网络流量
- 配置 AWS Cost Anomaly Detection 或 Azure Cost Management 告警
## 工作流程
### 步骤 1:通过多重信号建立检测
跨四个信号类别部署检测:成本异常、计算资源利用率、网络流量和运行时进程。
```bash
# AWS Cost Anomaly Detection
aws ce create-anomaly-monitor \
--anomaly-monitor '{
"MonitorName": "EC2CostSpike",
"MonitorType": "DIMENSIONAL",
"MonitorDimension": "SERVICE"
}'
aws ce create-anomaly-subscription \
--anomaly-subscription '{
"SubscriptionName": "CryptoMiningAlert",
"MonitorArnList": ["arn:aws:ce::123456789012:anomalymonitor/monitor-id"],
"Subscribers": [{"Address": "security@company.com", "Type": "EMAIL"}],
"Threshold": 50.0,
"Frequency": "IMMEDIATE"
}'
# CloudWatch CPU 利用率激增告警
aws cloudwatch put-metric-alarm \
--alarm-name HighCPUUtilization \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--statistic Average \
--period 300 \
--threshold 90 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 3 \
--alarm-actions "arn:aws:sns:us-east-1:123456789012:security-alerts"
```
### 步骤 2:监控 GuardDuty 加密货币发现
为针对 EC2、ECS 和 EKS 工作负载上加密货币挖矿活动的 GuardDuty 发现配置告警。
GuardDuty 加密挖矿关键发现类型:
- `CryptoCurrency:EC2/BitcoinTool.B` - 到加密货币相关域名的网络连接
- `CryptoCurrency:Runtime/BitcoinTool.B` - 运行时检测到挖矿进程执行
- `Impact:EC2/BitcoinTool.B` - EC2 实例与已知比特币挖矿池通信
- `Impact:Runtime/CryptoMinerExecuted` - 运行时 Agent 检测到加密挖矿程序执行
```bash
# 针对加密货币发现的 EventBridge 规则
aws events put-rule \
--name CryptoMiningDetection \
--event-pattern '{
"source": ["aws.guardduty"],
"detail-type": ["GuardDuty Finding"],
"detail": {
"type": [
{"prefix": "CryptoCurrency:"},
{"prefix": "Impact:EC2/BitcoinTool"},
{"prefix": "Impact:Runtime/CryptoMiner"}
]
}
}'
# 加密货币发现的自动修复 Lambda
aws events put-targets \
--rule CryptoMiningDetection \
--targets '[{
"Id": "CryptoAutoRemediate",
"Arn": "arn:aws:lambda:us-east-1:123456789012:function/crypto-remediate"
}]'
```
### 步骤 3:分析到挖矿池的网络流量
监控 VPC Flow Logs 和 DNS 查询,识别到已知加密货币挖矿池在常用端口(3333、4444、5555、8333、9999、14444)上运行的连接。
```kql
// Sentinel KQL 查询,检测挖矿池连接
AzureNetworkAnalytics_CL
| where TimeGenerated > ago(24h)
| where DestPort_d in (3333, 4444, 5555, 8333, 9999, 14444, 14433, 45700)
| summarize ConnectionCount = count(), BytesSent = sum(BytesSent_d)
by SrcIP_s, DestIP_s, DestPort_d, bin(TimeGenerated, 1h)
| where ConnectionCount > 10
| project TimeGenerated, SrcIP_s, DestIP_s, DestPort_d, ConnectionCount, BytesSent
```
```bash
# AWS Athena 查询,检测 VPC Flow Logs 中的挖矿池连接
cat << 'EOF' > mining-detection.sql
SELECT srcaddr, dstaddr, dstport, protocol,
COUNT(*) as connection_count,
SUM(bytes) as total_bytes
FROM vpc_flow_logs
WHERE dstport IN (3333, 4444, 5555, 8333, 9999, 14444)
AND action = 'ACCEPT'
AND start >= date_add('hour', -24, now())
GROUP BY srcaddr, dstaddr, dstport, protocol
HAVING COUNT(*) > 10
ORDER BY connection_count DESC
EOF
```
### 步骤 4:检测容器环境中的挖矿
监控 ECS 任务定义和 EKS Pod 部署,识别已知挖矿容器镜像和可疑进程执行。
```bash
# 检查最近注册的含有可疑镜像的 ECS 任务定义
aws ecs list-task-definitions --sort DESC --max-items 50 | \
jq -r '.taskDefinitionArns[]' | while read arn; do
aws ecs describe-task-definition --task-definition "$arn" \
--query 'taskDefinition.containerDefinitions[*].[name,image]' --output text
done
# 需要监控的已知恶意挖矿镜像特征:
# - 来自未知镜像仓库且拉取次数极高的镜像
# - 包含 xmrig、cpuminer、minergate 或 ccminer 二进制文件的镜像
# - 入口点指向 /tmp/.hidden 或 /dev/shm 路径的镜像
# 监控 CloudTrail 中可疑的 ECS/EKS 活动
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=RegisterTaskDefinition \
--start-time $(date -d '-24 hours' +%Y-%m-%dT%H:%M:%S) \
--query 'Events[*].[EventName,Username,EventTime]'
```
### 步骤 5:响应和遏制挖矿活动
确认挖矿后立即执行遏制操作,在终止恶意工作负载前保留取证证据。
```python
# 加密货币挖矿事件的自动修复 Lambda
import boto3
import json
def lambda_handler(event, context):
finding = event['detail']
resource_type = finding['resource']['resourceType']
if resource_type == 'Instance':
instance_id = finding['resource']['instanceDetails']['instanceId']
ec2 = boto3.client('ec2')
# 在隔离前对 EBS 卷创建取证快照
volumes = ec2.describe_instances(InstanceIds=[instance_id])
for reservation in volumes['Reservations']:
for instance in reservation['Instances']:
for vol in instance['BlockDeviceMappings']:
volume_id = vol['Ebs']['VolumeId']
ec2.create_snapshot(
VolumeId=volume_id,
Description=f'取证快照 - 加密货币挖矿 - {instance_id}',
TagSpecifications=[{
'ResourceType': 'snapshot',
'Tags': [{'Key': 'Incident', 'Value': 'CryptoMining'},
{'Key': 'SourceInstance', 'Value': instance_id}]
}]
)
# 如果攻击者设置了 API 终止保护,先禁用它
ec2.modify_instance_attribute(
InstanceId=instance_id,
DisableApiTermination={'Value': False}
)
# 使用空安全组隔离实例
vpc_id = finding['resource']['instanceDetails']['networkInterfaces'][0]['vpcId']
isolation_sg = ec2.create_security_group(
GroupName=f'crypto-isolation-{instance_id}',
Description='加密挖矿隔离 - 禁止所有流量',
VpcId=vpc_id
)
# 撤销默认出站规则
ec2.revoke_security_group_egress(
GroupId=isolation_sg['GroupId'],
IpPermissions=[{'IpProtocol': '-1', 'IpRanges': [{'CidrIp': '0.0.0.0/0'}]}]
)
ec2.modify_instance_attribute(
InstanceId=instance_id,
Groups=[isolation_sg['GroupId']]
)
return {'status': 'contained', 'instance': instance_id}
```
### 步骤 6:追踪初始访问向量
通过调查 CloudTrail 日志,确定攻击者如何获取访问权限以部署挖矿工作负载。常见向量包括被入侵的 IAM 凭据、暴露的访问密钥以及通过容器镜像进行的供应链攻击。
```bash
# 追踪被入侵身份的初始访问记录
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=Username,AttributeValue=compromised-user \
--start-time 2025-02-01T00:00:00Z \
--query 'Events[?EventName==`ConsoleLogin` || EventName==`GetSessionToken`].[EventTime,SourceIPAddress,EventName]' \
--output table
# 检查在异常区域的 RunInstances 调用
for region in $(aws ec2 describe-regions --query 'Regions[*].RegionName' --output text); do
count=$(aws cloudtrail lookup-events \
--region $region \
--lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances \
--start-time $(date -d '-7 days' +%Y-%m-%dT%H:%M:%S) \
--query 'Events | length(@)')
if [ "$count" -gt 0 ]; then
echo "区域: $region - RunInstances 调用数: $count"
fi
done
```
## 核心概念
| 术语 | 定义 |
|------|------|
| 加密劫持(Cryptojacking) | 未授权使用云计算资源挖掘加密货币,通常是门罗币(XMR),因其 CPU 友好的算法 |
| Stratum 协议(Stratum Protocol) | 在 TCP 端口 3333、4444 或自定义端口上运行的挖矿池通信协议,可在网络流日志中识别 |
| XMRig | 开源门罗币挖矿软件,常见于加密劫持攻击,通常以隐藏二进制文件部署在容器中 |
| API 终止保护(API Termination Protection) | 攻击者启用的 EC2 属性,用于阻止安全团队快速终止被入侵的挖矿实例 |
| Cost Anomaly Detection | AWS 服务,使用机器学习识别可能表明未授权资源使用的异常消费模式 |
| Runtime Monitoring(运行时监控) | GuardDuty 功能,部署 Agent 检测进程级别的活动,包括加密挖矿程序执行 |
| 攻击序列(Attack Sequence) | GuardDuty 扩展威胁检测发现,将凭据窃取、基础设施部署和挖矿执行关联为单个严重事件 |
## 工具与系统
- **Amazon GuardDuty**:通过网络流量分析、DNS 查询和运行时进程监控检测加密货币挖矿
- **AWS Cost Anomaly Detection**:基于机器学习的服务,识别挖矿实例部署导致的意外成本增加
- **VPC Flow Logs**:显示到挖矿池 IP 地址和端口连接的网络流量元数据
- **Falco**:开源运行时安全工具,用于检测容器中的加密挖矿进程执行
- **Amazon Detective**:基于图形的调查工具,用于追踪从初始访问到挖矿部署的攻击路径
## 常见场景
### 场景:被入侵的 IAM 凭据用于大规模 EC2 挖矿
**场景背景**:公开 GitHub 仓库中泄露的 IAM 凭据在 10 分钟内被用于在 8 个 AWS 区域启动 200 个 GPU 实例。攻击者在每个区域启用了 API 终止保护并禁用了 CloudTrail。
**方法**:
1. AWS Cost Anomaly Detection 触发告警,显示每小时 EC2 费用超过 15,000 美元
2. GuardDuty 生成 Stealth:IAMUser/CloudTrailLoggingDisabled 和 CryptoCurrency:EC2/BitcoinTool.B 发现
3. 立即停用被入侵的 IAM 访问密钥
4. 在所有受影响区域重新启用 CloudTrail 以恢复可见性
5. 禁用所有 200 个实例的 API 终止保护并终止它们
6. 在终止前对具有代表性的实例创建取证快照
7. 检查 GitHub 提交历史,识别并删除暴露的凭据
8. 部署 AWS Config 规则,防止禁用 CloudTrail 并强制使用 IMDSv2
**常见陷阱**:未检查所有 AWS 区域的挖矿实例会导致未被发现的区域中的矿机持续运行。在停止实例前未禁用 API 终止保护会浪费响应时间。
## 输出格式
```
加密货币挖矿事件响应报告
=======================================
事件 ID: INC-2025-0223-CRYPTO
检测时间: 2025-02-23T14:23:00Z
遏制时间: 2025-02-23T14:41:00Z(18 分钟)
初始访问:
向量: IAM 访问密钥暴露于公开 GitHub 仓库
凭据: AKIAIOSFODNN7EXAMPLE(用户: ci-deploy)
首次恶意活动: 2025-02-23T14:12:00Z
影响:
启动实例数: 200 个(p3.2xlarge GPU 实例)
受影响区域: 8 个(us-east-1, us-west-2, eu-west-1, eu-central-1 等)
估计成本: 4,200 美元(18 分钟,每小时 15,400 美元)
挖矿池: stratum+tcp://pool.supportxmr.com:3333
加密货币: 门罗币(XMR)
检测信号:
[14:15] GuardDuty: Stealth:IAMUser/CloudTrailLoggingDisabled(高)
[14:18] 成本异常: EC2 费用超基准 4,200%
[14:23] GuardDuty: CryptoCurrency:EC2/BitcoinTool.B(高)x 200
遏制操作:
[14:25] IAM 访问密钥 AKIAIOSFODNN7EXAMPLE 已停用
[14:30] CloudTrail 已在所有 8 个区域重新启用
[14:35] 200 个实例的 API 终止保护已禁用
[14:41] 所有 200 个实例已终止
修复措施:
- 被入侵的访问密钥已删除
- GitHub 仓库密钥扫描已启用
- AWS Config 规则已部署: cloudtrail-enabled(自动修复)
- SCP 已部署: 拒绝在未经审批的情况下为 GPU 实例类型执行 ec2:RunInstances
```Related Skills
securing-kubernetes-on-cloud
本技能涵盖通过实施 Pod 安全标准(Pod Security Standards)、网络策略、工作负载身份、RBAC 权限控制、镜像准入控制和运行时安全监控,对 EKS、AKS 和 GKE 上的托管 Kubernetes 集群进行加固。涉及云平台特定安全功能,包括 EKS 的 IRSA、GKE 的工作负载身份(Workload Identity)以及 AKS 的托管身份(Managed Identity)。
performing-cloud-storage-forensic-acquisition
通过收集 API 远程数据和端点设备本地同步客户端制品,对 Google Drive、OneDrive、Dropbox 和 Box 等云存储服务执行取证获取和分析。
performing-cloud-penetration-testing
对 AWS、Azure 和 GCP 云环境执行授权渗透测试,识别 IAM 错误配置、暴露的存储桶、过度宽松的安全组、 无服务器函数漏洞以及从初始访问到账户沦陷的云特定攻击路径。测试人员使用云原生工具及 Pacu、 ScoutSuite 等专用框架枚举并利用云基础设施。适用于云渗透测试、AWS 安全评估、Azure 渗透测试 或云基础设施安全测试等请求场景。
performing-cloud-penetration-testing-with-pacu
使用开源 AWS 利用框架 Pacu 执行已授权的 AWS 渗透测试,枚举 IAM 配置、发现权限提升路径、测试凭据收集,并通过系统化的攻击模拟验证安全控制。
performing-cloud-native-forensics-with-falco
使用 Falco YAML 规则在容器和 Kubernetes 中进行运行时威胁检测,监控系统调用以检测 shell 生成、文件篡改、网络异常和权限提升。通过 Falco gRPC API 管理 Falco 规则并解析 Falco 告警输出。适用于构建容器运行时安全或调查 k8s 集群入侵。
performing-cloud-incident-containment-procedures
在 AWS、Azure 和 GCP 中执行云原生事件遏制,包括隔离受攻陷资源、撤销凭据、保全取证证据,以及应用安全组限制以防止横向移动。
performing-cloud-forensics-with-aws-cloudtrail
使用 CloudTrail 日志对 AWS 环境执行取证调查,重建攻击者活动、识别受损凭据并分析 API 调用模式。
performing-cloud-forensics-investigation
通过收集和分析来自 AWS、Azure 和 GCP 服务的日志、快照和元数据,在云环境中开展取证调查。
performing-cloud-asset-inventory-with-cartography
使用 Cartography 执行全面的云资产清单和关系映射,在 AWS、GCP 和 Azure 中构建包含基础设施资产、IAM 权限和攻击路径的 Neo4j 安全图谱。
managing-cloud-identity-with-okta
本技能涵盖将 Okta 部署为云环境集中身份提供商,配置与 AWS、Azure 和 GCP 的 SSO 集成,使用 Okta FastPass 部署抗钓鱼 MFA,管理用户预配置和取消配置的生命周期自动化,以及基于设备态势和风险信号实施自适应访问策略。
implementing-zero-trust-in-cloud
本技能指导组织按照 NIST SP 800-207 和 Google BeyondCorp 原则在云环境中实施零信任(Zero Trust)架构,涵盖以身份为中心的访问控制、微分段(Micro-Segmentation)、持续验证、设备信任评估,以及部署身份感知代理(Identity-Aware Proxy)以消除 AWS、Azure 和 GCP 环境中的隐式网络信任。
implementing-ddos-mitigation-with-cloudflare
配置 Cloudflare DDoS 防护,包括托管规则集、速率限制、WAF 规则、Bot 管理和源站保护,以缓解容量型、协议型和应用层攻击。