BSc research
Unravelling WannaCry: an in-depth analysis of the largest ransomware attack in history
WannaCry reached systems in more than 150 countries in May 2017 by pairing ransomware with a worm that spread through an unpatched flaw in SMBv1. This project reconstructs how the attack worked, compares the three main ways of detecting ransomware, and tests a defensive tool I built, the Morpheus IOC Scanner, against a ransomware sample of my own, KRYPT0S, using YARA rules.
Problem
On 12 May 2017 WannaCry locked machines at hospitals, telecoms firms and logistics companies. Microsoft had published the fix, bulletin MS17-010, on 14 March, 59 days earlier. The exploit WannaCry relied on, EternalBlue, targets CVE-2017-0144 in SMBv1 and had been leaked by a group calling itself the Shadow Brokers.
Three questions follow from that. How did the exploit, the worm behaviour and the encryption fit together? Why did so many organisations stay exposed for two months? And which detection approach would catch a ransomware sample nobody had seen before?
Objectives
- Reconstruct the timeline and spread of the outbreak, including the kill switch and the gap between patch and attack.
- Explain the technical mechanisms: the SMB protocol, how EternalBlue chains its flaws, how the kill switch gated execution, and how files were encrypted.
- Compare signature-based, behavioural and heuristic detection and how each performs against ransomware.
- Assess the economic and operational impact.
- Build a defensive scanner and test whether it can flag a new ransomware sample.
Methodology
The work has two parts. The analysis is a structured review of public material: Microsoft and CISA advisories, security-vendor technical write-ups, a national audit office report on the NHS, news reporting and the detection literature. Technical claims are tied to named sources, and figures such as infection counts and damage totals are reported as estimates from those sources.
The practical part asks a narrower question: can a small open tool driven by YARA rules flag ransomware it has not met before? I built Morpheus, wrote a ransomware proof of concept (KRYPT0S) to act as the unknown sample, wrote a detection rule for it, and ran the scanner against it in a lab setting.
What the analysis found
How the attack worked
WannaCry behaved as a worm. EternalBlue gave it code execution on any reachable host running SMBv1, and from there it installed its ransomware component and looked for more exposed hosts. The exploit chains three flaws. A size-calculation error during a format conversion produces an undersized buffer and an overflow. A mismatch in how two related SMB sub-commands define packet size makes that overflow reachable. Heap spraying then places attacker-controlled code where the overflow can reach it.
Before encrypting anything, the malware tried to contact a hard-coded domain that did not exist. If the connection succeeded, it did nothing. A researcher registered the domain on 13 May, and new copies stopped running their payload. Where the check failed, WannaCry encrypted user files with a hybrid scheme using AES and RSA-2048, appended a .WNCRY extension, changed the wallpaper and showed a ransom screen with a countdown.
- Exposed hostA Windows machine reachable over SMB, with SMBv1 on and MS17-010 not applied.
- EternalBlueExploits CVE-2017-0144 to run code on the host.
- Ransomware installedThe ransomware component is dropped and started.
- Kill-switch checkTries to reach a hard-coded domain.
The kill-switch check ran before any file was encrypted, which is why registering one domain slowed new infections.
Why it spread
MS17-010 had been available for 59 days. Some enterprises delay patches, and the worst-hit sectors, insurance and healthcare, often run older systems. Windows 7 accounted for 67 percent of the infected addresses BitSight observed, an address-level count and not a count of machines.
Day counts run from the publication of MS17-010.
What it cost
Estimates put the damage near 4 billion dollars. Blockchain records show about 280 ransom payments totalling 42.2 bitcoin, a small fraction of the cost, because most organisations rebuilt from backups instead of paying. In England the National Audit Office counted at least 80 of 236 NHS trusts as disrupted, along with 603 primary care organisations, 595 of them GP practices. Some hospitals cancelled appointments and diverted ambulances.
42.2 BTCpaid across about 280 ransom payments
About $4 billionestimated total damage
Both figures are estimates from public sources and the scales do not share an axis.
How the three detection approaches compare
| Method | Works well when | Falls short when | Against ransomware |
|---|---|---|---|
| Signature-based | The threat is known. Matches are fast and false positives are rare. | The sample is new or polymorphic, and rule sets need constant upkeep. | Strong for a known family like WannaCry once a profile exists. |
| Behavioural | The threat is new. It watches patterns such as file access and API calls and can catch zero-days. | Normal activity looks unusual. It also collects a lot of user activity data, which raises privacy questions. | Flags mass file changes and unusual disk and CPU use early. |
| Heuristic | Static and dynamic features are enough to classify an unknown or altered sample. | Code is obfuscated or encrypted, and legitimate programs get flagged. | Catches variants that have no signature yet. |
The practical part uses the simplest of the three, rule matching, and adds external reputation context.
Implementation
Morpheus V2 is a Python tool with two modes. The default offline mode scans a file against YARA rules and extracts file information, including PE details through pefile. The online mode submits a file or hash to VirusTotal with the user's own API key. It runs on Windows and Linux, uses multithreading to speed up large scans, pulls rule updates from GitHub-hosted rule sets with an updater script, offers a lighter or fuller rule set at setup, and compiles results into a PDF report. An AI-generated verdict summarises the scan findings.
Default scan, offline
- Input file
- File informationPE details and file properties.
- YARA scanSynced rule sets plus the custom KRYPT0S rule.
- Match results
- Verdict and PDF reportFindings summarised and exported.
VirusTotal scan, online
- File or hashSubmitted with the user's own API key.
- VirusTotal lookupMulti-engine results and community context.
- Vendor detections
The offline mode needs no network after setup. The online mode only helps for files VirusTotal has already seen.
KRYPT0S is a ransomware and wiper proof of concept written in Python. It is archived, not maintained, and built for isolated, authorised labs only. In this project it plays one role: a purpose-built sample for the scanner to meet.
My contributions
I wrote the analysis of the outbreak and the comparison of detection methods. I built Morpheus V2, including the local scanning, rule updates, reputation lookups and PDF reporting. I wrote KRYPT0S as a controlled test sample, wrote its detection rule, and ran the scan in a lab setting.
Results
The review found that the damage came from the combination of a worm-capable exploit, a patch that went unapplied for two months and a delivery mechanism that spread without user action. The kill switch limited the outbreak, though it was a flaw in the malware and not a defence anyone had planned. The detection comparison showed that no single method covers the gaps of the others.
In the lab, Morpheus flagged the KRYPT0S sample using the custom YARA rule. That confirms the pipeline works from end to end: rule delivery, matching and reporting. The project README also documents a scan of a real WannaCry sample, with the YARA result, the VirusTotal lookup and the generated PDF.
Limitations
The WannaCry analysis relies on secondary sources, and infection and damage figures vary between them, so I treat them as estimates.
The scanner test used one purpose-built sample and a rule written for it. It shows the pipeline works. It does not give detection rates or false-positive rates against real ransomware families, and the project does not claim complete coverage. Rule matching also shares the weakness the review identifies in signature detection: a modified or obfuscated sample can slip past. Reputation lookups only help for files VirusTotal already knows. The offline mode depends on a heavy set of dependencies and results can vary between systems. Morpheus is research code for authorised lab and defensive analysis, not a production detection service.