Drill Case
Rule Range
Write a regex, a Sigma rule, a YARA rule and a query pipeline, each graded live against samples, some of which you never see.
The case
The investigation is done and the findings need to turn into detections. Each stage asks you to build something, and the page grades it live against sample text, events or files.
Edit until every case shows the result it should. Some stages also check samples you never see, so a rule that only fits the visible ones will not pass.
- Regex 11 questions
- Sigma 8 questions
- YARA 8 questions
- Query pipeline 10 questions
What you will be able to do
- Write a character class that accepts exactly the range you mean and nothing adjacent to it (RegEx Cheat Sheet)
- Anchor a pattern so it matches a whole field rather than a substring of one
- Use quantifiers and alternation to cover several shapes of the same value without over-matching
- Recognize when a pattern only fits the samples in front of you, the failure mode that makes a detection rule useless in production
- Write a Sigma rule that fires on the events you mean and stays silent on the ones you don't (Sigma Rule Tester)
- Choose the field a technique cannot function without, rather than the one that happens to be in the sample
- Combine several field constraints and several selections, and say what the condition line actually evaluates
- Recognize a rule that only fits the events in front of you: the failure that turns into missed detections in production
- Write a YARA rule that fires on the files you mean and stays silent on the ones you don't (YARA Rule Tester)
- Choose between a text string and a hex pattern, and use a wildcard byte where a field varies between builds
- Apply the ascii, wide and nocase modifiers deliberately, rather than adding all three out of habit
- Write a condition that counts (any, all, or N of them) instead of reaching for the first string that happens to differ
- Recognize a rule that only fits the samples in front of you, which is the failure that turns into a missed family in production
- Order a KQL pipeline so every stage can see the fields it references (KQL Query Builder)
- Order an SPL pipeline, and tell the base search apart from a later where (Splunk SPL Query Builder)
- Predict which fields survive an aggregation and which are discarded by it
- Filter raw fields before aggregating and computed fields after, without having to think about it
- Recognize the orderings that still return rows but return the wrong ones
Read first: RegEx Cheat Sheet, Sigma Rule Tester & Builder, YARA Rule Tester, Number Base Converter, KQL Cheat Sheet, Splunk SPL Cheat Sheet.
Notes for teaching it
- Works well as a paired exercise: one learner writes the pattern, the other proposes a string that should break it before the Check button is pressed.
- The hidden test cases exist to punish over-fitting, so a learner who passes every visible case and still fails has learned the most valuable thing in the drill. Say so before they start, or it reads as the tool being unfair.
- This drill is JavaScript regex. Grep/PCRE and RE2 differ on lookaround and backreferences: worth a sentence if the class works in a SIEM.
- The closest thing on this site to real detection-engineering work, and the best capstone for a class that has already done the regex drill: the |re modifier is a plain regular expression.
- Grading is behavioral, not textual: any rule with the right effect passes, so this works well as a compare-your-answers exercise. Two learners solving the same challenge differently is the interesting outcome, not an error.
- The unseen-event checks are the lesson worth stopping on. A learner whose rule passes every visible event and is still rejected has just been shown, concretely, why detections get tested against data they were not written from.
- It uses an explicitly scoped subset of Sigma: no logsource, no field lists, no negation. Say so up front, or a learner who knows Sigma will assume the tool is broken rather than deliberately limited.
- The natural partner to the Sigma drill: same build-it-live shape, but static file content rather than log events. Either can be run first, though YARA is the gentler introduction because a string match is easier to picture than a field selection.
- Grading is behavioral. Any rule with the right effect passes, so two learners solving a challenge differently is the interesting outcome rather than an error: worth running as a compare-your-answers exercise.
- The unseen-sample checks are the lesson worth stopping on. A learner whose rule satisfies every visible sample and is still rejected has just been shown why signatures get tested against data they were not written from.
- It uses an explicitly scoped subset of YARA: no modules, no filesize, no offset expressions, and no "not". Say so up front, or a learner who knows YARA will assume the tool is broken rather than deliberately limited.
- The hex challenge is where beginners stall. It helps to say plainly that "??" stands for exactly one unknown byte, and that the samples are text only because bytes below 0x80 are easier to read that way.
- The pair to the Sigma and YARA drills, and deliberately not the same shape. Those grade a rule by running it; this one grades an order, because the site's KQL and SPL utilities build queries and never execute them: inventing an interpreter to grade against would risk teaching behavior the real product does not have.
- Both languages in one drill on purpose. The lesson transfers completely: a learner who understands why the filter precedes the aggregation in KQL already understands it in SPL, and the only thing left to learn is the spelling.
- The dedup question is the one to stop on. Every other wrong order fails loudly; that one returns results happily and quietly answers a different question, which is the failure mode worth fearing in real hunting.
- Grading is exact-order, so each challenge's order comes from a data dependency, not from style. If a class argues an alternative order works, check whether a stage references a field that does not exist yet. That is usually what settles it.
- Works well immediately before letting people loose on the query builders, since the builders enforce a valid pipeline and this explains why that pipeline is the shape it is.
Terms behind it
- Sigma Rule: A vendor-agnostic rule format for writing log-based detection logic.
- YARA: A pattern-matching rule language to classify malware.
- Detection Rule: Logic that defines the conditions under which an alert fires.
- False Positive: An alert that flags benign activity as malicious.
- Detection Engineering: The discipline of designing, building, and maintaining detections.
Worksheet
Every question on one page, to print or to read without JavaScript. The answer key has the answers and why.
Regex, 11 questions
-
Find any mention of PowerShell in a log line. Plain characters in a regex match themselves, so no special syntax is needed yet.
-
Match a drive-letter reference to C:, D:, or E:, but not other drive letters. [ABC] matches any ONE of the characters inside the brackets.
-
Match a process-ID-looking reference of 4 or more digits in a row (real Windows PIDs are rarely shorter).
-
Match lines that START with the word ERROR, not lines where ERROR merely appears somewhere inside.
-
Match a mention of one of three commonly-abused script extensions: vbs, ps1, or bat.
-
Match the literal text '4624' followed by a period, but not '4624' followed by any OTHER single character. A bare . normally matches ANY character.
-
Match the standalone word 'admin' as a username, not as part of a longer word like 'administrator' or 'badmin'.
-
Match a bracketed severity tag that is NOT [INFO], e.g. [WARN], [ERROR], [CRIT]. A caret right after the opening bracket of a character class negates it.
-
Detect a word typed twice in a row with a space between (a common paste-duplication artifact). Match only when the SAME word repeats.
-
Match a credential-looking token containing BOTH a digit and an uppercase letter, in any order.
-
Final challenge: match a genuine IPv4 address (four dot-separated numbers, each in the real 0-255 range) while correctly REJECTING an out-of-range octet like 300 or 999. Counting digits alone will not be enough here.
Sigma, 8 questions
-
Fire on any execution of whoami.exe, wherever it was run from. Match on the image path ending, not on the full path: the same binary copied somewhere else is still the same binary.
-
Fire only when the built-in Administrator account runs net.exe. Both facts have to be true at once; either one alone is ordinary.
-
Write a rule that alerts on the first one and stays silent on the second.
-
Write one rule that catches both the original and the renamed copy, without firing on Control Panel. If your step-1 rule already does this, that is the lesson. Say why.
-
Alert on the encoded execution and on nothing else here.
-
Catch both -enc and the bare -e form, and leave -ExecutionPolicy alone. The case-insensitive string modifiers cannot separate these. You will need |re, which is matched case-sensitively and exactly as written.
-
Alert on the memory dump and not on the registration.
-
Extend the rule to cover both techniques in one rule, using a second selection and a condition that fires when either one matches.
YARA, 8 questions
-
Fire on any file containing the string "EvilDropper". This is the simplest rule YARA can express: one text string, and a condition that says it has to be there.
-
Fire on the mutex name "Global\SuperMutex99" however it is capitalized. Malware authors are inconsistent about case, and a rule that only matches one spelling misses the rest of the family.
-
A loader family carries three telltale strings, but any given build only ships two of them. Fire when at least 2 of the 3 are present, and stay silent when only one is.
-
Windows APIs frequently store strings as UTF-16LE, where every ASCII character is followed by a null byte. Fire on the path "\AppData\Roaming\updater.exe" whether it is stored as ASCII or as UTF-16LE.
-
Fire on the byte sequence 6A 40 68 00 30 00 00 (a common VirtualAlloc prologue), allowing the third byte to be anything, since that field varies between builds.
-
This family renamed its mutex between versions: older builds use "SvcHostMtx_A1", newer ones use "WinUpdMtx_B7". A single rule should catch both, and a build carrying neither should stay quiet.
-
A ransomware note is identified by three strings that always appear together. Fire only when every one of them is present; any two on their own are too common to alert on.
-
Fire on the command "whoami /priv", but not on "whoami /privileges", a different, unrelated command that starts with the same characters. The starter rule below matches both. Tighten it.
Query pipeline, 10 questions
-
KQL: In Defender, find devices where powershell.exe ran more than 10 times in the last 7 days, busiest first. Put the pipeline stages in the order that works.
-
KQL: List the ten accounts with the most failed sign-ins, showing just the account and the total. Put the pipeline stages in the order that works.
-
KQL: Find network connections to a suspect IP in the last day, newest first. Put the pipeline stages in the order that works.
-
KQL: Bucket process executions into hours and show the busiest hours. Put the pipeline stages in the order that works.
-
KQL: Count how many distinct devices each signed-in account touched. Put the pipeline stages in the order that works.
-
SPL: In Splunk, find source IPs with more than 20 failed logons, worst first, top 25. Put the pipeline stages in the order that works.
-
SPL: Group process executions by the parent process name in lowercase, and show the rarest. Put the pipeline stages in the order that works.
-
SPL: Show accounts that authenticated from more than three distinct workstations. Put the pipeline stages in the order that works.
-
SPL: Produce a readable table of recent service installations. Put the pipeline stages in the order that works.
-
SPL: Show the first time each distinct process path was seen on each host. Put the pipeline stages in the order that works.
Next: Terminal. All drills