A Level Computer Science · Chapter 11 · Component 01: Computer systems
Every network faces attackers who want to read, change or block its data, so it is defended in layers, from strong passwords and firewalls to encryption.
This chapter teaches the main threats to networks: malware, social engineering, attacks on software and denial of service. It then teaches the defences against them, including passwords and authentication, firewalls and proxy servers, encryption, and the everyday measures that keep systems safe.
In this chapter · jump to a section
Start here
Your route through this chapter
By the end of this chapter you will be able to:
- describe the aims of network security, and the kinds of attacker a network faces
- distinguish viruses, worms, trojans, ransomware and spyware, and model how a worm spreads
- explain phishing, social engineering, SQL injection and denial-of-service attacks
- calculate the number of possible passwords and the time to crack them, and explain two-factor authentication
- explain how a firewall filters packets with ordered rules, and what a proxy server does
- explain how encryption, patching, access rights and other measures protect a network
Time: two sessions, about 3 hours, plus the programming task.
You need first: packets and the TCP/IP stack from Networks, protocols and the internet, and encryption and hashing from Compression, encryption and hashing.
The big picture
The big picture
Networks carry the data that people and organisations depend on: bank balances, medical records, school reports, private messages. That makes them targets. Some attackers want to steal data, some want to change it, and some simply want to stop a service working, for money, for a cause or for the challenge.
Network security has three aims, often called the CIA triad. Confidentiality means that only authorised people can read the data. Integrity means that the data cannot be changed without permission, and that any change is noticed. Availability means that the system and its data are there when authorised users need them.
No single defence stops every attack. Instead, a network is protected in layers, an approach called defence in depth. A firewall stops some attacks at the edge of the network. Strong passwords and two-factor authentication stop others at the login screen. Encryption protects data that is intercepted, and backups recover from attacks that get through. Each layer catches some of what the others miss.
Security always involves trade-offs. Every defence costs money, takes time to manage, and can make systems harder to use. A bank must protect its customers' money very strongly, even if logging in takes longer. A school's homework website needs good protection, but not the same as a bank's. Deciding how much security is enough means weighing the value of what is protected against the cost and inconvenience of protecting it.
People are part of every layer. Many successful attacks do not break any technology at all; they trick a person into opening a door. So training staff to recognise attacks matters as much as any piece of software.
Security is also a process, not a product. Attackers keep inventing new methods, software keeps changing and staff come and go. An organisation must keep reviewing its risks, testing its defences and practising what to do when an attack succeeds. A plan for responding to an incident, written before it is needed, turns a crisis into a set of steps that people already know.
Section 1
Threats and attackers
Who attacks networks
Attackers range widely. Criminals steal data or demand ransoms for money. Activists attack the websites of organisations they oppose. Some governments run attacks to spy on or disrupt other countries. Some attackers are simply curious, and some use ready-made tools without understanding them. Each kind has different skills, resources and aims.
Attackers also differ in how they choose their targets. Some attacks are untargeted: the same phishing email or worm is sent to millions of people, and the attacker profits from whoever falls for it. Other attacks are targeted at one organisation, researched for weeks and carefully planned. Untargeted attacks are stopped by good everyday habits; targeted ones need stronger, layered defences and staff who know they might be singled out.
Not every threat comes from outside. An insider is someone with legitimate access, such as an employee, who misuses it. An insider may steal data to sell, take revenge after being dismissed, or simply make a careless mistake, such as emailing a file to the wrong person. Insiders are dangerous because they are already past many of the defences.
Organisations reduce insider risk in several ways. They check the backgrounds of staff who will handle sensitive data. They give each person access only to what their job needs, and record who looks at what. When someone leaves, their accounts are closed the same day. None of this assumes staff are dishonest; it simply limits the harm that any one account can do, whether through malice, carelessness or a stolen password.
Common mistake: thinking only outsiders are a threat to a network. Many breaches involve people who already have access, through malice or carelessness. Good security limits what each user can reach, records what they do, and removes access as soon as someone leaves.
Interception
Data travelling across a network can be intercepted. On a shared wireless network, anyone in range can capture the packets sent through the air. On the internet, data passes through many routers owned by other organisations. An attacker who captures unencrypted packets can read passwords, messages and card details as easily as the intended receiver can.
Public wireless networks, such as those in cafés and stations, are especially risky. Anyone can join them. An attacker can even set up a fake network with a convincing name, so that nearby devices connect to it instead of the real one. Every packet then passes through the attacker's equipment. Encrypted connections, such as HTTPS and VPNs, make the captured data unreadable.
A more active attack places the attacker between two parties, so that each thinks it is talking to the other. The attacker can read everything, and can also change the messages before passing them on. This is called a man-in-the-middle attack. Encryption and certificates, covered in section 6, are the defence against both.
Worked example 1: the cost of downtime
An online shop takes £4,500 an hour. An attack takes it offline for 6 hours, and the repair costs £12,000. What did the attack cost?
| Working | Reason |
|---|---|
| Lost sales = 4500 × 6 = £27,000 | Each hour offline loses an hour's takings |
| Total cost = 27000 + 12000 = £39,000 | Add the cost of the repair |
| The shop's reputation may suffer too | Customers may not come back |
| Defences costing less than this are worthwhile | Security is weighed against the cost of attacks |
Check yourself. Which of the three aims of security does an attacker break by changing the marks in a school's database?
Show the answer
Integrity, because the data has been changed without permission. The marks may still be readable and available, but they can no longer be trusted.
Section 2
Malware
Kinds of malware
Malware is malicious software: any program written to cause harm. It comes in several kinds, each spreading and acting in its own way.
A virus attaches itself to another program or file. When the infected program runs, the virus runs too, copies itself into other programs, and may carry out a harmful action, called its payload. A virus needs a person to run the infected file, for example by opening an email attachment.
A worm is a standalone program that spreads by itself across a network, usually by exploiting a weakness in software that many computers run. It needs no human action. Worms can spread around the world in hours, and even a worm with no payload can slow networks to a crawl with the traffic it creates.
Because a worm needs no human help, the speed of patching decides how far it gets. A weakness in a widely used program may be fixed by its maker within days of being found, but many organisations take weeks or months to install the fix. Worms that exploit weaknesses which already have patches still spread, through every machine that has not been updated.
A trojan is a program that pretends to be useful, such as a free game or a tool, but secretly does something harmful. Unlike viruses and worms, trojans do not copy themselves; they rely on people choosing to install them. Many trojans open a back door that lets an attacker control the computer remotely.
Common mistake: thinking all malware is a virus. A virus attaches to another program and needs a person to run it. A worm spreads on its own across a network, and a trojan disguises itself as something useful. Each needs a different defence.
Ransomware and spyware
Ransomware encrypts the files on a computer, or across a whole network, and demands a payment for the key. It can stop a hospital or a council working for weeks. Paying does not guarantee the files will be returned, so the best defence is regular backups kept where the ransomware cannot reach them.
Modern ransomware gangs often steal a copy of the data before encrypting it, and threaten to publish it unless they are paid. Backups then restore the files but do not stop the leak, so preventing the attack in the first place matters even more. Ransomware usually gets in through a phishing email or an unpatched weakness, which is why those two defences come up again and again.
Spyware secretly gathers information, such as the websites a person visits or the keys they press. A keylogger records every keystroke, capturing passwords as they are typed. Adware shows unwanted advertisements, and some of it also tracks the user.
Malware reaches computers in many ways. It may arrive as an email attachment or hide inside a download from an unofficial site. It can even be installed by a visit to a website that exploits a weakness in the browser. Memory sticks can carry it from one computer to another, even to computers that are never connected to the internet. Each route needs its own precaution, from scanning attachments to blocking unknown programs.
A botnet is a large network of computers infected with malware that lets an attacker control them all at once. The owners usually have no idea their machines are involved. Botnets are rented out for sending spam, guessing passwords and running denial-of-service attacks, and some contain millions of machines, from laptops to internet-connected cameras with weak default passwords.
How a worm spreads
A worm grows exponentially. Suppose each infected machine infects k new machines in each round of spreading. Then after every round the number infected is multiplied by k + 1, because the old machines are still infected and the new ones join them.
Worked example 2: a spreading worm
One machine is infected by a worm. Each round, every infected machine infects 2 more. How many machines are infected after 4 rounds?
| Working | Reason |
|---|---|
| Each round multiplies the total by 2 + 1 = 3 | Old infections stay and new ones join |
| Rounds: 1, 3, 9, 27, 81 | Multiply by 3 each time |
| After 4 rounds, 81 machines are infected | That is three to the fourth power |
| After 10 rounds, 3¹⁰ = 59,049 | The growth is exponential, not steady |
Derivation: how fast a worm spreads
Start with I₀ infected machines. If each infected machine infects k more in every round, the total after one round is I₀ + kI₀ = (k + 1)I₀, and each later round multiplies by k + 1 again.
To reach N machines, solve for the number of rounds.
With I₀ = 1 and k = 2, reaching a million machines needs log(10⁶) ÷ log 3 ≈ 12.6, so 13 rounds. If a round takes a few minutes, a worm can cover the world within an hour or two.
Worked example 3: rounds to reach a million
How many rounds does the same worm need to infect 1,000,000 machines?
| Working | Reason |
|---|---|
| 3¹² = 531,441 | Still below a million after 12 rounds |
| 3¹³ = 1,594,323 | Above a million after 13 rounds |
| So 13 rounds are needed | The first round count to pass the target |
| Patching early matters enormously | Each round of delay triples the damage |
Defending against malware
Anti-malware software scans files for the signatures of known malware, and watches programs for suspicious behaviour, such as encrypting many files at once. It must be updated constantly, because new malware appears every day. Keeping the operating system and applications patched closes the weaknesses that worms exploit, and limiting which programs users may install stops many trojans.
Check yourself. A program spreads from computer to computer across a network without anyone running it. Is it a virus, a worm or a trojan?
Show the answer
It is a worm. A worm spreads by itself across a network, while a virus needs a person to run an infected file, and a trojan relies on people installing it.
Section 3
Attacks on people and software
Phishing and social engineering
Social engineering means manipulating people into giving away information or access. It works because people are helpful, trusting and busy. An attacker might phone the IT help desk pretending to be a manager who has forgotten a password. Another might leave an infected memory stick in a car park labelled "salaries".
Phishing is social engineering by message. An email, text or post pretends to come from a trusted organisation, such as a bank or a delivery company. It asks the reader to click a link and enter their details. The link leads to a fake site that collects whatever is typed. Spear phishing targets one person with a message tailored to them, which makes it far more convincing.
Phishing messages share warning signs. They create urgency, such as an account about to be closed. They ask for details that a real organisation would never request by email. The sender's address or the link's real destination often differs slightly from the genuine one, and the greeting may be general rather than using the reader's name. Teaching people to pause and check these signs stops many attacks.
Other social engineering tricks work face to face. Shoulder surfing means watching someone type a password or PIN. Tailgating means following an authorised person through a secure door before it closes. Pretexting means inventing a believable story, such as being a new member of staff or a repair engineer, to persuade someone to help. All of them exploit politeness and trust.
Worked example 4: a phishing campaign
An attacker sends a phishing email to 2,000 staff. If 3% click the link and a third of those enter their password, how many passwords are captured?
| Working | Reason |
|---|---|
| Clicks = 2000 × 0.03 = 60 | Three in every hundred click |
| Passwords = 60 ÷ 3 = 20 | A third of those who click type a password |
| One password may be enough to get in | Attackers need only one success |
| Training and two-factor authentication both help | Fewer clicks, and stolen passwords are not enough |
SQL injection
SQL injection attacks a website that builds database queries from what users type. If a login form simply pastes the username into a query, an attacker can type text that changes the query's meaning. For example, typing ' OR '1'='1 into a password box can turn a check that should fail into one that is always true. The attacker then logs in without a password.
The defence is to keep user input separate from the command, using parameterised queries. Whatever is typed is then always treated as data, never as part of the SQL. Input should also be validated, so that a name field that contains SQL symbols is rejected.
SQL injection is one of a family of attacks that exploit programs which trust their input. A program that copies more data into memory than it has room for can be overwritten, letting an attacker run their own code; this is a buffer overflow. A web page that displays what users type without checking it can be made to run another user's script. The rule in every case is the same: never trust input, and always check it before it is used.
Denial of service
A denial-of-service attack floods a server with so many requests that it cannot answer genuine users. In a distributed denial-of-service attack, or DDoS, the requests come from thousands of computers at once, often a botnet of machines infected with malware without their owners knowing. Because the traffic comes from everywhere, it is hard to block.
Common mistake: thinking a denial-of-service attack steals data. A DDoS attack attacks availability, not confidentiality. It stops a service working by overwhelming it, but takes no data. It is sometimes used as a distraction while a separate attack steals data elsewhere.
Worked example 5: a botnet flood
A server can handle 20,000 requests a second. A botnet of 10,000 machines each sends 50 requests a second, while genuine users send 1,000. How overloaded is the server, and what share of genuine requests is answered?
| Working | Reason |
|---|---|
| Botnet traffic = 10000 × 50 = 500,000 per second | Every bot sends its share |
| Load = 500000 ÷ 20000 = 25 times capacity | The server is swamped |
| Answered = 20000 ÷ 501000 = 4.0% | Requests are answered at random |
| So 96% of genuine users are turned away | The service is effectively down |
Defences against DDoS include services that absorb huge amounts of traffic across many data centres and filter out the attack. Firewalls can also limit how many requests a single source may send. Large sites spread their servers across the world, so that no single location can be overwhelmed.
Attacks on people and on software often work together. A phishing email might carry a link to a site that exploits a browser weakness, installing malware that joins the computer to a botnet. That botnet is later used for a denial-of-service attack on someone else. Understanding each technique separately helps to see how a whole campaign is built from them.
Check yourself. Why is a DDoS attack harder to block than an attack from a single computer?
Show the answer
The traffic comes from thousands of different addresses, so blocking one address barely helps, and the attack traffic is hard to tell apart from genuine users' requests.
Section 4
Passwords and authentication
Authentication
Authentication proves who a user is. It can rely on something the user knows, such as a password or PIN, or something they have, such as a phone or a security key. It can also rely on something they are, such as a fingerprint or face. Each has weaknesses: passwords can be guessed or stolen, phones can be lost, and fingerprints cannot be changed if they are copied.
How many passwords?
An attacker who steals a database of password hashes can try guesses offline, as fast as their hardware allows, without any login screen to slow them down. Modern hardware can try billions of guesses a second. A password's strength depends on how many passwords the attacker would have to try.
That is why websites store salted hashes rather than passwords, as Compression, encryption and hashing explains. A stolen hash cannot simply be read; the attacker must guess passwords, hash each guess and compare. Deliberately slow hash functions make each guess take longer, which multiplies the time for the whole search without inconveniencing a genuine user who logs in once.
If a password has n characters, each chosen from a set of c characters, there are cⁿ possible passwords. Making the set bigger helps, but making the password longer helps far more, because the length is the power.
Figure 11.1 shows how many passwords an attacker must search, and how long it takes on average. Change the length and the characters used. Then switch on the wrong model.
Password strength
- Possible passwords
- 2.09 × 10¹¹
- Entropy
- 37.6 bits
- Average time to crack
- 10.4 seconds
Common mistake: thinking each extra character adds a fixed amount of strength. Each extra character multiplies the number of possible passwords by the size of the character set. An eight-letter password has 26⁸, about 209 billion, possibilities, not 26 × 8 = 208.
Worked example 6: an eight-letter password
A password has 8 lower-case letters. How many passwords are possible, and how long does it take, on average, to crack at ten billion guesses a second?
| Working | Reason |
|---|---|
| Combinations = 26⁸ = 208,827,064,576 | 26 choices for each of 8 places |
| Average guesses = half of these | On average the right one is found half way |
| Time = 208827064576 ÷ 2 ÷ 10¹⁰ ≈ 10.4 s | Divide by the guessing rate |
| An eight-letter password falls in seconds | It is far too weak |
Worked example 7: longer and richer passwords
Compare the average cracking time for 8 characters from letters and digits with 12 characters from the same set.
| Working | Reason |
|---|---|
| Letters and digits give 62 characters | Lower case, upper case and digits together |
| 8 characters: 62⁸ ≈ 2.18 × 10¹⁴, about 10,900 s | That is roughly three hours |
| 12 characters: 62¹² ≈ 3.23 × 10²¹, about 1.6 × 10¹¹ s | That is roughly five thousand years |
| Four more characters multiply the time by 62⁴ | That is nearly 15 million |
Derivation: password strength and entropy
With c possible characters in each of n places, the number of possible passwords is
Strength is often measured in bits of entropy: the number of binary choices that would give the same number of possibilities.
Each extra character adds log₂ c bits, so the number of passwords doubles log₂ c times. For 8 lower-case letters, H = 8 × 4.7 = 37.6 bits; for 12 letters and digits, H = 12 × 5.95 = 71.5 bits.
Better authentication
Password rules help, but people find long random passwords hard to remember, so they reuse them across sites. If one site is breached, attackers try the same email and password everywhere. Password managers solve this by generating and storing a different strong password for every site.
Two-factor authentication requires two different kinds of evidence, usually a password and a code from a phone or security key. A stolen password alone is then not enough. Systems also limit login attempts: locking an account after a few wrong guesses stops online guessing, although it cannot slow down an attacker who has stolen the hashes.
Attackers rarely try every possible password in order. They start with dictionary attacks, trying common passwords, words and names first, with simple changes such as adding a number or swapping letters for symbols. A password such as Summer2026! looks complicated, but it follows a pattern so common that it falls almost at once. Long passphrases made of several random words are both easier to remember and far harder to guess.
Biometric methods, such as fingerprints and face recognition, are quick and cannot be forgotten. But they are not secret: a face is seen by everyone, and a fingerprint is left on every glass. They work best as one factor among two, combined with something the user has, such as the phone that holds the fingerprint reader.
Worked example 8: a four-digit PIN
A phone uses a four-digit PIN and locks for an hour after 5 wrong guesses. How long would it take, on average, to guess the PIN by trying every one?
| Working | Reason |
|---|---|
| Combinations = 10⁴ = 10,000 | Ten digits in each of four places |
| Average guesses = 5,000 | Half of all the PINs |
| 5,000 ÷ 5 = 1,000 hours of lockouts | Five guesses are allowed each hour |
| About 42 days, so lockouts make a short PIN workable | The limit, not the PIN, does the protecting |
Check yourself. How many bits of entropy does a password of 8 random characters from 94 keyboard symbols have?
Show the answer
Each character adds log₂ 94 ≈ 6.55 bits, so 8 characters give about 8 × 6.55 = 52.4 bits.
Section 5
Firewalls and proxy servers
Packet filtering
A firewall sits between a network and the outside world, usually in the router, and checks the traffic passing through. A packet-filtering firewall examines each packet's header: its source and destination IP addresses, its protocol and its port number. It compares these with a list of rules, and allows or blocks the packet.
The rules are checked in order, from the top. The first rule that matches the packet decides what happens to it, and the rest are ignored. If no rule matches, the packet is blocked by a default rule, so only traffic that has been deliberately allowed gets through.
Figure 11.2 runs six packets through a firewall's rules. Step through the packets and see which rule decides each one. Then switch on the wrong model.
Packet filtering
- Decision
- allow
- Deciding rule
- 2
Common mistake: thinking the last rule that matches decides. A packet filter stops at the first matching rule. So the order of the rules matters: a general allow rule placed above a specific deny rule lets through traffic the deny rule was meant to stop.
Worked example 9: following the rules
Using the rules in Figure 11.2, decide what happens to packet 2: TCP, port 80, from 203.0.113.9.
| Working | Reason |
|---|---|
| Rule 1 allows port 443, which does not match | The packet is for port 80 |
| Rule 2 allows TCP port 80, which matches | Checking stops at the first match |
| The packet is allowed | Rule 2 is the deciding rule |
| Rule 3, blocking 203.0.113, is never reached | The order of the rules let the attacker in |
Worked example 10: two more packets
Decide what happens to packet 4, TCP port 22 from 81.2.69.1, and packet 6, TCP port 25 from 203.0.113.5.
| Working | Reason |
|---|---|
| Packet 4: rule 4 allows port 22 only from 10.0.* | The source does not match |
| No rule matches packet 4, so it is denied | The default rule blocks it |
| Packet 6: rule 3 matches its source, 203.0.113 | Rules 1 and 2 are for other ports |
| Packet 6 is denied by rule 3 | The first match decides |
The fix for packet 2 is to move the deny rule for 203.0.113 above the allow rules, so it is checked first. Firewall rules are usually ordered from the most specific to the most general, with deny rules for known bad sources near the top.
A firewall is only as good as its rules. Rules that allow too much leave doors open, while rules that block too much stop people working, and they quietly find ways around the firewall. Rules must also be reviewed as the network changes, because a rule written for a server that no longer exists may still let traffic through. Good firewall management means writing down why each rule exists.
More advanced firewalls use stateful inspection. They remember the connections that computers inside the network have opened, and allow replies to those connections while blocking unrequested traffic. Some also look inside the packets, checking the data itself for signs of attacks.
Firewalls are not only found at the edge of a network. Most operating systems include a software firewall that protects each computer on its own, blocking programs from accepting connections they should not. Large organisations also use internal firewalls between parts of their network. An attacker who gets into one part, such as the guest Wi-Fi, then cannot reach another, such as the finance servers.
Proxy servers
A proxy server acts on behalf of the computers on a network. When a pupil's browser requests a web page, the request goes to the proxy, which fetches the page and passes it back. The website sees only the proxy's address, not the pupil's.
A proxy can filter requests, blocking sites that are not allowed, and can scan the pages it fetches for malware. It can also cache popular pages, so that a page requested by many pupils is fetched from the internet only once, saving bandwidth. A proxy hides the internal network's addresses from the outside world, which makes attacks on individual machines harder.
Because all web traffic passes through the proxy, it can also keep a log of the sites each user visits. This helps an organisation investigate misuse and meet its duty to protect young people, as in a school, but it also raises questions of privacy. Users should be told what is logged and why, which is a theme of Legal, moral, ethical and cultural issues.
Check yourself. A packet is UDP, port 53, from 198.51.100.53. What do the rules in Figure 11.2 decide?
Show the answer
Rules 1 to 4 do not match: rules 1, 2 and 4 are for TCP, and rule 3 is for another source. Rule 5 allows UDP port 53, so the packet is allowed.
Section 6
Encryption and other defences
Encryption on the network
Encryption makes intercepted data useless to anyone without the key. HTTPS encrypts web traffic between a browser and a website, using the hybrid method from Compression, encryption and hashing. Public-key encryption agrees a session key, then fast symmetric encryption protects the rest. Wireless networks encrypt everything sent through the air, and email can be encrypted from sender to receiver.
A virtual private network, or VPN, creates an encrypted tunnel across the internet between a device and another network. Staff working from home use a VPN to reach their organisation's network as if they were in the office. Everything passing through the tunnel is protected from anyone watching the connection in between.
Common mistake: thinking HTTPS means a website is trustworthy. HTTPS only means the connection is encrypted and the certificate matches the site's name. A phishing site can have HTTPS too. It protects the data on the way, but says nothing about whether the site's owner is honest.
Worked example 11: an encrypted key
A session key has 128 bits. An attacker can test a trillion keys a second. How long would a brute-force attack take on average?
| Working | Reason |
|---|---|
| Keys = 2¹²⁸ ≈ 3.4 × 10³⁸ | Every bit doubles the number of keys |
| Average = 2¹²⁷ ÷ 10¹² ≈ 1.7 × 10²⁶ s | Half the keys at a trillion a second |
| About 5.4 × 10¹⁸ years | Divide by the seconds in a year |
| Brute force is hopeless, so attackers target people and software instead | The weak point is rarely the cipher |
Patching and access rights
Many attacks exploit known weaknesses in software that has not been updated. Software companies publish patches as soon as weaknesses are found, so keeping systems patched closes the door before most attackers arrive. An attack on a weakness that has no patch yet, because it was unknown, is called a zero-day attack.
Patching sounds simple, but it has costs. An update may break other software, so organisations often test patches before installing them everywhere. Old systems may no longer receive patches at all, because their makers have stopped supporting them. Such systems should be replaced, or at least separated from the rest of the network by firewalls, so that an attack on them cannot spread.
Access rights limit what each user can do. The principle of least privilege gives every user only the access they need for their job: a teacher can change their own class's marks but not the payroll. Administrator accounts, which can change anything, are kept for the few people who need them, and even they use an ordinary account for everyday work such as reading email. If an account is taken over, the damage is limited to what that account could reach.
Testing and monitoring
Penetration testing means hiring experts to attack a network, with permission, to find weaknesses before real attackers do. The testers write a report of every weakness they find and how serious it is, so the organisation can fix the worst first. Network forensics examines logs after an attack to find out what happened and how. Auditing records who accessed what, so that misuse can be spotted. Intrusion detection systems watch traffic for patterns that match known attacks and raise an alarm.
Backups
When every defence fails, backups are the last line. Regular copies of the data, kept offline or in a separate location, let an organisation recover from ransomware, a fire or a deleted file. A backup must be tested, by actually restoring from it, because a backup that cannot be restored is no backup at all.
A common rule is to keep three copies of important data, on two different kinds of storage, with one copy kept off site. A fire or flood that destroys the office then cannot destroy every copy. Backups that are always connected to the network can be encrypted by ransomware along with everything else. So at least one copy should be disconnected, or kept in a system that cannot be overwritten.
Worked example 12: choosing defences
A school wants to protect pupils' records from three threats: stolen passwords, a worm and ransomware. Match a defence to each.
| Working | Reason |
|---|---|
| Stolen passwords: two-factor authentication | A password alone is then not enough |
| Worm: patching and a firewall | They close the weakness and block the traffic |
| Ransomware: offline backups, tested regularly | The files can be restored without paying |
| Train staff to spot phishing as well | People are the first line of defence |
Check yourself. What does the principle of least privilege mean?
Show the answer
Each user is given only the access they need to do their job, and no more. If their account is misused, the damage is limited to what that account could reach.
Reference
Key algorithms and definitions
| Term or algorithm | What it means | Example | Cost or rule to learn |
|---|---|---|---|
| CIA triad | Confidentiality, integrity, availability | Marks changed breaks integrity | Every threat attacks one or more |
| Virus, worm, trojan | Attaches; spreads alone; disguises itself | An infected attachment | Each needs its own defence |
| Worm spread | Each machine infects k per round | 1, 3, 9, 27, 81 | I = I₀(k + 1)^r |
| Phishing | Fake messages to steal details | A fake bank email | Training and 2FA |
| SQL injection | Commands slipped into a query | ' OR '1'='1 | Parameterised queries |
| DDoS | A flood from a botnet | 500,000 requests a second | Attacks availability |
| Password strength | Number of possible passwords | 26⁸ ≈ 2.1 × 10¹¹ | P = cⁿ, H = n log₂ c |
| Packet filtering | Ordered rules on headers | Allow TCP 443 | First match decides; default deny |
| Proxy server | Requests made on users' behalf | A school web filter | Filters, caches, hides addresses |
| Defence in depth | Many layers of protection | Firewall, 2FA, backups | Each layer catches what others miss |
Programming task
Programming task: a packet filter
Aim
Write a Python program that applies an ordered list of firewall rules to a list of packets. For each packet it must print whether it is allowed or denied, and which rule decided, using the first matching rule and denying any packet that no rule matches.
Design
Each rule is a dictionary with an action and any of three conditions: protocol, port and source. A condition that is missing matches anything. The source condition matches any address that starts with the given text, so "10.0." matches every address in that range. Each packet is a dictionary with a protocol, a port and a source address.
The filter loops through the rules in order. For each rule it checks every condition the rule contains; if all of them match, it returns that rule's action and its number. If the loop ends with no match, it returns "deny" and no rule number.
Code
rules = [
{"action": "allow", "protocol": "TCP", "port": 443},
{"action": "allow", "protocol": "TCP", "port": 80},
{"action": "deny", "source": "203.0.113."},
{"action": "allow", "protocol": "TCP", "port": 22, "source": "10.0."},
{"action": "allow", "protocol": "UDP", "port": 53},
]
def matches(rule, packet):
if "protocol" in rule and rule["protocol"] != packet["protocol"]:
return False
if "port" in rule and rule["port"] != packet["port"]:
return False
if "source" in rule and not packet["source"].startswith(rule["source"]):
return False
return True
def decide(rules, packet):
for number, rule in enumerate(rules, start=1):
if matches(rule, packet):
return rule["action"], number
return "deny", None
packet = {"protocol": "TCP", "port": 80, "source": "203.0.113.9"}
print(decide(rules, packet))
Returning as soon as a rule matches is what makes the first match decide. The final return gives the default deny, so only traffic that a rule has deliberately allowed can pass.
Testing
| Test | Input | Expected output | Why this test |
|---|---|---|---|
| 1 | TCP 443 from 81.2.69.1 | allow, rule 1 | A normal web request |
| 2 | TCP 80 from 203.0.113.9 | allow, rule 2 | Matches worked example 9 |
| 3 | TCP 22 from 10.0.14.22 | allow, rule 4 | Remote access from inside |
| 4 | TCP 22 from 81.2.69.1 | deny, no rule | Matches worked example 10 |
| 5 | UDP 53 from 198.51.100.53 | allow, rule 5 | A DNS reply |
| 6 | TCP 25 from 203.0.113.5 | deny, rule 3 | Blocked by its source |
| 7 | Test 2 with rule 3 moved to the top | deny, rule 1 | Rule order matters |
Evaluation
The filter gives the expected decision for every packet, and test 7 shows that moving the deny rule to the top blocks the attacker in test 2. This confirms that the first matching rule decides, and that rule order is part of a firewall's design.
The filter only looks at single packets, so it cannot tell a reply to a request from an unrequested packet. An improvement would add stateful inspection, by remembering the connections opened from inside and allowing only replies to them, and would log every denied packet for later investigation.
Practice
Practice ladder
Rung 1: Recall and fluency
Q1. State what each part of the CIA triad means.
Worked solution to Q1
Confidentiality means only authorised people can read the data. Integrity means data cannot be changed without permission. Availability means the system and data are there when authorised users need them.
Q2. Describe how a trojan differs from a worm.
Worked solution to Q2
A trojan pretends to be a useful program, and relies on people choosing to install it; it does not copy itself. A worm is a standalone program that spreads by itself across a network, with no human action needed.
Q3. State two things a proxy server can do for a school network.
Worked solution to Q3
It can filter web requests, blocking sites that are not allowed, and it can cache popular pages so they are fetched from the internet only once. It also hides the pupils' addresses from the websites they visit.
Rung 2: Application
Q4. How many passwords of 6 digits are possible, and how long would they take to search at ten billion guesses a second?
Worked solution to Q4
There are 10⁶ = 1,000,000 possible passwords, ten choices in each of six places. At ten billion guesses a second, even the whole set takes only a ten-thousandth of a second, so such a password is useless against offline cracking.
Q5. A worm starts on 5 machines, and each infected machine infects 3 more every round. How many rounds until at least 100,000 are infected?
Worked solution to Q5
Each round multiplies the total by 4. After 7 rounds there are 5 × 4⁷ = 81,920, still below the target, and after 8 rounds 327,680. So 8 rounds are needed.
Q6. A botnet of 200,000 machines each sends 10 requests a second to a server that can handle 500,000. By what factor is it overloaded?
Worked solution to Q6
The botnet sends 200,000 × 10 = 2,000,000 requests a second in total. Dividing by the server's capacity gives 2,000,000 ÷ 500,000 = 4, so it is overloaded four times over.
Q7. Decide, with the rules of Figure 11.2, what happens to a packet that is TCP port 443 from 203.0.113.7.
Worked solution to Q7
Rule 1 allows TCP port 443 from anywhere, so it matches first and the packet is allowed. The deny rule for 203.0.113 is never reached, which is another reason to put it at the top.
Rung 3: Analysis
Q8. Explain why making a password longer increases its strength more than adding symbols to the character set.
Worked solution to Q8
The number of passwords is cⁿ, so the length n is the power and the set size c is the base. Each extra character multiplies the total by c, while a bigger set only raises the base. For example, 26¹² is far bigger than 94⁸.
Q9. A login form builds its query by pasting in whatever the user types. Explain the danger and how to fix it.
Worked solution to Q9
An attacker can type SQL that changes the meaning of the query, for example to log in without a password or to read other users' data. The fix is a parameterised query, which passes the input separately so it is always treated as data.
Q10. Explain why two-factor authentication protects an account even if its password is phished.
Worked solution to Q10
Logging in needs a second factor as well, such as a code from the user's phone. The attacker has the password but not the phone, so the stolen password alone does not let them in.
Q11. A shop loses £8,000 an hour while offline. A DDoS attack lasts 5 hours and the clean-up costs £15,000. Find the total cost.
Worked solution to Q11
The shop loses its takings for every hour it is offline, so the lost sales come to 8,000 × 5 = £40,000. Adding the cost of cleaning up gives the total cost of the attack, 40,000 + 15,000 = £55,000.
Rung 4: Stretch
Q12. Find the entropy of a 12-character password from 62 letters and digits, and compare it with 8 lower-case letters.
Worked solution to Q12
It has 12 × log₂ 62 ≈ 12 × 5.95 = 71.5 bits. Eight lower-case letters give 8 × 4.70 = 37.6 bits, so the longer password has about 34 more bits, making it roughly 2³⁴ times harder to crack.
Q13. Using the derivation, find how many rounds a worm with k = 2 needs to go from one machine to a billion.
Worked solution to Q13
The number of rounds is log(10⁹) ÷ log 3 = 9 ÷ 0.477 ≈ 18.9. Since 3¹⁸ is about 387 million and 3¹⁹ about 1.16 billion, 19 rounds are needed.
Q14. Explain why defence in depth is better than relying on one very strong defence.
Worked solution to Q14
Every defence can fail or be bypassed, for example a firewall cannot stop a phished password. With several layers, an attack that gets past one is likely to be stopped by another, and backups allow recovery if all of them fail.
Exam practice
Exam technique and worked answer workshop
When describing a threat, say what it does, how it gets in and which aim of security it attacks. When describing a defence, link it to the threat it stops: "two-factor authentication means a stolen password alone cannot be used" earns more than "use two-factor authentication".
Be precise with malware. A virus needs a host program and a person to run it, a worm spreads on its own, and a trojan disguises itself. Mixing them up loses marks quickly.
For firewall questions, work through the rules in order and stop at the first match. Say which rule decided, and remember the default deny when no rule matches.
Exam question 1 (4 marks · Paper 01 · about 5 minutes)
(a) Describe how a worm spreads. [2]
(b) Describe what ransomware does, and one way to reduce its impact. [2]
Mark scheme for exam question 1
- B1 a worm is a standalone program that copies itself
- B1 it spreads across a network by exploiting weaknesses, with no human action needed
- B1 ransomware encrypts files and demands payment for the key
- B1 regular backups kept offline let the files be restored without paying
Exam question 2 (5 marks · Paper 01 · about 7 minutes)
A password is made of 8 lower-case letters.
(a) Calculate the number of possible passwords. [2]
(b) Calculate the average time to crack it at 10¹⁰ guesses a second. [2]
(c) Suggest one change that makes the password much stronger. [1]
Mark scheme for exam question 2
- M1 26⁸
- A1 208,827,064,576, about 2.09 × 10¹¹
- M1 half of the combinations divided by 10¹⁰
- A1 about 10.4 seconds
- B1 make it longer, for example 12 or more characters, since each character multiplies the combinations
Exam question 3 (5 marks · Paper 01 · about 7 minutes)
A firewall's rules are: 1 allow TCP port 443; 2 allow TCP port 80; 3 deny any packet from 203.0.113.*; and a final default deny.
(a) State the decision for a packet that is TCP port 80 from 203.0.113.9, and which rule makes it. [2]
(b) Explain why this may not be what the administrator intended, and how to fix it. [2]
(c) State the decision for UDP port 161 from 81.2.69.1. [1]
Mark scheme for exam question 3
- B1 allowed
- B1 by rule 2, the first rule that matches
- B1 rule 3 was meant to block that source, but is never reached
- B1 move the deny rule above the allow rules
- B1 denied, by the default rule
Exam question 4 (4 marks · Paper 01 · about 5 minutes)
(a) Explain what a distributed denial-of-service attack is. [2]
(b) Explain why it is difficult to defend against. [2]
Mark scheme for exam question 4
- B1 a server is flooded with more requests than it can handle, so genuine users cannot be served
- B1 the requests come from many computers at once, often a botnet of infected machines
- B1 the traffic comes from thousands of addresses, so blocking one barely helps
- B1 attack requests look like genuine ones, so they are hard to filter out
Exam question 5 (6 marks · Paper 01 · about 9 minutes)
A small accountancy firm stores clients' financial records on its network, and staff sometimes work from home. Discuss the threats to its data and the measures it should take.
Mark scheme for exam question 5
Level 3 (5–6 marks): a balanced discussion of several threats and matching defences, linked to the firm's data and home working, showing an understanding of defence in depth. The answer reaches a justified conclusion. It is well organised and uses technical terms accurately.
Level 2 (3–4 marks): correct threats and defences with some link to the firm. The matching of defences to threats is limited.
Level 1 (1–2 marks): some relevant points, such as using a firewall, with little application. The answer may lack structure.
0 marks: no response or no response worthy of credit.
Indicative content:
- clients' financial records are valuable to criminals, so confidentiality matters most
- phishing emails could trick staff into giving away passwords; train staff and use two-factor authentication
- ransomware could encrypt the records; keep tested offline backups
- data sent from home could be intercepted; use a VPN and encryption
- a firewall blocks unrequested traffic from the internet
- keeping software patched closes weaknesses that malware exploits
- least privilege limits each member of staff to the records they need
- insiders, or a lost laptop, are risks too; encrypt laptops and remove access when staff leave
- conclusion: no single measure is enough, so the firm needs several layers of defence
Annotated model answer: exam question 5
"Clients' financial records are valuable to criminals, so confidentiality matters most. A phishing email could trick a member of staff into giving away a password. So the firm should train its staff and use two-factor authentication." (A threat linked to the firm, with two defences.)
"Ransomware could encrypt every record and stop the firm working, so it needs regular backups kept offline and tested. Staff working from home send data over the internet, where it could be intercepted, so they should connect through a VPN." (Two more threats with matching defences.)
"A firewall, patched software and least privilege reduce the chance of an attack succeeding, and limit the damage if one does. Laptops should be encrypted in case they are lost." (Further layers.)
"No single measure would protect the records, so the firm should combine these layers, which is defence in depth." (A justified conclusion.)
This answer reaches Level 3 and scores 6 marks. It matches each defence to a threat the firm really faces and draws them together.
Exam question 6 (5 marks · Paper 01 · about 7 minutes)
(a) Explain how SQL injection works. [2]
(b) Explain how it can be prevented. [2]
(c) State which aim of security it attacks. [1]
Mark scheme for exam question 6
- B1 the attacker types SQL into a form field
- B1 the website pastes it into a query, changing the query's meaning
- B1 use parameterised queries, so input is always treated as data
- B1 validate input, rejecting unexpected characters
- B1 confidentiality or integrity, as data may be read or changed
Exam question 7 (5 marks · Paper 01 · about 7 minutes)
A worm starts on one machine, and each infected machine infects 2 more every round.
(a) Calculate the number of infected machines after 4 rounds. [2]
(b) Calculate the number of rounds needed to infect a million machines. [2]
(c) Explain why patching quickly is so important. [1]
Mark scheme for exam question 7
- M1 multiplying by 3 each round
- A1 81
- M1 3¹² = 531,441 is below and 3¹³ above a million
- A1 13 rounds
- B1 the number infected grows exponentially, so every round of delay multiplies the damage
Exam question 8 (6 marks · Paper 02 · about 9 minutes)
A password is stored as a string. Write a function strength(password) that returns the number of possible passwords of the same length using the same kinds of character. Use 26 for lower case only, 52 for upper and lower case, and 62 if it also contains digits. State what it returns for "pass1234".
Mark scheme for exam question 8
- B1 a function header taking the password
- B1 a loop through every character
- B1 flags set for lower case, upper case and digits
- B1 the character set size chosen from the flags: 26, 52 or 62
- M1 the size raised to the power of the password's length
- A1 the result returned, which is 62⁸ ≈ 2.18 × 10¹⁴ for "pass1234", because it contains digits
Annotated model answer: exam question 8
function strength(password)
lower = false
upper = false
digit = false
for i = 0 to password.length - 1
c = password[i]
if c >= "a" AND c <= "z" then lower = true endif
if c >= "A" AND c <= "Z" then upper = true endif
if c >= "0" AND c <= "9" then digit = true endif
next i
size = 26
if upper then size = 52 endif
if digit then size = 62 endif
return size ^ password.length
endfunction
The header and the loop earn the first two marks, and the three flags the third. Choosing the set size from the flags earns the fourth, and raising it to the power of the length earns the method mark. Returning 62⁸ for "pass1234", which contains digits, earns the last. A real checker would also test the password against lists of common passwords, because pass1234 is one of the first guesses any attacker tries.
Connections
Synoptic link
Packet filters read the headers described in Networks, protocols and the internet, and HTTPS and VPNs use the hybrid encryption of Compression, encryption and hashing. Password hashes, salts and brute-force times also come from that chapter.
SQL injection attacks the queries of SQL and transaction processing. The Computer Misuse Act, which makes unauthorised access and malware illegal, is covered in Legal, moral, ethical and cultural issues. The exponential growth of a worm is the same mathematics as the growth rates in Algorithm analysis and Big O notation.
Synoptic question 1. Each extra bit of a key doubles a brute-force attack's time. How many more bits make an attack a million times slower?
Answer to synoptic question 1
A million is about 2²⁰, since 2¹⁰ = 1,024. So adding 20 bits makes the attack about a million times slower.
Recap
Recap and next step
- Security protects confidentiality, integrity and availability, against outsiders and insiders, and uses defence in depth.
- Viruses attach to programs, worms spread on their own, trojans disguise themselves; ransomware encrypts files and spyware watches. A worm grows as I₀(k + 1)^r.
- Phishing and social engineering target people; SQL injection targets queries; DDoS floods servers to attack availability.
- There are cⁿ passwords of length n from c characters, so length matters most; two-factor authentication defeats stolen passwords.
- Packet filters apply ordered rules to headers, with the first match deciding and a default deny; proxies filter, cache and hide addresses.
- Encryption, VPNs, patching, least privilege, monitoring and tested backups complete the defences.
Next chapter: Web technologies and search engines looks at how web pages are built and how search engines find and rank them.
For your exam board
OCR A Level Computer Science (H446): this chapter covers network security and threats in section 1.3.3, Networks, in Component 01: the use of firewalls, proxies and encryption, and threats such as malware, phishing, SQL injection and denial of service.
AQA A Level Computer Science (7517): network security, including firewalls, packet filtering, proxy servers, stateful inspection, encryption, digital certificates, and viruses, worms and trojans, appears in the fundamentals of communication and networking section, assessed on Paper 2.