Cyber attacks: intrusion, malware and hacking
Clear, exam-focused notes on cyber attacks (intrusion, malware, hacking): definitions, attack models (kill chain), intrusion detection types, malware taxonomy, detection metrics with formulas and worked examples, common exam mistakes and question types.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two sentences: Engineers design, operate and defend computing systems. Understanding intrusion, malware and hacking helps you find weaknesses, detect attacks and plan correct responses in real systems (networks, servers, embedded devices).
Key ideas
Start by defining every term simply.
- Threat: any circumstance or event that can cause harm to an information system.
- Vulnerability: a weakness in hardware, software, procedure or human behaviour that can be exploited.
- Exploit: a method or piece of code that uses a vulnerability to do something unintended.
- Attack: an intentional act that attempts to exploit a vulnerability to harm an information system.
- Intrusion: unauthorized access or actions inside a computer system or network. (So an intrusion is a kind of attack outcome.)
- Hacking: the activity of finding and exploiting system weaknesses. In exams, treat it neutrally: someone who finds a security flaw is a hacker; legality depends on authorization and jurisdiction (ethical hacking requires explicit permission); intent alone does not determine legality.
- Malware: any software designed to harm, exploit, or abuse a system. (This is a superset term; malware includes viruses, worms, trojans, ransomware, rootkits, spyware, adware, and bots.)
Malware taxonomy (define and give distinguishing property):
- Virus: code that attaches to host files and requires user action (like running the file) to spread. Draw: a file icon labeled "host" with virus code attached; arrow from user double-click to another file infected.
- Worm: self-replicating code that spreads across networks without user action. Draw: nodes A–E connected; arrows showing worm copy from A to B to C.
- Trojan (Trojan horse): malware disguised as useful software but contains malicious payload; it relies on user installation.
- Ransomware: malware that encrypts user data and demands payment for decryption.
- Rootkit: code that hides the presence of malware by modifying OS-level or firmware-level behavior.
- Bot (bot malware): malware that enrolls a host for remote control; a botnet is the collection of many infected hosts controlled by a command-and-control (C2) server, used for DDoS, spam, etc.
- Spyware/Adware: software that gathers information or shows unwanted ads.
Attack lifecycle — the classical steps to draw (the "kill chain") and label: 1) Reconnaissance, 2) Weaponization, 3) Delivery, 4) Exploitation, 5) Installation, 6) Command & Control (C2), 7) Actions on Objectives. For each step write one short example: Reconnaissance = scan IP range; Weaponization = craft exploit + payload; Delivery = phishing email; Exploitation = buffer overflow; Installation = writing malware to disk; C2 = persistent channel; Actions on Objectives = data exfiltration.
Intrusion detection categories (define):
- Network-based Intrusion Detection System (NIDS): monitors network traffic for signs of attacks (placed at network choke points). Draw: router → mirror port → NIDS box.
- Host-based Intrusion Detection System (HIDS): runs on an endpoint and monitors OS logs, file changes and process behavior.
- Signature-based detection: matches known patterns (signatures) of attacks. Good for known threats, fails on novel ones.
- Anomaly-based detection: builds a model of "normal" behavior and flags deviations. Can detect novel attacks, but has more false positives.
- Hybrid detection: combines signature and anomaly approaches.
- Intrusion Prevention System (IPS): inline security control that inspects traffic and can block or modify it in real time (prevention), often using the same detection methods as IDS.
Attack vectors and common techniques (short definitions): phishing (fraudulent email to trick users), SQL injection (attacker-supplied input alters a database query), DoS/DDoS (deny service by resource exhaustion), man-in-the-middle (MITM) (intercepting communications), brute-force/password cracking (systematically trying many candidate passwords or keys), privilege escalation (gaining higher privileges than initially authorized — vertical or horizontal), supply-chain attacks (compromising third-party software, hardware, or update mechanisms to reach the target).
Detection performance and evaluation: explain confusion matrix labels unambiguously: TP (true positive): attack correctly detected; FP (false positive): benign activity flagged as attack; FN (false negative): attack missed; TN (true negative): benign activity correctly ignored.
Important assumptions to state in answers: whether the system model is network-level or host-level; whether attacker is external or insider; whether user action is required for spreading; base rate of attacks (this strongly affects posterior probabilities when interpreting alerts).
If an exam asks for a diagram of IDS placement: draw network with Internet → firewall → DMZ (web server) → internal network; place NIDS at firewall egress/ingress and HIDS on important hosts. Label arrows and boxes.
Formulas
Precision = TP / (TP + FP) — TP and FP are counts (unitless). Use when you want the fraction of alerts that are true attacks.
Recall = TP / (TP + FN) — fraction of actual attacks the system finds.
F1 = 2 · Precision · Recall / (Precision + Recall) — harmonic mean of precision and recall.
Accuracy = (TP + TN) / (TP + TN + FP + FN) — overall correct classification fraction; can be misleading for imbalanced classes.
False positive rate (FPR) = FP / (FP + TN) — probability non-attack is flagged.
False negative rate (FNR) = FN / (FN + TP) — probability an attack is missed.
Specificity (True negative rate, TNR) = TN / (TN + FP) — probability a non-attack is correctly ignored.
P(A | B) = P(B | A) · P(A) / P(B) — Bayes' theorem; P(A) is prior probability, P(B|A) is likelihood, used when computing probability an alert corresponds to a real attack.
All symbols are counts or probabilities (unitless). Apply these when evaluating IDS or classifier outputs.
Worked examples
Numerical IDS metrics (standard exam style): Given: a host-based detector produced: TP = 80, FP = 20, FN = 20, TN = 980. Step 1: Precision = TP / (TP + FP) = 80 / (80 + 20) = 80 / 100 = 0.8. Step 2: Recall = TP / (TP + FN) = 80 / (80 + 20) = 80 / 100 = 0.8. Step 3: F1 = 2 · 0.8 · 0.8 / (0.8 + 0.8) = 1.28 / 1.6 = 0.8. Step 4: Accuracy = (TP + TN) / total = (80 + 980) / 1100 = 1060 / 1100 ≈ 0.9636. Final answers (bold): Precision = 0.8, Recall = 0.8, F1 = 0.8, Accuracy ≈ 0.9636.
Bayes / base-rate example (shows why false positives matter): Assume: prior probability of an intrusion at any time P(Attack) = 0.001 (0.1%), IDS detection rate (sensitivity) P(Alert | Attack) = 0.99, false positive rate P(Alert | No Attack) = 0.01. Compute P(Attack | Alert). Step 1: P(Alert) = P(Alert | Attack)·P(Attack) + P(Alert | No Attack)·P(No Attack) = 0.99·0.001 + 0.01·0.999 = 0.00099 + 0.00999 = 0.01098. Step 2: Bayes: P(Attack | Alert) = 0.99·0.001 / 0.01098 ≈ 0.00099 / 0.01098 ≈ 0.09016. Final answer (bold): Posterior probability ≈ 0.09 (9%). Comment: despite high sensitivity, most alerts are false because attacks are rare.
Model long-answer: "Explain differences between virus, worm and trojan with examples and countermeasures" — a graded model answer should: define each term (as above), list one or two distinguishing technical features (spread mechanism, need for host action), give a short real-world example (e.g., worms: Code Red, Morris worm; trojans: banking trojans), and provide one prevention/mitigation measure for each (anti-virus signatures and scanning for viruses, network segregation and patching for worms, least-privilege and application whitelisting for trojans). State assumptions (e.g., networked environment, Windows/Linux differences) and conclude with recommended detection tools (NIDS, HIDS, endpoint protection).
Common mistakes
- Confusing false positive with false negative; explain each with an example (FP: firewall blocks legitimate client; FN: malware runs undetected).
- Forgetting to state assumptions about where the IDS is placed (network vs host) or whether users can be tricked (social engineering).
- In Bayes calculations, forgetting to include P(Alert | No Attack)·P(No Attack) term in denominator.
- Calling all unauthorized access "hacking" without distinguishing intent or method.
For your exam
Question types you will see: definitions (short), short notes (one-paragraph), diagrams (draw and label kill chain, IDS placement), derivations (derive F1 from precision and recall), numericals (compute precision/recall/Bayes), and long answers (compare malware types, describe countermeasures and design an IDS placement for a network). A full-marks answer should:
- Start with clear definitions of terms used and state assumptions.
- If asked for a diagram, draw components and label directions and key points (e.g., for the kill chain, label each step). If asked for IDS placement, draw network boxes (Internet, firewall, DMZ, internal LAN) and mark sensors.
- For numerical problems, show the confusion matrix, list formulas used, substitute numbers step-by-step, and give final answer with units or as a probability.
- For design or mitigation questions, give practical, feasible controls (technical + process) and explain why each control helps against the given threats.
Quick check
- Define malware in one sentence.
- What is the difference between a signature-based IDS and an anomaly-based IDS (one sentence each)?
- If TP = 50, FP = 50, FN = 50, TN = 850, what is Precision and Accuracy? Show final numbers. Answers: 1) Malware is any software intentionally designed to harm, exploit or abuse a computer system. 2) Signature-based IDS matches known patterns of attacks (good for known threats); Anomaly-based IDS flags deviations from a learned normal profile (can detect novel attacks). 3) Precision = 50 / (50 + 50) = 0.5; Accuracy = (50 + 850) / 1000 = 900 / 1000 = 0.9.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?