Everyone Can Learn Program
中文 Start learning
Specialty · SecurityLesson 1 of 9Free to read

Threats and risk · Cyber Security Basics

What are we protecting, and from what?

Course contents

Why you need it

Security starts before any code: first you name what could go wrong. Every later lesson in this course (hashing, injection, logs, firewalls) protects one of three things, and knowing which one tells you what to fix first.

One rule for the whole course: only test systems you own or have written permission to test. Everything here runs inside your browser, on data made up for the lesson.

The intuition

Think of your diary.

  • Confidentiality: only you can read it.
  • Integrity: nobody can change a page without you noticing.
  • Availability: it's there when you want to open it.

A threat is anything that could break one of the three: a thief, a flood, a bug. A risk is how much a threat should worry you: how likely it is times how bad it would be. You can't fix everything at once, so you score risks and fix the biggest first.

Definition

CIA triad

Confidentiality, integrity and availability: the three properties security protects. Data is kept secret from the wrong people, unchanged by the wrong people, and reachable by the right people.

Risk

A simple risk score is likelihood × impact, each rated on a small scale such as 1 to 5. Higher scores are fixed first.

Examples

Which goal was hit?

Try it yourself

Each incident breaks one of the three goals. A dictionary maps each incident to its goal.

incidents = {
    "Someone reads the customer list": "confidentiality",
    "A price is changed from 100 to 1": "integrity",
    "The website is down for 3 hours": "availability",
}
for event, goal in incidents.items():
    print(goal.upper(), "-", event)
Step by step
  1. L1A dictionary: incident → the goal it breaks.
  2. L6.items() gives each key with its value.
  3. L7.upper() turns the goal into capitals so it stands out.CONFIDENTIALITY - Someone reads the customer list

Score and rank risks

Try it yourself

Likelihood and impact go from 1 (low) to 5 (high). sorted with key= sorts by whatever the function returns.

risks = [
    ("Weak admin password", 4, 5),
    ("Stolen laptop", 2, 4),
    ("Server disk full", 3, 2),
]

def score(risk):
    name, likelihood, impact = risk
    return likelihood * impact

for risk in risks:
    print(risk[0], score(risk))
ranked = sorted(risks, key=score, reverse=True)
print("Fix first:", ranked[0][0])
Step by step
  1. L1Each risk is a tuple: (name, likelihood, impact).
  2. L8Unpack the tuple into three variables, then multiply.
  3. L124 × 5 = 20, 2 × 4 = 8, 3 × 2 = 6.Weak admin password 20
  4. L13reverse=True puts the biggest score first.
  5. L14The weak password wins: fix it first.Fix first: Weak admin password

Common mistakes

Security only means secrets

Keeping data secret is one goal of three. A site that is down (availability) or has prices changed by an attacker (integrity) is also a security failure.

Testing without permission

Trying attacks on a system you don't own is illegal in most countries, even "just to see". Practise on your own machines, lab environments and these lessons.

Quick quiz

1. Ransomware encrypts a hospital's files so doctors can't open patient records. Which goal is hit first?

  1. AConfidentiality
  2. BIntegrity
  3. CAvailability
Show the answer

Answer: C

The data still exists and may be unread, but the people who need it can't reach it: that's availability.

2. What does this print?

likelihood = 3
impact = 4
score = likelihood * impact
if score >= 15:
    print("high")
elif score >= 8:
    print("medium")
else:
    print("low")
  1. A
    high
  2. B
    medium
  3. C
    low
Show the answer

Answer: B

3 × 4 = 12: not 15 or more, but 8 or more, so medium.

Practice

3 exercises in three steps: predict what a program prints, change a program to meet a new requirement, then write one from scratch. Your code runs in the browser and is checked the moment you submit.

  1. PredictBiggest risk

    Type exactly what this program prints.

  2. ModifyOnly the serious ones

    The program prints every risk with its score. Change it so it prints only risks with a score of 10 or more, in this form:

    HIGH: Weak admin password (20)
  3. WriteRisk level

    Write a function risk_level(likelihood, impact) that returns:

    • "high" when likelihood × impact is 15 or more
    • "medium" when it is 8 or more
    • "low" otherwise

Practise this lesson

Open the interactive lesson to edit and run these examples and solve the exercises with instant feedback. Free to start, no sign-up.

Terms in this lesson

TermChineseDefinition
Confidentiality机密性Only the right people can read the data.
Integrity完整性Data can't be changed without the change being noticed.
Availability可用性The system and data are reachable when they are needed.
Threat威胁Anything that could break confidentiality, integrity or availability.
Risk风险How much a threat matters, often scored as likelihood times impact.