Detection and Response¶
Build custom detection logic with automated response actions.
Documentation¶
- Detection and Response Examples - Sample detection rules
- Detection on Alternate Targets - Detections beyond endpoint events
- False Positive Rules - Managing false positives
- Writing and Testing Rules - Rule development guide
- Stateful Rules - Rules with state tracking
- Sensor Variables - Share state across rules with per-sensor variables
- Unit Tests - Testing detection rules
- Replay - Replaying events for testing
Programmatic Management¶
Prerequisites
You need a valid API key with dr.list and dr.set permissions.
See API Keys for setup instructions.
List D&R Rules¶
from limacharlie.client import Client
from limacharlie.sdk.organization import Organization
from limacharlie.sdk.hive import Hive
client = Client(oid="YOUR_OID", api_key="YOUR_API_KEY")
org = Organization(client)
hive = Hive(org, "dr-general")
rules = hive.list()
for name, record in rules.items():
print(name, record.enabled)
import limacharlie "github.com/refractionPOINT/go-limacharlie/limacharlie"
client, _ := limacharlie.NewClient(limacharlie.ClientOptions{
OID: "YOUR_OID",
APIKey: "YOUR_API_KEY",
}, nil)
org, _ := limacharlie.NewOrganization(client)
rules, _ := org.DRRules()
for name, rule := range rules {
fmt.Println(name, rule)
}
Get a Rule¶
Create or Update a Rule¶
curl -s -X POST "https://api.limacharlie.io/v1/hive/dr-general/YOUR_OID/my-new-rule/data" \
-H "Authorization: Bearer $LC_JWT" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'data={"detect":{"event":"NEW_PROCESS","op":"ends with","path":"event/FILE_PATH","value":".bat"},"respond":[{"action":"report","name":"bat-file-execution"}]}' \
-d 'usr_mtd={"enabled":true}'
from limacharlie.sdk.hive import Hive, HiveRecord
hive = Hive(org, "dr-general")
hive.set(HiveRecord(
name="my-new-rule",
data={
"detect": {
"event": "NEW_PROCESS",
"op": "ends with",
"path": "event/FILE_PATH",
"value": ".bat",
},
"respond": [
{"action": "report", "name": "bat-file-execution"}
],
},
enabled=True,
))
detection := limacharlie.Dict{
"event": "NEW_PROCESS",
"op": "ends with",
"path": "event/FILE_PATH",
"value": ".bat",
}
response := limacharlie.List{
limacharlie.Dict{"action": "report", "name": "bat-file-execution"},
}
err := org.DRRuleAdd("my-new-rule", detection, response,
limacharlie.NewDRRuleOptions{
IsReplace: true,
IsEnabled: true,
})
Delete a Rule¶
Enable / Disable a Rule¶
# 1. Read current metadata to preserve tags, expiry, comment:
CURRENT=$(curl -s -X GET \
"https://api.limacharlie.io/v1/hive/dr-general/YOUR_OID/my-rule/mtd" \
-H "Authorization: Bearer $LC_JWT")
# 2. Merge and update (set enabled to false, keep other fields):
curl -s -X POST "https://api.limacharlie.io/v1/hive/dr-general/YOUR_OID/my-rule/mtd" \
-H "Authorization: Bearer $LC_JWT" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'usr_mtd={"enabled":false,"expiry":0,"tags":["my-tag"],"comment":"kept"}'
Warning
The API replaces usr_mtd entirely. Sending only {"enabled":false} will reset tags, expiry, and comment to their defaults. Always read the current metadata first and resend all fields.
hc := limacharlie.NewHiveClient(org)
// Read current metadata first to preserve tags, expiry, comment.
existing, _ := hc.GetMTD(limacharlie.HiveArgs{
HiveName: "dr-general",
PartitionKey: org.GetOID(),
Key: "my-rule",
})
enabled := false
hc.Add(limacharlie.HiveArgs{
HiveName: "dr-general",
PartitionKey: org.GetOID(),
Key: "my-rule",
Enabled: &enabled,
Tags: existing.UsrMtd.Tags,
Expiry: &existing.UsrMtd.Expiry,
Comment: &existing.UsrMtd.Comment,
})
Test a Rule Against Sample Events¶
Replay a Rule Against Historical Data¶
Validate Rule Components¶
curl -s -X POST "https://api.limacharlie.io/v1/hive/dr-general/YOUR_OID/test-rule/validate" \
-H "Authorization: Bearer $LC_JWT" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'data={"detect":{"event":"NEW_PROCESS","op":"is","path":"event/FILE_PATH","value":"test.exe"},"respond":[{"action":"report","name":"test"}]}'
from limacharlie.sdk.hive import Hive, HiveRecord
hive = Hive(org, "dr-general")
result = hive.validate(HiveRecord(
name="test-rule",
data={
"detect": {
"event": "NEW_PROCESS",
"op": "is",
"path": "event/FILE_PATH",
"value": "test.exe",
},
"respond": [
{"action": "report", "name": "test"}
],
},
))
print(result)