New Issue: Orbital Catastrophe Ahead? Read Now

How does a computer virus scan work?

Geoff Kuenning, a professor of computer science at Harvey Mudd College, provides this explanation.

Malicious software comes in several flavors, distinguished primarily by their method of propagation. The two most pervasive forms are viruses and worms. A virus attaches itself to an existing program such that, when that program is executed, bad things happen. Like a biological virus, it cannot live without a host. In contrast, a worm is an independent program that reproduces itself without requiring a host program. Depending on the form, a worm may be able to propagate without any action on the victim's part. Most malicious software today consists of worms rather than viruses.

Worms and viruses require slightly different protection mechanisms because of their different propagation methods. A virus scanner operates by searching for the signatures of known viruses. A signature is a characteristic pattern that occurs in every copy of a virus. It might be a string of characters, such as a message that the virus will display on the screen when activated, or it might be binary computer code or even a particular bit of data that is embedded in the virus. These patterns are identified by technicians at organizations specializing in computer security and are then made available on security Web sites. Virus scanners can then download the patterns to bring their internal pattern lists up to date.


On supporting science journalism

If you're enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.


There are three complications with this scheme. The first is that the patterns, if ill chosen, can legitimately appear in uninfected files. For example, a pattern containing just the word "hello" would not be very useful. Part of the technicians' job is to find patterns that are unique to the viruses.

The second complication is that virus writers do not want their viruses to be detected, so they engage in a war of stealth techniques. For example, many viruses store themselves in an encrypted form, varying the encryption key as they travel so that the encrypted patterns are different on each victim machine. Virus scanners can beat this technique either by setting their patterns to search for the part of the program that decrypts the virus (this code must necessarily be unencrypted) or by duplicating the decryption operation before doing their matching.

The third complication has to do with performance. Theoretically, a virus could attach itself to any executable program. On a modern computer, there may be hundreds or even thousands of potential host programs. Scanning every one of these programs every time the virus scanner is run would take an unreasonably long time. So virus scanners usually limit themselves to a smaller list of probable hosts. For example, floppy and removable disks are common virus vectors, so removable disks are usually scanned whenever they are inserted. On Microsoft Windows, programs in the \WINDOWS\SYSTEM folder are popular virus targets, so a virus scanner will usually check those files. The scanner's internal pattern list can also identify other files that are known to be targets of a particular virus.

Because worms are independent programs, they are somewhat easier to detect than viruses. Being independent, they must reside in a file of their own somewhere and that file must be constructed such that the computer will automatically execute it. These constraints place limits on such characteristics as where the file can appear and how it is named. The scanner can simply check those well-known places and then apply the same pattern-matching techniques that are used for viruses.

Present-day scanners also look for known vectors for worms. Since most worms propagate through e-mail, a scanner can be set up to look at incoming e-mail before it is delivered to the user and to scan outgoing messages as they are sent. If a worm is detected, it can be removed from the message. If the worm is in an outgoing e-mail, it must, of course, also be removed from the infected computer.

Cleaning up after a worm or virus is relatively straightforward. If a software manufacturer provided an infected file, it can be replaced with a clean copy. Private files cannot usually be replaced but it is possible to delete the infected portion or overwrite it with something harmless. As well as detection patterns, the scanner's master pattern list can contain instructions about what files are normally infected by a particular piece of malicious software and how to clean them up. Like the patterns, security technicians create these instructions, normally at the same time as the patterns themselves.

Subscribe to Support Independent Journalism

Great science journalism requires human expertise, time, effort and creativity. And it costs money. That’s why I and the journalists here at Scientific American hope you’ll join our community.

When you subscribe, you are supporting staff and freelance journalists who are passionate about telling science stories that are true, important and compelling. Our editors and reporters are often experts in their fields, which means they understand the nuances of big discoveries and can untangle the breakthroughs from the hype. With a subscription, you are also supporting rigorous fact-checking to ensure the words we publish are precise and accurate. And you’re supporting original illustrations, graphics and photos that bring you closer to an advanced laboratory, an ice sheet in Antarctica or a space mission in orbit. You’re helping us craft other types of high-quality journalism as well: Our newsletters are carefully written, edited and curated by staffers you have or will come to know and love. Our Science Quickly podcast is based on original reporting, collaboration with editors and scientists and exacting production.

Subscriptions keep this engine running so we can continue to deliver thoughtful, rigorous and independent science journalism to you. In an era of viral misinformation, this work is crucial. If you value what we do, I hope you’ll consider joining us as a subscriber

Thank you,

Jeanna Bryner, Editor in Chief, Scientific American

Subscribe