Detecting cryptocurrency mining (cryptojacking) before the €50,000 bill arrives

Cloud cryptojacking does not usually start with a clear “security” alert. It starts with small operational anomalies that, if not correlated, end up in a disproportionate bill. The goal here is not to wait for FinOps to warn you about costs, but to detect mining while it is still an incident of hours, not weeks.

In companies with multiple teams deploying resources, the attacker (or malware) benefits from the noise: new instances, network changes, credential rotation, nightly deployments. Effective detection consists of identifying anomalous usage patterns that, combined, are hard to justify as legitimate load.

What usually goes wrong: signals that are ignored until the cost is already real damage

The first signal usually comes from “operations”: someone notices new instances in regions the business does not use, or a spike in Spot interruptions without explanation. When the warning comes from cost, normally the attacker has already optimized profitability: GPUs, stable pools, host rotation, and persistence via autoscaling or compromised images.

In practice, what fails is not the lack of tools, but the lack of thresholds and context. A company can have CloudTrail/Activity Logs, VPC Flow Logs/NSG Flow Logs, and a SIEM, but without correlation the events look like “normal changes”. Cryptojacking camouflages itself well in environments where creating instances on demand and opening egress without control is allowed.

A typical corporate mistake is relying on a single source: “if the EDR does not alert, nothing is happening” or “if the cost does not go up, we are fine”. Mining can be spread across multiple accounts/subscriptions or projects to avoid triggering simple alerts, and still consume enough resources to degrade services and generate operational debt.

Operational IOCs in cloud: patterns that give away mining before FinOps screams

Useful indicators tend to be infrastructure and network, not process. Mining needs sustained resources and specific connectivity; that leaves repeatable traces. A very common case: creation of GPU instances in “cheap” or little-used regions by the company, because the attacker optimizes cost per hash. If your organization operates in Europe and GPUs appear in regions that are not on the deployment map, it is not a “load test”.

Another pattern that appears early is Spot/Preemptible instances being aborted en masse. Mining tolerates interruptions: the attacker launches many cheap Spot, loses them, relaunches, and so on. In operations this translates into a noise of interruption/termination events that does not fit typical corporate workloads (controlled batch, CI/CD, etc.).

  • GPUs outside the business pattern

Look for GPU instance types or equivalent families in your cloud, especially if they appear in “non-production” accounts or in regions without justification. In companies, legitimate GPU use is usually bounded (specific teams, specific projects, specific windows). When it appears “out of nowhere”, the probability of abuse is high.

  • Security Groups/NSG opening egress or ports towards pools

Mining needs to talk to pools (Stratum and variants) or specific endpoints. It is not necessary to “open inbound” to mine; many campaigns live with egress open. Even so, it is common to see new “temporary” rules that open broad ranges or unusual ports. If the rule is also created by an unusual identity (CI role, human user outside working hours), it is an early signal.

  • High instance churn and Spot events

When you see hundreds of launches/terminations in a few hours, the cost may still be contained, but the intent is already clear. In corporate environments, that churn often breaks inventories, saturates logs, and generates operational false positives that “cover up” the real incident.

How to do it in practice: event-based detection and minimum viable correlation

Effective detection starts by accepting that you do not need “AI” for 80% of cases. You need reliable events, normalization, and three or four correlations with defensive thresholds. The approach that works best in enterprises is event-driven: each instance creation, network change, and public IP assignment triggers a quick evaluation.

Set up audit ingestion (e.g., CloudTrail / Azure Activity Log) and compute events (e.g., Auto Scaling/VM events) to a bus (EventBridge/Event Grid) and also record network telemetry (VPC Flow Logs/NSG Flow Logs). You do not need to inspect every packet: it is enough to detect suspicious destinations/ports, unusual egress, and persistence.

  • Rule: GPU instance creation in a non-approved region

Implement a list of “allowed regions” per account/project and alert/block if GPU compute appears outside it. In a real company, this is validated by reviewing the historical inventory: if in the last 90 days there was no GPU in that region, the event deserves automatic response or at least human approval.

  • Rule: spike in Spot interruptions + automatic recreation

