flowchart TD
A[Detection Request] --> B[Requirement Elicitation]
B --> C[Requirement Analysis]
C --> D{Strategy Aligned?}
D -- No --> E((Drop Request))
D -- Yes --> F{Prerequisites Satisfied?}
F -- No --> G[Prerequisites Engineering]
G -- Achieved / Re-assess --> F
G -- Unachievable / Too Costly --> E
F -- Yes --> H[Rule Design & Documentation]
H --> I[Leverage Existing Solutions]
I --> J[Implement Rule Logic]
J --> K[Test & Tune]
K -- Refine --> J
K -- Approved --> L[Peer Review]
L -- Rework --> J
L -- Approved --> M((Deploy Rule))
While working in a Threat Detection Engineering (TDE) team, I’ve observed a common practice: engineers often begin coding new detection rules immediately upon receiving a ticket. The critical documentation — including rule description, context, and taxonomy (often MITRE ATT&CK mapping) — is frequently left to the final step before the rule is pushed to production.
Is this the best approach? I’d argue it is not. Drawing on my software engineering (SWE) classes, I want to show how a more structured, engineering-first approach can lead to better and faster-deployed detection rules.
Building Software: A Pre-Coding Imperative
In software engineering, when an engineer receives a request for new software, the first phase is dedicated to understanding the problem. As highlighted in “Software Engineering, 10th Edition by Ian Sommerville,” this involves specifying requirements to grasp what needs to be built, why it’s necessary, and who will use it.
Once functional and non-functional requirements are clearly defined, the engineer assesses their alignment with the team’s overall scope and strategy. If alignment is confirmed, the process moves to the design phase. Here, architectural patterns, data models, interfaces, and algorithms are designed and carefully documented, serving as a blueprint for the implementation that follows.
A key aspect of the design phase is reusing existing solutions. Engineers actively seek out and use design patterns, libraries, frameworks, and other pre-existing components. This reuse speeds up development and also improves safety, as these components are typically well-tested and validated, assuming adherence to good software practices.
Building a Detection Rule: A Methodical Path
Applying this same methodology to the creation of a detection rule, a TDE engineer would begin by scrutinizing the requirements specified in the incoming ticket. This involves clearly articulating the detection requirements, detailing precisely what is expected to be detected and identifying potential sources of false positives. This specification would also encompass any prerequisites for log ingestion or monitoring, such as the deployment of EDR agents, the integration of IDS/IPS devices into the network, or the centralization of logs within a SIEM.
In my experience, clients frequently ask the TDE team to create specific rules, even outlining multiple rules they deem necessary within a single request. This approach is often suboptimal because existing rules might already cover the requested detection, the request may not align with the team’s strategic focus, or the proposed rules might need to be split or consolidated for better efficacy. Consequently, a request for five rules could, for instance, result in seven rules, two rules, or even no new rules at all.
To build a more effective process, TDE teams should ideally engage with a limited, pre-defined list of authorized requesting teams. Furthermore, all such requests should be framed as use cases, potentially including rule suggestions if the requestor has specific ideas. A use case, in this context, consists of a problem statement with relevant context, followed by a description of the expected detection outcome.
Armed with such a detailed list, it becomes possible to understand whether the proposed use case aligns with the team’s strategic objectives and if all essential prerequisites for rule construction are met. A clear misalignment with strategy would warrant dropping the request, while a failure to meet fundamental requirements — like the absence of necessary logs in a SIEM — would require sub-requests, leading to either a delay or abandonment of the rule creation.
Detective controls, the domain where Detection Engineering teams primarily operate, are complementary to preventative controls, not a replacement for them. The best strategy invariably combines both prevention and detection. It’s also important to understand they are not mutually exclusive; a detective control can often monitor a preventative control to highlight suspicious activity. For example, one could monitor if an EDR is triggering an excessive number of blocks for a given user or device, which could indicate a possible compromise.
The requirement elicitation phase must involve analyzing existing preventative controls for the use case. This ensures new detection rules avoid redundancy and precisely target actual security gaps. Any gap in preventative controls must be highlighted, as they could be blockers for creating new rules.
Assuming development is approved to proceed, the engineer enters the design phase. This involves writing a clear one-paragraph statement for each mapped rule, outlining its purpose and providing full context. Here, the company’s operational idiosyncrasies must be considered, and the rule’s goals must be explicitly stated. Finally, with this foundational documentation in hand, the new rule must be appropriately categorized using the MITRE ATT&CK taxonomy, specifying relevant tactics and techniques.
This foundational documentation serves a key purpose: it lets the engineer search public repositories for existing rules that align with the defined goals. The MITRE ATT&CK taxonomy is particularly useful here, acting as effective keywords for targeted searches. Even if a rule precisely monitoring the exact TTP within the exact context isn’t readily available, similar rules can often be adapted with minimal effort.
Having the rule context and the related MITRE ATT&CK tactics and techniques makes it trivial to query well-known public resources, such as MITRE ATT&CK itself, Sigma, Elastic, and Splunk. Projects like Rulehound effectively aggregate many of these, providing invaluable starting points for detection development. 🔍
A crucial note regarding MITRE ATT&CK mapping is its inherent lack of “how-to” specifics, as procedures are not directly mapped within the matrix. As Katie Nickels demonstrated years ago, an entire universe of context exists beneath each technique. This is why full context must always accompany ATT&CK mapping.
MITRE ATT&CK continues to evolve, offering detection ideas under each technique, including data sources, data components, and the targets that should be monitored. Alongside publicly available rulesets, this is a valuable resource, letting engineers develop new rules without starting from scratch or reinventing the wheel.
The diagram below summarizes this process with some abstractions.
Key Advantages of Structured Detection Engineering
One might be tempted to believe that an MVP-like approach—starting immediate log analysis to construct queries—would be faster. While this might work for scenarios where the team is highly familiar with the data source and use case, the documentation and validation of the new rule will still be necessary. Reusing existing, tested rules based on early documentation speeds up the testing phase and instills greater confidence in the outcome.
Through this careful research and reuse, rules are built on solid references and good documentation. This foundation gives incident response teams more confidence when handling alerts. And when applied consistently, this approach identifies and mitigates false positives, which reduces alert fatigue. 😎
Conclusion
Adopting a structured process that prioritizes engineering requirements, develops full documentation, and researches existing artifacts (rules and documents) can substantially reduce the time spent on data analysis (logs) and detection validation. Reusing existing rules and building on established documentation is a hallmark of senior engineering and a smart decision.
While this approach might initially look like unnecessary overhead, especially for simpler rules or those the team is highly proficient with, remember that every rule, before being moved to production, must be properly documented and thoroughly tested. So any time invested in documentation is worth it. And while researching artifacts might seem less critical for familiar logs and tools, it can still surface useful findings about novel telemetry or alternative monitoring approaches for a given data source. ✌️
Appendix: Examples
Use Case Example
Problem Statement & Context
We are concerned about our third-party BPO personnel potentially accessing our corporate systems from locations other than their designated and secured BPO premises. Our contract with the BPO explicitly states that access should only occur from their controlled facilities to ensure data security and compliance. We are worried that if BPO employees access our systems from unsecured personal networks (e.g., home Wi-Fi), it could expose sensitive customer data or violate our agreements.
Expected Outcome
We need a way to know if any BPO user accounts are accessing our applications or data from IP addresses that are not part of their approved BPO office networks. The goal is to detect and ideally alert on such unauthorized access attempts or successful logins.
Requirements Elicitation Example
Rule Context Example
Rule 1: Initial Unauthorized Access Alert This rule serves as the primary line of defense against straightforward policy violations or potential account compromises. Its purpose is to immediately identify and alert on instances where a BPO user account successfully authenticates to the organization’s systems, but the originating IP address for that authentication does not belong to the list of pre-approved and designated BPO network ranges. The context for this rule is the strict policy requiring BPO personnel to access corporate assets exclusively from their secure premises. By focusing on direct access from explicitly unapproved external locations, this rule aims to catch the most obvious deviations from policy, signaling either a direct attempt to bypass security controls or a compromised BPO user account being leveraged from an untrusted network.
TA0001Initial Access:T1078.004Valid Accounts: Cloud AccountsTA0003Persistence:T1078.004Valid Accounts: Cloud AccountsTA0005Defense Evasion:T1078.004Valid Accounts: Cloud Accounts
Rule 2: Anomalous Geographic Access Alert This rule provides a more nuanced layer of detection, designed to catch more sophisticated or subtle forms of unauthorized access that might evade a simple IP allowlist. Even if a BPO user successfully authenticates from an IP address that appears to be within an approved BPO range, this rule examines the geographical context derived from that IP address. Its purpose is to alert if the actual geographical location associated with the originating IP is inconsistent with the known physical location of the specific BPO premise (e.g., an IP listed for the São Paulo office suddenly resolves to a city hundreds of kilometers away). This context is critical for identifying scenarios such as compromised VPN egress points, BPO internal network misconfigurations, or the use of sophisticated proxy services that route traffic through approved IP addresses but from an unexpected physical location, thus providing an additional security layer against more advanced policy breaches or potential compromises.
TA0001Initial Access:T1078.004Valid Accounts: Cloud Accounts,T1133External Remote ServicesTA0003Persistence:T1078.004Valid Accounts: Cloud Accounts,T1133External Remote ServicesTA0005Defense Evasion:T1078.004Valid Accounts: Cloud Accounts
Reuse
Citation
@online{lopes2025,
author = {Lopes, Joe},
title = {Engineering {Detection} {Rules}},
date = {2025-06-20},
url = {https://lopes.id/log/engineering-detection-rules/},
langid = {en}
}