TExcelTAD
Home › Security Foundations: Concepts, Law, Ethics & Your Lab › Security Auditing and Controls

Security Auditing and Controls

A customer asks your company to "prove you are secure" before signing a contract. Saying "we take security seriously" is not proof. What they want is evidence: which controls you have, that they are designed to address your risks, and that they actually work. Producing that evidence, or checking someone else's, is security auditing, and it is also the best way to find out whether your own defences exist outside the policy document.

Intuition: a car inspection

A car inspection doesn't ask the owner whether the brakes are good. The inspector looks at a checklist, tests each item, notes what was seen ("front left pad 2 mm"), and records pass or fail. A security audit works the same way: a criterion, a test, evidence, a finding. The difference is that a security audit also asks whether the checklist itself fits the risks.

Controls: what they do and what they are

A control is any measure that reduces risk (the risk register is where each one is justified). Controls are classified two ways at once: by function, when in an incident they act, and by kind, what they are made of.

Function Acts Examples
Deterrent discourages the attempt warning banners, a signed acceptable-use policy, visible cameras
Preventive stops the attempt MFA, firewalls, locked doors, parameterised queries
Detective notices the attempt or the damage log alerts, IDS, file-integrity monitoring, access reviews, CCTV
Corrective limits damage and restores restoring backups, revoking a stolen token, re-imaging a machine
Compensating stands in for a control that can't be used extra monitoring on an old system that can't do MFA
Kind Also called Examples
Administrative managerial, procedural policies, training, background checks, access reviews
Technical logical encryption, authentication, logging, endpoint protection
Physical locks, badges, guards, fire suppression

Some lists add directive (a rule that tells people what to do) and recovery. A good set of controls is defence in depth: several layers of different functions and kinds, so one failure doesn't decide the outcome. A quick way to find gaps is to place every control in the grid:

python · try it yourself
# Classify a small control catalogue by function and by kind, and find the gaps.
controls = [
    ("C1", "Acceptable-use policy signed by staff",   "deterrent",    "administrative"),
    ("C2", "MFA on webmail and VPN",                  "preventive",   "technical"),
    ("C3", "Badge readers on the server room",        "preventive",   "physical"),
    ("C4", "Failed-login alerts to the on-call phone", "detective",   "technical"),
    ("C5", "Quarterly access review",                 "detective",    "administrative"),
    ("C6", "Restore from offline backup",             "corrective",   "technical"),
    ("C7", "CCTV at the entrance",                    "detective",    "physical"),
    ("C8", "Extra log review while the old ERP can't do MFA", "compensating", "administrative"),
]
functions = ["deterrent", "preventive", "detective", "corrective", "compensating"]
kinds = ["administrative", "technical", "physical"]
print(f"{'':<15}" + "".join(f"{k:<16}" for k in kinds).rstrip())
for f in functions:
    row = [",".join(c[0] for c in controls if c[2] == f and c[3] == k) or "-" for k in kinds]
    print(f"{f:<15}" + "".join(f"{cell:<16}" for cell in row).rstrip())
missing = [f for f in functions if f != "compensating" and not any(c[2] == f and c[3] == "physical" for c in controls)]
print("physical controls missing for:", ", ".join(missing))
               administrative  technical       physical
deterrent      C1              -               -
preventive     -               C2              C3
detective      C5              C4              C7
corrective     -               C6              -
compensating   C8              -               -
physical controls missing for: deterrent, corrective

The grid is a thinking tool, not a target to fill: not every cell needs a control. Read it row by row. Only one control is corrective (C6), so restoring data is planned but recovering from, say, a stolen laptop or a lost badge is not. The physical column stops and records a break-in (C3, C7) but nothing says what happens afterwards, such as replacing locks and badges.

The audit process

  1. Scope and criteria. Which systems, which period, against what: an internal policy, a contract, or a framework.
  2. Plan and collect evidence. Interviews, documents, configuration exports, system queries, samples of records (for example 25 random access requests from the year, each checked for an approval).
  3. Test. Design: would the control address the risk if it worked? Operating effectiveness: did it actually work throughout the period?
  4. Findings. For each failed criterion: condition (what was found), criterion (what was expected), cause, effect (the risk) and a recommendation, rated by severity.
  5. Report and follow-up. Management responds with an owner and a date; the auditor retests.

Evidence must be specific and reproducible: a timestamped command output, a screenshot with the system name, a configuration file with its hash. "The admin said MFA is on" is a lead, not evidence.

Frameworks give the criteria so you don't invent them. You will meet these names often: ISO/IEC 27001:2022 (requirements for an information security management system, with its Annex A list of 93 controls, used for certification), NIST Cybersecurity Framework 2.0 (functions Govern, Identify, Protect, Detect, Respond, Recover), and the CIS Critical Security Controls v8.1 (18 prioritised technical controls with safeguards grouped into implementation groups IG1 to IG3). Laws and industry rules (PCI DSS for card data, privacy law: see the on-ramp's Privacy & Compliance) add their own criteria. An audit checks against criteria; a vulnerability assessment or penetration test looks for weaknesses; you need both.

A technical audit you can run

Many audit checks are short commands with a clear pass or fail. The session below runs in your sandbox only: it builds a small fictional application directory with two common mistakes, runs four checks against it with evidence, and compares the system's SUID programs with an approved baseline (SUID programs run with their owner's rights, see privilege escalation).

