Install any skill in seconds. Free to start, no credit card required.
Get Started Free →This skill teaches security teams how to detect and respond to unauthorized cryptocurrency mining operations in cloud environments. It covers identifying cryptomining indicators through compute usage anomalies, network traffic patterns to mining pools, GuardDuty CryptoCurrency findings, and runtime process monitoring on EC2, ECS, EKS, and Azure Automation workloads.
.claude/skills/detecting-cryptomining-in-cloud/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-22 | ✗→✓ | ▲ Improved | — | — |
| case-02 | ✗→✓ | ▲ Improved | — | — |
| case-07 | ✗→✓ | ▲ Improved | — | — |
| case-06 | ✗→✓ | ▲ Improved | — | — |
| case-08 | ✗→✓ | ▲ Improved | — | — |
Do not use for legitimate cryptocurrency mining operations, for non-cloud mining detection on physical hardware, or for general malware analysis unrelated to mining activity.
Deploy detection across four signal categories: cost anomalies, compute utilization, network traffic, and runtime processes.
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 alarm for CPU utilization spike 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"
Configure alerting for GuardDuty findings specific to cryptocurrency mining activity on EC2, ECS, and EKS workloads.
Key GuardDuty finding types for cryptomining:
CryptoCurrency:EC2/BitcoinTool.B - Network connections to crypto-related domainsCryptoCurrency:Runtime/BitcoinTool.B - Runtime detection of mining process executionImpact:EC2/BitcoinTool.B - EC2 instance communicating with known Bitcoin mining poolsImpact:Runtime/CryptoMinerExecuted - Crypto mining binary execution detected by runtime agentbash# EventBridge rule for cryptocurrency findings 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"} ] } }' # Auto-remediation Lambda for crypto findings aws events put-targets \ --rule CryptoMiningDetection \ --targets '[{ "Id": "CryptoAutoRemediate", "Arn": "arn:aws:lambda:us-east-1:123456789012:function/crypto-remediate" }]'
Monitor VPC Flow Logs and DNS queries for connections to known cryptocurrency mining pools operating on common ports (3333, 4444, 5555, 8333, 9999, 14444).
kql// Sentinel KQL query for mining pool connections 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 query for VPC Flow Logs mining pool detection 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
Monitor ECS task definitions and EKS pod deployments for known mining container images and suspicious process execution.
bash# Check for recently registered ECS task definitions with suspicious images 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 # Known malicious mining images to watch for: # - Images with high pull counts from unknown registries # - Images containing xmrig, cpuminer, minergate, or ccminer binaries # - Images with entrypoint pointing to /tmp/.hidden or /dev/shm paths # Monitor CloudTrail for suspicious ECS/EKS activity 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]'
Execute immediate containment actions when mining is confirmed, preserving forensic evidence before terminating the malicious workloads.
python# Auto-remediation Lambda for cryptomining incidents 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') # Snapshot EBS volumes for forensics before isolation 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'Forensic snapshot - crypto mining - {instance_id}', TagSpecifications=[{ 'ResourceType': 'snapshot', 'Tags': [{'Key': 'Incident', 'Value': 'CryptoMining'}, {'Key': 'SourceInstance', 'Value': instance_id}] }] ) # Disable API termination protection if set by attacker ec2.modify_instance_attribute( InstanceId=instance_id, DisableApiTermination={'Value': False} ) # Isolate instance with empty security group vpc_id = finding['resource']['instanceDetails']['networkInterfaces'][0]['vpcId'] isolation_sg = ec2.create_security_group( GroupName=f'crypto-isolation-{instance_id}', Description='Cryptomining isolation - no traffic allowed', VpcId=vpc_id ) # Revoke default egress rule 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}
Investigate CloudTrail logs to determine how the attacker gained access to deploy mining workloads. Common vectors include compromised IAM credentials, exposed access keys, and supply chain attacks through container images.
bash# Trace the initial access for the compromised identity 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 # Check for RunInstances calls in unusual regions 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: $region - RunInstances calls: $count" fi done
| Term | Definition | |------|------------| | Cryptojacking | Unauthorized use of cloud compute resources to mine cryptocurrency, typically Monero (XMR) due to its CPU-friendly algorithm | | Stratum Protocol | Mining pool communication protocol operating on TCP ports 3333, 4444, or custom ports, identifiable in network flow logs | | XMRig | Open-source Monero mining software commonly found in cryptojacking attacks, often deployed as a hidden binary in containers | | API Termination Protection | EC2 attribute that attackers enable to prevent security teams from quickly terminating compromised mining instances | | Cost Anomaly Detection | AWS service that uses machine learning to identify unusual spending patterns that may indicate unauthorized resource usage | | Runtime Monitoring | GuardDuty capability that deploys agents to detect process-level activity including crypto mining binary execution | | Attack Sequence | GuardDuty Extended Threat Detection finding correlating credential theft, infrastructure deployment, and mining execution into a single Critical event |
Context: Exposed IAM credentials from a public GitHub repository are used to launch 200 GPU instances across 8 AWS regions within 10 minutes. The attacker enables API termination protection and disables CloudTrail in each region.
Approach:
Pitfalls: Failing to check all AWS regions for mining instances leaves active miners running in overlooked regions. Not disabling API termination protection before attempting to stop instances wastes response time.
Cryptomining Incident Response Report
=======================================
Incident ID: INC-2025-0223-CRYPTO
Detection Time: 2025-02-23T14:23:00Z
Containment Time: 2025-02-23T14:41:00Z (18 minutes)
INITIAL ACCESS:
Vector: Exposed IAM access key in public GitHub repository
Credential: AKIAIOSFODNN7EXAMPLE (user: ci-deploy)
First Malicious Activity: 2025-02-23T14:12:00Z
IMPACT:
Instances Launched: 200 (p3.2xlarge GPU instances)
Regions Affected: 8 (us-east-1, us-west-2, eu-west-1, eu-central-1, ...)
Estimated Cost: $4,200 (18 minutes at $15,400/hour)
Mining Pool: stratum+tcp://pool.supportxmr.com:3333
Cryptocurrency: Monero (XMR)
DETECTION SIGNALS:
[14:15] GuardDuty: Stealth:IAMUser/CloudTrailLoggingDisabled (HIGH)
[14:18] Cost Anomaly: EC2 spend 4,200% above baseline
[14:23] GuardDuty: CryptoCurrency:EC2/BitcoinTool.B (HIGH) x 200
CONTAINMENT ACTIONS:
[14:25] IAM access key AKIAIOSFODNN7EXAMPLE deactivated
[14:30] CloudTrail re-enabled in all 8 regions
[14:35] API termination protection disabled on 200 instances
[14:41] All 200 instances terminated
REMEDIATION:
- Compromised access key deleted
- GitHub repository secret scanning enabled
- AWS Config rule deployed: cloudtrail-enabled (auto-remediate)
- SCP deployed: deny ec2:RunInstances for GPU instance types without approval| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +45 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.