Offensive SecurityJun 16, 2026 · 10 min read

Malware: the main types and how to defend against them

Viruses, trojans, ransomware, and spyware are different malware with one goal: compromising your systems. See how they differ, get in, and how to defend.
A security analyst reviewing a malware alert on an endpoint protection dashboard.

Malware is the collective name for software built to harm a system, steal data, or hand control to an attacker. The term covers a wide range of programs, from a virus that hides inside a file to ransomware that encrypts a whole estate, but they share one goal: to get into your environment and exploit it for the attacker's benefit. For a regulated company in finance, healthcare, critical infrastructure, or SaaS, a malware infection is rarely just an IT inconvenience. It is a reportable security incident, a potential data breach, and a direct threat to the services your customers and regulators depend on.

Understanding how malware behaves matters because the controls that stop it are not interchangeable. The defenses that block a phishing-borne trojan are different from the ones that contain a worm spreading across a flat network, and both differ from what limits the damage of a fileless attack that never writes to disk. This guide explains what malware is, the main types and how they differ, how it gets in, the stages of an infection, the signs to watch for, and the layered defense that keeps it under control. It also explains why detection and response matter, because no prevention is perfect, and what to do the moment you suspect an infection.

We help companies detect and stop malware before the damage grows, through threat detection and response and managed detection and response, and we test resilience to it through offensive security.

What malware actually is

Malware, short for malicious software, is any code written to act against the interests of the system owner. That intent is what separates it from a buggy application or an aggressive but legitimate program. The intent can be theft of data or credentials, disruption of operations, extortion through encryption, covert surveillance, or simply maintaining a foothold for a later attack. A single piece of modern malware often pursues several of these at once.1

The categories below are useful for understanding behavior, but real attacks rarely fit one box. An attacker might use a phishing email to deliver a trojan, which downloads a rootkit to stay hidden, recruits the machine into a botnet, and finally deploys ransomware. Naming the types helps you reason about how each spreads and what it targets, but you defend against the chain, not the label.

The main types of malware

The types differ in how they spread, what they target, and how they hide. Most campaigns combine several of them, so treat the table as a description of behaviors that show up together rather than mutually exclusive products.1

TypeHow it works
VirusAttaches to a legitimate file or program and spreads when a user runs it.
WormSpreads across a network on its own, with no user action, by exploiting vulnerabilities.
TrojanPoses as a useful program while hiding a malicious function the user installs unknowingly.
RansomwareEncrypts data and demands payment, often after first stealing the data for double extortion.
SpywareSecretly collects data, browsing habits, and credentials and sends them to the attacker.
RootkitHides an attacker's presence and maintains persistent, privileged access to the system.
KeyloggerRecords keystrokes to capture passwords, card numbers, and other typed secrets.
BotnetA network of infected devices the attacker controls remotely for spam, DDoS, or fraud.
FilelessRuns in memory using built-in tools like PowerShell, leaving little or nothing on disk.
The most common types of malware and how each behaves.

Two of these deserve a closer look because they defeat older defenses. Fileless malware lives in memory and abuses trusted system tools, so traditional antivirus that scans files on disk often sees nothing. Ransomware has shifted from simple encryption to double extortion, where the attacker steals the data first and threatens to publish it, so even a clean restore from backup does not remove the leverage. Both are reasons signature-based detection alone is no longer enough.

How malware gets into a system

Almost every infection starts at one of a few predictable entry points, which is exactly where defense has the most leverage. Spending effort here stops the attack before it begins rather than chasing it once it is inside.

  • Phishing messages with infected attachments or links remain the most common entry point, which is why phishing and social engineering defense is central to malware defense.
  • Unpatched vulnerabilities in operating systems, applications, and internet-facing services that attackers exploit within days of disclosure.
  • Infected USB devices and removable media, still effective in environments where staff plug in unknown drives.
  • Pirated or fake software and malicious downloads that bundle a payload with something the user wanted.
  • Supply chain compromise, where trusted software from a vendor is poisoned at the source and delivered through a normal update.

The supply chain route deserves particular attention for regulated firms, because it bypasses the trust you place in your own perimeter. The malware arrives signed and through an update channel you deliberately allowed. This is why vendor risk management and monitoring outbound behavior matter as much as guarding the front door.

The stages of an infection

Malware rarely does its damage the instant it lands. It moves through stages, and each stage is a chance to detect and stop it before the worst happens. Understanding the sequence is what turns monitoring into useful early warning.

  1. 01
    Initial access
    The payload arrives through phishing, an exploited vulnerability, USB media, or a poisoned update, and runs for the first time.
  2. 02
    Execution and persistence
    The malware establishes a way to survive reboots, through registry keys, scheduled tasks, or services, so it is not lost when the machine restarts.
  3. 03
    Command and control
    It calls back to the attacker's infrastructure to receive instructions and download further tools, a step that often shows up as unusual outbound traffic.
  4. 04
    Privilege escalation and lateral movement
    It gathers credentials and moves from the first machine to others, hunting for higher privileges and valuable systems.
  5. 05
    Objective
    It completes its goal: encrypting data for ransom, exfiltrating records, or quietly maintaining surveillance over weeks or months.

The gap between initial access and the final objective is often days or weeks, not minutes. That window is the entire reason detection and response work. An attacker who lands on one laptop has not yet won; an attacker who has moved laterally to your domain controller usually has.

Signs of an infection

Modern malware tries to stay hidden, but it usually leaves traces. None of these signs is conclusive on its own, but each is worth investigating, because early detection limits the damage.

  • A sudden, unexplained drop in performance, or a device that runs hot and slow without obvious cause.
  • Unusual outbound network traffic, especially to unfamiliar addresses or at odd hours.
  • Security tools that have been disabled, or that cannot be re-enabled.
  • Unexpected pop-ups, new browser toolbars, or settings that change on their own.
  • Files that will not open, have been renamed, or carry an unfamiliar extension, a classic sign of ransomware.
  • New user accounts, scheduled tasks, or services that no one in your team created.

