What Is a Computer Virus? Types, Lifecycle & Defense Guide. Computer Virus vs Malware

Learn what a computer virus is, how it differs from worms, and explore 13 major types (Polymorphic, Boot Sector, Macro) along with detection and defense tips.

Vikash KushwahaVikash Kushwaha
10 min read
What Is a Computer Virus? Types, Lifecycle & Defense Guide. Computer Virus vs Malware

Advertisement

A computer virus is a parasitic, self-replicating type of malicious software engineered to alter device operations by inserting its own executable instructions into legitimate host binaries, system records, or macro-supported documents. Unlike autonomous worms that propagate across networks independently, a true computer virus requires a host carrier file and an execution trigger—such as a user launching an infected application—to activate its replication routine and execute its payload.

Once executed in volatile memory, a computer virus compromises data integrity, corrupts filesystem allocations, consumes computational resources, and systematically contaminates clean local or shared files. Understanding the mechanics of viral code injection, evasion routines, and persistence architectures is critical for effective threat hunting and incident response.

Anatomy of the Viral Infection Lifecycle

A computer virus executes its operations through four distinct chronological phases:

  • The Dormant Phase: The virus resides undetected within an infected host file or physical drive sector. During this phase, it avoids executing malicious actions to evade heuristic monitoring and prolong its stealth profile until a preconfigured trigger (such as a specific calendar date, reboot counter, or application launch) is met.
  • The Propagation Phase: When the host file is executed, the virus launches into active system memory. It scans the storage environment—such as local directories, mapped network drives, or removable media—and inserts copies of its machine code into target binaries, expanding its footprint.
  • The Triggering Phase: A logic condition transitions the virus from simple propagation to operational activation. Triggers can include system idle timers, specific user keystrokes, or reaching a set threshold of infected files.
  • The Execution Phase: The virus executes its payload. Depending on the author's intent, this can range from harmless visual alerts to data exfiltration, arbitrary disk overwriting, or firmware bricking.

Technical Taxonomy: Primary Types of Computer Viruses

Computer viruses are categorized by where they reside, how they attach to host files, and the evasion techniques they employ to bypass endpoint security controls.

Spacefiller (Cavity) Viruses

Standard file infectors typically append or prepend their malicious code to the ends of a target binary, altering the file's overall byte size and triggering integrity-check alarms. Spacefiller viruses instead analyze the internal structure of executable formats (such as Portable Executables / PE files) to identify unallocated, empty blocks of code known as cavities.

  • By splitting its code and inserting it into these empty gaps without expanding the host file's byte count, the cavity virus maintains the original file size.
  • This technique allows the virus to evade simple size-comparison monitoring tools and legacy integrity verifiers.

Encrypted Viruses

To evade static signature scanners, an encrypted virus encrypts the main body of its code, prepending a lightweight, unencrypted decryption stub.

Advertisement

  • Every time the virus infects a new host binary, it generates a new cryptographic key, ensuring that the encrypted body of the code looks different on disk in every instance.
  • Antivirus scanners struggle to detect the virus using disk signatures alone. Instead, they must catch the file in active memory during execution, when the decryption loop unpacks the plain-text malicious instructions into RAM.

Companion Viruses

Companion viruses exploit operating system execution priority rules rather than modifying existing file contents directly.

  • In DOS and Windows environments, running a command without an explicit extension causes the shell to execute files following a predefined hierarchy (e.g., executing .com files before .exe files).
  • A companion virus creates an infected clone named program.com in the same directory as a legitimate program.exe. When the user types program, the system inadvertently executes the companion virus first, which runs its malicious routine before silently launching the real program to avoid user suspicion.

Network Viruses

Network viruses specialize in lateral movement across corporate intranets and Local Area Networks (LANs).

  • These threats rapidly probe for open network shares, misconfigured file permissions, and exposed administrative protocols (such as SMB or RPC).
  • Once a network share is compromised, the virus drops infected executables or script hooks into shared directories accessed by multiple client workstations, triggering network-wide outbreaks.

