Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 55 ยท Security and Care

Malware, Phishing and Safe Habits

Learn what viruses, ransomware and spyware do, how phishing and scams trick people, and the habits that keep you safe: updates, least privilege and firewalls.

Most computer break-ins do not start with a movie-style hacker typing furiously. They start with an ordinary person clicking something, opening something or trusting something they should not have. Attackers go after people because people are easier to fool than well-built software. The good news is that a small set of habits blocks the large majority of everyday attacks.

This lesson describes the main kinds of malware (malicious software), explains phishing and other scams, and then turns the defenses into habits: updates, least privilege, firewalls and healthy suspicion. The stand-ins are small JavaScript scorers; they show how rules can flag danger, and also why rules alone are never enough. It builds on Passwords, Hashing and Encryption and What an Operating System Does.

The malware family

"Virus" is used loosely for everything bad, but the names describe different behavior:

  • Virus: code that attaches itself to a legitimate file or program and spreads when that file is shared or run. It needs a person or a program to carry it.
  • Worm: spreads on its own across networks by exploiting a weakness in software, with no click needed.
  • Trojan: pretends to be something useful, such as a free tool or a cracked game, but does harm when you run it. It does not spread by itself; you invite it in.
  • Ransomware: encrypts your files (see encryption in the previous lesson) and demands payment for the key. Backups are the best defense, because paying does not guarantee you get the data back. See Backups and Data Recovery.
  • Spyware and keyloggers: secretly watch what you do or record what you type, to steal passwords and card numbers.
  • Adware and unwanted extensions: flood you with ads or change your browser's search page.
  • Botnet client: quietly makes your computer one of thousands that attackers rent out to send spam or attack websites.
  • Rootkit: hides itself deep in the system so that normal tools cannot see it.

How does malware get in? Rarely by magic. The common doors are: email attachments and links, downloads from untrustworthy sites, pirated software, infected USB drives, malicious browser extensions or fake apps, and unpatched security holes in software you already have.

Signs of infection include sudden slowness, programs you did not install, a changed browser start page, constant pop-ups, a fan that runs at full speed when you are idle, or files that suddenly cannot be opened. None of these proves infection (see Troubleshooting, Performance and Upgrades), but together they justify a scan.

Phishing and other scams

Phishing is a message that pretends to come from a trusted sender, such as a bank, a delivery company, a boss or a government office, to make you click a link, open a file or give away a secret. The same trick has other names: smishing (by text message), vishing (by phone call), and spear phishing (a message written specifically for you, using details found online). Related scams include fake tech-support pop-ups, romance and investment scams, and "your relative is in trouble" calls.

Nearly all of them pull the same levers:

  1. Urgency: "act within 24 hours or your account closes."
  2. Fear or greed: a threat, or a prize you never entered for.
  3. Authority: it looks like the bank, your manager or the police.
  4. A request that bypasses normal channels: send gift cards, share a code, install a program, keep it secret.
flowchart TD
  M["A message arrives"] --> Q1{"Did you expect it?"}
  Q1 -->|"no"| Q2{"Does it rush you or ask<br/>for secrets or money?"}
  Q1 -->|"yes"| Q3{"Does the link or sender<br/>match what you know?"}
  Q2 -->|"yes"| X["Stop. Do not click or reply."]
  Q2 -->|"no"| Q3
  Q3 -->|"no"| X
  Q3 -->|"yes"| OK["Probably fine. When in doubt,<br/>go to the site by typing its address."]
  X --> V["Verify through a channel you trust:<br/>the official app or a known phone number"]

A quick decision path for any unexpected message.

A link's visible text can say anything, so look at the real address. The part that matters is the registered domain, the name just before the final ending: in https://login.shop.example.com/cart, the site belongs to example.com. Everything to the left is a "sub-domain" that the owner can name freely. So paypal.com.account-verify.example belongs to account-verify.example, not to PayPal, no matter how it starts. Other tricks: text before an @ sign (browsers treat it as a username, not the host), raw IP addresses instead of names, and look-alike letters from other alphabets, shown in raw form as xn-- (called punycode).

