Skip to main content

Network Security

1. Threats and Vulnerabilities

Types of Threats

ThreatDescription
MalwareMalicious software (viruses, worms, trojans, ransomware)
PhishingFraudulent emails/messages tricking users into revealing credentials
DDoS attackOverwhelming a server with traffic from multiple sources
Man-in-the-middleAttacker intercepts communication between two parties
SQL injectionInserting malicious SQL into input fields to manipulate databases
Brute force attackSystematically trying all possible passwords/keys
Social engineeringManipulating people into divulging confidential information

The CIA Triad

The three core principles of information security:

  1. Confidentiality: Data is accessible only to authorised parties
  2. Integrity: Data is accurate and has not been tampered with
  3. Availability: Data and services are accessible when needed

2. Symmetric Encryption

Definition

Symmetric encryption uses the same key for both encryption and decryption.

C=EK(M),M=DK(C)C = E_K(M), \quad M = D_K(C)

where MM is the plaintext, CC is the ciphertext, EE is the encryption function, DD is the decryption function, and KK is the shared secret key.

AES (Advanced Encryption Standard)

AES is the most widely used symmetric encryption algorithm.

PropertyValue
Key sizes128, 192, 256 bits
Block size128 bits
Rounds10 (128-bit), 12 (192-bit), 14 (256-bit)
TypeSubstitution-permutation network

Key Distribution Problem

Symmetric encryption requires both parties to share the same secret key. Distributing this key securely is a fundamental challenge — if the key is intercepted during exchange, the encryption is compromised.


3. Asymmetric Encryption

Definition

Asymmetric encryption (public-key cryptography) uses a pair of keys: a public key (shared openly) and a private key (kept secret).

C=Epub(M),M=Dpriv(C)C = E_{\mathrm{pub}}(M), \quad M = D_{\mathrm{priv}}(C)

  • Anyone can encrypt using the public key
  • Only the private key holder can decrypt

RSA Algorithm

