Security and ethical hacking

Malware and its types

Malware is not one category but several different behaviours: one copies itself, one holds a door open, one encrypts your files and one only watches. The useful way to sort them is by behaviour, because the symptom you see and the response you need both come from behaviour, not from the name.

  • Lesson 5 of 12
  • Beginner
  • Free, no signup

Seven behaviours and the symptom each one gives away

Malwaresorted by behaviour
  • Virus

    Attaches itself to other files. A program whose behaviour changed or that throws odd errors.

  • Worm

    Spreads with no human involvement. Internal network traffic with no reason for existing.

  • Trojan

    Poses as useful and you invite it in. For a simple job it asks for unrelated permissions.

  • Ransomware

    Encrypts the files and wants money. Files that will not open and have a changed extension.

  • Spyware

    Watches and sends. The least visible category; its only trace is unfamiliar logins on your accounts.

  • Adware

    Shows adverts and changes the browser. A start page and extensions you never chose.

  • Miner

    Mines currency on your processor. A fan running for no reason and a battery draining fast.

These branches are not separate. A modern sample usually does several of them at once, which is why which type is this is almost never the useful question.

Last checked: Facts and tool names in this lesson are re-checked against their sources on this date.

Why sort by behaviour rather than by name

The names everybody has heard, virus and worm and trojan, are all talking about one thing: how the program got in and how it spreads. A virus attaches itself to another file and travels with it. A worm moves from one machine to the next without human help. A trojan does not spread at all; it poses as something useful and you invite it in.

Those names do not tell you what you will see once you are infected or what you should do. Behaviour tells you that: encrypting your files, reading what you type, holding a door open, burning your processor to mine currency, or simply showing adverts.

And one fact separates this classification from a classroom exercise: a modern sample is usually several of these at once. Something that arrives like a trojan holds the door open for the next thing, collects passwords, and if it is worth the trouble encrypts the files at the end. So which type is this is almost never the useful question.

The useful question is: what is being lost, and what prevents it? If the answer is my files, the defence is backups. If the answer is my passwords, the defence is two-factor and changing passwords from a different device. If the answer is control of my site, the defence lives somewhere else and comes in the fifth section. This lesson is laid out on exactly that basis.

A tree of seven glass creatures, one splitting, one holding a door, one chaining a file, one watching

Seven behaviours, each with the symptom that gives it away

Seven behaviours that almost everything fits into. For each, one sentence on what it does and one symptom an ordinary user can actually see.

Virus. Attaches itself to other files. Its symptom has faded these days and shows up mostly as programs whose behaviour changed or that throw odd errors.

Worm. Moves from machine to machine without human involvement, usually inside a network. A network administrator sees its symptom more often than a user does: internal traffic with no reason for existing.

Trojan. Poses as a useful program. Its symptom is the moment of installation: something that, for a simple job, asks for permissions unrelated to that job.

Ransomware. Encrypts the files and wants money for the key. Its symptom cannot be missed: files that will not open and have a changed extension, plus a note giving payment instructions.

Spyware. Watches and sends: what you type, what your browser saved, sometimes the screen. It is the least visible category and that is what makes it dangerous; its only indirect trace is unfamiliar logins on your accounts.

Adware. Shows adverts and changes browser behaviour. Its symptom is obvious: a start page and a search engine you did not choose, and extensions you do not remember installing.

Miner. Uses your processor to mine currency. Its symptom is physical: a fan running for no reason, a hot device and a battery draining fast while nothing heavy is open.

There is an eighth category with no common name, and for anybody who runs a site it matters more than all of these: a backdoor, a file that exists for no purpose except letting somebody in again. The fifth section is about exactly that.

Ransomware: why the real answer is a backup

Ransomware differs from the rest because it steals nothing; it takes away your access. The files are still there and they do not open. And for exactly that reason it is the only category with one clearly defined defence, and that defence is not technical but operational: having another copy of those same files.

Let us settle the question of paying first, because everybody asks it first. Paying guarantees nothing; what you are buying is a promise from somebody who has already lied to you. Even when a key does arrive, the restore is rarely complete. And in many countries paying such groups carries legal consequences of its own; we put that generally because laws differ and we are not legal advisers. Our practical line: paying is the last option, and with a proper backup you never enter that discussion at all.

Now the real question: which kind of backup survives ransomware? Because much of what people call a backup gets encrypted right alongside the original.

Three properties are needed. First, the copy has to sit somewhere the malware cannot write to. A drive permanently plugged into the computer, a network share that is always mounted, or a synced folder are all reachable by the very program encrypting your files. Second, old versions have to be kept. Syncing alone is not a backup: when the encrypted file replaces the healthy one, the sync service faithfully carries that encrypted version everywhere. What saves you is version history. Third, it has to have been restored at least once for real. A backup that was never tested is an assumption, not a backup.

How to build such a thing in practice, with the tools and the details, has its own lesson in the computer basics track, and we will not repeat it here. We will borrow one sentence from it because it bears directly on this lesson: a backup that has not proved itself is only a claim.