Layered defense against malware

No single control stops every infection, so a real defense is built in layers that each make entry, spread, or impact harder. The aim is depth: if one layer fails, another catches the attack before it reaches its objective.

  1. 01
    Deploy EDR or XDR
    Endpoint and extended detection and response watch for malicious behavior, not just known signatures, and can isolate an infected machine automatically. See SIEM, EDR, and XDR for how they fit together.
  2. 02
    Patch quickly
    Patch operating systems, applications, and internet-facing services on a regular cycle, because attackers weaponize known vulnerabilities within days.
  3. 03
    Enforce least privilege
    Give accounts and services only the access they need, so an infection on one account cannot compromise the whole estate.
  4. 04
    Segment the network
    Separate critical systems so a worm or an attacker who lands in one zone cannot move freely into another.
  5. 05
    Keep tested backups
    Maintain regular, offline, and immutable backups, and rehearse the restore, so recovery after ransomware is possible and quick.
  6. 06
    Train your people
    Most infections start with a human action, so security awareness training against phishing has an outsized effect.
Prevention reduces how often you are breached; detection and response decide how badly it hurts when you are.

Why detection and response matter

Prevention is necessary but it is never perfect. Determined attackers find unpatched systems, craft phishing that fools careful people, and use fileless techniques designed to evade your tools. A security program that bets everything on keeping malware out will eventually lose that bet. The question is not whether something gets in, but how fast you notice and how quickly you contain it.

This is where the stages of an infection become an advantage. Because malware needs time to move from a single foothold to its real objective, an organization that watches for command-and-control traffic, lateral movement, and privilege escalation can stop the attack in the gap. Managed detection and response and a strong security operations center exist to shrink that gap, turning what could be a breach into a contained incident. The measure that matters is dwell time: how long an attacker operates before you detect and evict them.

Detection only helps if it leads to a fast, rehearsed response. An alert that no one acts on for hours is little better than no alert at all. That is why a tested incident response plan sits alongside detection, defining who isolates the machine, who decides on disclosure, and who talks to regulators under frameworks like NIS2 and DORA.

What to do if you suspect an infection

The first hour shapes the outcome. Act deliberately, preserve evidence, and avoid the instinct to simply wipe and move on, which destroys the information you need to understand the scope.

  1. 01
    Isolate, do not power off
    Disconnect the affected device from the network to stop spread, but leave it running where possible, so memory-resident evidence is preserved for analysis.
  2. 02
    Engage your responders
    Activate your incident response plan and bring in the people, internal or external, who will investigate. Do not let well-meaning staff start deleting files.
  3. 03
    Scope the incident
    Determine what the malware is, how it got in, and how far it reached, including whether data was accessed or stolen, before you decide on recovery.
  4. 04
    Eradicate and recover
    Remove the malware and its persistence, then restore from clean, verified backups. Rebuild rather than clean where a rootkit or fileless compromise leaves doubt.
  5. 05
    Report and learn
    Meet any regulatory reporting duties under GDPR, NIS2, or DORA, then run a review so the same entry point is closed for good.

How Raptoric helps

We help companies detect and stop malware before the damage grows, through threat detection and response and managed detection and response, and we verify that those defenses hold through offensive security. As an independent, vendor-neutral firm, we are not tied to a single product, so the layered defense we recommend is the one that fits your risk, not a license we resell. Book a scoping call.

Frequently asked questions

What is the difference between a virus, a worm, and a trojan?
A virus attaches to a file and spreads when a user runs it. A worm spreads across a network on its own, with no user action, by exploiting vulnerabilities. A trojan poses as a useful program while hiding a malicious function, relying on the user to install it. They differ mainly in how they spread.
Is antivirus enough to protect against malware?
No. Antivirus catches known malware by its signature, but fileless attacks and custom payloads are built to evade it. You also need behavioral detection through EDR or XDR, fast patching, least privilege, network segmentation, tested backups, and user training. Defense works in layers, not from a single tool.
What is fileless malware?
Fileless malware runs in memory and abuses legitimate built-in tools like PowerShell or WMI, rather than writing a malicious file to disk. Because there is little or nothing on disk to scan, traditional antivirus often misses it. Detecting it requires behavioral monitoring that watches what processes do, not just what files exist.
How does malware spread most often?
The most common entry point is phishing, with infected attachments or links. Close behind are unpatched vulnerabilities in software and internet-facing services, infected USB media, malicious or pirated downloads, and supply chain compromise where a trusted vendor's software is poisoned at the source and delivered through a normal update.
How do I know if a device is infected?
Watch for a sudden drop in performance, unusual outbound network traffic, disabled security tools, unexpected pop-ups, files that will not open or have new extensions, and accounts or scheduled tasks no one created. No single sign is conclusive, but each warrants investigation, because early detection sharply limits the damage.
What should I do first if I suspect malware?
Isolate the affected device from the network to stop spread, but leave it running where possible to preserve evidence in memory. Then activate your incident response plan and bring in responders before anyone deletes files. Scope the incident, eradicate the malware, restore from clean backups, and meet any regulatory reporting duties.

Sources

  1. 1ENISA. ENISA Threat Landscape. European Union Agency for Cybersecurity, 2024. Link
  2. 2NIST. Guide to Malware Incident Prevention and Handling (SP 800-83). National Institute of Standards and Technology, 2013. Link
Related service
Offensive Security
Want this tested on your own systems?
Our team will scope it with you on a 30-minute call.
Book a scoping call