Key Generation

  1. Choose two large primes pp and qq
  2. Compute n=p×qn = p \times q
  3. Compute ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1) (Euler's totient)
  4. Choose ee such that 1<e<ϕ(n)1 \lt{} e \lt{} \phi(n) and gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1
  5. Compute dd such that de1(modϕ(n))d \cdot e \equiv 1 \pmod{\phi(n)}

Public key: (e,n)(e, n). Private key: (d,n)(d, n).

Encryption and Decryption

Encrypt: C=MemodnC = M^e \bmod n

Decrypt: M=CdmodnM = C^d \bmod n

Correctness Proof

Theorem. RSA decryption correctly recovers the original message: (Me)dM(modn)(M^e)^d \equiv M \pmod{n} for all M[0,n)M \in [0, n).

Proof. We need to show MedM(modn)M^{ed} \equiv M \pmod{n}.

Since ed1(modϕ(n))ed \equiv 1 \pmod{\phi(n)}, we have ed=1+kϕ(n)ed = 1 + k\phi(n) for some integer kk.

Case 1: gcd(M,n)=1\gcd(M, n) = 1 (M is coprime to n).

By Euler's theorem: Mϕ(n)1(modn)M^{\phi(n)} \equiv 1 \pmod{n}.

Therefore: Med=M1+kϕ(n)=M(Mϕ(n))kM1kM(modn)M^{ed} = M^{1 + k\phi(n)} = M \cdot (M^{\phi(n)})^k \equiv M \cdot 1^k \equiv M \pmod{n}. ✓

Case 2: gcd(M,n)1\gcd(M, n) \neq 1. Since n=pqn = pq, MM must be divisible by pp or qq (but not both, since M<n=pqM \lt{} n = pq).

Without loss of generality, let M0(modp)M \equiv 0 \pmod{p}. Then Med0M(modp)M^{ed} \equiv 0 \equiv M \pmod{p}. ✓

For qq: since M≢0(modq)M \not\equiv 0 \pmod{q}, gcd(M,q)=1\gcd(M, q) = 1. By Fermat's little theorem: Mq11(modq)M^{q-1} \equiv 1 \pmod{q}. Since ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1):

Med=M1+k(p1)(q1)=M(Mq1)k(p1)M1k(p1)M(modq)M^{ed} = M^{1 + k(p-1)(q-1)} = M \cdot (M^{q-1})^{k(p-1)} \equiv M \cdot 1^{k(p-1)} \equiv M \pmod{q}

By the Chinese Remainder Theorem: MedM(modn)M^{ed} \equiv M \pmod{n}. ✓ \square

Key Sizes and Security

Key sizeSecurity levelNotes
1024 bits~80 bitsInsecure, deprecated
2048 bits~112 bitsMinimum recommended
3072 bits~128 bitsHigh security
4096 bits~150 bitsVery high security

4. Digital Signatures

Purpose

A digital signature provides:

  1. Authentication: Proves who sent the message
  2. Integrity: Proves the message wasn't altered
  3. Non-repudiation: The sender cannot deny sending it

Process

Signing: S=Dpriv(H(M))S = D_{\mathrm{priv}}(H(M))

where HH is a hash function. The sender hashes the message and "decrypts" the hash with their private key.

Verification: H(M)=?Epub(S)H(M) \stackrel{?}{=} E_{\mathrm{pub}}(S)

The receiver encrypts the signature with the sender's public key and compares it to the hash of the received message.

Correctness: Since only the sender knows the private key, only they could have produced SS. If the message was altered, H(M)H(M) would differ, and verification would fail.


5. Hash Functions

Definition

A cryptographic hash function H:{0,1}{0,1}nH: \{0,1\}^* \to \{0,1\}^n maps arbitrary-length input to a fixed-length output (hash/digest).

Properties

  1. Pre-image resistance: Given hh, it is computationally infeasible to find MM such that H(M)=hH(M) = h
  2. Second pre-image resistance: Given M1M_1, it is infeasible to find M2M1M_2 \neq M_1 with H(M1)=H(M2)H(M_1) = H(M_2)
  3. Collision resistance: It is infeasible to find any pair M1M2M_1 \neq M_2 with H(M1)=H(M2)H(M_1) = H(M_2)
  4. Avalanche effect: A small change in input produces a completely different hash
  5. Deterministic: Same input always produces the same output

Common Hash Functions

AlgorithmOutput sizeStatus
MD5128 bitsBroken (collisions found)
SHA-1160 bitsBroken (collision attack)
SHA-256256 bitsSecure
SHA-512512 bitsSecure

Applications

  • Password storage: Store H(password)H(\mathrm{password}) instead of the plaintext password
  • Data integrity: Compare hashes before and after transmission
  • Digital signatures: Sign the hash instead of the entire message
  • Blockchain: Hash pointers link blocks

Password Hashing

Why not just hash? Simple hashing is vulnerable to rainbow tables (precomputed hash-lookup tables).

Salting: Add a random string (salt) before hashing: H(salt+password)H(\mathrm{salt} + \mathrm{password}). Each user gets a unique salt, making rainbow tables useless.

Key stretching: Use slow hash functions (bcrypt, PBKDF2, Argon2) that deliberately take many iterations, making brute-force attacks impractical.


6. Firewalls

Definition

A firewall is a network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules.

Types

TypeHow it worksLayer
Packet filteringExamines source/destination IP and portNetwork (L3)
StatefulTracks connection stateTransport (L4)
Application-layerInspects actual contentApplication (L7)
Next-generationCombines all above + IDS/IPS, deep inspectionAll layers
info

info

  • AQA requires symmetric encryption (AES), asymmetric encryption (RSA), digital signatures, SSL/TLS, firewalls, and malware types
  • CIE (9618) covers encryption methods, network security protocols, and threats; may include specific protocol details
  • OCR (A) requires understanding of encryption, digital certificates, authentication methods, and network security protocols
  • Edexcel covers network security fundamentals including encryption and firewalls

Problem Set

Problem 1. Given RSA parameters p=5p = 5, q=11q = 11, e=3e = 3, encrypt the message M=7M = 7 and then decrypt it. Show all steps.

Answer

n=p×q=5×11=55n = p \times q = 5 \times 11 = 55

ϕ(n)=(51)(111)=40\phi(n) = (5-1)(11-1) = 40

Verify: gcd(3,40)=1\gcd(3, 40) = 1

Find dd: 3d1(mod40)3d \equiv 1 \pmod{40}. Try: 3×27=81=2×40+13 \times 27 = 81 = 2 \times 40 + 1. So d=27d = 27.

Encrypt: C=73mod55=343mod55=3436×55=343330=13C = 7^3 \bmod 55 = 343 \bmod 55 = 343 - 6 \times 55 = 343 - 330 = 13.

Decrypt: M=1327mod55M = 13^{27} \bmod 55.

Using repeated squaring: 132=169mod55=413^2 = 169 \bmod 55 = 4. 134=42=1613^4 = 4^2 = 16. 138=162=256mod55=3613^8 = 16^2 = 256 \bmod 55 = 36. 1316=362=1296mod55=129623×55=12961265=3113^{16} = 36^2 = 1296 \bmod 55 = 1296 - 23 \times 55 = 1296 - 1265 = 31.

1327=1316×138×132×131=31×36×4×1313^{27} = 13^{16} \times 13^8 \times 13^2 \times 13^1 = 31 \times 36 \times 4 \times 13

31×36=1116mod55=111620×55=11161100=1631 \times 36 = 1116 \bmod 55 = 1116 - 20 \times 55 = 1116 - 1100 = 16

16×4=64mod55=916 \times 4 = 64 \bmod 55 = 9

9×13=117mod55=1172×55=79 \times 13 = 117 \bmod 55 = 117 - 2 \times 55 = 7

Decrypted message: 7. ✓

Problem 2. Explain why symmetric encryption is faster than asymmetric encryption.

Answer

Symmetric encryption (e.g., AES) uses simple operations: substitution boxes (S-boxes), bit permutations, and XOR — all of which are fast hardware operations. AES-128 requires only 10 rounds of these operations.

Asymmetric encryption (e.g., RSA) relies on computationally expensive mathematical operations: modular exponentiation on very large numbers (hundreds of digits). RSA encryption requires computing MemodnM^e \bmod n where nn is at least 2048 bits (617 decimal digits). Modular exponentiation of such large numbers is orders of magnitude slower than AES.

Typical performance: AES processes ~1 GB/s on modern hardware. RSA-2048 processes ~1,000 operations/second. AES is roughly 1000× faster.

Problem 3. A user's password is stored as SHA-256("password123") = ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f. Explain why this is insecure and how to improve it.

Answer

Problems:

  1. No salt: identical passwords produce identical hashes → vulnerable to rainbow table attacks
  2. SHA-256 is too fast: an attacker can try billions of hashes per second using a GPU
  3. No key stretching: a single hash computation is very fast, enabling brute-force attacks

Improvements:

  1. Use a unique salt per user: Store salt and bcrypt(salt + password) instead
  2. Use a slow hash function: bcrypt, PBKDF2, or Argon2 are designed to be slow (configurable cost parameter)
  3. Use key stretching: Multiple iterations of the hash function (PBKDF2 does this)

Example secure storage: argon2id(salt="random_16_bytes", password, iterations=3, memory=64MB)

Problem 4. Explain how a man-in-the-middle attack works and how HTTPS prevents it.

Answer

MITM attack:

  1. Attacker positions themselves between the client and server (e.g., on a public Wi-Fi network)
  2. The client sends data to the attacker, thinking it's the server
  3. The attacker reads/modifies the data and forwards it to the server
  4. The server responds to the attacker, who forwards it to the client
  5. Neither party is aware of the interception

How HTTPS prevents MITM:

  1. TLS handshake: The server presents an SSL certificate signed by a trusted Certificate Authority (CA)
  2. Certificate verification: The client checks that the certificate is valid, signed by a trusted CA, and matches the domain
  3. Key exchange: The client and server establish a shared secret using asymmetric encryption (Diffie-Hellman or RSA), without ever sending the secret over the network
  4. Encryption: All subsequent communication is encrypted with the shared secret

Even if the attacker intercepts the traffic, they cannot:

  • Decrypt the data (they don't have the shared secret)
  • Forge a valid certificate (they don't have the CA's private key)
  • Modify the data without detection (TLS includes integrity checks)

Problem 5. Explain the difference between a virus, a worm, and a Trojan.

Answer
MalwareReproductionNeeds hostUser action requiredPurpose
VirusAttaches to filesYes (infects other files)Yes (open infected file)Various
WormSelf-replicates over networkNoNoSpread, payload
TrojanDoes not replicateNo (disguised as legitimate)Yes (install it)Data theft, backdoor

Virus: Attaches to legitimate programs and spreads when the infected program is run. Can corrupt or modify files.

Worm: Self-replicating malware that spreads over networks without user interaction. Example: the WannaCry ransomware worm spread via SMB.

Trojan: Malware disguised as legitimate software. Does not replicate. Creates backdoors for attackers. Named after the Trojan Horse of Greek mythology.

Problem 6. Explain the role of a Certificate Authority (CA) in public-key cryptography.

Answer

A Certificate Authority (CA) is a trusted entity that issues digital certificates binding a public key to an identity (domain name, organisation, person).

Process:

  1. A website generates a key pair and sends the public key + identity to a CA
  2. The CA verifies the applicant's identity (domain ownership, business registration)
  3. The CA signs the certificate with its own private key: Sign_CA(domain, public_key, expiry)
  4. The website presents this certificate to browsers during the TLS handshake
  5. The browser verifies the signature using the CA's public key (pre-installed in the browser)

Why important: Without CAs, an attacker could create a certificate for any domain, and browsers would have no way to distinguish legitimate certificates from fraudulent ones. CAs provide the trust infrastructure that makes HTTPS work.

Problem 7. Compute the SHA-256 hash of the empty string "". Then compute the SHA-256 hash of "a". What does this demonstrate about hash functions?

Answer

SHA-256("") = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

SHA-256("a") = ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb

This demonstrates:

  1. Determinism: The same input always produces the same output
  2. Avalanche effect: Changing a single character ("a" vs "") produces a completely different hash — no similarity between the two outputs
  3. Fixed output size: Both hashes are 256 bits (64 hex characters), regardless of input length

Problem 8. Describe a SQL injection attack and explain how to prevent it.

Answer

SQL injection: An attacker inserts malicious SQL code into an input field that is concatenated into a database query.

Vulnerable code:

query = f"SELECT * FROM users WHERE username = '{username}' AND password = '{password}'"

Attack: Input username = ' OR '1'='1 → query becomes:

SELECT * FROM users WHERE username = '' OR '1'='1' AND password = 'anything'

This always evaluates to true, granting access without valid credentials.

Prevention:

  1. Parameterised queries (prepared statements): Use placeholders instead of string concatenation:
cursor.execute("SELECT * FROM users WHERE username = ? AND password = ?", (username, password))
  1. Input validation: Reject or sanitise inputs containing SQL metacharacters
  2. Least privilege: Database accounts should have minimum necessary permissions
  3. Stored procedures: Pre-compiled SQL that accepts parameters safely

For revision on network fundamentals, see Network Fundamentals.


7. Worked Examples: Firewall Rules and Encryption

Worked Example: Designing Firewall Rules

A company web server (IP 203.0.113.10) needs the following access:

  • Allow HTTP from any source
  • Allow HTTPS from any source
  • Allow SSH only from the admin network (10.0.0.0/24)
  • Deny all other inbound traffic
RuleDirectionSourceDestinationPortProtocolAction
1InboundAny203.0.113.1080TCPAllow
2InboundAny203.0.113.10443TCPAllow
3Inbound10.0.0.0/24203.0.113.1022TCPAllow
4InboundAnyAnyAnyAnyDeny

Rule 4 is the default deny rule — it blocks everything not explicitly allowed. Rules are processed top-to-bottom, so the specific rules (1-3) are evaluated before the catch-all deny.

Worked Example: Symmetric vs Asymmetric Encryption in HTTPS

HTTPS uses both symmetric and asymmetric encryption:

  1. Asymmetric encryption (RSA or ECDHE) is used during the TLS handshake to establish a shared secret. This is slow but solves the key distribution problem — the client and server never transmit the secret directly.
  2. Symmetric encryption (AES-256-GCM) is used for all subsequent data transfer. This is fast and provides confidentiality and integrity.

The asymmetric step happens once per session. The symmetric step happens for every packet.

Worked Example: WPA2-PSK Authentication

WPA2-Personal (PSK) uses a pre-shared key:

  1. 4-way handshake: The access point and client prove they both know the PSK without transmitting it
  2. Key derivation: The PSK is combined with the network name (SSID) using PBKDF2 to derive a Pairwise Master Key (PMK)
  3. Session key: The PMK is used to generate a unique Pairwise Transient Key (PTK) for each session
  4. Encryption: Data is encrypted with AES-CCMP using the PTK

The PSK is never transmitted over the air. An attacker capturing the handshake can attempt an offline brute-force attack against the PSK.


8. SQL Injection Prevention in Detail

Types of SQL Injection

TypeDescriptionExample
Classic (in-band)Attacker sees results directly in the application' OR '1'='1
Blind (boolean)Attacker infers results from true/false responses' AND 1=1 -- vs ' AND 1=2 --
Blind (time-based)Attacker infers results from response delays'; WAITFOR DELAY '0:0:5' --
Out-of-bandAttacker triggers data exfiltration via DNS or HTTP' UNION SELECT ... INTO OUTFILE

Defence in Depth

  1. Parameterised queries: The primary defence. The database treats parameters as data, never as executable SQL.
cursor.execute(
"SELECT * FROM users WHERE username = ? AND password_hash = ?",
(username, password_hash)
)
  1. Input validation: Reject characters that have no legitimate purpose (e.g., ;, ', --, /*)

  2. Least privilege: The application's database account should only have permissions for the operations it needs (SELECT, INSERT — not DROP, ALTER)

  3. Stored procedures: Pre-compiled SQL that accepts parameters, preventing injection at the database layer

  4. Web Application Firewall (WAF): A secondary defence that inspects HTTP requests for known injection patterns


9. DDoS Attack Types

Attack typeLayerDescription
SYN floodL4 (Transport)Sends SYN packets without completing the handshake, exhausting server connection table
UDP floodL4 (Transport)Sends massive UDP traffic to random ports, forcing the server to send ICMP responses
ICMP floodL3 (Network)Overwhelms the target with ping requests
HTTP floodL7 (Application)Sends legitimate-looking HTTP requests that are computationally expensive
DNS amplificationL3/L7Sends small queries to open DNS resolvers with the victim's spoofed IP, causing a massive response

SYN flood exploits the TCP handshake: the server allocates resources for each half-open connection. When the table fills, legitimate connections are dropped. Mitigation: SYN cookies — the server encodes state in the SYN-ACK without allocating memory until the ACK is received.

DNS amplification exploits the large response-to-request ratio of DNS queries. A 60-byte request can generate a 4000-byte response, providing a ~66x amplification factor.


10. Common Pitfalls

PitfallExplanationCorrect approach
Using MD5 or SHA-1 for passwordsFast hashes allow billions of guesses per secondUse bcrypt, PBKDF2, or Argon2
Relying on encryption alone for securityEncryption does not verify identityCombine with authentication and integrity checks
Writing your own cryptoCustom algorithms are almost always brokenUse well-vetted libraries (OpenSSL, libsodium)
Storing passwords in plaintextAny database breach exposes all passwordsAlways hash and salt passwords
Confusing hashing with encryptionHashes are one-way; encryption is reversibleHash passwords, encrypt data that needs to be retrieved
Firewall rules in wrong orderRules are evaluated top-to-bottom; a broad allow before a specific deny defeats the denyPlace specific rules first, default deny last

11. Additional Problem Set

Problem 1. A firewall has the following rules in order. Determine whether a TCP packet from 10.0.0.5 to 192.168.1.10 on port 80 is allowed or denied.

RuleSourceDestinationPortAction
110.0.0.0/24192.168.1.1022Allow
2Any192.168.1.1080Allow
3AnyAnyAnyDeny
Answer

Rule 1: Source matches 10.0.0.0/24 (yes, 10.0.0.5 is in this range), destination matches 192.168.1.10, but port 80 does not match port 22. Rule 1 does not apply.

Rule 2: Source is "Any" (matches), destination matches 192.168.1.10, port 80 matches port 80. Rule 2 applies — Allow.

The packet is allowed by Rule 2.

Problem 2. Explain how a SYN flood DDoS attack works and describe how SYN cookies mitigate it.

Answer

SYN flood: The attacker sends a large volume of SYN packets with spoofed source IP addresses. The server responds with SYN-ACK to each, allocates memory for the half-open connection, and waits for the ACK that never arrives (because the source IP is spoofed). The server's connection table fills up, preventing legitimate connections.

SYN cookies mitigation: Instead of allocating state for each half-open connection, the server encodes the connection state (a hash of source IP, source port, destination IP, destination port, and a secret) into the initial sequence number of the SYN-ACK. When the ACK arrives, the server recomputes the hash from the packet headers and verifies it matches. Only if the ACK is valid does the server allocate memory for the connection. This eliminates the resource exhaustion problem.

Problem 3. A database stores user passwords as unsalted SHA-256 hashes. An attacker obtains the database. Explain two attacks the attacker can use and how salting prevents each.

Answer

Attack 1: Rainbow table attack. The attacker uses a precomputed table mapping common passwords to their SHA-256 hashes. They look up each stored hash in the table to find the original password.

How salting prevents it: A unique random salt is added to each password before hashing: SHA-256(salt + password). The attacker would need a separate rainbow table for every possible salt, which is computationally infeasible.

Attack 2: Dictionary attack. The attacker hashes a list of common passwords and compares each hash to the stored values. Identical passwords produce identical hashes, so cracking one reveals all users with the same password.

How salting prevents it: With unique salts, identical passwords produce different hashes. The attacker must crack each hash independently, even if multiple users have the same password.

Problem 4. Explain why symmetric encryption alone is insufficient for secure communication over the internet, and describe how asymmetric encryption solves this problem.

Answer

Symmetric encryption requires both parties to share the same secret key. Sending this key over the internet exposes it to interception — a chicken-and-egg problem: you need a secure channel to establish the key, but you need the key to create a secure channel.

Asymmetric encryption solves this because the public key can be transmitted openly. The sender encrypts the symmetric session key with the receiver's public key. Only the receiver's private key can decrypt it. This is how TLS works: the asymmetric handshake establishes a shared secret, and all subsequent data uses fast symmetric encryption.

Without asymmetric encryption, there would be no practical way to establish secure communication between parties who have never met in person.

Problem 5. Describe three principles of defence in depth and explain how each contributes to network security.

Answer
  1. Multiple layers of security: No single defence is perfect. Using a firewall, intrusion detection system, encryption, and access control together means that if one layer fails, the others still provide protection. Example: even if a firewall is misconfigured, encrypted data prevents an attacker from reading intercepted traffic.

  2. Least privilege: Users and systems should only have the minimum permissions needed for their role. If an account is compromised, the attacker's access is limited. Example: a web application's database account should have SELECT and INSERT permissions but not DROP TABLE.

  3. Fail-safe defaults: Systems should default to the most secure configuration. If a rule or configuration is missing, the system should deny access rather than allow it. Example: a firewall's final rule should be "deny all" — anything not explicitly permitted is blocked.

:::