The scorer below applies these rules. It is a teaching model: the "last two labels" shortcut breaks for endings such as .co.uk, and attackers invent new tricks, so a clean score is never a guarantee.

JS A suspicious-link scorer

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Reading a message

Links are only half of it. The next stand-in scans message text for the persuasion tricks listed above. Look closely at its last result: the scorer misses a message that has no obvious keywords. A real scam can be polite and plain, which is why your own judgment (and verifying through a trusted channel) matters more than any keyword list.

JS A scam-message red-flag counter

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The second message is harmless. The fourth also shows no flags, yet it could be a trap if you never ordered a parcel. The scorer cannot know what you ordered; you can.

Safe habits that work

Keep software updated. Updates fix security holes that attackers already know about. Turn on automatic updates for the operating system, browser and apps. An old, unpatched program is the easiest door for a worm.

Use least privilege. The principle of least privilege says every account and program should have only the permissions it needs. Do daily work in a standard user account, not an administrator account, so that malware you accidentally run cannot change the whole system. When the operating system asks for an administrator password, stop and ask: did I just start an installation? If not, say no.

Install from trusted sources. Use official app stores or the publisher's own website. Avoid cracked software and "free" versions of paid programs; they are among the most common carriers of trojans. Keep browser extensions to a minimum and read what permissions they ask for.

Use a firewall. A firewall filters network traffic using rules: which direction, which port, which address. By default it blocks unsolicited incoming connections, so that a service on your computer cannot be reached from the internet unless you allow it. Your operating system and your home router both include one. The rules are checked in order and the first match wins; if nothing matches, the default applies. The best default is "deny".

JS A first-match firewall

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Run security software sensibly. Built-in protection such as Microsoft Defender or macOS's own safeguards is good enough for most people if it is kept on and updated. One security product is enough; several fight each other. Scanners find known patterns, so they complement good habits, they do not replace them.

Protect accounts. Unique passwords, a password manager and two-factor authentication (see the previous lesson) mean that a stolen password alone is not enough.

Back up. A recent, tested backup turns ransomware or a dead disk from a disaster into an annoyance. See the next lesson.

If something goes wrong

  1. Disconnect from the network (turn off Wi-Fi or unplug the cable) to stop spreading or data theft.
  2. Do not pay a ransom or call a number shown in a pop-up.
  3. From a different, clean device, change passwords for important accounts, starting with email, and check for unfamiliar sign-ins.
  4. Run a full scan with your security software, or restore from a clean backup. For serious infections, a clean reinstall of the operating system is the safest cure.
  5. Tell your bank if card details may be exposed, and your workplace if it was a work device.

What is real here and what is a stand-in? The malware types, scam techniques, firewall rule ordering and URL tricks are all real. The scorers are simple rule lists written for teaching. Real filters combine hundreds of signals, reputation databases and machine learning, and they still make mistakes in both directions.

Security threats, access control and authentication

Security means protecting three things, often called the CIA triad:

  • Confidentiality: only the right people can read the data.
  • Integrity: the data is not changed without permission.
  • Availability: the system and data are there when needed.

A threat is anything that could harm one of these. It helps to sort them into two groups.

Physical threats

Harm to the equipment itself: theft of laptops and phones, fire, flood and power surges, dust and overheating, drops and spills, and someone with physical access who plugs in a USB stick or reads a screen over your shoulder. Defences: locks and cable locks, keeping devices out of sight, surge protectors and uninterruptible power supplies (UPS), screen locks, full-disk encryption (so a stolen disk is unreadable), and backups stored in a different place.

Non-physical (logical) threats

Harm done through software or deception: malware (viruses, worms, trojans, ransomware, spyware), phishing and other social engineering, password guessing and credential stuffing (trying leaked passwords on other sites), denial-of-service (DoS) attacks that flood a service with traffic so real users cannot reach it, man-in-the-middle attacks that intercept traffic on an untrusted network, SQL injection and other attacks on badly written websites, unpatched software with known holes, and insider threats (careless or malicious people with legitimate access). Earlier sections describe malware and phishing in detail; the defences are updates, firewalls, antivirus, encryption, sensible habits and the ideas that follow.

