
लॉग प्रविष्टियों के विरुद्ध Sigma डिटेक्शन नियमों को पार्स और निष्पादित करने के लिए Go लाइब्रेरी, जो फील्ड मॉडिफायर्स, CIDR मैचिंग और कस्टम फील्ड रिज़ॉल्वर्स को सुरक्षा निगरानी के लिए सपोर्ट करती है।
github.com/runreveal/sigmalitesigmalite पैकेज Sigma detection format के लिए एक पार्सर और एक निष्पादन इंजन प्रदान करता है।
rule, err := sigmalite.ParseRule([]byte(`
title: My example rule
detection:
keywords:
- foo
- bar
selection:
EventId: 1234
condition: keywords and selection
`))
if err != nil {
return err
}
entry := &sigmalite.LogEntry{
Message: "Hello foo",
Fields: map[string]string{
"EventId": "1234",
},
}
isMatch := rule.Detection.Matches(entry, nil)
go get github.com/runreveal/sigmalite
नियम YAML प्रारूप में लिखे जाते हैं और न्यूनतम रूप से, इसमें एक title और एक detection शामिल होना चाहिए:
title: My example rule
detection:
keywords:
- foo
- bar
selection:
EventId: 1234
condition: keywords and selection
detection ब्लॉक में condition फ़ील्ड एक तार्किक अभिव्यक्ति है जो detection ब्लॉक में अन्य फ़ील्ड चयनकर्ताओं को जोड़ता है। इस उदाहरण में, यह नियम किसी भी लॉग प्रविष्टि से मेल खाएगा जिसमें EventId फ़ील्ड बिल्कुल 1234 है और उसके संदेश में "foo" या "bar" है।
फ़ील्ड्स को regular expressions का उपयोग करके भी मिलान किया जा सकता है:
title: My example rule with a timestamp
detection:
selection:
Timestamp|re: ^2024-06-01T(01|02|03):[0-5][0-9]:[0-5][0-9]$
condition: selection
साथ ही CIDRs:
title: My example rule with IP addresses
detection:
local:
DestinationIp|cidr:
- "127.0.0.0/8"
- "10.0.0.0/8"
- "172.16.0.0/12"
- "192.168.0.0/16"
- "169.254.0.0/16"
- "::1/128" # IPv6 loopback
- "fe80::/10" # IPv6 link-local addresses
- "fc00::/7" # IPv6 private addresses
condition: not local
अधिक जानकारी official Sigma rules documentation में पाई जा सकती है।
यह लाइब्रेरी निम्नलिखित field modifiers का समर्थन करती है:
FieldResolver इंटरफ़ेस मानक Sigma विनिर्देश का विस्तार करता है ताकि सरल key/value जोड़ियों से परे जटिल फ़ील्ड लुकअप परिदृश्यों का समर्थन किया जा सके। यह आपको निम्नलिखित के लिए कस्टम फ़ील्ड रिज़ॉल्यूशन लॉजिक लागू करने की अनुमति देता है:
event.process.user) का उपयोग करके गहराई से नेस्टेड फ़ील्ड तक पहुँचेंprocess.*.user या network[*].ip जैसे फ़ील्ड पैटर्न का समर्थन करेंtype FieldResolver interface {
Resolve(fieldName string, entry *LogEntry) []string
}
Resolve विधि आपके Sigma नियम से एक फ़ील्ड नाम लेती है और सभी मिलान मानों को एक स्ट्रिंग स्लाइस के रूप में लौटाती है। यदि कोई मिलान नहीं मिलता है, तो nil या एक खाली स्लाइस लौटाएँ।
// CustomResolver demonstrates field resolution for structured logs
type CustomResolver struct{}
func (r *CustomResolver) Resolve(fieldName string, entry *sigma.LogEntry) []string {
switch fieldName {
case "process.users":
// Aggregate user fields from multiple sources
var users []string
if user, ok := entry.Fields["Event.Process.User"]; ok {
users = append(users, user)
}
if user, ok := entry.Fields["Event.Login.User"]; ok {
users = append(users, user)
}
if user, ok := entry.Fields["Event.Session.User"]; ok {
users = append(users, user)
}
return users
case "network.internal_ips":
// Extract all IP addresses from network-related fields
var ips []string
for fieldName, value := range entry.Fields {
if strings.Contains(strings.ToLower(fieldName), "ip") {
// Simple IP validation (in real usage, use proper validation)
if strings.Contains(value, ".") {
ips = append(ips, value)
}
}
}
return ips
default:
return nil
}
}
func matches(detection *sigmalite.Detection) bool {
opts := &sigmalite.MatchOptions{
FieldResolver: CustomResolver{},
},
entry := &sigmalite.LogEntry{
Message: string("Message Text"),
Fields: nil, // Using resolver so this can be empty
}
return detection.Matches(entry, opts)
}
फ़ील्ड रिज़ॉल्वर सभी field modifiers के साथ सहजता से काम करते हैं, जिससे आप रेगेक्स पैटर्न, केस-असंवेदनशील मिलान और अन्य परिवर्तनों को रिज़ॉल्व किए गए मानों पर लागू कर सकते हैं।