0Pricing
Cloud & IT Cert Prep · Lesson

Viruses, Worms, and Trojans

Compare self-replicating viruses, network-spreading worms, and disguised Trojans — understanding how each propagates and what damage it typically causes.

Viruses, Worms, and Trojans is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Makes Software Malicious

Malware (malicious software) is any software designed to disrupt, damage, gain unauthorized access to, or exfiltrate data from systems. The term encompasses many distinct categories that differ in how they spread, what they do, and what detection techniques they evade. Security+ tests your ability to differentiate between malware types by their propagation mechanism (how they spread), payload (what damage or action they perform), and persistence mechanism (how they survive reboots). The three foundational categories are viruses, worms, and Trojans.

Viruses: Infection and Self-Replication

A virus is malware that attaches itself to a legitimate host file and requires a human action (executing the infected file) to spread. When the infected file runs, the virus replicates by injecting its code into other executables, documents, or boot sectors. Virus types include file infectors (attach to .exe files), macro viruses (embed in Office documents and run when macros execute), boot sector viruses (infect the MBR and load before the OS), and polymorphic viruses (change their code signature with each infection to evade signature-based detection).

# Virus detection evasion techniques:
# Polymorphic:  changes code signature each replication
# Metamorphic:  rewrites itself entirely each time (harder to detect)
# Stealth:      intercepts OS calls to hide infected files
# Encrypted:    body encrypted, only decryptor visible to scanner

# File infector: appends or prepends code to executable
# Macro virus:   lives in Office document; runs via VBA macros
# Boot sector:   infects MBR/VBR; loads before OS; bypasses AV

Worms: Self-Propagating Without a Host

A worm is self-replicating malware that spreads independently across networks without requiring a host file or human action. Worms exploit network vulnerabilities or weak credentials to copy themselves to other systems. The 2003 SQL Slammer worm infected 75,000 systems in 10 minutes using a single UDP packet. The 2017 WannaCry ransomware spread as a worm via the EternalBlue exploit targeting SMBv1. Worms cause massive damage through network congestion and payload delivery at scale. Patching and network segmentation are the primary defenses.

# Worm propagation methods:
# Network vulnerability: EternalBlue (SMBv1 RCE) - WannaCry, NotPetya
# Credential brute-force: weak/default passwords (Mirai)
# Email: attaches to outgoing email (ILOVEYOU worm)
# IM/Social: spreads via messaging platforms
# File shares: copies to network drives

# WannaCry timeline:
# 1. Exploits EternalBlue (SMBv1 CVE-2017-0144)
# 2. Installs DoublePulsar backdoor
# 3. Deploys ransomware payload
# 4. Scans for more SMBv1 hosts -> repeat

Trojans: Disguised Malware

A Trojan horse (or Trojan) is malware disguised as legitimate software. Unlike viruses and worms, Trojans do not self-replicate — they rely on the user to install them by believing they are something useful: a free game, a cracked application, a useful utility, a fake antivirus, or a software update. Once installed, the Trojan executes its malicious payload, which may include installing a backdoor, serving as a RAT (Remote Access Trojan), logging keystrokes, or downloading additional malware. Trojans are frequently used to establish initial access before deploying more damaging payloads.

# Trojan examples and categories:
# Backdoor Trojan: opens listening port for remote control
# RAT (Remote Access Trojan): full remote control, keylog, screenshot
#   Examples: DarkComet, NetBus, Sub7, njRAT, AsyncRAT
# Downloader Trojan: downloads and installs additional malware
#   Examples: Emotet (banking -> loader), TrickBot
# Banking Trojan: intercepts online banking sessions
#   Examples: Zeus, Dridex, Ursnif
# Fake AV: pretends to be antivirus, demands payment to 'clean'

Comparing Virus, Worm, and Trojan

The Security+ exam frequently tests the distinctions between these three categories. The critical differentiators: Viruses require a host file and human action to spread; they infect legitimate files. Worms are self-contained and self-propagating — they spread automatically over networks without attaching to other files or requiring user interaction. Trojans are not self-replicating and rely on deception — the user must be tricked into installing them. A piece of malware may combine characteristics (a worm that drops a Trojan payload), so focus on the dominant propagation mechanism when classifying.

# Classification comparison:
# Characteristic      Virus    Worm    Trojan
# Requires host file    YES      NO      NO
# Self-replicates       YES      YES     NO
# Requires user action  YES      NO      YES (install)
# Network spread        SLOW     FAST    NO (user-driven)
# Typical goal          Damage   Spread  Persistence/backdoor

Botnets and Command-and-Control (C2)

Many Trojans and worms establish communication with a Command-and-Control (C2) server — a remote server the attacker uses to issue instructions to infected hosts. A large number of C2-connected hosts forms a botnet. Botnets are used for DDoS attacks, spam campaigns, cryptocurrency mining, and credential theft. C2 communication may use HTTP/HTTPS to blend with normal web traffic, DNS tunneling to hide in DNS queries, or peer-to-peer protocols that have no central server to take down. Detecting C2 traffic requires DNS monitoring, proxy logs, and network flow analysis for anomalous beaconing patterns.

# C2 detection indicators:
# Beaconing: regular outbound connections at fixed intervals
# Unusual DNS: long subdomains, high query volume, new domains
# HTTPS to non-CDN IPs: encrypted C2 often uses bulletproof hosting
# Non-standard port HTTPS: HTTPS on port 8443, 4443, etc.
# Large outbound data: data exfiltration spike

# Block C2 at network level:
# DNS sinkhole + proxy with URL categorization
# Threat intelligence feeds for known C2 domains/IPs

Virus Signature vs Behavioral Detection

