Network Security
1. Threats and Vulnerabilities
Types of Threats
| Threat | Description |
|---|---|
| Malware | Malicious software (viruses, worms, trojans, ransomware) |
| Phishing | Fraudulent emails/messages tricking users into revealing credentials |
| DDoS attack | Overwhelming a server with traffic from multiple sources |
| Man-in-the-middle | Attacker intercepts communication between two parties |
| SQL injection | Inserting malicious SQL into input fields to manipulate databases |
| Brute force attack | Systematically trying all possible passwords/keys |
| Social engineering | Manipulating people into divulging confidential information |
The CIA Triad
The three core principles of information security:
- Confidentiality: Data is accessible only to authorised parties
- Integrity: Data is accurate and has not been tampered with
- Availability: Data and services are accessible when needed
2. Symmetric Encryption
Definition
Symmetric encryption uses the same key for both encryption and decryption.
where is the plaintext, is the ciphertext, is the encryption function, is the decryption function, and is the shared secret key.
AES (Advanced Encryption Standard)
AES is the most widely used symmetric encryption algorithm.
| Property | Value |
|---|---|
| Key sizes | 128, 192, 256 bits |
| Block size | 128 bits |
| Rounds | 10 (128-bit), 12 (192-bit), 14 (256-bit) |
| Type | Substitution-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).
- Anyone can encrypt using the public key
- Only the private key holder can decrypt
RSA Algorithm
Key Generation
- Choose two large primes and
- Compute
- Compute (Euler's totient)
- Choose such that and
- Compute such that
Public key: . Private key: .
Encryption and Decryption
Encrypt:
Decrypt:
Correctness Proof
Theorem. RSA decryption correctly recovers the original message: for all .
Proof. We need to show .
Since , we have for some integer .
Case 1: (M is coprime to n).
By Euler's theorem: .
Therefore: . ✓
Case 2: . Since , must be divisible by or (but not both, since ).
Without loss of generality, let . Then . ✓
For : since , . By Fermat's little theorem: . Since :
✓
By the Chinese Remainder Theorem: . ✓
Key Sizes and Security
| Key size | Security level | Notes |
|---|---|---|
| 1024 bits | ~80 bits | Insecure, deprecated |
| 2048 bits | ~112 bits | Minimum recommended |
| 3072 bits | ~128 bits | High security |
| 4096 bits | ~150 bits | Very high security |
4. Digital Signatures
Purpose
A digital signature provides:
- Authentication: Proves who sent the message
- Integrity: Proves the message wasn't altered
- Non-repudiation: The sender cannot deny sending it
Process
Signing:
where is a hash function. The sender hashes the message and "decrypts" the hash with their private key.
Verification:
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 . If the message was altered, would differ, and verification would fail.
5. Hash Functions
Definition
A cryptographic hash function maps arbitrary-length input to a fixed-length output (hash/digest).
Properties
- Pre-image resistance: Given , it is computationally infeasible to find such that
- Second pre-image resistance: Given , it is infeasible to find with
- Collision resistance: It is infeasible to find any pair with
- Avalanche effect: A small change in input produces a completely different hash
- Deterministic: Same input always produces the same output
Common Hash Functions
| Algorithm | Output size | Status |
|---|---|---|
| MD5 | 128 bits | Broken (collisions found) |
| SHA-1 | 160 bits | Broken (collision attack) |
| SHA-256 | 256 bits | Secure |
| SHA-512 | 512 bits | Secure |
Applications
- Password storage: Store 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: . 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
| Type | How it works | Layer |
|---|---|---|
| Packet filtering | Examines source/destination IP and port | Network (L3) |
| Stateful | Tracks connection state | Transport (L4) |
| Application-layer | Inspects actual content | Application (L7) |
| Next-generation | Combines all above + IDS/IPS, deep inspection | All layers |
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 , , , encrypt the message and then decrypt it. Show all steps.
Answer
Verify: ✓
Find : . Try: . So .
Encrypt: .
Decrypt: .
Using repeated squaring: . . . .
✓
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 where 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:
- No salt: identical passwords produce identical hashes → vulnerable to rainbow table attacks
- SHA-256 is too fast: an attacker can try billions of hashes per second using a GPU
- No key stretching: a single hash computation is very fast, enabling brute-force attacks
Improvements:
- Use a unique salt per user: Store
saltandbcrypt(salt + password)instead - Use a slow hash function: bcrypt, PBKDF2, or Argon2 are designed to be slow (configurable cost parameter)
- 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:
- Attacker positions themselves between the client and server (e.g., on a public Wi-Fi network)
- The client sends data to the attacker, thinking it's the server
- The attacker reads/modifies the data and forwards it to the server
- The server responds to the attacker, who forwards it to the client
- Neither party is aware of the interception
How HTTPS prevents MITM:
- TLS handshake: The server presents an SSL certificate signed by a trusted Certificate Authority (CA)
- Certificate verification: The client checks that the certificate is valid, signed by a trusted CA, and matches the domain
- 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
- 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
| Malware | Reproduction | Needs host | User action required | Purpose |
|---|---|---|---|---|
| Virus | Attaches to files | Yes (infects other files) | Yes (open infected file) | Various |
| Worm | Self-replicates over network | No | No | Spread, payload |
| Trojan | Does not replicate | No (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:
- A website generates a key pair and sends the public key + identity to a CA
- The CA verifies the applicant's identity (domain ownership, business registration)
- The CA signs the certificate with its own private key:
Sign_CA(domain, public_key, expiry) - The website presents this certificate to browsers during the TLS handshake
- 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:
- Determinism: The same input always produces the same output
- Avalanche effect: Changing a single character ("a" vs "") produces a completely different hash — no similarity between the two outputs
- 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:
- Parameterised queries (prepared statements): Use placeholders instead of string concatenation:
cursor.execute("SELECT * FROM users WHERE username = ? AND password = ?", (username, password))
- Input validation: Reject or sanitise inputs containing SQL metacharacters
- Least privilege: Database accounts should have minimum necessary permissions
- 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
| Rule | Direction | Source | Destination | Port | Protocol | Action |
|---|---|---|---|---|---|---|
| 1 | Inbound | Any | 203.0.113.10 | 80 | TCP | Allow |
| 2 | Inbound | Any | 203.0.113.10 | 443 | TCP | Allow |
| 3 | Inbound | 10.0.0.0/24 | 203.0.113.10 | 22 | TCP | Allow |
| 4 | Inbound | Any | Any | Any | Any | Deny |
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:
- 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.
- 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:
- 4-way handshake: The access point and client prove they both know the PSK without transmitting it
- Key derivation: The PSK is combined with the network name (SSID) using PBKDF2 to derive a Pairwise Master Key (PMK)
- Session key: The PMK is used to generate a unique Pairwise Transient Key (PTK) for each session
- 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
| Type | Description | Example |
|---|---|---|
| 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-band | Attacker triggers data exfiltration via DNS or HTTP | ' UNION SELECT ... INTO OUTFILE |
Defence in Depth
- 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)
)
-
Input validation: Reject characters that have no legitimate purpose (e.g.,
;,',--,/*) -
Least privilege: The application's database account should only have permissions for the operations it needs (SELECT, INSERT — not DROP, ALTER)
-
Stored procedures: Pre-compiled SQL that accepts parameters, preventing injection at the database layer
-
Web Application Firewall (WAF): A secondary defence that inspects HTTP requests for known injection patterns
9. DDoS Attack Types
| Attack type | Layer | Description |
|---|---|---|
| SYN flood | L4 (Transport) | Sends SYN packets without completing the handshake, exhausting server connection table |
| UDP flood | L4 (Transport) | Sends massive UDP traffic to random ports, forcing the server to send ICMP responses |
| ICMP flood | L3 (Network) | Overwhelms the target with ping requests |
| HTTP flood | L7 (Application) | Sends legitimate-looking HTTP requests that are computationally expensive |
| DNS amplification | L3/L7 | Sends 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
| Pitfall | Explanation | Correct approach |
|---|---|---|
| Using MD5 or SHA-1 for passwords | Fast hashes allow billions of guesses per second | Use bcrypt, PBKDF2, or Argon2 |
| Relying on encryption alone for security | Encryption does not verify identity | Combine with authentication and integrity checks |
| Writing your own crypto | Custom algorithms are almost always broken | Use well-vetted libraries (OpenSSL, libsodium) |
| Storing passwords in plaintext | Any database breach exposes all passwords | Always hash and salt passwords |
| Confusing hashing with encryption | Hashes are one-way; encryption is reversible | Hash passwords, encrypt data that needs to be retrieved |
| Firewall rules in wrong order | Rules are evaluated top-to-bottom; a broad allow before a specific deny defeats the deny | Place 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.
| Rule | Source | Destination | Port | Action |
|---|---|---|---|---|
| 1 | 10.0.0.0/24 | 192.168.1.10 | 22 | Allow |
| 2 | Any | 192.168.1.10 | 80 | Allow |
| 3 | Any | Any | Any | Deny |
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
-
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.
-
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.
-
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.
:::