Logging, Monitoring and SIEM: Seeing Attacks in the Data
What to log, where it lives and how to make it useful: log sources and formats, time synchronisation, centralised collection, SIEM correlation and detection rules, alert tuning, the Security Operations Centre workflow, and common detections. Practise analysing an SSH log for brute-force attacks in Python.
You cannot detect what you cannot see
Prevention fails sometimes. Attackers get in through a phished password, an unpatched server or a mistake. What decides whether that becomes a minor incident or a catastrophic breach is how quickly you notice and how well you can reconstruct what happened. Industry reports repeatedly find attackers inside networks for weeks or months before detection. Logging and monitoring shorten that time.
Three words, three jobs:
- Logging: recording events (who did what, when, from where, with what result).
- Monitoring: watching those records and system health, in real time.
- Detection and response: recognising malicious patterns and acting on them.
What to log
Log security-relevant events from every layer, and aim for coverage of the places attackers must touch:
| Source | Examples of valuable events |
|---|---|
| Identity | Sign-ins (success and failure), MFA prompts, password resets, new devices, privilege changes, account creation and deletion |
| Endpoints | Process creation, PowerShell and script activity, new services, scheduled tasks, EDR alerts, USB use |
| Servers | SSH and RDP logins, sudo use, file changes in sensitive paths, service errors |
| Network | Firewall allow and deny, VPN sessions, DNS queries, proxy and web gateway logs, NetFlow, IDS/IPS alerts |
| Cloud | Audit logs (CloudTrail, Activity Log), storage access, security group changes, key use |
| Applications | Authentication, authorisation failures, input validation errors, business-logic events (large exports, payment changes) |
| Delivery, attachments, inbox-rule changes, forwarding rules | |
| Databases | Privileged queries, schema changes, bulk reads |
Do not log secrets (passwords, tokens, card numbers) or unnecessary personal data. Mask sensitive fields, and protect the logs themselves, because they can contain sensitive information.
What a good log entry contains
The classic “5 Ws”: what happened, when (a timestamp in UTC), who (user or account), where (source and destination system and address) and the outcome (success or failure). Add a request or session identifier so events can be linked.
Oct 21 10:02:11 srv sshd[812]: Failed password for root from 203.0.113.9 port 51522 ssh2
Oct 21 10:02:19 srv sshd[815]: Accepted password for ada from 198.51.100.4 port 40112 ssh2
Sources and formats
- Syslog (RFC 5424) is the standard for network devices and Unix systems: a facility, a severity (0 emergency to 7 debug) and text. Forward over TCP with TLS where possible, not plain UDP.
- Windows Event Logs: the Security log (logon events 4624 success and 4625 failure, 4672 special privileges assigned, 4688 process creation, 4720 account created, 1102 log cleared), System and Application, plus Sysmon for detailed endpoint telemetry and PowerShell script block logging.
- JSON and CEF/LEEF structured formats make parsing easier than free text.
- Cloud audit logs, flow logs, web server access logs and application logs.
- The Linux journal and
auth.log/secure(see the Linux course’s logging lesson).
Time: the quiet requirement
Correlation depends on accurate, consistent timestamps. Synchronise every system with NTP from trusted sources, record time in UTC with the time zone, and monitor for clock drift. A one-hour skew between two systems can make an attack look impossible or hide the real order of events.
Centralise and protect
Collect logs from all sources into one place:
- Forward in near real time (agents, syslog, cloud connectors), so evidence is safe even if a host is destroyed.
- Normalise into a common structure (field names such as
src_ip,user,action), so a search works across vendors. - Protect integrity: restrict who can read, change and delete; use write-once or append-only storage; separate the log platform from the systems it watches; hash or sign archives.
- Retain long enough for investigations and obligations. Many organisations keep 90 days “hot” for fast search and a year or more in cheaper archive, and regulators or contracts can require specific periods. Balance against cost and privacy.
- Monitor the log pipeline itself: alert when a source stops sending. Silence is a finding.
SIEM: making sense of it
A Security Information and Event Management (SIEM) platform is the central brain:
- Collects and normalises logs from many sources.
- Correlates events across sources to spot patterns no single log shows (“a user signed in from two countries within ten minutes, then a new inbox forwarding rule appeared”).
- Detects with rules, statistical baselines and machine learning, and enriches alerts with context (asset owner, threat intelligence, geolocation).
- Alerts and tracks cases, and supports search, dashboards and reporting (compliance evidence).
Examples: Splunk, Microsoft Sentinel, Elastic Security, IBM QRadar, Google Chronicle, Wazuh (open source), Graylog. Related tools: SOAR (security orchestration and automated response) automates routine response steps, EDR/XDR gather deep endpoint and cross-domain telemetry, UEBA profiles normal user behaviour to spot anomalies, NDR analyses network traffic, and threat intelligence platforms supply known-bad indicators.
Detection: from logs to alerts
A detection rule is a precise question asked of the data continuously. Good detections are tied to attacker behaviour (the MITRE ATT&CK techniques from the attack lifecycle lesson), not just single indicators.
Common detections:
| Detection | Logic |
|---|---|
| Brute force / password spraying | Many failed logins for one account (brute force) or one source across many accounts (spraying) within a short window |
| Successful login after many failures | A success from a source that just produced numerous failures |
| Impossible travel | Sign-ins from locations too far apart for the time between them |
| Privilege escalation | A user added to an admin group; a new admin account |
| Log cleared / auditing disabled | Event 1102 or a stopped logging service |
| Suspicious process chain | An Office application spawning PowerShell or cmd |
| Beaconing | Regular, periodic outbound connections to one rare destination |
| Large outbound transfer | A host sending unusual volumes to a new external address |
| New persistence | New scheduled task, service or autorun entry |
| Cloud changes | A security group opened to 0.0.0.0/0, a new access key, a disabled audit trail |
| Mailbox rules | An inbox rule that deletes security alerts or forwards mail externally |
Start with high-value, low-noise rules, and map your coverage against ATT&CK to find gaps.
Tuning: the discipline that makes it work
Alert fatigue is a major cause of missed attacks: if analysts see hundreds of meaningless alerts, they stop looking carefully. Manage quality:
- Track precision: for each rule, how many alerts were real? Retire or fix rules with a high false-positive rate.
- Add context (asset criticality, user role, known scanner addresses) to raise or lower severity.
- Use thresholds and time windows sensibly.
- Allow-list known good activity (the vulnerability scanner, the backup service) explicitly and review the list.
- Test detections by simulating the behaviour (red-team tools, atomic tests) so you know they fire.
- Treat rules as code: version control, peer review, documentation of intent and response steps.
The Security Operations Centre (SOC)
A SOC is the team (and processes and tools) that monitors, detects, investigates and responds around the clock. Typical tiers:
- Tier 1: triage alerts, filter false positives, follow playbooks, escalate.
- Tier 2: deeper investigation, containment steps, correlation.
- Tier 3 / threat hunters / detection engineers: advanced analysis, proactive hunting, building detections, forensics.
- Plus a SOC manager, and links to incident response, IT operations and the business.
The alert workflow: detect, triage (is it real? how severe? what asset?), investigate (scope, timeline, root cause), respond (contain, eradicate, recover; see the incident response lesson) and learn (improve detections and controls). Document each case, with the evidence, decisions and times. Measure mean time to detect (MTTD) and mean time to respond (MTTR).
Small organisations may not have a 24/7 SOC. Options include a managed detection and response (MDR) provider, a smaller team with automation and on-call, or focusing on a handful of high-value detections plus good alert routing.
Threat hunting
Hunting is proactively searching for attackers that detections missed, driven by a hypothesis (“an attacker using stolen credentials would sign in from a new country, then access the file server at night”). It uses the same data, checks it in new ways, and feeds new detection rules back into monitoring.
Privacy and legal considerations
Logs contain personal data (usernames, IP addresses, browsing). Collect what you need for security and legal purposes, tell users in policy (acceptable use), restrict access, set retention, and follow data-protection law. Evidence for legal or disciplinary action needs a documented chain of custody.
Lab: find the brute-force attack in an SSH log
Below is a sample of sshd log lines. Write three functions:
failed_by_ip(lines): return a dictionary of source IP to the number of “Failed password” lines from that IP.flagged(counts, threshold=5): return the list of IPs with at leastthresholdfailures, highest count first.compromised(lines, threshold=5): return the IPs that reached the threshold of failures and then had anAcceptedlogin from the same IP later in the log (a probable successful brute force).
Use a regular expression such as from (\d+\.\d+\.\d+\.\d+) to pull out the address.
What you learned
Good detection starts with logging the right events with accurate time, collecting them centrally and protecting them. A SIEM correlates across sources, rules express attacker behaviour, and tuning keeps alerts worth reading. A SOC turns alerts into investigation and response, which the next lesson covers.
Your SIEM shows a successful VPN login for an executive at 03:10 from a country they have never visited, 20 minutes after a failed-login burst from the same address. What do you do first?
Treat it as a probable account compromise. Triage: confirm the sign-in details and the pattern in the logs, check whether MFA was satisfied and from what device, and look at what the session did afterwards. Contain by disabling or resetting the account, revoking active sessions and blocking the address, then escalate under the incident response plan and widen the search for other accounts from the same source.
Can You Explain It?
Close the lesson and answer these without looking back. The goal isn't the wording — it's whether you've formed a usable mental model.
- List six sources you would collect logs from and one useful event from each.
- Why do time synchronisation and log integrity matter for investigations?
- What is alert fatigue and what practices keep detections useful?
🧪 Want to practise this on your own computer? See how to set up your lab →