TExcelTAD
Home › Security Foundations: Concepts, Law, Ethics & Your Lab › Security Foundations Exercises

Security Foundations Exercises

Twenty-four exercises across the whole course, most of them small enough to do on paper. Try each one before opening the answer. The numeric answers are checked by one program at the end, which you can edit and run.

# Exercise Practises
1 Pick the access-control model CIA, AAA and Access Control
2 Label the vocabulary Threat, Vulnerability, Exploit and Risk
3 Which socket is exposed? Attack Vectors and the Attack Surface
4 Score and price a risk Risk Assessment
5 Classify the controls Security Auditing and Controls
6 One incident, several categories A Map of the Attack Categories
7 Online and offline guessing Brute Force and Password Spraying
8 Read the headers Phishing and Social Engineering
9 Amplification arithmetic Denial of Service and DDoS
10 Why a nonce and a timestamp Man-in-the-Middle and Replay Attacks
11 Fix the cookie Session Hijacking and Credential Theft
12 Find the spoofed reply DNS and ARP Spoofing
13 Entropy by hand Malware and Ransomware
14 Typosquats and checksums Supply-Chain Attacks
15 Safe and unsafe sudo rules Privilege Escalation, Linux Permissions
16 Which engagement? Red, Blue and Purple Teams
17 In scope or not? Authorization, Scope and Rules of Engagement
18 After Van Buren US Law
19 NIS2 deadlines and the Computer Misuse Act UK and EU Law
20 Which Vietnamese law applies? Vietnamese Law
21 Repair a security.txt Responsible Disclosure
22 Read the credentials and the crash Processes, Privileges and System Calls, Memory Protection
23 Reconstruct a Windows incident Windows Accounts, Tokens and UAC, The Windows Registry and Event Log, Linux Services and Logs
24 Choose the network mode Hypervisors, VM Networks and Snapshots, Lab Machines and Vulnerable Apps, Lab Safety

Exercise 1: Pick the access-control model

Name the model (DAC, MAC, RBAC or ABAC) for each rule: (a) "a nurse may read the records of patients on her own ward, during her shift"; (b) "everyone in the accounting role may approve invoices"; (c) "the owner of a file decides who else may read it"; (d) "a document labelled SECRET can't be read by a user cleared only for CONFIDENTIAL, whatever the owner wants".

Answer

