š How to Build a Custom Security Baseline in Microsoft Defender for Endpoint (MDE)


Most organizations rely on industry-standard baselines like CIS or STIG to secure their endpointsābut these out-of-the-box policies often donāt align perfectly with the real-world needs of diverse environments. Thatās where custom security baselines come in.
In this post, Iāll walk you through how I create and implement custom security baselines in Microsoft Defender for Endpoint (MDE)āthe same way we do in enterprise environments. Whether you're a security analyst, compliance lead, or IT engineer, you'll find real XML examples, baseline tuning techniques, and KQL validation methods that will help you strike the right balance between security and stability.
š§© Step-by-Step: How I Build a Custom Security Baseline in MDE
Creating a tailored security baseline involves more than just downloading templates. Hereās my real-world workflowāone Iāve used with enterprise clients to align configurations with both compliance standards and operational practicality.
ā 1. Download the Default Baseline
Start with Microsoftās official MDE security baseline from their GitHub repository. It typically includes:
xccdf
file: Defines the configuration rulesoval
file: Describes the conditions under which rules applyREADME: Provides implementation and deployment guidance
š¦ These XML files form the foundation of your baseline logic.
ā 2. Identify Irrelevant or Break-Prone Rules
Not all default rules will fit your environment. I usually:
Run a test deployment in a sandbox VM
Monitor for performance degradation, conflicting policies, or feature breakage
Collaborate with compliance teams to apply waivers or exceptions
š§ Example: Disabling SMBv1 is critical, but disabling all legacy TLS versions might break internally hosted applications or legacy endpoints.
ā 3. Edit the xccdf Rules to Fit Your Environment
Open the .xccdf.xml
file using a text editor like Visual Studio Code. You'll see structured rule definitions like:
<xccdf:Rule id="Ensure-SMBv1-Disabled">
<xccdf:title>Ensure SMBv1 is Disabled</xccdf:title>
<xccdf:description>Disable the SMBv1 protocol to reduce attack surface.</xccdf:description>
<xccdf:fix>Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol</xccdf:fix>
</xccdf:Rule>
š§ You can modify the <xccdf:fix>
command to suit your systems, or comment out the rule if it causes conflicts.
ā 4. Test in a Controlled Lab Environment
Before deploying across the org, I always:
Use an isolated VM or pilot group for testing
Monitor the system using Microsoft Defender logs
Validate changes using KQL queries (covered below)
š”ļø Bonus Tip: Use Attack Surface Reduction (ASR) logs in Defender to detect blocked behavior related to your new baseline.
ā 5. Package and Deploy via Intune or Group Policy
Once the baseline passes lab validation:
Package the updated XML for deployment
Use Microsoft Endpoint Manager (Intune) or Group Policy for rollout
Follow a phased deployment: pilot group ā department ā full org
š§© If you're managing infra-as-code, integrate this step into Azure DevOps pipelines for automated compliance enforcement.
š§Ŗ Validating the Baseline Using KQL (Kusto Query Language)
After deployment, the job isnāt over. You need to verify that your baseline is functioning correctly, and identify any drift or misconfiguration. For that, I use KQL queries in Microsoft Defender and Azure Sentinel.
ā Common Validation Queries
š Check if a Policy Was Successfully Applied
DeviceEvents
| where ActionType == "PolicyChanged"
| where AdditionalFields contains "SMBv1"
š” This shows if your SMBv1 rule was triggered and applied successfully across devices.
š Detect Failed Policy Applications
DeviceEvents
| where ActionType == "PolicyApplicationFailed"
| project Timestamp, DeviceName, AdditionalFields
š” Use this to identify endpoints where your config couldnāt be applied.
š§Ŗ Check Compliance Status of Critical Rules
DeviceTvmSecureConfigurationAssessment
| where ConfigurationId == "Ensure-SMBv1-Disabled"
| project DeviceName, AssessedTime, ConfigurationValue, ExpectedValue, IsCompliant
š” This query tracks the compliance state of the SMBv1 rule over time.
āļø Combine With Alerts & Automation
You can go beyond manual checks by:
Triggering alerts for non-compliance using Defenderās alerting engine
Visualizing results in Power BI dashboards
Embedding queries in Azure Workbooks for scheduled compliance audits
ā This KQL-based validation step helps you catch silent failures early and prove that your secure configurations are being enforcedānot just assumed.
š Conclusion
Custom baselines give you the power to enforce security without breaking your business-critical apps. Microsoft Defender for Endpoint offers an incredibly flexible framework to help you do thisāif you know how to tweak it.
By editing xccdf
and oval
files, testing rigorously, and validating through KQL and PowerBI, youāre no longer just applying policies. Youāre building a resilient, transparent, and compliant security posture.
š¬ Have questions about MDE, baselines, or KQL?
Leave a comment below or connect with me on LinkedIn ā I'm happy to help you build more secure systems.
š Follow @cybershiv for real-world cybersecurity tutorials, red teaming insights, and cloud security tips from the trenches.
š Enjoyed this guide? Support my work here ā BuyMeACoffee.com/cybershiv
Subscribe to my newsletter
Read articles from Shivam Mathur directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Shivam Mathur
Shivam Mathur
š¼ Cybersecurity Consultant | Red Teamer | Defender + KQL Specialist I break configs (safely), hunt threats, and write about real-world security use cases. Follow along as I turn secure baselines, CVEs, and red team experiments into actionable content for modern defenders.