Skip to content
Tutorials Center
My learning

Topics

Lesson 49 of 80 ยท Malware and Endpoint Security

Malware Types and How They Spread

Learn the main kinds of malware, how viruses, worms, trojans, ransomware, spyware and botnets spread, and which defenses break each infection path.

Malware is any software built to do something its victim did not agree to: steal data, lock files, spy, take over a machine, or simply cause damage. The word is a blend of "malicious" and "software", and it covers a wide family of programs that differ in two ways that matter to a defender: how they get onto a machine, and what they do once they are there.

This lesson is about recognizing and stopping malware, not building it. You'll learn the classic categories, the infection paths they use, and which defenses break each path. The examples are small simulations on invented data. Nothing here touches real files or networks, and the course never teaches how to write working malware. If you want to see where malware fits in a whole intrusion, The Attack Lifecycle and MITRE ATT&CK is the companion lesson.

Two questions for any malware

When you meet a new sample or an incident report, ask:

  1. How did it arrive and spread? (the delivery and propagation)
  2. What is it for? (the payload and the attacker's goal)

The traditional names mix both answers. A virus and a worm are named for how they spread. Ransomware and spyware are named for what they do. A single piece of malware often combines several, which is why the categories are a vocabulary, not strict boxes.

The main families

Type Defining behavior Needs a user action? Typical goal
Virus Attaches itself to a host file or program and spreads when that host is run or shared Yes (running the infected file) Damage, persistence, spreading
Worm Copies itself across a network on its own, usually through a flaw in a service No Rapid spread, installing other payloads
Trojan Looks like useful software but carries a hidden function Yes (the victim installs it) Remote access, stealing, downloading more malware
Ransomware Encrypts or locks data, then demands payment Often the entry is a phishing click or a stolen password Extortion
Spyware / infostealer Records activity or collects passwords, cookies and files Often a trojan delivers it Account takeover, fraud
Keylogger Records keystrokes Delivered by another method Capturing passwords and messages
Rootkit Hides the malware and its processes from the operating system Needs high privileges first Stealth and persistence
Botnet agent (bot) Connects the machine to a controller that sends commands Delivered by another method Spam, DDoS, proxying, mining
Cryptominer Uses the victim's CPU or GPU to mine cryptocurrency Delivered by another method Quiet profit
Adware / PUP Shows unwanted ads or changes browser settings Often bundled with free software Advertising revenue
Fileless malware Runs inside legitimate tools and memory instead of leaving a program file Often a document or script Evading file-based scanners
Logic bomb Stays dormant until a condition (a date, a deleted account) is met Planted by an insider or earlier compromise Sabotage

Three of these deserve a closer look because they define how people think about malware.

Worms are the reason patching matters. A worm needs no victim to click anything: it finds a machine running a vulnerable service, exploits it, and repeats from the new host. Some outbreaks have crossed the world in hours because every unpatched machine on a flat network was a stepping stone.

Ransomware is today's most costly category for organizations. Modern operators rarely just encrypt files. They first steal copies of the data (so they can threaten to publish it), try to delete or encrypt backups, and demand payment for both the decryption key and silence. This is why recovery planning is part of security. See Backups, Resilience and Business Continuity.

Botnets show the economics. A bot on a home router or a forgotten server has little value alone, but thousands of them rent out as a service to send spam or flood a site. You met the result in Common Network Attacks and Defenses.

Many headlines say "virus" for everything. In incident reports, use the precise word: it tells responders what to look for. A worm means check for lateral spread; ransomware means check backups first.

How malware gets in

flowchart TD
    A["Attacker"] --> B["Phishing email<br/>or message"]
    A --> C["Exploited vulnerability<br/>(unpatched service)"]
    A --> D["Stolen or weak credentials<br/>(RDP, VPN, SSH)"]
    A --> E["Malicious download<br/>or fake installer"]
    A --> F["Compromised supplier<br/>or update"]
    A --> G["Removable media"]
    B --> H["Foothold on one machine"]
    C --> H
    D --> H
    E --> H
    F --> H
    G --> H
    H --> I["Persistence, spread, payload"]

Most intrusions start with one of six doors. Closing them matters more than knowing every malware name.

  • Phishing and malicious attachments or links. Still the most common start. The message tricks a person into opening a document, running a file or typing a password. See Phishing and Social Engineering.
  • Unpatched software. A known, fixed vulnerability in a browser, VPN appliance or server is an open door. Attackers scan the internet for exactly these.
  • Weak or stolen credentials. Remote desktop, VPN and SSH exposed to the internet with a guessable or reused password let attackers log in like an employee. No malware is needed to get in; it is installed afterward. Multi-Factor Authentication and Passkeys is the defense.
  • Malicious or trojanized downloads. Cracked software, fake browser extensions, "free" tools and poisoned search ads deliver trojans and infostealers.
  • Supply chain. An attacker compromises a vendor, a package or an update channel, so the malware arrives signed and trusted. See Dependency and Supply Chain Security.
  • Removable media and shared drives. USB sticks and network shares still spread malware, especially into isolated environments.

Once inside: the typical sequence

After the foothold, many malware families follow a similar path. They establish persistence (a startup entry, a scheduled task) so they survive a reboot, try to gain higher privileges, contact a command-and-control server for instructions, move laterally to other machines, and finally act on their goal: encrypt, steal, or wait. Each step leaves traces, and each is a chance to detect the intruder. Later lessons turn those traces into detections: Detecting Malicious Behavior and Logging, Log Analysis and SIEM.

Simulation: why a worm spreads faster than a virus

You can see why patching and segmentation matter with a very small model. Below, 200 imaginary machines each talk to a few others. A worm infects the neighbors of every infected machine on each tick. We compare a flat network (everyone can reach everyone) with the same machines split into four segments, where only one link connects segments. The random seed is fixed, so the numbers are repeatable. No real network traffic is involved.

Python Worm spread: flat network vs segments

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Look at the three rows. In the flat unpatched network the infection saturates within a few ticks. Patching removes the vulnerable stepping stones, so the worm runs out of targets. Segmentation does not stop the first infection, but it slows the climb because the worm must cross the narrow bridge. Real defenders use both, plus monitoring that notices the outbreak while it is still small. Firewalls, Segmentation and Zero Trust covers the design.

Defenses mapped to infection paths

A useful habit is to pair each door with the control that closes it, instead of buying tools by name. The next snippet is a lookup table you could keep in a runbook. It also counts how many of a sample organization's controls cover each path, which shows gaps at a glance.

Python Which controls cover which door?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The table is a thinking aid, not a score. A single strong control (multi-factor authentication) often matters more than three weak ones, but a door with nothing on it is always worth attention first.

Signs of infection

No single symptom proves malware, but patterns are suspicious: a computer that is suddenly slow with the fan running (a miner), files with a new extension that cannot be opened (ransomware), browser home pages that change, security tools that stop on their own, new accounts or scheduled tasks nobody created, and outbound connections to unfamiliar hosts at odd hours. If you suspect an infection on a real machine, disconnect it from the network (unplug or turn off Wi-Fi) but leave it powered on if you can, and tell your security team. Do not delete things or "clean up" before they have looked, because that destroys evidence. The process is covered in The Incident Response Process.

What to remember

Defenders do not need to memorize malware families. They need layers: patch quickly, require multi-factor authentication, give users the least privilege, restrict what software can run, filter email, segment the network, keep tested offline backups, and collect logs so that a foothold is noticed early. If one layer fails, another has a chance.

Adware, pop-ups and riskware

Adware shows unwanted advertisements, often as persistent pop-ups, injected banners or redirects, and may track browsing. It usually arrives bundled with free software. A sudden rise in pop-ups, a changed home page or a new browser extension you did not install are classic signs. Remove it through the system's app list and the browser's extension page, then run a scan. Browsers' built-in pop-up blocker is the first defense; never click "Allow notifications" on unfamiliar sites.

Riskware (also called potentially unwanted programs) is legitimate software that can be abused, such as remote-administration tools, password recovery utilities or some packet sniffers. It is not malicious by itself, but it is dangerous when an attacker uses it or when it is installed without the owner's knowledge. Many security products flag it for review rather than deleting it.

Spyware at the extreme: commercial mobile spyware

Spyware secretly collects data: keystrokes, screens, microphone, location. At the high end are commercial surveillance tools sold to governments. The best-known example, Pegasus, was reported to use "zero-click" attacks, where a malicious message is processed by the phone without the user touching anything, to read messages and activate sensors on targeted journalists, lawyers and activists. For ordinary people the practical advice is: install updates fast (they close the zero-day holes these tools use), reboot phones regularly, and use the platform's Lockdown Mode if you are at high risk.

Anti-malware tools and 2FA as a safety net

On personal computers the built-in antivirus of the operating system is a good baseline. Second-opinion scanners from reputable vendors (Malwarebytes and similar products) can be run on demand, and free tools have limits: fewer layers of real-time protection, weaker support and sometimes upsell prompts. Download them only from the vendor's own site. Whatever you use, a clean scan is not proof of a clean system, so add two-factor authentication on important accounts: even if malware steals a password, the thief still lacks the second factor. See multi-factor authentication and passkeys.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What most clearly separates a worm from a virus?

    Worms self-propagate, often through a vulnerable network service, while viruses attach to a host and rely on it being executed or passed on.
  2. 2. A program is advertised as a free video converter but also gives an attacker remote access. What is it?

    A trojan pretends to be useful software while carrying a hidden function. The victim installs it willingly, which is how it gets past the first door.
  3. 3. Why do modern ransomware crews often steal data before encrypting it?

    Double extortion makes backups only part of the answer. Restoring files does not stop a leak, so prevention and data minimization matter too.
  4. 4. Which control most directly stops a worm that exploits a known flaw in a network service?

    The worm needs a vulnerable service. Patching removes the flaw, and segmentation limits how far the worm can reach if one machine is missed.
  5. 5. You suspect a workstation is infected. What is the best first step?

    Isolating the machine stops spread and data loss, while keeping it intact preserves evidence for responders. Deleting or reformatting destroys clues.

Summary

  • Malware is classified by how it spreads (virus, worm, trojan) and what it does (ransomware, spyware, botnet agent, miner), and real samples mix both.
  • Most infections begin through phishing, unpatched software, stolen credentials, trojanized downloads, supply-chain compromise or removable media.
  • After the foothold, malware typically persists, escalates, contacts a controller, moves laterally and then acts; each step can be detected.
  • Patching, multi-factor authentication, least privilege, application control, segmentation, backups and logging are layered defenses that close the common doors.
  • On a suspected infection, isolate the machine, preserve evidence and report it.

Next: Phishing and Social Engineering, the most common way malware gets its first foothold.