How Malware Works and Its Types, Explained
If you are reading this, you have probably heard "virus", "worm", "trojan" and "ransomware" used as if they all meant the same thing, and you want to know what each really is, how malware works from start to finish, and what actually protects against it.
By the end you will be able to define malware, follow its path from delivery to damage, tell the main types apart, recognise five real cases and what each taught, explain how malware is detected, and describe the layered defences and the first steps when something is infected. It connects many earlier posts, such as Phishing, Drive-by Attack and Privilege Escalation.
1. What malware is
Malware is short for malicious software: software built to harm, spy on, or take control of a system without the owner's permission. NIST gives several wordings in its glossary, including:
"Software or firmware intended to perform an unauthorized process that will have adverse impact on the confidentiality, integrity, or availability of an information system."
Those three words are the CIA triad. Malware attacks one or more of them: spyware attacks confidentiality, a virus that alters files attacks integrity, and ransomware attacks availability.
Malware is not the same as a bug. A bug is a mistake in legitimate software. Malware is written on purpose to do harm. Malware also often uses bugs (zero-days and unpatched flaws) to get in.
Words you will meet
| Word | Meaning |
|---|---|
| Payload | The harmful part: what the malware actually does once it runs |
| Dropper / downloader / loader | A small program whose job is to install or fetch the real malware. Droppers contain it; downloaders fetch it |
| Command and control (C2) | The server(s) the attacker uses to send instructions to infected machines and collect stolen data |
| Persistence | A way to survive a reboot or log-out, so the malware starts again |
| Indicator of compromise (IOC) | A trace that suggests infection: a file hash, a domain, an IP address, a registry key |
| Exploit | Code that abuses a vulnerability. It is often the delivery tool, not the malware itself |
| Obfuscation / packing | Disguising code so it is harder to analyse or detect |
2. How malware gets in
Malware has to be run somehow. Almost every route is one of these:
| Route | How it works | Related post |
|---|---|---|
| Deceptive messages | An email, text or chat message with a malicious attachment or link. A very common door | Phishing, Smishing, Spam vs Spim |
| Malicious websites and ads | Visiting a page that exploits the browser or tricks you into downloading | Drive-by Attack, Watering Hole Attack |
| Fake or look-alike downloads | A trojanised installer, a cracked program, a fake update, a mistyped address | Typosquatting |
| Unpatched vulnerabilities | Malware that scans for a known flaw and spreads by itself | Zero-day |
| Weak or default passwords on exposed services | Remote desktop, SSH, cameras and routers with factory logins | Brute Force vs Password Spraying |
| Removable media | An infected USB drive plugged in | Stuxnet (section 5) |
| The software supply chain | A compromised update or library installed by a trusted program | OWASP Top 10, A03 |
| Other malware | One infection downloads another. Emotet worked this way | Section 5 |
Notice how often the first step is a person, not a computer. That is why social engineering and malware are so closely linked.
3. What malware does once it runs
Security teams describe attacker behaviour with MITRE ATT&CK, a public catalogue of the tactics (goals) attackers pursue and the techniques they use. Its Enterprise matrix currently lists 15 tactics, each introduced with the sentence "The adversary is trying to…". Malware does not always do every step, but this is the common pattern:
| Tactic (ATT&CK's wording) | What happens | Typical examples |
|---|---|---|
| Initial Access (get into your network) | The first foothold | A phishing attachment opened; an exposed service exploited |
| Execution (run malicious code) | The malicious code starts running | A document macro runs a script; a user double-clicks a fake installer |
| Persistence (maintain their foothold) | It keeps access across restarts and changed credentials | A scheduled task, a startup entry, a new account, a modified system process |
| Privilege Escalation (gain higher-level permissions) | It gets more power | See Privilege Escalation |
| Stealth (hide and conceal their actions, appearing as normal behaviour) and Defense Impairment (break security mechanisms so defenders cannot see or trust what is happening) | It avoids and disables detection | Obfuscated code, switching off security tools, using legitimate built-in tools so nothing looks foreign. (Older ATT&CK versions called this one tactic "Defense Evasion") |
| Credential Access (steal account names and passwords) | It steals logins | Keylogging, reading saved passwords, dumping memory |
| Discovery (figure out your environment) | It looks around | Listing files, users, network shares and other machines |
| Lateral Movement (move through your environment) | It spreads inside the network | Using stolen credentials or a flaw to reach other machines |
| Collection (gather data of interest) and Exfiltration (steal data) | It gathers data and sends it out | Copying documents and uploading them to the attacker |
| Command and Control (communicate with compromised systems to control them) | It talks to the attacker | A regular "beacon" to a server. ATT&CK describes attackers blending in with existing traffic by using ordinary protocols such as web, DNS, mail and file transfer |
| Impact (manipulate, interrupt or destroy systems and data) | The damage | Encrypting files, wiping disks, taking a service down |
This is why defenders talk about breaking the chain: block delivery, stop execution, spot the beacon, limit lateral movement, back up data. Stopping any one step can stop the attack.
4. The types of malware
The three classic "how it spreads" types
NIST's definitions show the difference clearly:
| Type | NIST wording (shortened) | Needs a host program? | Needs a person to run it? | Spreads by itself? |
|---|---|---|---|---|
| Virus | A program that replicates itself by attaching to other programs or files, where it hides until activated | Yes, it infects a host | Yes, the host must run | By infecting files that then get shared |
| Worm | A self-replicating program that propagates itself through a network onto other systems without requiring a host program or any user intervention | No | No | Yes, over the network |
| Trojan horse | A program that appears to have a useful function, but also has a hidden and potentially malicious function | No | Yes, the user installs or opens it believing it is useful | No, it relies on being shared or downloaded |
A good memory aid: a virus hides in other files, a worm crawls across networks on its own, and a trojan is a gift with something inside. A trojan does not copy itself, so it depends on deceiving you, which links it back to social engineering.
What the malware does
| Type | What it does | Key points |
|---|---|---|
| Ransomware | Locks your data (usually by encrypting it) and demands payment. CISA's wording: malware designed to encrypt files on a device, rendering any files and the systems that rely on them unusable | Often double extortion: the attackers also steal data and threaten to leak or sell it if you do not pay |
| Spyware | NIST: software secretly installed to gather information on individuals or organizations without their knowledge | Tracks browsing, records the screen, steals messages and files |
| Keylogger | Records what is typed | A form of spyware. MITRE notes it is used to obtain credentials and cannot easily be stopped by preventive controls alone, because it abuses normal system features, so detection and strong authentication matter |
| Information stealer | Collects saved passwords, cookies, browser data and wallets | Often sold as a service; stolen logins are then used in other attacks |
| Backdoor / RAT | A hidden way back in, or a remote access trojan giving the attacker control of the machine (screen, files, camera) | Gives long-term access, often installed after the first break-in |
| Rootkit | NIST: a collection of files installed on a host to alter its standard functionality in a malicious and stealthy way | Hides the attacker's files and processes, sometimes deep in the operating system or even before it starts (a bootkit). Very hard to remove; reinstalling is often the answer |
| Botnet / bot | A network of infected machines the attacker controls remotely | Used for DDoS attacks, spam, fraud and spreading more malware |
| Cryptominer ("cryptojacking") | Secretly uses your processor to mine cryptocurrency for the attacker | Signs are slowness, heat and high power use |
| Adware / PUP | Shows unwanted ads or changes browser settings; "potentially unwanted programs" | Sometimes bundled with free software, and sometimes a route for worse malware |
| Wiper | Destroys data with no way to get it back | Used for sabotage rather than money |
| Logic bomb | NIST: a piece of code intentionally inserted into a software system that will set off a malicious function when specified conditions are met | The trigger could be a date or an event, such as an account being removed. It is often discussed as an insider threat |
| Fileless / "living off the land" | Abuses legitimate tools already on the system (such as PowerShell) so it blends in with normal activity. CISA and its partners describe this as "living off the land" and note these tools are trusted by security systems, which lowers the chance of detection | Little or nothing new needs to be written to disk, so file scanning helps less and behaviour monitoring matters |
| Dropper / loader / downloader | Delivers other malware | Malware-as-a-service: one group infects machines and sells access to others |
Many real threats combine types. A phishing email delivers a trojan (a fake invoice) that acts as a loader, which installs an information stealer and later ransomware, and uses worm-like spreading inside the network. NIST's malware guide (SP 800-83) calls malware that uses multiple infection or transmission methods a blended attack. Labels describe behaviour, not neat boxes.
5. Five real cases
| Year | Malware | Type | What happened | What it teaches |
|---|---|---|---|---|
| 1988 | Morris worm | Worm | Released on 2 November 1988 by Robert Tappan Morris, then a Cornell graduate student. It spread through a debug mode flaw in the Unix sendmail program, a buffer overflow in the finger service, and weak passwords combined with trusted remote-execution services. It infected about 6,000 computers, roughly 10% of the around 60,000 then connected to the internet (estimates). A design flaw made it re-infect machines repeatedly, which overloaded them. Morris received the first felony conviction under the 1986 Computer Fraud and Abuse Act, and the incident led to the creation of the CERT Coordination Center |
Patching and strong passwords matter, and a network is only as strong as its weakest connected machine |
| 2010 | Stuxnet | Worm | First identified in June 2010 by a Belarusian antivirus company. It exploited four Windows zero-day vulnerabilities, used drivers signed with stolen certificates, spread through USB drives and networks, and stayed dormant unless it found specific Siemens industrial control software. Reports say it damaged centrifuges at Iran's Natanz nuclear facility. No government has officially acknowledged building it, though news organizations widely reported it as a US-Israeli operation | Malware can target physical machines, and an "air-gapped" network can still be reached by a USB drive |
| 2014 onward | Emotet | Trojan, loader, botnet | First detected in 2014, according to Wikipedia. CISA described it as an advanced, modular banking trojan that mainly works as a downloader or dropper of other banking trojans. It spread by spam made to look like payment receipts, shipping notices or overdue invoices, with malicious links, PDFs or macro-enabled Word documents, then used modules that harvest credentials and try to spread across shared drives. It was polymorphic to evade signature-based detection. In January 2021 a coordinated law-enforcement operation, with international activity coordinated by Europol and Eurojust, disrupted it, taking over at least 700 servers. Security reports say it reappeared in November 2021 | Email is the main door; one infection can open the way to many others; criminals sell access; and a takedown disrupts a botnet but may not end it |
| 2016 | Mirai | Botnet | CISA's alert describes a bot that scanned for internet-connected devices such as home routers, cameras and video recorders and logged in using a short list of 62 common default usernames and passwords, building a botnet used for very large DDoS attacks. A September 2016 attack on a security journalist's site exceeded 620 Gbps, and in October 2016 attacks on the DNS provider Dyn disrupted many well-known sites. The source code was published, so copies followed | Default passwords on connected devices are a real threat |
| 2017 | WannaCry | Ransomware that spreads like a worm | Appeared on 12 May 2017 and exploited a Windows SMB vulnerability, MS17-010, for which Microsoft had released a fix on 14 March 2017. CISA reported tens of thousands of infections in over 150 countries; other sources estimate over 200,000 computers. The UK and US governments attributed it to North Korea, which denied involvement. A researcher stopped its spread by registering a domain hard-coded in the malware (the "kill switch"), which did not decrypt files already locked. Mitigations: apply the patch, disable SMBv1 if you cannot, and block the SMB ports at the network edge | Apply security updates promptly. The fix existed two months earlier |
6. How malware is detected and analysed
Detection methods
| Method | How it works | Strength | Weakness |
|---|---|---|---|
| Signature-based | Compares files with a database of known malware (hashes and byte patterns) | Fast and accurate for known malware | Misses new or disguised samples. Emotet's polymorphism was designed to defeat this |
| Heuristic | Looks for suspicious traits in code | Can catch variants | Can raise false alarms (see False Positives and False Negatives) |
| Behavioural / EDR | Watches what programs do: encrypting many files quickly, disabling security tools, odd child processes | Catches new and fileless malware | Needs tuning and monitoring |
| Sandboxing | Runs a sample in an isolated environment and records its behaviour | Shows real behaviour safely | Some malware detects the sandbox and stays quiet |
| Network monitoring | Spots beacons, unusual destinations and bulk uploads | Finds malware that hides on the host | Encrypted traffic limits visibility |
Analysis
Analysts study malware in two ways. Static analysis examines the file without running it (strings, structure, hash, imports). Dynamic analysis runs it in a safe environment and watches what it does (files created, registry changes, network connections). The aim is to extract indicators of compromise that other defenders can use, and to understand what it does and who might be behind it. Tools you will hear about include VirusTotal (its documentation says it inspects files and URLs with over 70 antivirus scanners and URL and domain blocklisting services) and YARA (a tool that helps malware researchers identify and classify samples using rules built from textual or binary patterns).
Safety rule: never run suspicious files on your normal computer. Analysts use an isolated virtual machine with snapshots, no shared folders and a restricted network.
Signs a device may be infected
Unexpected slowness or heat, programs you did not install, browser settings or home page changed, security tools turned off, files renamed or unreadable, a ransom note, unexplained network traffic, pop-ups, or accounts doing things you did not do. None of these proves infection, but together they justify a check.
7. How to prevent it
Because malware uses many routes, no single control is enough. The defence is layered:
| Layer | What to do | Stops or limits |
|---|---|---|
| Patch quickly | Keep operating systems, browsers, apps and device firmware updated | Exploit-based infection, as with WannaCry |
| Reduce what is exposed | Turn off unneeded services and ports (the joint ransomware guide says to disable SMB versions 1 and 2 and move to version 3, and to limit remote desktop), and block SMB from outside the network | Worms, remote exploitation |
| Strong, unique logins and MFA | Change default passwords; use multi-factor authentication (the joint guide recommends phishing-resistant MFA) and unique passwords of at least 15 characters | Mirai-style takeover; reuse of stolen passwords |
| Least privilege | Daily work as a standard user, not an administrator | Limits what malware can do and change |
| Email and web protection | Filter attachments and links; block known bad sites | Phishing delivery, drive-by downloads |
| Control macros and scripts | Microsoft began blocking macros in Office files from the internet by default in 2022 (Windows only; Access, Excel, PowerPoint, Visio, Word and others; Current Channel from 27 July 2022). Keep it on, and restrict script tools such as PowerShell to the people who need them | Document-based loaders such as Emotet |
| Application allowlisting | Allow only approved programs to run | Unknown executables, trojans |
| Endpoint protection (antivirus and EDR) | Signature plus behaviour detection | Known and new malware |
| Backups you can restore | CISA, NSA and FBI advise offline, encrypted backups of critical data, regularly tested. They warn that automated cloud backups may not be enough, because encrypted local files can be synced over good copies | The main way to recover from ransomware without paying |
| Network segmentation | Separate systems so one infection cannot reach everything | Lateral movement |
| Monitoring and logging | Watch for beacons, bulk file changes and new admin accounts | Early detection |
| Trusted sources | Download software only from official sites; check what you install | Trojans, fake updates, typosquatting |
| Awareness training | Teach staff to spot and report suspicious messages | The most common first step |
| USB and device control | Restrict or scan removable media | Stuxnet-style spread |
8. If you think a device is infected
Steps for an individual or a small team. An organization should follow its own incident response plan (see Security Operations); the points below that cite CISA, NSA and FBI come from their joint #StopRansomware Guide.
- Isolate it from the network (unplug the cable or remove it from Wi-Fi) to stop spreading and stop data leaving. The guide's advice for an organization is to isolate in a coordinated way, using out-of-band communication such as phone calls, because attackers may watch for signs they have been discovered and could spread or deploy ransomware faster if they notice.
- Power it off only as a last resort. The guide says to power down devices only if you cannot disconnect them from the network, because powering down loses evidence held in volatile memory.
- Tell the right person (IT or security) straight away.
- Do not log in to other accounts from that device, because a keylogger may record the passwords.
- Keep evidence: note any messages, file names and times, and avoid deleting things before the response team has looked.
- Clean or rebuild: security teams often reinstall from a known-good image rather than trying to clean a device, especially after a rootkit.
- Change passwords from a clean device, and revoke sessions and keys that may have been exposed.
- Restore data from clean backups, after the malware is removed.
- For ransomware: the #StopRansomware Guide says the authoring organizations do not recommend paying ransom, because paying will not ensure your data is decrypted, that your systems or data will no longer be compromised, or that your data will not be leaked. It also points out that paying may pose sanctions risks and advises contacting your local FBI field office. The guide adds that a ransomware event may be the sign of an earlier, unresolved compromise, and lists droppers such as Emotet among the precursors to look for. The No More Ransom project, launched on 25 July 2016 by the Dutch National Police, Europol, McAfee and Kaspersky, offers free decryption tools for some ransomware families.
9. Common mistakes
| Myth | The facts |
|---|---|
| "Virus" means any malware | A virus is one type. The general word is malware |
| "I only get malware from shady sites" | Phishing emails, ads, fake updates and trusted-but-compromised sites also deliver it |
| "Macs, Linux and phones do not get malware" | They get less of certain kinds, but all platforms are targeted |
| "Antivirus is enough" | It is one layer. New and fileless malware can evade signatures, so patching, backups and behaviour monitoring also matter |
| "Deleting the file removes it" | Persistence mechanisms may start it again, and the malware may already have stolen data or opened a backdoor |
| "Ransomware only locks files" | Many groups also steal data first and threaten to publish it |
| "Paying gets everything back" | There is no guarantee, and it funds the attackers |
| "A trojan spreads on its own" | That is a worm. A trojan relies on the user being fooled |
| "If nothing looks wrong, I am clean" | Spyware, rootkits and backdoors are designed to stay unnoticed |
| "Opening the email is what infects you" | Usually opening the attachment or clicking the link does, though some attacks exploit the viewer itself, which is why updates matter |
Closing
Malware is software made to harm, spy on or control systems. It arrives through people (deceptive messages and downloads), through unpatched flaws and weak passwords, and through the supply chain. Once running, it follows a pattern: persist, escalate, evade, steal, spread, talk to its operators and cause damage. The names describe behaviour: viruses attach to files, worms spread by themselves, trojans pretend to be useful, and ransomware, spyware, rootkits and botnets describe what they do. Defence is layered: patch, limit privilege, filter email and web, use multi-factor authentication, keep restorable backups, monitor behaviour, and train people.
Keep these points:
- Malware is a general word; virus, worm, trojan and the rest are types.
- Virus: attaches to a host. Worm: spreads itself. Trojan: pretends to be useful.
- Most infections start with a person opening, clicking or installing something.
- Malware follows a chain; breaking any link stops the attack.
- Patching, least privilege, MFA, offline backups and behaviour monitoring are the core defences.
- CISA, NSA and FBI do not recommend paying a ransom; isolate, report, and rely on tested offline backups and free decryption tools where they exist.