Which Logs Answer Which Security Questions
Choose log sources from the threats you face (identity, endpoint, network, cloud audit and application logs), then set retention, off-host integrity and time synchronisation so the evidence holds up. Two small runnable scripts rank sources against threats and show why a local hash chain is not enough.
Contentsand lesson path
On this page
- Why it matters
- Five families of security log sources
- Start from threats, not from products
- Clocks and time zones
- Retention and integrity
- Check your understanding
- Apply it
- Review prompt
Lessons of Security Logging & SIEM
- Which Logs Answer Which Security Questions Concept · 20 min
- Standing Up a Lab SIEM and Onboarding Sources Lab · 30 min
- Parsing and Normalising to a Common Schema Worked example · 20 min
- Investigation Queries Across Sources Lab · 25 min
- Alert Triage, Case Notes and Playbook Automation Worked example · 30 min
- Logging & SIEM Check Knowledge check · 10 questions
What you will learn
- Select log sources for an environment (identity, endpoint, network, cloud audit, application) based on its threats, and set retention, integrity and time synchronisation requirements.
01. Why it matters
A log is useful only if it answers a question that someone will ask. During an incident the questions are short: who did this, what did they do, when, and from where? Each question is answered by a different system, and you have to decide which systems to collect from long before the incident starts. If nobody kept the identity provider's sign-in log, no search will ever show that an attacker signed in with a stolen password from an unusual country.
Collecting everything is not the answer either. Storage costs money, every source needs a parser, and an analyst who searches through noise works more slowly. This lesson shows how to pick sources from the threats you face, and then how to keep what you collect trustworthy: long enough retention, protection from the attacker, and clocks that agree. Later lessons build a small SIEM (security information and event management system: one place that collects, normalises, searches and alerts on logs) around five of these sources.
02. Five families of security log sources
Most security questions are answered by one of five families of sources, and each family sees a different part of an attack.
Identity logs come from the identity provider (IdP), the service that checks who a user is: Microsoft Entra ID, Okta, Keycloak or an on-premises Active Directory. Its sign-in log records who signed in, to which application, from which address and device, and whether multi-factor authentication (MFA) succeeded. Its audit log records changes such as a new MFA device or a password reset. On Windows domain controllers the security log holds events such as 4624 (an account was successfully logged on) and 4625 (an account failed to log on). Account takeover of cloud email or single sign-on happens here. The attacker connects straight to the cloud service, so a sensor on the office network never sees the traffic.
Endpoint logs come from the machines themselves. An EDR (endpoint detection and response) agent records processes, files and connections. On Windows, Sysmon adds Event ID 1 (process creation, with the full command line) and Event ID 3 (network connection). On Linux, /var/log/auth.log or the systemd journal records SSH and sudo, and the audit daemon auditd can record every program that runs. These logs answer which process ran, who started it and what it did next.
Network logs come from firewalls, flow exporters, DNS resolvers, web proxies and DHCP servers. They answer which internal host talked to which outside address, which host looked up a domain, and which device held an IP address at a given moment. They see every host, including ones without an agent, but they rarely know the user.
Cloud audit logs record actions on the cloud control plane: AWS CloudTrail, the Azure activity log and Google Cloud Audit Logs. They answer who created an access key, changed a permission or made a storage bucket public. None of this is visible from a server's own logs.
Application logs are the events your own software writes: sign-ins, failed permission checks, administrator actions, exports of customer data. The OWASP Logging Cheat Sheet lists what each event needs (when, where, who and what) and what must never be logged, such as passwords and session tokens.
03. Start from threats, not from products
A good log plan starts with a short list of threats that matter to the organisation. For each threat, write the questions an investigator would ask, then find the source that answers each question. Sources that answer questions for several threats come first. The script below does this for a small company that has only firewall logs today. It needs Python 3.10 or later and nothing else. Save it as sources.py in a new folder and run python3 sources.py.
"""Threat-driven log source selection for a small company (fixed example data)."""
# Which log source can answer each investigation question?
ANSWERS = {
"who signed in, from where, with or without MFA": "identity provider",
"which process ran, its parent and command line": "endpoint (EDR/Sysmon/auditd)",
"which internal host talked to an outside address": "firewall or flow logs",
"which host looked up a domain name": "DNS resolver",
"who changed cloud permissions or storage sharing": "cloud audit log",
"which app user exported data or changed a role": "application audit log",
}
# The threats this company worries about, and the questions each one raises.
THREATS = {
"takeover of email and SSO accounts": [
"who signed in, from where, with or without MFA",
"which app user exported data or changed a role"],
"ransomware on laptops": [
"which process ran, its parent and command line",
"which internal host talked to an outside address",
"who signed in, from where, with or without MFA"],
"malware calling home": [
"which host looked up a domain name",
"which internal host talked to an outside address"],
"public cloud bucket exposed": [
"who changed cloud permissions or storage sharing"],
}
ONBOARDED = {"firewall or flow logs"}
unlocks = {}
for threat, questions in THREATS.items():
missing = sorted({ANSWERS[q] for q in questions} - ONBOARDED)
status = f"missing {len(missing)}" if missing else "covered"
print(f"{threat:<36} {status}")
for source in missing:
unlocks.setdefault(source, []).append(threat)
print("\nOnboard next (threats each source helps with):")
for source, threats in sorted(unlocks.items(), key=lambda kv: (-len(kv[1]), kv[0])):
print(f" {len(threats)} {source}")takeover of email and SSO accounts missing 2
ransomware on laptops missing 2
malware calling home missing 1
public cloud bucket exposed missing 1
Onboard next (threats each source helps with):
2 identity provider
1 DNS resolver
1 application audit log
1 cloud audit log
1 endpoint (EDR/Sysmon/auditd)Every threat has a gap. The identity provider appears first because two threats depend on it: account takeover obviously, and ransomware too, because ransomware operators often move between machines with stolen accounts. MITRE ATT&CK lists the use of stolen credentials as its own technique, T1078 Valid Accounts, and records many threat groups using it.
A count is only a start. Weigh each threat by its likely impact, and each source by its cost: events per day, parser effort, and who must change a setting to turn it on. A firewall that logs every allowed connection can outweigh all other sources yet answer fewer questions than the DNS resolver.
04. Clocks and time zones
An investigation joins events from many systems into one timeline, so every system must agree on the time. Two different problems break this.
The first is clock drift. A computer's clock runs slightly fast or slow, and without correction the error grows by seconds or minutes. NTP (the Network Time Protocol, RFC 5905) keeps clocks close to a reference. Point every server, network device and appliance at the same internal NTP servers, and monitor the offset as a health check. A typical symptom of drift is an effect that seems to happen before its cause. Suppose a VPN gateway records that a session started at 08:15:40, but the file server logged that session's first file read at 08:14:58. The read cannot come before the session, so at least one clock is wrong by 42 seconds or more.
The second is time zones. A timestamp such as 10:07:12 means nothing until you know its zone. Store and compare times in UTC (Coordinated Universal Time), or keep the offset with each timestamp, as in 10:07:12+01:00. A wrong zone usually shows up as a shift of whole hours (or half hours for zones such as India's +05:30), while drift shows up as odd seconds. Some log formats carry no zone at all. The classic syslog format, which lesson 2 parses, is one of them.
05. Retention and integrity
Retention is how long you keep logs. Decide it from the questions you need to answer, then check the rules that apply to you. Intrusions are often found weeks or months after they began, so you need enough history to find the first step, not only the last. Contracts and regulations can set minimum periods, for example for payment card systems or the public sector. Privacy law pulls the other way: logs about people should not be kept longer than needed, and should not contain more personal data than needed. Many teams keep recent data in fast searchable storage and older data in a cheaper archive tier that can be restored when an investigation needs it. NIST's SP 800-92 (2006) covers log management planning; its revision, SP 800-92 Rev. 1, was released as a draft in October 2023.
Integrity means the logs still show what happened. An attacker with administrator rights on a host can edit or delete its local logs, stop the logging agent, and change any checksum or key stored on that host. Protection therefore has to live somewhere else. Forward events off the host within seconds to a central store that the host cannot change: append-only or write-once storage, managed by different administrators with different credentials. The OWASP cheat sheet gives the same advice: copy log data to read-only media as soon as possible. Alert when a source goes quiet, because a stopped agent looks exactly like a quiet night.
The next script shows why local checks are not enough. It builds a hash chain over four log lines (each digest covers its line and all lines before it), keeps a copy as if it had been forwarded, then plays an attacker with root who deletes their lines and rebuilds the chain. Save it as chain.py next to sources.py and run python3 chain.py.
"""A hash chain on the same host proves little; an off-host copy proves more."""
import hashlib
def chain(lines):
digest, out = "0" * 64, []
for line in lines: # each digest covers this line and every line before it
digest = hashlib.sha256((digest + line).encode()).hexdigest()
out.append(digest)
return out
def consistent(lines, digests):
return chain(lines) == digests
log = ["09:01:00 sshd Failed password for root from 203.0.113.45",
"09:07:12 sshd Accepted password for deploy from 203.0.113.45",
"09:09:40 sudo deploy : COMMAND=/usr/bin/cp /tmp/invoice.js /var/www/html/js/",
"09:30:11 sshd Accepted password for asmith from 10.20.1.5"]
digests = chain(log)
off_host = list(log) # forwarded within seconds to write-once storage elsewhere
# An attacker with root removes their lines and simply rebuilds the local chain.
local = [line for line in log if "203.0.113.45" not in line and "invoice" not in line]
local_digests = chain(local)
print("local chain still consistent:", consistent(local, local_digests))
print("matches the digest shipped off-host:", local_digests[-1] == digests[-1])
for line in off_host:
if line not in local:
print(" only in off-host copy:", line[:60])local chain still consistent: True
matches the digest shipped off-host: False
only in off-host copy: 09:01:00 sshd Failed password for root from 203.0.113.45
only in off-host copy: 09:07:12 sshd Accepted password for deploy from 203.0.113.45
only in off-host copy: 09:09:40 sudo deploy : COMMAND=/usr/bin/cp /tmp/invoice.js /The local chain is still consistent, because the attacker could recompute it. Only the copy that left the host shows what was removed. A hash chain is useful when its latest digest is also stored somewhere the attacker cannot reach; on its own, on the same disk, it proves very little.
06. Check your understanding
07. Apply it
Write a one-page log source plan for the skill project: two Linux hosts and one Windows host running SSH, sudo, a web server and DNS.
- List three threats and, for each, the questions an investigator would ask.
- Copy
sources.pyand replace its data with your environment. Which source comes first, and does that match your judgement of impact and cost? - For each source, write its retention (searchable and archive), how it leaves the host, and who can delete it at the destination.
- Write the NTP servers every host uses and how you would notice a host whose clock is off by more than a few seconds.
08. Review prompt
Without looking back:
- Name the five families of log sources and one question each answers.
- Why does an office network sensor miss most cloud account takeovers?
- How do you tell clock drift from a time zone mistake in a timeline?
- Why does a hash chain on the same host fail to protect logs from an attacker with root, and what does protect them?
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.