Types of Malware: How Infections Happen, Prevention and Response
What is malware?
Malware (malicious software) is any program or code written to harm a system, steal data, spy on users or take control of devices without permission. Common types include viruses, worms, trojans, ransomware, spyware, rootkits and bots. Malware usually arrives through phishing, unpatched software, malicious downloads or stolen credentials, so prevention combines technical controls with careful user habits.
The main types of malware
| Type | How it behaves | Typical impact |
|---|---|---|
| Virus | Attaches to a host file or document and runs when it is opened | Corrupts files, spreads through shared files |
| Worm | Spreads by itself across networks by exploiting vulnerabilities | Rapid outbreaks, network disruption |
| Trojan | Pretends to be legitimate software to trick the user into running it | Installs backdoors or other malware |
| Ransomware | Encrypts files and demands payment; often steals data first | Business shutdown, data leak threats |
| Spyware and infostealers | Secretly collects keystrokes, passwords, cookies and browser data | Account takeover, fraud |
| Rootkit | Hides itself and other malware deep in the operating system or firmware | Long-term hidden control |
| Bot and botnet | Infected devices controlled together through a command-and-control server | DDoS attacks, spam, credential stuffing |
Real samples often combine types: a trojan delivered by email may install an infostealer, then ransomware. Other names you will meet include adware, cryptominers, remote access trojans (RATs) and fileless malware, which runs in memory using built-in tools such as PowerShell.
How infections happen: common vectors
- Phishing: malicious attachments, links to fake downloads or credential theft pages. See recognising phishing.
- Unpatched internet-facing services: VPN gateways, remote desktop, web applications and file-transfer servers with known vulnerabilities.
- Stolen or weak credentials: exposed RDP or SSH with reused passwords and no MFA.
- Pirated software and cracks: a frequent source of trojans and infostealers.
- Malicious ads and fake update pop-ups: drive-by downloads from compromised or look-alike websites.
- Removable media: infected USB drives moved between computers.
- Supply chain: a compromised software update, browser extension or third-party package.
Notice that most vectors need either a human action or a missing patch. That is why prevention focuses on both.
Prevention: layered defences
- Patch promptly: operating systems, browsers and especially internet-facing devices. Turn on automatic updates.
- Run endpoint protection: Microsoft Defender or an EDR product, kept updated and monitored.
- Use least privilege: daily work in standard accounts, administrator rights only when needed.
- Enforce MFA: on email, VPN, remote access and admin portals.
- Filter email and web traffic: block executable attachments and Office macros from the internet.
- Segment the network: so one infected laptop cannot reach every server, as explained in network security fundamentals.
- Keep backups that malware cannot reach: follow the 3-2-1 approach with at least one offline or immutable copy, and test restores.
- Allow only approved software: application allow-listing on servers and high-risk machines.
# Windows PowerShell: check Microsoft Defender status and run a quick scan
Get-MpComputerStatus | Select-Object AMServiceEnabled, RealTimeProtectionEnabled, AntivirusSignatureLastUpdated
Update-MpSignature
Start-MpScan -ScanType QuickScan Signs of infection and quick checks
Symptoms include unexpected pop-ups, a browser home page that changes, files renamed with unfamiliar extensions, security tools that are suddenly disabled, unusual outbound traffic, new user accounts and high CPU use when the machine is idle. None proves an infection on its own, but each deserves a check.
# Linux: look for unexpected listeners, processes, services and scheduled jobs
ss -tupn # current connections and their processes
ps aux --sort=-%cpu | head -n 10 # busiest processes
systemctl list-units --type=service --state=running
crontab -l; ls -la /etc/cron.d/ # scheduled tasks
sha256sum /path/to/suspicious-file # hash to compare with threat intelligenceMore on reading these outputs is in our Linux commands reference.
Responding to a malware infection
- Isolate: disconnect the device from the network (unplug the cable or disable Wi-Fi). Avoid shutting it down if investigators may need memory evidence.
- Report: tell your IT or security team at once. Organisations in India must report specified incident types to CERT-In within six hours of noticing them, under its 2022 directions.
- Identify: find the malware, how it got in and which accounts and systems it touched.
- Contain and eradicate: block the indicators, reset exposed passwords from a clean device, and usually rebuild affected machines from known-good images.
- Recover: restore data from clean backups and monitor closely for signs of return.
- Learn: record what happened and fix the gap that allowed it.
Rebuilding is usually safer than cleaning. Antivirus may remove the file it detected while leaving behind a second backdoor, a new scheduled task or a stolen password the attacker can reuse. Reinstalling from a trusted image, then restoring only data files that have been scanned, removes that doubt. Keep the hashes, file names, IP addresses and domains you found, because they help other teams search for the same infection elsewhere.
Practical exercise: harden and test one computer you own
- Confirm that automatic updates and real-time protection are on, and record the date of the last signature update.
- Create a standard user account for daily use if you currently work as an administrator.
- Download the EICAR anti-malware test file from its official website on your own machine and confirm your antivirus detects it. It is a harmless test string, not real malware.
- List every running service and listening port, and research any you do not recognise.
- Back up an important folder to an external drive, disconnect it, then restore one file to prove the backup works.
You are done when you have a one-page checklist showing each control and its result. Endpoint and network defence labs are part of the Networking Foundation course.
Common mistakes
- Keeping the only backup on a drive or share that stays connected, where ransomware can encrypt it too.
- Installing cracked software or unknown browser extensions on a work machine.
- Wiping an infected machine before anyone has worked out how the attacker got in.
- Changing passwords from the infected computer, where a keylogger can capture the new ones.
- Exposing remote desktop directly to the internet without a VPN and MFA.
Frequently asked questions
What is the difference between a virus and a worm?
A virus needs a host file and a user action to spread, such as opening an infected document. A worm spreads on its own across networks by exploiting vulnerabilities.
Can phones get malware?
Yes. Android and iOS devices can be infected, mostly through malicious apps from outside official stores, fake APK files shared over messaging apps and links in SMS messages.
How do I check whether a file is known malware without running it?
Calculate its SHA-256 hash and search for that hash in a reputable threat intelligence service, or scan the file with your endpoint protection. Never open an unknown file just to see what it does; analysts use isolated sandboxes for that.
Is free antivirus enough for a home computer?
For most home users, the built-in Microsoft Defender with automatic updates, a standard account, MFA on important accounts and offline backups gives sound protection. Businesses usually need centrally managed EDR.