Authentication: proving who you are

Authentication answers "who are you?". Evidence comes in three kinds, called factors:

Factor Meaning Examples Weakness
Something you know A secret in your head Password, PIN, security question Can be guessed, phished or leaked
Something you have An object only you hold Phone with an authenticator app, hardware security key, bank card Can be lost or stolen
Something you are A body trait Fingerprint, face, iris Cannot be changed if copied; false matches are possible

Multi-factor authentication (MFA) combines two or more different kinds, for example a password plus a code from your phone. Using two passwords is not MFA, because both are "something you know". MFA stops most attacks that rely on a stolen password, which is why you should turn it on for email, banking and social accounts. Hardware keys and passkeys (cryptographic logins tied to your device) are the strongest everyday options because they cannot be phished like a typed code. For how passwords are stored and protected, see Passwords and Encryption.

Python Classify login methods and check for real multi-factor

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Authorization and access control

Authentication proves who you are; authorization decides what you may do. Access control is the set of rules that enforce it. Systems use three main models.

Model Who decides How it works Example
DAC (discretionary) The owner of the resource The owner grants permissions to others File permissions on Windows and Linux; sharing a document
MAC (mandatory) The system, by policy Labels such as "secret" on data and clearances on users; users cannot override Military and high-security systems, SELinux
RBAC (role-based) The organization Permissions attach to roles (nurse, manager); users get roles Hospital, company and cloud systems

Two principles guide good design. Least privilege: give each person or program only the access they need, and no more, so that a mistake or a stolen account does limited harm. Separation of duties: no single person controls a whole sensitive process (the person who requests a payment is not the one who approves it). Access control is also checked and recorded: accounting (logging) keeps a trail of who did what, so that problems can be investigated. Together these three steps are known as AAA: authentication, authorization, accounting.

Python A tiny role-based access check

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Protective measures in short

  • Firewalls filter network traffic by rules; antivirus and endpoint protection detect malware.
  • Encryption protects data stored on disks and sent over networks (HTTPS, VPN, full-disk encryption).
  • Updates and patches close known holes; most attacks use flaws that already have a fix.
  • Backups are the last line of defence against ransomware and failures.
  • Training and habits: most breaches begin with a person clicking something, so awareness matters as much as technology.
  • Monitoring and incident response: logs, alerts, and a plan for what to do when something goes wrong.
  • Defence in depth: use several layers (lock, password, MFA, firewall, backups) so that one failure does not mean total loss.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which kind of malware encrypts your files and demands payment?

    Ransomware locks files with encryption and sells the key. Tested backups are the best defense.
  2. 2. Whose website is https://paypal.com.account-verify.example/login?

    The registered domain is the last part before the ending: account-verify.example. Everything to its left is just a sub-domain the owner chose.
  3. 3. What do most phishing messages have in common?

    Well-written scams exist, so spelling is not a reliable test. The pressure and the unusual request are the common signs.
  4. 4. Why use a standard user account for daily work?

    This is the principle of least privilege: limited accounts limit the damage a mistake or a malicious program can cause.
  5. 5. You receive an unexpected message from your bank asking you to confirm your login. What is the best response?

    Contact the organization through a channel you trust, never through details supplied by the suspicious message.

Summary

  • Malware comes in many forms (virus, worm, trojan, ransomware, spyware); most arrive through attachments, links, pirated or fake software, and unpatched holes.
  • Phishing and scams rely on urgency, fear, greed and authority; verify through a channel you trust, not through the message.
  • To read a link, find the registered domain; sub-domains, @ tricks, raw IP addresses and look-alike letters are common disguises.
  • Keep software updated, use least privilege, install from trusted sources, and keep the firewall on with a deny-by-default rule set.
  • Rule-based checkers help but cannot replace judgment; one clean scan is not proof of safety.
  • If you are hit: disconnect, do not pay, change passwords from a clean device, clean or restore, and report.

Next, prepare for the day something is lost: Backups and Data Recovery.