Macro Viruses

Macro viruses target productivity platforms that support embedded automation scripts, most notably Microsoft 365, Word, and Excel.

  • Written in Visual Basic for Applications (VBA), macro viruses embed their instructions directly into shared documents, templates (.dotm), or spreadsheets.
  • When a user opens an untrusted document and enables macros, the virus executes, infecting the user's global document template (Normal.dotm). Every subsequent document created or opened on the system automatically receives the malicious macro code.

File Infector (Append and Prepend) Viruses

The standard category of viral malware attaches itself directly to binary files (such as .exe, .dll, .sys, or .com).

  • Prependers: Inject malicious code directly at the entry point of the binary, ensuring the virus runs immediately when the application is launched before passing execution back to the legitimate program.
  • Appenders: Attach the virus code to the end of the file and redirect the binary's entry point address in the PE header to point to the malicious code block first.

Nonresident Viruses

A nonresident virus executes without maintaining a permanent, continuous presence in volatile memory (RAM).

Advertisement

  • It contains a dedicated finder module that activates only when the infected host file is launched.
  • The finder module searches local directories and storage drives for uninfected target files, writes the virus code into them, and immediately terminates its process, leaving zero running background processes for task managers to flag.

Resident Viruses

Unlike nonresident variants, a resident virus installs itself directly into volatile system memory (RAM) upon initial execution.

  • It remains active in memory even after the original host application terminates, hooking into operating system system calls and interrupt vectors.
  • Whenever the operating system opens, copies, or runs any clean file, the resident virus intercepts the operation in memory and infects the target file on the fly.

Stealth Viruses

Stealth viruses hide from diagnostic tools by intercepting input/output system calls directed at the operating system storage layer.

  • When an antivirus scanner or file integrity monitor requests read access to an infected binary to calculate its hash or check for signatures, the stealth virus intercepts the call.
  • It temporarily feeds the security software a clean, uninfected version of the file from memory, disguising unauthorized modifications until the system is booted into a clean, uninfected environment.

Sparse Infectors

Sparse infectors delay discovery by deliberately limiting how often and under what conditions they infect new files.

  • Rather than contaminating every file it encounters, a sparse infector may only infect every twentieth executed file, target files that fall within a strict kilobyte size range, or activate only on specific days of the month.
  • This slow infection pace prevents rapid performance drops or mass file timestamp modifications that typically alert systems administrators.

Overwrite Viruses

An overwrite virus is designed for direct disruption.

  • Instead of inserting code and preserving host functionality, it systematically overwrites the host file's existing data with its own code.
  • The original application instructions are destroyed. Once an overwrite virus affects a file, the file cannot be disinfected or repaired; it must be completely deleted and restored from clean backups.

Boot Sector (System Record) Infectors

Boot sector viruses target physical storage records, specifically the Master Boot Record (MBR) or partition boot sectors of physical hard drives and external USB storage.

Advertisement

  • If an infected bootable drive is connected during startup, the computer reads the compromised boot sector before loading the operating system kernel.
  • This allows the virus to execute before endpoint security agents and operating system protections initialize, giving it low-level control over hardware interrupts and disk access.

Multipartite Viruses

Multipartite viruses combine multiple infection and propagation techniques into a single payload.

  • They can simultaneously infect system executable files and the storage drive's boot sector.
  • If a systems administrator purges the infected .exe files from disk but overlooks the corrupted boot record, the virus re-executes on the next system reboot, reinfecting clean executable applications across the drive.

Polymorphic Viruses

Polymorphic viruses constantly mutate their physical binary signature while preserving their underlying logic.

  • Using an internal mutation engine and dynamic encryption routines, the virus changes its encryption key, decryption algorithms, and instruction sequencing with every replication.
  • Because signature-based antivirus scanners rely on static byte patterns to identify known threats, polymorphic code changes its digital footprint on every copy, requiring advanced behavioral analysis and CPU emulation sandboxes for detection.