Traditional antivirus relies on signature-based detection — comparing files against a database of known malware signatures (hashes or code patterns). Signatures are fast but fail against new or modified malware. Behavioral detection (used by EDR platforms) monitors program behavior in real time: creating child processes, modifying registry keys, injecting code into other processes, or contacting known-bad IPs. Heuristic analysis statically analyses code for malware-like patterns without requiring an exact signature match. Sandboxing executes suspicious files in an isolated environment to observe behavior safely.

# Detection method comparison:
# Signature-based:
#   + Fast, low false-positive rate for known malware
#   - Fails on new, polymorphic, encrypted malware

# Heuristic:
#   + Catches variants of known families
#   - Higher false-positive rate

# Behavioral (EDR):
#   + Catches zero-day and fileless malware
#   - Requires tuning to reduce alert fatigue

# Sandbox:
#   + Definitive judgment by observing actual execution
#   - Sophisticated malware detects sandbox and stays dormant

Multipartite and Macro Viruses

A multipartite virus uses multiple infection vectors simultaneously — infecting both executable files and the boot sector, for example. This makes complete removal harder since cleaning only one vector leaves the other active for reinfection. Macro viruses infect document files by embedding malicious VBA (Visual Basic for Applications) macros in Microsoft Office documents. When the document is opened and macros are enabled, the virus runs. Macro viruses spread easily via email attachments. The primary defense is disabling macros by default and only allowing digitally signed macros from trusted publishers.

# Macro virus defense - Group Policy:
# Office 365/2016+: Trust Center -> Macro Settings
# 'Disable all macros except digitally signed macros'
# Or: 'Disable all macros with notification'
#
# Advanced: Attack Surface Reduction (ASR) rules in Defender:
# 'Block all Office applications from creating child processes'
# 'Block Office applications from creating executable content'
# 'Block execution of potentially obfuscated scripts'

Propagation Prevention Strategies

Preventing malware spread requires layered defenses. For viruses: disable macro execution, scan all file transfers (email gateway, web proxy, USB scanning), and maintain updated endpoint protection. For worms: patch promptly (most worm exploits target known CVEs), disable unnecessary network protocols (disable SMBv1), segment networks to limit lateral reach, and enforce strong authentication on all networked services. For Trojans: enforce application allowlisting, educate users on not installing unauthorized software, and verify software hashes before installation. Defense in depth catches what each individual control misses.

# Disable SMBv1 (prevent WannaCry-style worm propagation):
# PowerShell:
Set-SmbServerConfiguration -EnableSMB1Protocol $false
# Or Group Policy:
# Computer Config -> Admin Templates -> Network -> Lanman Server
# 'Enable insecure guest logons' = Disabled

# Verify SMBv1 is disabled:
Get-SmbServerConfiguration | Select EnableSMB1Protocol

Drive-By Downloads and Watering Hole Attacks

Drive-by downloads occur when visiting a malicious or compromised website silently installs malware without any user action beyond loading the page. Attackers exploit browser or plugin vulnerabilities (old Flash, Java, PDF reader) to execute malicious code. Watering hole attacks compromise legitimate websites that the target population frequently visits, planting drive-by download code to infect visitors. Rather than going directly after the target, the attacker 'poisons the watering hole' and waits for victims to come to it. Defenses include keeping browsers and plugins updated, using click-to-play for plugins, and deploying a web proxy that blocks known malicious sites.

# Drive-by download defense:
# 1. Keep browser, OS, and plugins fully patched
# 2. Disable Flash, Java, and legacy plugins entirely
# 3. Use web proxy with URL filtering
# 4. Enable click-to-play for remaining plugins
# 5. Use browser content security policies (CSP header)
# 6. Consider browser isolation (remote browser in cloud sandbox)
#    -> no local code execution even if site is malicious

Malware Incident Response

When malware is detected, the response follows the NIST IR lifecycle. Containment: isolate the infected host immediately (remove from network or apply host-based firewall rules) to stop spreading. Eradication: reimaging is safer than attempting cleanup for serious infections; cleaning leaves risk of persistence mechanisms surviving. Evidence preservation: take a memory image and disk image before reimaging if forensics are required. Recovery: restore from clean backups, verify integrity, and monitor closely for signs of reinfection. Document indicators of compromise (IoCs) to improve future detection.

# Malware containment (immediate isolation):
# Network level: firewall rule to block host traffic
iptables -I INPUT 1 -s 192.168.1.50 -j DROP
iptables -I OUTPUT 1 -d 192.168.1.50 -j DROP

# Host level: disable network adapter (prevents spread)
ip link set eth0 down

# Memory image before remediation:
winpmem_mini_x64.exe memory.dmp
# Disk image:
dcfldd if=/dev/sda of=/forensics/sda.img hash=sha256

Quick Check

Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.

Lesson Recap

In this lesson you learned: viruses attach to host files and require user action to spread, using techniques like polymorphism to evade signature detection, worms self-propagate across networks without user action by exploiting vulnerabilities, causing rapid large-scale infection, and Trojans are disguised as legitimate software to trick users into installation, often establishing backdoors and C2 communication. Next up we explore ransomware and cryptolockers in detail.

Frequently asked questions

Is the “Viruses, Worms, and Trojans” lesson free?

Yes — the full text of “Viruses, Worms, and Trojans” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.

What will I learn in “Viruses, Worms, and Trojans”?

Compare self-replicating viruses, network-spreading worms, and disguised Trojans — understanding how each propagates and what damage it typically causes. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cloud & IT Cert Prep?

No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Viruses, Worms, and Trojans” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cloud & IT Cert Prep lesson?

Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Viruses, Worms, and Trojans
  2. Ransomware and Cryptolockers
  3. Rootkits, Spyware, and Keyloggers
  4. Fileless Malware and Living-off-the-Land Attacks
← Back to Cloud & IT Cert Prep