← IB Computer Science

A2.4 · Book pp. 144–165

Network security

Your level

No single tool keeps a network safe. Real protection comes from layers, so that one failure does not become a disaster.

What you need to know

PointTopicLevel
A2.4.1The effectiveness of firewallsSL + HL
A2.4.2Common network vulnerabilitiesHL
A2.4.3Common network countermeasuresHL
A2.4.4Encryption and digital certificatesSL + HL

⚠️ Use this responsibly

Only test systems that you own or have permission to test. Trying these ideas on real networks, including the school’s, can be illegal.

Next: firewalls →

A2.4.1 Firewalls

A firewall inspects packets and filters them using rules. Allow lists and deny lists hold IP addresses or ranges, and often port numbers. Each packet is checked against the rules until one matches.

Stateful inspection tracks active connections, so packets in an allowed connection can keep flowing until it closes. Firewalls also log traffic, which helps to detect suspicious activity.

🔬 Lab: first matching rule wins

RuleActionSource starts withPort

Limits of firewalls

  • They are weak against insiders, or attackers who get onto the internal Wi-Fi.
  • Most do not inspect content, so harmful data can reach a legitimate destination.
  • Sophisticated attacks can mimic normal traffic.
  • They are only as good as their configuration and updates.

NAT and security

NAT hides internal addresses, which makes internal systems harder to reach directly. It was not designed for security, so treat it as a bonus: security by obscurity, not a defence by itself.

Next: vulnerabilities →

Next: encryption →

HL A2.4.2 Common vulnerabilities

VulnerabilityWhat happensCountermeasure
DDoSMany compromised devices flood a target until it cannot serve real usersRate limiting, traffic analysis, cloud protection services
Insecure protocolsHTTP, FTP and Telnet send data unencryptedUse HTTPS, SFTP and SSH
MalwareViruses, worms, trojans and ransomware harm devices and spreadEndpoint protection, updates, email filtering, backups
Man-in-the-middleAn attacker secretly intercepts or alters trafficEncrypted protocols, certificates, VPNs
PhishingA fake message tricks a victim into giving away detailsEmail filtering, training, multifactor authentication
SQL injectionInput is run as a database commandInput validation and parameterized queries
Cross-site scripting (XSS)Injected code runs in other users’ browsersInput validation and a content security policy
Unpatched softwareKnown holes are left open, and updates advertise themApply updates quickly
Weak authenticationPoor password storage or easily guessed loginsHashing and salting, multifactor authentication, tested login systems
Zero-day exploitA flaw is attacked before a patch existsLayered defence, intrusion detection, regular testing

🔬 Lab: how SQL injection changes a query

Query built by joining strings:

Parameterized query, where the input stays as data:

✍️ Try it safely on your own computer

This Python uses a temporary database in memory.

import sqlite3

db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE users (name TEXT, secret TEXT)")
db.execute("INSERT INTO users VALUES ('mali', 'blue-42')")

typed = "x' OR '1'='1"

# Unsafe: the input becomes part of the command
unsafe = "SELECT * FROM users WHERE name = '" + typed + "'"
print(db.execute(unsafe).fetchall())          # every row!

# Safe: the input is only ever data
print(db.execute("SELECT * FROM users WHERE name = ?", (typed,)).fetchall())   # []

Next: countermeasures →

HL A2.4.3 Countermeasures

CountermeasureWhat it does
Content security policyAn HTTP header listing the allowed sources of content
Password policies and passkeysLonger passwords, fewer of them, and passkeys that use biometrics, a PIN or a pattern
DDoS mitigationRate limits, traffic analysis and cloud services
Email filteringScans for malicious attachments, phishing and spam
Encrypted protocolsHTTPS, SFTP and SSH instead of HTTP, FTP and Telnet
Input validationPresence, length, type and format checks
IDS and IPSAn intrusion detection system watches and alerts. An intrusion prevention system also blocks
Multifactor authenticationTwo of: something you know, have or are
TLS certificatesProve a website’s identity and support encryption
Software updatesApply security patches as soon as possible
VPNsEncrypted remote access to a private network
Testing and trainingPenetration tests, assessments and regular staff training
Wireless securityStrong encryption, plus a MAC allow-list as a basic extra step
Secured backupsRegular, encrypted copies kept away from the main system

✏️ Book note

The book lists MAC allow-lists as a wireless measure. Remember that MAC addresses can be copied, so this only adds a little friction. Use it alongside strong Wi-Fi encryption.

⚠️ Common mistake

“Install anti-malware” or “use encryption” is too vague for full marks. Match a specific countermeasure to the specific threat and say how it helps.

🔬 Lab: match the threat

Next: encryption →

A2.4.4 Encryption and digital certificates

Encryption turns data into a form that unauthorized people cannot understand. A key is the value fed into the algorithm.

SymmetricAsymmetric
KeysOne shared keyPublic key encrypts, private key decrypts
SpeedFast, good for large filesMuch slower
ProblemSharing the key safelyProving a public key is genuine
Used forThe bulk of a sessionAgreeing a symmetric key, and signing

🔬 Lab: tiny RSA (for interest, not examined)