bash · try it yourself
mkdir -p app/uploads app/etc
printf '[db]\nuser = shop\npassword = lab-only-pw\n' > app/etc/shop.ini
printf 'PermitRootLogin yes\nPasswordAuthentication no\nX11Forwarding no\n' > app/etc/sshd_config
chmod 644 app/etc/shop.ini
chmod 777 app/uploads
check() { if eval "$2"; then echo "PASS  $1"; else echo "FAIL  $1"; fi; }
check "A1 config with secrets not readable by others" '[ -z "$(find app/etc -name "*.ini" -perm -o=r)" ]'
check "A2 no world-writable directories in app/"     '[ -z "$(find app -type d -perm -o=w)" ]'
check "A3 sshd: PermitRootLogin no"                 'grep -qx "PermitRootLogin no" app/etc/sshd_config'
check "A4 sshd: PasswordAuthentication no"          'grep -qx "PasswordAuthentication no" app/etc/sshd_config'
echo "--- evidence"
stat -c '%a %n' app/etc/shop.ini app/uploads
grep -n PermitRootLogin app/etc/sshd_config
echo "--- SUID baseline"
printf '%s\n' /usr/bin/chfn /usr/bin/chsh /usr/bin/gpasswd /usr/bin/mount /usr/bin/newgrp /usr/bin/passwd /usr/bin/su /usr/bin/umount > approved-suid.txt
find / -xdev -perm -4000 -type f 2>/dev/null | sort > found-suid.txt
echo "found $(wc -l < found-suid.txt), not in the approved list: $(comm -13 approved-suid.txt found-suid.txt | wc -l)"
FAIL  A1 config with secrets not readable by others
FAIL  A2 no world-writable directories in app/
FAIL  A3 sshd: PermitRootLogin no
PASS  A4 sshd: PasswordAuthentication no
--- evidence
644 app/etc/shop.ini
777 app/uploads
1:PermitRootLogin yes
--- SUID baseline
found 8, not in the approved list: 0

The checks are read-only and repeatable, and each FAIL comes with the evidence an auditor would attach: mode 644 means the database password is readable by every local user, 777 means anyone can drop files into the upload folder, and line 1 of the SSH configuration allows root logins. The SUID part is a baseline comparison: the audit doesn't judge each file, it reports anything new since the approved list was made. Configuration benchmarks such as the CIS Benchmarks for Linux distributions are long lists of checks like these; tools like OpenSCAP and Lynis run them for you.

How weak controls are detected

  • Paper controls: a policy says "access is reviewed quarterly" but no review record exists. Ask for the last three.
  • Drift: a configuration passed last year and fails now. Automated checks on a schedule catch it in days, not at the next audit.
  • Detective controls that nobody watches: alerts sent to an unread mailbox. Test by triggering one (in your lab) and timing the response.
  • Incidents: every incident is an unplanned audit. Ask which control should have stopped or caught it.

How it is fixed

Each finding gets an owner, a deadline and a fix that addresses the cause, not only the symptom: chmod 640 on shop.ini fixes today's file, but a deployment script that sets the mode, plus the automated check A1 in the pipeline, keeps it fixed. Then retest and keep the evidence.

Pitfalls

  • Compliance is not security. Passing an audit means meeting its criteria during its period; attackers don't read the scope.
  • Sampling the easy cases. Let the auditor pick the sample, at random.
  • Auditing your own work. Independence matters: the person who configured the firewall is the worst one to audit it.
  • Collecting secrets as evidence. Prove the password policy with settings, not with passwords.

Practice

  1. Classify: (a) a login banner "authorised use only", (b) a nightly file-integrity scan, (c) a guard checking badges, (d) re-imaging a laptop after malware.
  2. Write the four parts (condition, criterion, effect, recommendation) of a finding for check A2.
  3. How would you change check A3 so that PermitRootLogin prohibit-password also passes?
Answers
  1. (a) deterrent, administrative/technical (it is shown by a system but is a policy statement); (b) detective, technical; (c) preventive (and deterrent), physical; (d) corrective, technical.
  2. Condition: app/uploads has mode 777. Criterion: no application directory may be world-writable. Effect: any local user or compromised service can place or replace files that the application may serve or execute. Recommendation: owner shop, mode 750 (or 770 with a dedicated group), set by the deployment script, with check A2 in the pipeline.
  3. Match both accepted values, for example grep -Eqx "PermitRootLogin (no|prohibit-password)" app/etc/sshd_config. Also consider that sshd uses the first value it reads for a keyword, so an earlier line, or a file in sshd_config.d/ included at the top of the file, may override it: the real check is sshd -T, which prints the effective setting.

Test yourself

An alert that fires on ten failed logins in a minute is which type of control?

  1. Preventive
  2. Detective
  3. Corrective
  4. Deterrent

An old system cannot support MFA, so its logs are reviewed daily instead. What is that?

  1. A compensating control
  2. A deterrent control
  3. A physical control
  4. Risk avoidance

What does testing a control's operating effectiveness check?

  1. That the policy document exists
  2. That the control actually worked throughout the audit period
  3. That the control is cheap
  4. That a vendor sells it

In the session, why does check A1 fail?

  1. The file contains no password
  2. shop.ini has mode 644, so every user can read the password in it
  3. The directory is world-writable
  4. SSH allows root logins