Malware and Its Types
Distinguish viruses, worms, Trojans, spyware, keyloggers and rootkits by how they spread and what they do once inside.
The program that arrived with an invoice
Sameer Joshi in accounts opens an email attachment called invoice_march.pdf.exe, expecting a bill from a supplier. Nothing seems to happen, so he deletes the email and gets on with his day. Somewhere on his laptop, a program he never meant to install has just started running. Any software written to harm a computer or its user is called malware, short for malicious software. It is the attacker's most common tool, and it comes in families that behave very differently once they are inside.
Two questions sort almost every piece of malware into its family. How does it spread: does it need a person to carry or open it, or does it travel by itself? And what does it do once inside: damage files, watch you, open a door for the attacker, or hide? A doctor asks the same two questions about an infection (how is it caught, what does it do to the body), because the answers decide the treatment. The picture below shows the main ways each family reaches a Tulsi Health counter laptop.
One laptop, five families. Each arrives a different way and does a different job once inside, so each needs a different defence.
Viruses need a host and a human
A virus is malicious code that attaches itself to an ordinary file or program, called its host, and runs when that host is opened. When it runs, it copies itself into other files, which then infect whoever opens them next. Picture a counterfeit page slipped into a library book: every reader who borrows the book and photocopies a chapter for a friend spreads the fake page further, without ever knowing it. The virus cannot move on its own. It travels only when people share infected files, documents or pen drives.
Older viruses lived inside programs, while many modern ones hide in office documents as macros, small automation scripts that a spreadsheet or document can carry. That is why a spreadsheet that asks you to "Enable content" before it will display properly deserves suspicion. At a Tulsi Health store, a pen drive passed between the billing laptop and the photocopy shop next door is a classic way for a virus to travel.
Worms spread by themselves
A worm spreads without anyone opening anything. It finds a weakness in software that listens on the network, for example a file-sharing service with a known flaw that has not been fixed by an update, and uses that weakness to copy itself to the next machine, and the next. It is like a cold in a crowded local train compartment: nobody chooses to pass it on, and being close is enough. Because no human is in the loop, a worm can cross an entire company network in minutes.
The WannaCry outbreak of 2017 is the best-known example: a worm that spread through an unfixed flaw in Windows file sharing and locked files on hundreds of thousands of computers worldwide. If Tulsi Health's laptops share one flat network and all miss the same update, one infected laptop is enough to reach the rest. Step through the spread below and predict what happens at each stage, then switch to the second situation and see what updates and separated networks change.
Trojans arrive as gifts
A Trojan (named after the wooden horse in the old Greek story) is malware disguised as something you want: a free PDF reader, a cracked copy of paid software, a fake "MedLedger update", a game for your phone. You install it yourself because it looks useful, and it often does the useful thing too, while doing something else in the background. It is like an unexpected Diwali gift box from a sender you do not know: the sweets inside may be real, and so may whatever is hidden under them.
Trojans do not usually copy themselves; their job is to get the attacker inside. A common kind is the remote access Trojan, which quietly lets the attacker control the computer from far away, so they can look at files, take screenshots and install more malware. Sameer's invoice_march.pdf.exe is a Trojan. The name ends in .exe, which means it is a program, not a document, and because Windows hides the last part of file names by default, many people see only invoice_march.pdf.
Spyware and keyloggers watch you
Spyware is malware whose job is to watch and report: which websites you visit, what is on your screen, which files you open, and on a phone sometimes your location and microphone. A keylogger is a kind of spyware that records every key you press. It is like a stranger standing just behind you at an ATM, reading your PIN over your shoulder, except this stranger never leaves and writes everything down. Passwords, private messages and customer details all pass through the keyboard.
On a billing laptop, a keylogger would collect the MedLedger login, the staff email password and anything typed into the payment gateway's website. The recordings are sent quietly to the attacker, often in small pieces so they do not stand out. Spyware usually arrives inside a Trojan, so the two families often appear together.
Rootkits hide the evidence
A rootkit is malware built to hide itself, and usually other malware too, by burrowing deep into the operating system, the core software that runs the computer and answers questions about it. When an antivirus program or a person asks the system "which programs are running?", the rootkit changes the answer so that the malicious ones are left out. Imagine a burglar who also bribes the society watchman to tear his entry out of the gate register: the theft is real, but the record that would reveal it has been edited.
A rootkit hooks in beneath the tools that look for it, so those tools see only what it lets them see.
Because a rootkit lies from below, tools running on the infected system cannot fully trust what they see. The reliable fix is drastic: wipe the machine and reinstall everything from a clean source. Some protections stop rootkits before they load, such as Secure Boot, which checks at startup that the software loading the system has not been tampered with. The cards below put all five families side by side.
How each family spreads decides most of its defence: updates stop worms, caution about what you open and install stops viruses and Trojans.
How antivirus recognises known malware
The oldest way to detect malware is to keep a list of fingerprints of files already known to be bad. A fingerprint, called a hash, is a short code calculated from every byte of a file: the same file always gives the same hash, and any change at all gives a completely different one. It works like the barcode on a medicine strip, except that it is computed from the contents themselves. Antivirus software calculates the hash of each new file and compares it with its list of known-bad hashes, which are called signatures. The weakness of this method comes from the same property that makes hashes useful. Change even one character of a known harmful file and its fingerprint becomes completely different, so the near-copy no longer matches anything on the list and passes the scan. Attackers exploit exactly this by changing a few bytes in every copy they send.
The optional cell below lets you watch this happen with a real hash. Short pieces of harmless text stand in for files: a harmless report tool, an exact copy of a known Trojan, and the same Trojan with one character changed. You can press Run without knowing any Python. Then change the 8 at the end of the third file to 7, as the comment suggests, and run it again.
Expected output:
42c0a47bb73cdaa6 no match: allowed
d72b15e3dc842f8b matches the list: blocked
83dad8683a5fafa1 no match: allowed
| Line | What it does |
|---|---|
import hashlib |
Loads Python's built-in tools for calculating hashes |
known_bad = ... |
Calculates the fingerprint of the known Trojan and keeps its first 16 characters. This is the signature list, with one entry |
files = [...] |
The contents of the three new files. The b in front of each piece of text tells Python to treat it as raw file contents |
for contents in files: |
Repeats the indented lines once for each file |
fingerprint = ... |
Calculates that file's fingerprint in exactly the same way |
if ... else |
== asks "are these exactly the same?" If they are, the file is blocked; otherwise it is allowed |
Only the second file is blocked: the third differs from the known Trojan by a single character, gets a fingerprint that shares nothing with it, and is allowed through, which is why a signature list alone cannot keep up with attackers.
Modern antivirus therefore adds behaviour-based detection: instead of asking "have I seen this file before?", it asks "is this program acting like malware?", for example encrypting hundreds of files a minute or reading the keystrokes typed into other programs.
Now put the two questions to work. Each card below describes something Neha found on a Tulsi Health machine; decide which family it belongs to by asking how it spread and what it does.