(a) ABAC: the decision uses attributes of the user (ward, shift), the resource (patient's ward) and the environment (time). (b) RBAC. (c) DAC, as with Unix permissions set by the owner. (d) MAC: labels and clearances set by policy, which the owner can't override.

Exercise 2: Label the vocabulary

A web shop runs shopcart 2.10.0. An advisory says versions before 2.4.1 allow SQL injection in the search box; a criminal group scans for it; a published proof-of-concept request extracts the user table; the shop uses a web application firewall. Label the asset, the threat, the vulnerability, the exploit and the control. Is this shop affected? What does a naive string comparison "2.10.0" < "2.4.1" say?

Answer

Asset: the shop and its user data. Threat: the criminal group. Vulnerability: the SQL injection in versions before 2.4.1. Exploit: the proof-of-concept request. Control: the WAF (and, better, the patch). Version 2.10.0 is newer than 2.4.1, so the shop is not affected; but as strings "2.10.0" < "2.4.1" is True (the character 1 sorts before 4), so a scanner comparing strings reports a false positive. Compare versions as tuples of numbers.

Exercise 3: Which socket is exposed?

ss -tln on a server prints listeners on 127.0.0.1:5432, 0.0.0.0:8080, [::1]:6379 and 10.10.0.10:22. Which can be reached from another machine, and from where?

Answer

0.0.0.0:8080 listens on every IPv4 interface: reachable from any network the server is attached to. 10.10.0.10:22 is reachable from the network of that address (the lab network). 127.0.0.1:5432 and [::1]:6379 are loopback only: reachable from processes on the same machine, not from the network. The surface to review is therefore 8080 and 22 (and, if 8080 is not meant to be public, bind it to 127.0.0.1 or put a firewall rule in front).

Exercise 4: Score and price a risk

(a) Using the track's bands (low 1–4, medium 5–9, high 10–19, critical 20–25), score a risk with likelihood 2 and impact 5. (b) Laptops worth 30,000 each (data and rebuild included) are lost about 0.2 times a year; disk encryption, costing 600 a year, reduces the loss per incident to 1,500. Compute the ALE before and after and the net benefit.

Answer

(a) 2×5=102 \times 5 = 10: high.

(b) Before: SLE =30 000= 30\,000, ALE =30 000×0.2=6 000= 30\,000 \times 0.2 = 6\,000. After: ALE =1 500×0.2=300= 1\,500 \times 0.2 = 300. The reduction is 5,700 a year against a cost of 600: a net benefit of 5,100 a year.

Exercise 5: Classify the controls

Give the function (preventive, detective, corrective, deterrent) and the kind (administrative, technical, physical) of: a login banner warning that access is monitored; a nightly file-integrity scan; a guard at the server-room door; re-imaging a compromised laptop; a written password policy.

Answer

Banner: deterrent, technical (some count it administrative). Integrity scan: detective, technical. Guard: preventive (and deterrent), physical. Re-imaging: corrective, technical. Password policy: preventive, administrative. Real controls often have more than one function; an audit records the main one and checks that every risk has at least one preventive and one detective control.

Exercise 6: One incident, several categories

"An employee enters her password on a fake webmail page. Two days later someone logs in to her mailbox from abroad, sets a rule forwarding invoices to an outside address, and later uses her session to reach the file server, where a script becomes root through a writable cron job." Name each attack category and the stage it belongs to.

Answer

Phishing (initial access) → credential theft and use of valid accounts (initial access / credential access) → a mailbox forwarding rule (persistence and collection, the start of business email compromise) → lateral movement to the file server → privilege escalation through a writable cron job. The detections that could have stopped it: a login from an unusual country, a new forwarding rule, and a change to a root-owned cron file.

Exercise 7: Online and offline guessing

A password is 8 lowercase letters. How many candidates are there, and how long does an attacker need on average to find it at 1 guess per second (online, rate-limited) and at 101010^{10} guesses per second (offline, a fast hash on one GPU)? A sprayer tries one password against 400 accounts every 30 minutes from 50 addresses: which detector catches it, per-account lockout or a counter of failures across all accounts?

Answer

268=208 827 064 57626^8 = 208\,827\,064\,576 candidates; on average half must be tried: about 3,309 years online and about 10 seconds offline. That gap is why stolen hash databases are so dangerous and why slow password hashes matter. The sprayer makes only one attempt per account per half hour, far below any lockout threshold, and spreads its sources: only a global counter of failures (or of distinct accounts failing) per time window catches it.

Exercise 8: Read the headers

A message shows From: Finance <billing@lab.test>, Reply-To: billing@1ab.test and Authentication-Results: mx.lab.test; spf=pass smtp.mailfrom=1ab.test; dkim=none; dmarc=fail header.from=lab.test. List three warning signs. What is the edit distance between lab.test and 1ab.test, and between lab.test and labs.test?

Answer

(1) DMARC fails for the visible From domain; (2) SPF passes only for a different envelope domain, 1ab.test; (3) the Reply-To goes to that lookalike domain, so answers leave the organisation; (4) no DKIM signature. Both edit distances are 1 (one substitution l→1, one insertion s): lookalikes are one keystroke away, which is why checkers flag distances of 1 or 2 from your own domains.

Exercise 9: Amplification arithmetic

A reflector answers a 40-byte UDP request with 4,000 bytes. What is the amplification factor? With spoofed requests at 50 Mbit/s, how much traffic reaches the victim? Name two defences that work at the source and one at the target.

Answer

Factor 4000/40=1004000 / 40 = 100; 50 Mbit/s×100=5 Gbit/s50\ \text{Mbit/s} \times 100 = 5\ \text{Gbit/s}. At the source: ingress filtering against spoofed source addresses (BCP 38) and closing or rate-limiting open reflectors (resolvers, old UDP services). At the target: upstream scrubbing or a DDoS-protection service with more capacity than the attack, plus rate limits for what still arrives.

Exercise 10: Why a nonce and a timestamp

A receiver accepts a signed message if its HMAC is valid, its timestamp is within 300 seconds, and its nonce hasn't been seen. (a) Remove the nonce check: which replay now succeeds? (b) Why does the receiver only need to remember nonces for 300 seconds?

Answer

(a) An exact copy of a captured message, re-sent within 300 seconds: the HMAC is still valid and the timestamp still fresh. (b) After 300 seconds the timestamp check rejects the message anyway, so older nonces can be forgotten: the timestamp bounds the memory, the nonce closes the window.

Exercise 11: Fix the cookie

A capture shows Set-Cookie: session=lab42; HttpOnly sent over HTTP on port 80. Write the findings and the fixed header.

Answer

Findings: sent over cleartext HTTP; no Secure; no SameSite; no lifetime; a short, guessable value. Fixed: Set-Cookie: session=<256-bit random value>; Secure; HttpOnly; SameSite=Lax; Path=/; Max-Age=3600, served only over HTTPS with HSTS, and a new session id issued at every login (against fixation).

Exercise 12: Find the spoofed reply

In arp.pcap, 10.10.0.1 is-at 02:00:00:0a:0a:01 answers a request; five seconds later, with no request, 10.10.0.1 is-at 02:00:00:0a:0a:66 appears. Which packet is suspicious, why, and what stops it on a managed switch?

Answer

The third packet: an unsolicited reply that changes the MAC address of the gateway. ARP has no authentication, so hosts accept it and send their traffic to …:66. Detection: alert when an IP's MAC changes (arpwatch-style). Prevention: Dynamic ARP Inspection, which checks replies against the DHCP-snooping table, or a static ARP entry for the gateway on critical hosts.

Exercise 13: Entropy by hand

Compute the Shannon entropy, in bits per symbol, of AAAB, AABB and ABCD. Why does ransomware detection watch the entropy of written files?

Answer

AAAB: −34log⁡234−14log⁡214≈0.811-\tfrac34 \log_2 \tfrac34 - \tfrac14 \log_2 \tfrac14 \approx 0.811. AABB: 1. ABCD: 2 (four equally likely symbols). For bytes the maximum is 8 bits per byte. Encrypted output looks random, close to 8; documents and text are far lower. Many files being rewritten with near-maximal entropy (and renamed) in a short window is a strong ransomware signal, though compressed files are high too, which is why the rule combines entropy with rate and renames.

Exercise 14: Typosquats and checksums

(a) What is the edit distance between reqeusts and requests? (b) sha256sum -c SHA256SUMS is run against a downloaded file whose hash differs from the list. What does it print and with which exit code? (c) Why is a checksum downloaded from the same server as the file weak protection?

Answer

(a) 2: swapping two adjacent letters costs two substitutions in plain Levenshtein distance (1 in the Damerau variant, which counts transpositions). (b) <file>: FAILED, a warning that 1 computed checksum did NOT match, and exit code 1. (c) Whoever can replace the file on that server can replace the checksum too; it catches corruption, not a compromised source. Signatures with a key published elsewhere (or a lock file in your own repository) are needed for that.

Exercise 15: Safe and unsafe sudo rules

Which of these sudoers rules let dev become root? (a) dev ALL=(root) /usr/bin/systemctl restart web; (b) dev ALL=(root) /usr/bin/vim /etc/web.conf; (c) dev ALL=(root) /usr/bin/find; (d) dev ALL=(root) /opt/tools/deploy.sh where deploy.sh is writable by dev; (e) dev ALL=(root) NOPASSWD: ALL.

Answer

Unsafe: (b) vim can start a shell (:!sh) as root; use sudoedit instead. (c) find runs commands (-exec), so any command becomes root. (d) dev can edit the script, then run it as root. (e) is full root without even a password. (a) is reasonable: one fixed command with fixed arguments. Detection: review sudoers against a list of programs that can spawn shells, and check that every script named in sudoers is owned by root and not writable by others.

Exercise 16: Which engagement?

Match each request to a vulnerability assessment, a penetration test or a red-team exercise: (a) "List everything missing patches on our 300 servers"; (b) "Can an outsider reach customer data in the web shop, and how?"; (c) "Would our SOC notice a realistic, stealthy intrusion over four weeks?". After a purple-team retest, 7 of 10 tested techniques raise an alert and all 10 are logged. What are alert and visibility coverage?

Answer

(a) Vulnerability assessment: breadth, mostly automated. (b) Penetration test: depth on a defined scope, proving impact. (c) Red-team exercise: an objective-based test of detection and response. Coverage: alerts 70 %, visibility 100 %. The three silent techniques are the next detection-engineering tasks, and since they are logged, the data to write the rules exists.

Exercise 17: In scope or not?

The scope is 10.10.0.0/24 and names under *.app.lab.test, excluding 10.10.0.1 and 10.10.0.200/29, on 1–12 December 2026, 08:00–17:00 UTC, techniques discovery and web testing. Decide for each planned action: (a) web testing of 10.10.0.203 on 3 December at 10:00 UTC; (b) discovery of 10.10.0.40 at 18:30 UTC; (c) web testing of cdn.app.lab.test, which resolves to 203.0.113.50; (d) a load test of shop.app.lab.test (10.10.0.30) at noon UTC; (e) web testing of app.lab.test itself.

Answer

(a) No: 10.10.0.200/29 covers .200 to .207, so .203 is excluded. (b) No: outside the daily window. (c) No: the name matches, but it resolves to an address outside every in-scope range (a third party's CDN); stop and ask. (d) No: load testing is a denial-of-service technique and not allowed. (e) No: *.app.lab.test matches names below app.lab.test, not app.lab.test itself, unless the scope lists it. When in doubt, get it in writing before testing.

Exercise 18: After Van Buren

Two employees of a company with a database of customer records: Anna is allowed to open every record and looks up her neighbour out of curiosity, against company policy; Ben may open only his own region's records and changes a URL parameter to open another region's records. Under the US Supreme Court's 2021 reading of "exceeds authorized access", which conduct is that offence? Does the DOJ's 2022 policy protect Ben if he says he was testing?

Answer

Ben's: he entered an area of the system that was off limits to him (the "gate" was down). Anna's misuse of data she was entitled to reach is not "exceeds authorized access" under Van Buren, though it can still break her contract, privacy law or other statutes. The DOJ policy only guides federal prosecutors to decline cases of good-faith security research carried out to avoid harm; an employee poking into another region's records without authorization, telling nobody, hardly fits, and the policy authorises nothing in advance, binds neither state prosecutors nor civil suits.

Exercise 19: NIS2 deadlines and the Computer Misuse Act

(a) An essential entity becomes aware of a significant incident on Monday 2 March 2026 at 14:00. When are the early warning (24 hours) and the incident notification (72 hours) due? (b) Which section of the UK Computer Misuse Act fits each act: logging in to a router with its default password without permission; flooding a server until it stops answering; selling a tool believing it is likely to be used for such offences?

Answer

(a) Early warning by Tuesday 3 March 14:00; notification by Thursday 5 March 14:00; the final report within one month after the notification. (b) Section 1 (unauthorised access, even with a default password); section 3 (unauthorised acts impairing operation); section 3A (making, supplying or obtaining articles for use in offences).

Exercise 20: Which Vietnamese law applies?

A security company's 2025 contract template says testing is done "in accordance with Law No. 24/2018/QH14 on Cybersecurity and Law No. 86/2015/QH13 on Network Information Security". What must change for a contract signed in December 2026? Which Penal Code article covers illegally infiltrating another person's computer network?

Answer

Both laws were replaced on 1 July 2026 by the Law on Cybersecurity No. 116/2025/QH15; cite that law (and its implementing decrees) instead, and check that the company holds the licence the new law requires for security testing services. Illegal infiltration of another person's computer network, telecommunication network or electronic device is Article 289 of the Penal Code 2015 (amended 2017 and 2025); it applies when the intruder also takes control, interferes, touches data or uses services without permission, and lesser cases are administrative violations.

Exercise 21: Repair a security.txt

Find the problems in this file, checked on 22 November 2026, and write a valid version.

text
Contact: security@old.lab.test
Expires: 2026-01-31T00:00:00Z
Expires: 2028-01-01T00:00:00Z
Encryption: -----BEGIN PGP PUBLIC KEY BLOCK-----
Answer

Contact must be a URI (mailto:security@…); Expires appears twice (exactly one allowed), one copy is already in the past and the other is more than a year ahead; Encryption must be a URI pointing to the key, not the key itself. A valid version:

text
Contact: mailto:security@shop.lab.test
Expires: 2027-06-30T23:59:59Z
Encryption: https://shop.lab.test/.well-known/pgp-key.txt
Canonical: https://shop.lab.test/.well-known/security.txt

served at https://shop.lab.test/.well-known/security.txt, ideally signed.

Exercise 22: Read the credentials and the crash

(a) A process's /proc/<pid>/status shows Uid: 1000 0 0 0. What kind of program is it and whose permissions apply to its file accesses? (b) A test program prints *** stack smashing detected ***: terminated and the shell reports exit code 134. Which signal ended it, and which protection fired? (c) readelf -lW shows GNU_STACK … RWE. What does that mean?

Answer

(a) Real UID 1000, effective, saved and filesystem UID 0: a SUID-root program started by user 1000; file access uses root's permissions. (b) 134=128+6134 = 128 + 6: signal 6, SIGABRT, raised by the stack canary check (-fstack-protector). (c) The stack is executable: the binary was built with -z execstack, which breaks W^X/NX; rebuild without it.

Exercise 23: Reconstruct a Windows incident

Put these Security and System log events from one host in a plausible order and explain each: 7045, 4625 (four times), 1102, 4720, 4672, 4624, 4732. What would you collect before the 1102 to keep the evidence?

Answer

4625 ×4 (failed logons: guessing) → 4624 (successful logon) → 4672 (special privileges assigned: an administrator logon) → 4720 (a user account created) → 4732 (added to a local security group, such as Administrators: persistence) → 7045 (a new service installed, System log) → 1102 (the Security log cleared: covering tracks). Forward events to a central collector or SIEM as they happen; a log that only lives on the host can be cleared by whoever controls the host. The Linux equivalent is shipping auth.log/journal entries off the machine.

Exercise 24: Choose the network mode

For each lab machine choose NAT, bridged, host-only or internal: (a) Metasploitable, deliberately vulnerable; (b) the Kali VM while it downloads updates; (c) the Kali VM while testing Metasploitable; (d) a Juice Shop container. And rewrite ports: ["3000:3000"] so the container is not on your home network.

Answer

(a) Internal (or host-only), never bridged or NAT. (b) NAT, only while updating, and not attached to the lab network at the same time. (c) Internal, the same network as the target. (d) An internal: true Docker network shared with the testing container, or a port published on loopback only: ports: ["127.0.0.1:3000:3000"]. The plain 3000:3000 binds to 0.0.0.0, which exposes the app to every device that can reach your computer.

Check the numbers

The program recomputes the numeric answers of exercises 4, 7, 8, 9, 13, 14, 19 and 22.

python · try it yourself
import math
from collections import Counter
from datetime import datetime, timedelta

def entropy(s):
    n = len(s)
    return -sum(c / n * math.log2(c / n) for c in Counter(s).values())

def edit_distance(a, b):
    prev = list(range(len(b) + 1))
    for i, ca in enumerate(a, 1):
        cur = [i]
        for j, cb in enumerate(b, 1):
            cur.append(min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (ca != cb)))
        prev = cur
    return prev[-1]

ale_before, ale_after = 30_000 * 0.2, 1_500 * 0.2
print(f"4   score {2 * 5}; ALE {ale_before:,.0f} -> {ale_after:,.0f}; net benefit {ale_before - ale_after - 600:,.0f}")
space, year = 26 ** 8, 365.25 * 24 * 3600
print(f"7   {space:,} candidates; average {space / 2 / year:,.0f} years at 1/s, {space / 2 / 1e10:.1f} s at 1e10/s")
print(f"8   lab.test -> 1ab.test {edit_distance('lab.test', '1ab.test')}, -> labs.test {edit_distance('lab.test', 'labs.test')}")
print(f"9   factor {4000 // 40}, {50 * 4000 / 40 / 1000:.0f} Gbit/s")
print("13  " + ", ".join(f"{s} {entropy(s):.3f}" for s in ("AAAB", "AABB", "ABCD")))
print(f"14  reqeusts -> requests {edit_distance('reqeusts', 'requests')}")
aware = datetime(2026, 3, 2, 14, 0)
for label, hours in (("early warning", 24), ("notification", 72)):
    print(f"19  {label}: {(aware + timedelta(hours=hours)):%a %d %b %Y %H:%M}")
print(f"22  134 - 128 = {134 - 128} (SIGABRT)")
4   score 10; ALE 6,000 -> 300; net benefit 5,100
7   208,827,064,576 candidates; average 3,309 years at 1/s, 10.4 s at 1e10/s
8   lab.test -> 1ab.test 1, -> labs.test 1
9   factor 100, 5 Gbit/s
13  AAAB 0.811, AABB 1.000, ABCD 2.000
14  reqeusts -> requests 2
19  early warning: Tue 03 Mar 2026 14:00
19  notification: Thu 05 Mar 2026 14:00
22  134 - 128 = 6 (SIGABRT)

Test yourself

Which detector catches password spraying of one password across 400 accounts every 30 minutes?

  1. Per-account lockout after 5 failures
  2. A counter of failures (or distinct failing accounts) across all accounts per time window
  3. Antivirus on the server
  4. Checking the password length

10.10.0.200/29 is excluded from scope. Which address is excluded?

  1. 10.10.0.199
  2. 10.10.0.203
  3. 10.10.0.208
  4. 10.10.0.20

A process shows Uid: 1000 0 0 0. Which is it?

  1. A root shell started by root
  2. A SUID-root program started by user 1000
  3. A program of user 1000 without privileges
  4. A kernel thread

Which Docker port setting keeps a vulnerable app off your home network?

  1. 3000:3000
  2. 0.0.0.0:3000:3000
  3. 127.0.0.1:3000:3000
  4. 3000