TExcelTAD
Home › Cybersecurity › Malware Types & Defences

Malware Types & Defences

Malware (malicious software) is any program designed to harm, spy on or take control of a system. This lesson explains the main families, how they typically arrive, and the layered defences that stop them. It is purely conceptual: understanding behaviour is what lets defenders detect it.

Malware families

Type What it does How it spreads Typical sign
Virus Attaches to legitimate files and runs when they run Infected files shared by users Modified executables or documents
Worm Copies itself across networks without user action Exploits unpatched network services Sudden spike in connections between hosts
Trojan Pretends to be useful software Fake downloads, cracked software Unknown programs installed with "free" tools
Ransomware Encrypts files (and often steals them first), demands payment Phishing, exposed remote desktop, stolen VPN credentials Mass file renames, ransom notes
Spyware / infostealer Steals passwords, cookies, crypto wallets Malicious ads, trojans Logins to your accounts from unknown places
Keylogger Records keystrokes Bundled with trojans Usually invisible
Rootkit Hides itself and other malware deep in the OS After initial compromise Tools give inconsistent results
Botnet agent Joins a network of machines controlled remotely Worms, trojans, weak IoT passwords Regular "beacon" traffic to a command server
Adware / PUP Unwanted ads and toolbars Bundled installers Browser hijacking
Fileless malware Lives in memory and abuses built-in tools (PowerShell, WMI) Malicious documents, exploits Unusual command lines from Office apps

Real campaigns combine these: a phishing email delivers a trojan, which installs an infostealer, whose stolen credentials are sold to a ransomware group.

How malware gets in

Most infections still start in a few predictable ways, which is good news, because each has a known defence:

  • Phishing attachments and links: email filtering, attachment sandboxing, disabling Office macros from the internet, user training.
  • Unpatched internet-facing services: patching, reducing exposure.
  • Stolen or weak credentials for remote access: MFA, no RDP on the internet.
  • Malicious downloads: application allow-listing, standard (non-admin) user accounts.
  • Removable media: disable autorun, device control policies.
  • Supply chain: signed updates, dependency review.

Detection approaches

Approach Idea Strength Weakness
Signatures / hashes Match known-bad file hashes or byte patterns Precise, fast Trivially changed by attackers; misses new malware
Heuristics Score suspicious features (packed code, odd imports) Catches variants False positives
Behaviour (EDR) Watch what processes do Catches new and fileless malware Needs tuning and analysts
Sandboxing Run suspicious files in an isolated VM and observe Reveals hidden behaviour Malware may detect the sandbox
Allow-listing Only approved programs may run Very strong Effort to maintain

Hash matching against threat intelligence

The simplest check compares a file's SHA-256 with a list of known-bad hashes (indicators of compromise) shared by threat intelligence feeds. The "files" here are just harmless sample bytes:

python · try it yourself
import hashlib

files = {
    "invoice.pdf": b"%PDF-1.7 harmless sample invoice",
    "setup.exe": b"MZ sample installer marked bad by the feed",
    "notes.txt": b"meeting at 10",
}
KNOWN_BAD = {hashlib.sha256(b"MZ sample installer marked bad by the feed").hexdigest(): "Trojan.Demo"}

for name, content in files.items():
    digest = hashlib.sha256(content).hexdigest()
    verdict = KNOWN_BAD.get(digest, "no match")
    print(f"{name:<12} {digest[:16]}…  {verdict}")
invoice.pdf  5f8a0ccb7bb4eef0…  no match
setup.exe    6f87c33cbac9328a…  Trojan.Demo
notes.txt    03708019b4bad504…  no match

Changing a single byte of the malware gives a new hash, so hash lists only catch exact copies. That is why modern defences focus on behaviour.

Behaviour scoring

Behavioural detection looks at what a process does. Some actions are rarely legitimate together: a word processor starting a script interpreter, mass file renaming, deleting backup shadow copies. An EDR-style model assigns weights and alerts above a threshold:

python · try it yourself
WEIGHTS = {
    "office_app_spawns_script": 40,
    "downloads_executable": 20,
    "disables_security_tool": 50,
    "deletes_shadow_copies": 60,
    "renames_many_files": 40,
    "beacons_every_60s": 30,
    "runs_from_temp_folder": 15,
}
THRESHOLD = 80

processes = {
    "WINWORD.EXE -> powershell": ["office_app_spawns_script", "downloads_executable",
                                  "runs_from_temp_folder", "beacons_every_60s"],
    "backup-agent": ["renames_many_files"],
    "invoice_viewer.exe": ["runs_from_temp_folder", "disables_security_tool",
                           "deletes_shadow_copies", "renames_many_files"],
}
for name, behaviours in processes.items():
    score = sum(WEIGHTS[b] for b in behaviours)
    action = "ISOLATE HOST" if score >= THRESHOLD else "log only"
    print(f"{name:<28} score={score:>3}  {action}")
WINWORD.EXE -> powershell    score=105  ISOLATE HOST
backup-agent                 score= 40  log only
invoice_viewer.exe           score=165  ISOLATE HOST

The backup agent renames many files too (legitimately), but on its own that stays below the threshold. The fake invoice viewer shows the typical ransomware sequence: disable defences, delete shadow copies, encrypt and rename files.

Defence checklist

  1. Patch operating systems, browsers and internet-facing services quickly.
  2. EDR/antivirus on every endpoint and server, centrally monitored.
  3. Least privilege: users work without admin rights; admins use separate accounts.
  4. Block macros from internet documents; restrict script interpreters for normal users.
  5. Application allow-listing on servers and high-risk machines.
  6. Email and web filtering, with attachment sandboxing.
  7. Segment the network so one infected laptop can't reach everything.
  8. Offline, tested backups: the last line of defence against ransomware (see the Backups lesson).

Note: Analysing real malware is a specialist job done in isolated labs. If you suspect an infection, don't investigate on a production machine: isolate it and follow your incident response process.

Go further: Families of Malware Behaviour classifies samples by what they do, and the course goes on to safe static and dynamic analysis.

Test yourself

Which type of malware spreads across networks by itself, without user action?

  1. Trojan
  2. Worm
  3. Adware
  4. Keylogger

Why are file-hash blocklists alone a weak defence?

  1. Hashes are secret
  2. Changing one byte of the malware produces a new hash
  3. Hashing is too slow
  4. Hashes only work on Linux

A word processor starts PowerShell, which downloads an executable. What kind of detection flags this best?

  1. Signature matching
  2. Behavioural detection (EDR)
  3. Disk encryption
  4. Password policy