Architectural Comparison: High-Risk Virus Categories

Understanding the operational profiles of high-risk virus variants helps clarify their primary target zones, evasion mechanisms, and damage potential:

Boot Sector Infectors

  • Primary Target Zone: Master Boot Record (MBR) and drive partition sectors.
  • Evasion Strategy: Executes during initial hardware boot stages before the operating system and endpoint detection agents load into memory.
  • Impact Profile: Critical; achieves low-level persistence below OS security controls and requires hardware-level sector rebuilding.

Polymorphic Viruses

  • Primary Target Zone: Executable files, dynamic libraries, and memory address spaces.
  • Evasion Strategy: Mutates internal encryption algorithms and code structures on every replication cycle to bypass static signature databases.
  • Impact Profile: Critical; evades traditional pattern-matching engines and requires behavioral heuristics or sandboxed emulation.

Multipartite Viruses

  • Primary Target Zone: Executable application binaries and physical boot sectors simultaneously.
  • Evasion Strategy: Multi-stage persistence; uses uncleaned boot sectors to regenerate purged files after cleanup attempts.
  • Impact Profile: Critical; causes persistent reinfection loops if remediation does not clean both files and drive sectors at the same time.

Stealth Viruses

  • Primary Target Zone: Operating system interrupt tables and file system read APIs.
  • Evasion Strategy: Intercepts antivirus read requests and returns false, clean file attributes and hashes to scanners.
  • Impact Profile: High; conceals ongoing infections from standard administrative inspection tools.

Defensive Engineering: Detection and Remediation Protocols

Protecting enterprise endpoints and consumer systems from viral contamination requires multi-layered technical controls:

  • Heuristic and Behavioral Endpoint Protection: Modern Endpoint Detection and Response (EDR) platforms use dynamic behavioral heuristics and memory sandboxing rather than relying solely on static file signatures. These systems monitor for unauthorized API hooking, process memory modifications, and rapid file-write bursts.
  • Default Macro Hardening: Modern office productivity suites should be configured to disable all unsigned VBA macros by default. Blocking macros from running in files downloaded from external or internet zones neutralizes the primary delivery path for macro-based infections.
  • Secure Boot Implementation: Modern Unified Extensible Firmware Interface (UEFI) Secure Boot cryptographically validates bootloader signatures before handing over system execution, preventing unauthorized boot sector viruses from loading ahead of the operating system.
  • Least Privilege and Access Controls: Enforcing the Principle of Least Privilege (PoLP) ensures that standard domain users lack administrative rights. Without elevated privileges, executed viruses cannot write to system directories, modify MBR sectors, or alter protected registry keys.
  • Integrity Monitoring and Offline Remediation: Deploying automated file-integrity monitoring (FIM) allows administrators to detect unauthorized binary alterations and anomalous hash deviations immediately. If a system is compromised, disconnecting it from the network and booting into an isolated, clean operating environment ensures stealth and resident viruses cannot interfere with the cleanup process.

Note: "All technical concepts, case studies, and security frameworks discussed on this website are provided strictly for educational and defensive cybersecurity analysis."

Advertisement

🚀 Found This Insightful? Share the Knowledge

Know a student, colleague, or fellow science and tech enthusiast who would enjoy this? Pass it along in one click.

Share this article

Link copied to clipboard!
Vikash Kushwaha

About the Author

Vikash Kushwaha

Founder of EducationalTechs, exploring the intersections of education, emerging technology, career growth, space exploration, and science. Focused on turning complex ideas and new discoveries into clear, actionable guides for students, professionals, and curious minds.

Follow:

Related Posts

🔭 Stay Curious, Stay Ahead

Your weekly dose of science breakthroughs, space discoveries, emerging tech, and practical career & learning guides.

Enter your email to get our best explainers and future-ready insights delivered straight to your inbox—zero spam.

💬 Join the Conversation

What are your thoughts on this topic? Share your perspective, ask a question, or suggest a science, tech, or career topic you'd like us to explore next.