With primes 61 and 53: public key (3233, 17), private key (3233, 413).

RSA is safe because multiplying primes is easy, while factoring a huge product is extremely hard. Here the primes are tiny, so it could be broken at once. Large quantum computers running Shor’s algorithm could one day threaten it.

Diffie-Hellman key exchange

Two people can agree a secret in public. Think of mixing paint: combining colours is easy, but unmixing them is almost impossible.

🔬 Lab: agree a secret

Public: base 5, prime modulus 977.

✏️ Book correction

The book says Diffie-Hellman relies on the difficulty of finding prime factors. That is RSA. Diffie-Hellman relies on the discrete logarithm problem: from the public result, it is very hard to work out the secret exponent.

Digital signatures

The sender hashes the data, then encrypts the hash with their private key. The receiver decrypts it with the public key and compares it with their own hash. This proves who sent it and that it was not altered. The sender cannot later deny it, which is called non-repudiation.

🔬 Lab: tamper with a signed message

Change even one character. This hash is a tiny toy, and real ones are far longer.

Digital certificates

Encryption is little use if you are talking to an imposter. A certificate links a public key to an identity.

  1. The bank generates a key pair and keeps the private key secret.
  2. It sends the public key to a certificate authority (CA).
  3. The CA checks the identity, then signs the certificate with the CA’s private key.
  4. Browsers already trust the CA, so they can verify that signature with the CA’s public key.

Key pairs also allow SSH login without passwords. Your private key works like a password, so it must be stored safely.

✏️ Book corrections

  • The book warns against mixing up signatures and certificates, then says certificates are part of cryptocurrency. Blockchains use digital signatures and hashes, and usually no certificates.
  • It describes TLS certificates as a way for developers to sign software. That is code signing. A TLS certificate identifies a website.
  • “SSL” is the older name. Current systems use TLS.

Next: network project →

Optional project: a Raspberry Pi network

Build a small network as a class, using a separate network from the school’s. Each group runs one role on a Raspberry Pi.

RoleSoftwareTask
Router and firewallnftablesTurn on IP forwarding, then allow only HTTP, HTTPS and established traffic
Wireless access pointhostapdCreate a network with a strong passphrase
DHCP serverisc-dhcp-serverGive out 192.168.1.10 to 192.168.1.100, with fixed addresses for servers
Web servernginxHost a page from /var/www/html
Proxy serversquidCache pages and block a test URL
DNS server (optional)bind9Create a local domain such as myhome.local

✏️ Book note

The book gives the default login as pi / raspberry. Current Raspberry Pi OS makes you create your own user when you set it up. Follow the official guides for each tool, since settings change between versions.

Next: review →

Quick quiz

1. What does a firewall check on each packet?
2. What does stateful inspection add?
3. Which threat will a firewall handle worst?
4. How does NAT help security?
5. Symmetric encryption uses…
6. Alice wants to send Bob a secret. Which key should she encrypt with?
7. Who issues a certificate for a website?
8. A digital signature is the…
9. What does Diffie-Hellman let two people do?

HL Extra questions

1. Which attack uses thousands of compromised devices?
2. Why is a zero-day so dangerous?
3. An IDS differs from an IPS because it…
4. Password and fingerprint together are…

Exam-style questions

These are written for this site in the style of Paper 1. Answer on paper first, then open the mark points.

  1. Discuss whether a firewall alone is enough to protect a company network. [3]

    Mark points
    • A firewall filters traffic by addresses and ports [1].
    • It may not inspect content, so malicious data to a legitimate destination can pass [1].
    • It does not stop insiders, so other measures are needed as well [1].
  2. Distinguish between symmetric and asymmetric encryption. [3]

    Mark points
    • Symmetric encryption uses one shared key [1].
    • Asymmetric uses a public key to encrypt and a private key to decrypt [1].
    • Symmetric is faster, while asymmetric solves the problem of sharing a key [1].
  3. Describe how NAT contributes to network security. [2]

    Mark points
    • It replaces internal addresses with a public one [1].
    • So attackers cannot see or directly reach internal devices [1].
  4. Explain how a web browser can trust a bank’s website. [4]

    Mark points
    • The bank obtains a certificate from a certificate authority [1].
    • The CA verifies the bank and signs its public key with the CA’s private key [1].
    • The browser verifies that signature using the CA’s public key [1].
    • So it knows the public key belongs to the bank, not an imposter [1].
  5. Explain how a digital signature proves a document has not been changed. [3]

    Mark points
    • A hash of the document is encrypted with the sender’s private key [1].
    • The receiver decrypts it with the public key and hashes the document [1].
    • If the two hashes match, it has not been altered [1].

HL Exam-style questions

  1. Describe SQL injection and its effect on a website. [3]

    Mark points
    • The attacker enters SQL commands into an input field [1].
    • Unvalidated input is joined into a query and executed [1].
    • Data can be read, changed or deleted [1].
  2. Describe one vulnerability and a matching countermeasure for each of phishing and unpatched software. [4]

    Mark points
    • Phishing tricks users into revealing details [1].
    • Staff training and email filtering reduce this [1].
    • Unpatched software has publicly known flaws [1].
    • Applying security updates promptly closes them [1].