Skip to content

Commit 72f0973

Browse files
committed
feat(event): Parse RegSetValueInternal event parameters
1 parent dcab3fc commit 72f0973

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

pkg/event/event_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func (e *Event) IsLoadImageInternal() bool { return e.Type == LoadImageInte
233233
func (e *Event) IsImageRundown() bool { return e.Type == ImageRundown }
234234
func (e *Event) IsFileOpEnd() bool { return e.Type == FileOpEnd }
235235
func (e *Event) IsRegSetValue() bool { return e.Type == RegSetValue }
236+
func (e *Event) IsRegSetValueInternal() bool { return e.Type == RegSetValueInternal }
236237
func (e *Event) IsProcessRundown() bool { return e.Type == ProcessRundown }
237238
func (e *Event) IsProcessRundownInternal() bool { return e.Type == ProcessRundownInternal }
238239
func (e *Event) IsVirtualAlloc() bool { return e.Type == VirtualAlloc }

pkg/event/metainfo_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func AllWithState() []Type {
241241
s = append(s, CreateProcessInternal)
242242
s = append(s, ProcessRundownInternal)
243243
s = append(s, LoadImageInternal)
244+
s = append(s, RegSetValueInternal)
244245

245246
return s
246247
}

pkg/event/param_windows.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package event
2020

2121
import (
22+
"encoding/binary"
2223
"expvar"
2324
"fmt"
2425
"github.com/rabbitstack/fibratus/pkg/event/params"
@@ -33,7 +34,9 @@ import (
3334
"github.com/rabbitstack/fibratus/pkg/util/signature"
3435
"github.com/rabbitstack/fibratus/pkg/util/va"
3536
"golang.org/x/sys/windows"
37+
"golang.org/x/sys/windows/registry"
3638
"net"
39+
"path/filepath"
3740
"strconv"
3841
"strings"
3942
"time"
@@ -255,7 +258,7 @@ func (e *Event) produceParams(evt *etw.EventRecord) {
255258
}
256259
sid, soffset = evt.ReadSID(offset, true)
257260
name, noffset = evt.ReadAnsiString(soffset)
258-
cmdline, _ = evt.ReadUTF16String(soffset + noffset)
261+
cmdline, _ = evt.ReadUTF16String(noffset)
259262
e.AppendParam(params.ProcessObject, params.Address, kproc)
260263
e.AppendParam(params.ProcessID, params.PID, pid)
261264
e.AppendParam(params.ProcessParentID, params.PID, ppid)
@@ -508,6 +511,34 @@ func (e *Event) produceParams(evt *etw.EventRecord) {
508511
e.AppendParam(params.RegKeyHandle, params.Address, keyHandle)
509512
e.AppendParam(params.RegPath, params.Key, keyName)
510513
e.AppendParam(params.NTStatus, params.Status, status)
514+
case RegSetValueInternal:
515+
keyObject := evt.ReadUint64(0)
516+
status := evt.ReadUint32(8)
517+
valueType := evt.ReadUint32(12)
518+
keyName, koffset := evt.ReadUTF16String(20) // skip data size param (4 bytes)
519+
valueName, voffset := evt.ReadUTF16String(koffset)
520+
capturedSize := evt.ReadUint16(voffset)
521+
capturedData := evt.ReadBytes(2+voffset, capturedSize)
522+
523+
e.AppendParam(params.RegKeyHandle, params.Address, keyObject)
524+
e.AppendParam(params.NTStatus, params.Status, status)
525+
e.AppendParam(params.RegPath, params.Key, filepath.Join(keyName, valueName))
526+
e.AppendEnum(params.RegValueType, valueType, key.RegistryValueTypes)
527+
528+
if len(capturedData) > 0 {
529+
switch valueType {
530+
case registry.SZ, registry.MULTI_SZ, registry.EXPAND_SZ:
531+
e.AppendParam(params.RegData, params.UnicodeString, string(capturedData))
532+
case registry.BINARY:
533+
e.AppendParam(params.RegData, params.Binary, capturedData)
534+
case registry.DWORD:
535+
e.AppendParam(params.RegData, params.Uint32, binary.LittleEndian.Uint32(capturedData))
536+
case registry.DWORD_BIG_ENDIAN:
537+
e.AppendParam(params.RegData, params.Uint32, binary.BigEndian.Uint32(capturedData))
538+
case registry.QWORD:
539+
e.AppendParam(params.RegData, params.Uint64, binary.LittleEndian.Uint64(capturedData))
540+
}
541+
}
511542
case CreateFile:
512543
var (
513544
irp uint64

pkg/event/params/params_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ const (
149149
RegValue = "value"
150150
// RegValueType identifies the parameter that represents registry value type e.g (DWORD, BINARY)
151151
RegValueType = "value_type"
152+
// RegData identifies the parameter that stores the captured registry data
153+
RegData = "data"
152154

153155
// ImageBase identifies the parameter name for the base address of the process in which the image is loaded.
154156
ImageBase = "base_address"

pkg/event/types_windows.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ var (
6767
ThreadpoolGUID = windows.GUID{Data1: 0xc861d0e2, Data2: 0xa2c1, Data3: 0x4d36, Data4: [8]byte{0x9f, 0x9c, 0x97, 0x0b, 0xab, 0x94, 0x3a, 0x12}}
6868
// ProcessKernelEventGUID represents the Process Kernel event GUID
6969
ProcessKernelEventGUID = windows.GUID{Data1: 0x22fb2cd6, Data2: 0x0e7b, Data3: 0x422b, Data4: [8]byte{0xa0, 0xc7, 0x2f, 0xad, 0x1f, 0xd0, 0xe7, 0x16}}
70+
// RegistryKernelEventGUID represents the Registry Kernel event GUID
71+
RegistryKernelEventGUID = windows.GUID{Data1: 0x70eb4f03, Data2: 0xc1de, Data3: 0x4f73, Data4: [8]byte{0xa0, 0x51, 0x33, 0xd1, 0x3d, 0x54, 0x13, 0xbd}}
7072
)
7173

7274
var (
@@ -149,6 +151,10 @@ var (
149151
RegDeleteKCB = pack(RegistryEventGUID, 23)
150152
// RegKCBRundown enumerates the registry keys open at the start of the kernel session.
151153
RegKCBRundown = pack(RegistryEventGUID, 25)
154+
// RegSetValueInternal is the internal event that is used to
155+
// enrich the corresponding public RegSetValue event with
156+
// extra attributes
157+
RegSetValueInternal = pack(RegistryKernelEventGUID, 36)
152158

153159
// UnloadImage represents unload image kernel events
154160
UnloadImage = pack(ImageEventGUID, 2)
@@ -309,7 +315,7 @@ func (t Type) String() string {
309315
return "RegQueryValue"
310316
case RegCreateKCB:
311317
return "RegCreateKCB"
312-
case RegSetValue:
318+
case RegSetValue, RegSetValueInternal:
313319
return "RegSetValue"
314320
case LoadImage, LoadImageInternal:
315321
return "LoadImage"
@@ -367,7 +373,7 @@ func (t Type) Category() Category {
367373
FileRundown, FileOpEnd, ReleaseFile, MapViewFile, UnmapViewFile, MapFileRundown:
368374
return File
369375
case RegCreateKey, RegDeleteKey, RegOpenKey, RegCloseKey, RegQueryKey, RegQueryValue, RegSetValue, RegDeleteValue,
370-
RegKCBRundown, RegDeleteKCB, RegCreateKCB:
376+
RegKCBRundown, RegDeleteKCB, RegCreateKCB, RegSetValueInternal:
371377
return Registry
372378
case AcceptTCPv4, AcceptTCPv6,
373379
ConnectTCPv4, ConnectTCPv6,
@@ -527,7 +533,8 @@ func (t Type) OnlyState() bool {
527533
ReleaseFile,
528534
MapFileRundown,
529535
RegCreateKCB,
530-
RegDeleteKCB:
536+
RegDeleteKCB,
537+
RegSetValueInternal:
531538
return true
532539
default:
533540
return false
@@ -600,7 +607,7 @@ func (t Type) ID() uint {
600607
// Source designates the provenance of this event type.
601608
func (t Type) Source() Source {
602609
switch t.GUID() {
603-
case AuditAPIEventGUID, DNSEventGUID, ThreadpoolGUID, ProcessKernelEventGUID:
610+
case AuditAPIEventGUID, DNSEventGUID, ThreadpoolGUID, ProcessKernelEventGUID, RegistryKernelEventGUID:
604611
return SecurityTelemetryLogger
605612
default:
606613
return SystemLogger

0 commit comments

Comments
 (0)