The difference between a backup and a copy that gets encrypted with the original

A backup that survives ransomwareall three needed

The properties that save you

  • somewhere the malware cannot write to
  • keeping older versions, not only the latest state
  • one real restore that has actually been done
  • credentials separate from your everyday account

What does not help in this case

  • a synced folder as the only copy
  • an external drive that is always plugged in
  • a copy on the same computer or the same server
  • a copy nobody has ever opened

The right column is exactly what people call a backup. None of it is wrong; it simply does not work against this one threat.

Where malware actually comes from

The common picture is that infection comes from a dodgy site somebody opened by mistake. In practice there is almost always a human step in the middle, and the user took that step because it seemed reasonable at the time.

Four routes cover nearly all of it. First, the email attachment: a file claiming to be an invoice, a CV or a legal notice. Its tell is usually what the file asks for once opened, such as enabling editing or allowing content to run. If an invoice needs permission to run something in order to display, it is not an invoice.

Second, cracked software and repackaged installers. Somebody has been inside the file to get around the licence, and you do not know whether they only touched the licence or added something else. This route is heavier in Iran because of payment restrictions, and the computer basics track has a lesson that opens it up fully.

Third, the fake update. A page saying your browser or your media player is out of date and you should install the file it offers. One rule closes this route completely: a real update never comes from a web page. Browsers and operating systems update themselves, from inside themselves.

Fourth, the browser extension. It gets said too rarely and its reach is large: an extension is allowed to read and change the content of every page you open. An extension that has been passed around or has changed owners is one of the cleanest ways to watch somebody.

And a fifth route that concerns site owners only: a file a stranger uploads to your site. The next section is about that.

The four routes almost every infection arrives by

  • An email attachment

    An invoice or CV that, once opened, asks for permission to run something.

  • A repackaged installer

    Somebody was inside the file to get around the licence, and you do not know whether only the licence.

  • A fake update

    A page saying your browser is out of date. A real update never comes from a web page.

  • A browser extension

    It is allowed to read and change the content of every page you open.

how it arrived

All four routes have a human step in the middle, and that step always looked reasonable at the time. Which means closing them is a human job too, not only a technical one.

What malware looks like on a website

On a website, malware usually takes the shape of one small file that does one job: it lets anybody who knows its address run commands. The general name is a backdoor, and its value to an attacker is that it keeps working even after every password has been changed. That is why deleting one unfamiliar file and moving on usually does not work.

Now the point that pulls this whole section together: such a file has to sit somewhere the server is willing to execute it. And on a website those places are few. The only folders a visitor can cause a file to be written into are the ones built for uploads and for cache. Which turns the problem from how do we recognise a bad file into a much simpler question: is the folder that strangers write into allowed to execute code?

The right answer is no, and that is a few lines of web server configuration, not a security product. The place where uploaded files land should be able to hand a file over and nothing more. Other work is needed too, such as checking the real content of a file at upload time instead of trusting its extension, but this is the line of defence that stays standing even when the others fail.

And if one day you find an unfamiliar file on a site you run, the order is this: first assume it is not the only one, then restore the site from a backup dated before the event, then change every password and key from a different device, and last of all go looking for how it got in. Skip that last step and the same thing happens again. The service side of this work is on the website security page, and the signs that a site has been compromised are listed in the warning signs of a hacked site.

You think you are infected; what to do, in order

The first thing most people do is the most wrong: they log into email and banking from that same device to check everything is fine. If something really is on the machine, you have just handed it a fresh round of information.

The right order is this. Disconnect the device from the internet so whatever is there can neither send anything out nor pull anything new in. Then from a different device you are confident is healthy, change the password of the main email account and then the other important ones, and in the same settings close the active sessions. Up to this point you have not touched the device itself, and that is correct: rescuing the accounts is more urgent than cleaning the machine.

Then it is the device turn, and here we have an honest answer that is not pleasant. Scanning with a good tool and removing what it finds is enough for simple cases. But when something serious has been on a machine, no tool can promise everything is gone, because the thing that was hiding was good at hiding. For a device that work and money pass through, a fresh install of the operating system and restoring files from a backup is a more reliable answer than any scan.

And one job everybody forgets: after it is clean, change the passwords again. Passwords typed during the infected period, including new ones you created in the middle of it, are no longer trustworthy.

The fast path, with AI

The usual advice about a suspicious file is to scan it with your antivirus, which asks one engine. The fast path asks dozens at once and, more importantly, does it without publishing the file: instead of uploading the file itself you compute its fingerprint and search for that string. If the file has been seen anywhere before, the answer comes back immediately. That difference sounds small and is not: uploading a file to a public service means publishing it. The role of a language model here is only to read the report, not to decide; a fast, cheap model of the Flash class is enough, and our current pick is listed in this site AI section.

  1. Compute the fingerprint of the file on your own machine. On Windows certutil and on Mac and Linux shasum do it, and no special software is needed.
  2. Search that string on a multi-engine service, not the file. If a report exists it opens right there.
  3. Hand the report to the model and ask it to explain the pattern of results, not to deliver a verdict: how many engines flagged it, and whether the names they gave point at one family or are scattered.
  4. If there is no report, stop right there and make a decision: uploading the file means publishing it. For a file holding client data or a work document, the fingerprint search is the end of the road.

