Skip to main content

Custom Detection Rules

Create and manage custom security detection rules tailored to your environment and threat landscape.

API examples: base URL is configurable

The API examples below use http://localhost:5000 (default for an on‑prem/local Worker).

If your Worker runs on a different host/port, replace the base URL accordingly.

Two Rule Types

CastellanAI supports YARA rules for file-based detection and Security Event Rules for log-based detection.


Overview

CastellanAI supports two types of detection rules:

Rule TypePurposeManagement
Malware Rules (YARA)Signature-based file scanning patternsDashboard UI
Security Event RulesMap Windows Event IDs to security alertsAPI (Admin only)

Malware Rules (YARA)

YARA rules are the primary method for creating custom file-based detections using industry-standard syntax.

Accessing Malware Rules

Navigate to Malware Analysis in the sidebar, then access the Detection Rules section.

Importing Custom YARA Rules

Import Steps

  1. Click Import Rules on the Malware Analysis page
  2. Upload a YARA rule file (.yar, .yara, or .txt)
  3. Configure import settings:
SettingDescription
CategoryClassify the rule (Malware, Ransomware, Trojan, etc.)
AuthorRule author attribution
Skip DuplicatesAvoid importing existing rules
Enable by DefaultActivate rules immediately after import
  1. Click Import to add the rules

Managing YARA Rules

From the Malware Analysis page:

ActionDescription
Enable/DisableToggle rule activation
View DetailsSee full rule content and match statistics
DeleteRemove custom rules (built-in rules cannot be deleted)
FilterSearch by name, category, threat level, or status

Security Event Rules

Security Event Rules map Windows Event Log entries to security alerts with MITRE ATT&CK technique mappings.

Rule Structure

Rule Fields

FieldDescription
Event IDWindows Event ID (e.g., 4625 for failed logon)
ChannelLog source (e.g., "Security", "PowerShell/Operational")
Event TypeSecurity classification (e.g., "AuthenticationFailure")
Risk LevelSeverity: low, medium, high, critical
ConfidenceDetection confidence score (0-100)
SummaryHuman-readable description
MITRE TechniquesMapped ATT&CK technique IDs
Recommended ActionsResponse guidance for analysts

Creating Custom Security Event Rules

Admin Only

Custom Security Event Rules are managed via API and require Admin role.

Create a Rule

curl -X POST "http://localhost:5000/api/security-event-rules" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"eventId": 4688,
"channel": "Security",
"eventType": "ProcessCreation",
"riskLevel": "medium",
"confidence": 70,
"summary": "New process created",
"mitreTechniques": ["T1059"],
"recommendedActions": ["Review process details", "Check parent process"],
"isEnabled": true,
"priority": 100,
"description": "Monitors for suspicious process creation",
"tags": ["execution", "custom"]
}'

API Endpoints

EndpointMethodDescription
/api/security-event-rulesGETList all rules with optional filtering
/api/security-event-rules/{id}GETGet specific rule
/api/security-event-rulesPOSTCreate new rule (Admin)
/api/security-event-rules/{id}PUTUpdate rule (Admin)
/api/security-event-rules/{id}DELETEDelete rule (Admin)
/api/security-event-rules/refresh-cachePOSTRefresh rule cache (Admin)

Best Practices

YARA Rule Best Practices

DoDon't
Start with narrow, specific patternsCreate overly broad rules
Test thoroughly before enablingEnable untested rules in production
Use metadata (author, description, severity)Leave rules without context
Leverage community rules from trusted sourcesImport rules from unknown sources
⚠️ Common Mistakes to Avoid
MistakeImpactSolution
Enabling untested rulesHigh false positive rateTest in staging first
Overly broad patternsAlert fatigueStart specific, broaden gradually
Missing documentationHard to maintainAlways include description and author
Ignoring false positivesMissed real threatsReview and tune regularly
Setting everything as criticalAlert fatigueReserve critical for high-confidence threats

Availability

FeatureSmall BusinessMedium BusinessEnterprise
Built-in YARA rules
Import YARA rules
Built-in Event rules
Create Event rules via API-LimitedUnlimited
Rule performance analytics--

What's Next?

GuideDescription
Threat DetectionUnderstand detection methods
MITRE ATT&CKLearn about technique mappings
Malware ScanningFile-based threat detection
Taking ActionResponse procedures