◇ OpenCyber Academy
Technical · Chapter 4 · English

Chapter 4 — Scripting and data formats

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Chapter 4 — Scripting and data formats

Lesson map

Lesson 04 published. Map, example, EX013.

flowchart TD
  N0["Learning outcomes"]
  N1["4.1 Data formats"]
  N2["4.2 Baseline check"]
  N3["Lab — Checking laptop settings against a baseline"]
  N4["4.3 Reporting deviations"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5
  N5 --> EX["Worked example"]
  EX --> Q["Exercise EX013"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["4.1 Data formats"]
  N2["4.2 Baseline check"]
  N3["Lab — Checking laptop settings against a baseline"]
  N4["4.3 Reporting deviations"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5 --> Q["EX013"]
[Learning outcomes]
    |
    v
[4.1 Data formats]
    |
    v
[4.2 Baseline check]
    |
    v
[Lab — Checking laptop settings against a baseline]
    |
    v
[4.3 Reporting deviations]
    |
    v
[Synthesis]
    |
    v
[Worked example] --> [Exercise EX013]

Learning outcomes

You will (1) read structured data formats such as JSON; (2) check configurations against a baseline with a script; (3) report deviations clearly.

4.1 Data formats

Amina learns that systems export configuration and status data in formats such as CSV and JSON. JSON represents records as named fields, which makes it easy to read in Python with the standard json module. Fenwick's device management tool exports laptop settings as JSON. She learns that understanding data formats lets technicians check many devices quickly instead of clicking through each one, which saves time and reduces mistakes. In the next lab, the JSON export lets one short script check all four laptops against the baseline at once.

4.2 Baseline check

Fenwick's baseline requires disk encryption, a screen lock within ten minutes, automatic updates and no local administrator rights. The lab checks four laptops. FW-LT01 meets the baseline. FW-LT02 lacks disk encryption. FW-LT03 has a thirty-minute screen lock and local administrator rights. FW-LT04 has automatic updates turned off. A shorter screen lock, such as five minutes, is accepted because it is stricter than the baseline. Ms. Bell asks the class why FW-LT03 fails twice, and Amina points to its thirty-minute screen lock and its local administrator rights.

Lab — Checking laptop settings against a baseline

"""Check laptop configuration exports (JSON) against a baseline (synthetic Fenwick data)."""
import json
baseline = {"disk_encryption": True, "screen_lock_minutes": 10, "auto_update": True, "local_admin": False}
export = json.loads("""[
 {"host": "FW-LT01", "disk_encryption": true, "screen_lock_minutes": 10, "auto_update": true, "local_admin": false},
 {"host": "FW-LT02", "disk_encryption": false, "screen_lock_minutes": 10, "auto_update": true, "local_admin": false},
 {"host": "FW-LT03", "disk_encryption": true, "screen_lock_minutes": 30, "auto_update": true, "local_admin": true},
 {"host": "FW-LT04", "disk_encryption": true, "screen_lock_minutes": 5, "auto_update": false, "local_admin": false}]""")
for h in export:
    bad = []
    for k, v in baseline.items():
        if k == "screen_lock_minutes":
            if h[k] > v: bad.append(f"{k}={h[k]}")
        elif h[k] != v: bad.append(f"{k}={h[k]}")
    print(h["host"], "OK" if not bad else "DEVIATION " + ", ".join(bad))

Run with python3 lab_config.py. Verified output:

FW-LT01 OK
FW-LT02 DEVIATION disk_encryption=False
FW-LT03 DEVIATION screen_lock_minutes=30, local_admin=True
FW-LT04 DEVIATION auto_update=False

4.3 Reporting deviations

Amina reports each deviation with the laptop name and the failing setting, then asks the owners why. FW-LT02 was set up before encryption was standard. FW-LT03 belongs to a manager who asked for admin rights months ago. FW-LT04 had updates paused during a software problem and never resumed. She learns that each deviation has a story, and that recording the cause helps prevent the same deviation recurring on other devices. FW-LT04's paused updates, for example, suggest adding a review date whenever updates are paused for a software problem.

Worked example

Amina reads a JSON export, finds three of four laptops deviating from the baseline and records the cause of each.

Synthetic case. Laptop data are synthetic.

Errors and limits

Exports may be out of date. Baselines need review.

Exercises

Synthesis

Scripts reading structured exports turn baseline checks into fast, explained findings.

Continue studying — chapter 04 of 18

← Chapter 03 (draft) · Course chapter index · Chapter 05 (draft) →

Worked answers

EX013. Because named fields make records easy to read and check with scripts.

EX014. FW-LT01.

EX015. FW-LT03, with a 30-minute screen lock and local administrator rights.

EX016. Because a five-minute lock is stricter than the ten-minute requirement.