Correlate Spot interruption/termination events with new launches of the same type in a short window (for example, 10–20 minutes). A corporate batch usually has queue control and backoff; mining tends to relaunch aggressively to maintain hash rate.

  • Rule: Security Group/NSG change that enables outbound to atypical destinations/ports

Define a baseline: which outbound ports are normal for your workloads (443 almost always, 80 sometimes, others very specific). When a new egress appears and also coincides with creation of new instances, the set is stronger than each signal separately.

A practical point that avoids arguments: integrate “owner”, “cost-center”, and “purpose” labels/tags as a requirement. When the suspicious instance does not have mandatory tags or uses inconsistent values, treat it as an operational and security incident at the same time; in companies, that criterion is defensible and auditable.

Automating containment: Lambda/Azure Function that kills instances and isolates the network without breaking production

Automating does not mean “turn everything off”. It means applying a proportional and reversible response, with traceability. In cryptojacking, time matters: stopping a GPU at 5 minutes is worth more than analyzing it for 12 hours while it keeps mining. The typical strategy: stop/terminate the suspicious instance, cut egress, and preserve minimal evidence.

A pattern that works well is: creation/change event → serverless function → rule evaluation → actions. The function must be conservative to avoid shutting down legitimate training, but aggressive when the pattern is clear (GPU in non-approved region + SG modified + no tags).

Example of minimal IAM (AWS) for a containment Lambda (adjust resources to your account):

  • ec2:DescribeInstances, ec2:DescribeSecurityGroups to obtain context before acting.
  • ec2:StopInstances or ec2:TerminateInstances to cut consumption (according to your response policy).
  • ec2:ModifyInstanceAttribute to remove IAM profile/metadata options if your runbook contemplates it.
  • ec2:RevokeSecurityGroupEgress or move the instance to a precreated “quarantine” SG.

The real operational difference is in network quarantine. Instead of deleting rules (risks drift and breakage), create a Security Group/NSG quarantine with egress denied (or strictly to forensic endpoints) and apply that SG to the instance(s). That way you reduce collateral impact and simplify auditing.

Validation in AWS (concrete steps): verify in CloudTrail that the automatic action is recorded with a clear principal (the Lambda role) and with consistent request parameters; check in EC2 that the instance ended up in stopped/terminated and with the quarantine SG; and confirm in VPC Flow Logs that traffic to the suspicious destination disappears. If you do not see that network cut, your containment is “cosmetic”.

In Azure, the pattern is equivalent: Event Grid/Activity Log → Azure Function → actions on VM/Scale Set and NSG. The corporate key is the same: reversible quarantine, and a clear record for SOC and internal audit.

Recommendations for corporate environments

Early cryptojacking detection that avoids the €50,000 bill does not depend on a cost alert, but on recognizing operational IOCs: GPUs where they do not belong, anomalous Spot behavior, and network changes that facilitate outbound to pools. When those signals are correlated, the case stops being “noise” and becomes actionable.

The response that works best in enterprises combines speed and control: serverless automation to stop consumption and apply network quarantine, and operational validation through audit (CloudTrail/Activity Logs) and network telemetry (Flow Logs). The goal is to cut spend without breaking production and without losing traceability.

If you have to choose where to invest first, prioritize simple rules but hard to justify in the business (GPU outside approved regions, instances without mandatory tags, atypical egress after SG/NSG changes) and link them to reversible containment. That is what truly reduces the “time to cut” before cost is the final symptom.

Interested in Cloud Security?

Technical analysis, hands-on labs and real-world cloud security insights.

Cloud security analysis, no fluff

Real cases of attacks, defenses, and cloud architecture explained without filler. For architects, DevOps, and security leaders who don't have time to waste.

Privacy policy

Francisco Sepúlveda

Francisco Sepúlveda

Cloud Computing & Cybersecurity Instructor, Learning Experience Designer

Instructor and consultant in Cloud Computing, Cybersecurity and AI, with more than 25 years of hands-on experience in real enterprise environments. I design and deliver technical training programs, combining deep subject-matter expertise with learning experience design to make complex security concepts stick. I share practical, applied analysis on Cloud Security in Practice.

More about me →