Copy-ready recipe

Computing the fingerprint:

  Windows:  certutil -hashfile suspicious.zip SHA256
  Mac and Linux:  shasum -a 256 suspicious.zip

Then search that string, not the file.

The prompt, with the report text attached:

  This is a multi-engine service report about a file.
  Answer only from this text:
  1) How many engines out of how many reported something?
  2) Do the names they gave point at one specific family, or did each
     say something different?
  3) Which names are generic (things starting with generic or heuristic)
     and which are specific?
  4) Is this report old or recent? Give its date.
  Do not rule on whether the file is safe. Only tell me what this report
  says and what it does not say.

Before you trust the output: Three limits, without which this path misleads. First and most important: no report found means not found, not clean. A file built today is in no database, and those are exactly the dangerous ones. Second, uploading a file to a public service means publishing it; people have leaked their own confidential documents exactly this way. For any file holding client data, a contract or personal details, only the fingerprint search is allowed. Third, the model reads the report and never sees your file; a handful of engines reporting something under a generic name on a file the rest call clean is usually a false alarm, and that judgement is still a human job.

AI in this kind of work

On this topic a language model has one clear role: reading things full of unfamiliar names and saying which rows are ordinary. A scan report, a list of running processes, a list of browser extensions. Deciding whether a file is safe is not on that list at all, and the reason is below.

Tools that actually help

  • Gemini For reading a scan report and a process list, on its fast, cheap model. Google own page says the Gemini web app runs in over 230 countries and territories, and Iran is not on that list.
  • Claude For when you want a long report explained row by row. Iran is on neither of Anthropic two supported-countries lists, and we read that on their own page.
  • ChatGPT The same job. We make no claim about access from Iran: OpenAI supported-countries page returns 403 to this server.

Where it backfires

The first risk is asking a model is this file or this process dangerous? It will answer, the answer will look confident, and there is nothing behind it: the model neither opened your file nor saw your machine. Here it is not merely useless but actively dangerous, because people delete real system files on the strength of such answers and then the machine does not boot. Process names are also exactly what malware imitates in order to look ordinary. The second risk is about what you put into the chat: process lists and system logs are full of usernames, machine names and file paths, and a server error report may carry a key or a password. Whether content is retained or feeds training depends on the plan and settings of that service, and the companies write it down, including on Google privacy page for the Gemini apps. The rule is simple: tool output can go, file contents cannot.

Sources: Google: Gemini Apps privacy Where you can use the Gemini web app Anthropic supported countries

Where this advice stops

This lesson is a map, and a map is not a diagnosis. No checklist can tell from the outside whether one particular device is infected; the absence of symptoms is not proof of health, and the least visible category, spyware, is exactly the one that does the most damage. The second boundary was in the last section and we repeat it plainly here: once something serious has been on a machine, cleaning is not reliable and reinstalling the operating system is the more dependable answer. The third boundary is the scope: we talked about computers and websites here, and phones are a separate story, because mobile malware arrives more through permissions and installs from outside the store than through files. And the fourth is that the categories overlap; if you are hunting for one precise label for what you saw, you have probably asked the wrong question.

From our own work

The fifth section of this lesson says the real defence on the site side is refusing to execute code in the folder strangers write into. We wrote that sentence out of the configuration of the very server that handed you this page. In the web server config for this site there are two rules that deny execution of PHP files inside the uploads folder and inside the cache folder, and a third that returns an empty response for the path wp-includes/core.php. That third one is worth explaining: no such file is part of WordPress core at all, and we checked again today that it does not exist on this installation. So any request arriving for that path is either looking for a door somebody left open elsewhere, or trying to find one; either way, no real visitor ever types that address. What those three lines taught us is this: malware on a website is far less about recognising a bad file than you would think, and far more about which folder is allowed to execute. Those three lines, quietly and with no security product involved, catch the thing a scanner would otherwise have to find afterwards.

Real follow-up questions

Is the antivirus built into Windows enough, or should I buy one?

For a home user who keeps the system updated and takes software from official sources, the antivirus built into Windows is enough in practice. What genuinely makes a difference is not buying a more expensive product; it is keeping the operating system and browser current, because most infections arrive through the route those updates close. If you have a budget, spend it on backups.

Do phones get malware too?

Yes, but by a different route. On a phone the main path is not a file; it is installing an app from outside the official store, and then the permissions that app is granted. An app that asks for SMS, contacts and accessibility access in order to do something simple is the thing that should worry you. Reviewing permissions now and then does more on a phone than any scanner.

I found an unknown file on my site; do I just delete it and move on?

No, and the reason is that one file is almost never alone. Whatever managed to place a file once has usually placed more than one and may have created a fresh user or key as well. The right order is restoring from a backup dated before the event, then changing every password and key from a different device, then finding the way in. Skip that last step and the same thing happens again.