← All write-ups

Home Lab: Sentinel & KQL Detection Engineering

Building a SIEM from nothing, then proving it works by attacking it.

Personal home lab · Microsoft Azure — SIEM / Detection Engineering

Objective

Build a working SOC detection pipeline from scratch: ingest real telemetry, write detection logic in KQL, simulate an attack technique, and confirm the full alert-to-incident workflow — then surface it in a dashboard.

1. Environment Setup

Built the lab entirely on Azure's free tier:

Kept cost low by stopping/deallocating the VM whenever it wasn't actively being used — Sentinel, the workspace, and all ingested data stay intact and cost nothing extra while the VM is off.

2. Confirming Ingestion

Before building any detections, first confirmed logs were actually flowing by running a baseline query in Sentinel's Logs blade:

SecurityEvent
| take 10

First KQL query confirming SecurityEvent log ingestion

Getting rows back here confirmed the full pipeline — VM → Azure Monitor Agent → Data Collection Rule → Log Analytics workspace — was working end to end before writing any actual detection logic.

3. Simulating an Attack Technique

Rather than manually creating test data, used Invoke-AtomicRedTeam (Red Canary's open-source attack simulation framework, mapped to MITRE ATT&CK) to generate a realistic, repeatable event on the VM.

Ran T1136.001 — Create Local Account, a common persistence technique:

Set-ExecutionPolicy Bypass -Scope Process -Force
Import-Module "C:\AtomicRedTeam\invoke-atomicredteam\Invoke-AtomicRedTeam.psd1" -Force
Invoke-AtomicTest T1136.001

Atomic Red Team executing T1136.001 sub-tests, creating local accounts via CMD, PowerShell, and .NET

This single technique runs through several sub-tests — creating a local user via cmd, PowerShell, and as a Windows admin — each one generating a genuine Event ID 4720 (a new local account was created) on the VM, exactly as a real attacker establishing persistence would.

4. Writing the Detection Query

With real 4720 events now landing in SecurityEvent, wrote a KQL query to surface them cleanly:

SecurityEvent
| where EventID == 4720
| project TimeGenerated, TargetUserName, SubjectUserName, Computer

KQL query confirming EventID 4720 account-creation events from the atomic test

The results show each account created during the atomic test run (NewLocalUser, T1136.001_Admin, T1136.001_PowerShell, T1136.001_CMD) — proof the detection logic correctly isolates the exact behavior the attack simulation produced.

5. Building the Analytics Rule

Converted the manual query into an automated Scheduled Query Rule in Sentinel Analytics:

6. Confirming the Full Alert-to-Incident Pipeline

Re-ran the atomic test to generate fresh account-creation events, and within one scheduling cycle, Sentinel correctly fired the rule and generated incidents:

Four Medium-severity NewLocalAcctCreation incidents generated in Sentinel

Each atomic sub-test that created an account produced its own incident — confirming the detection isn't just matching historical data, but actively catching new activity as it happens, the same way a production SOC rule would.

7. Building the Detection Overview Workbook

Finally, built a Sentinel Workbook to visualize the lab's activity in one place — table volumes by type, incident status breakdown, and a running count of new incidents:

SecOps Lab Detection Overview workbook showing table volumes and incident status

This turns raw detection data into something a SOC lead or stakeholder could actually glance at — which is as much a part of the job as writing the detection logic itself.


Key Takeaways