Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(filter): Introduce TEB filter field #334

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/filter/accessor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ func (t *threadAccessor) Get(f fields.Field, kevt *kevent.Kevent) (kparams.Value
return kevt.GetParamAsString(kparams.StartAddress), nil
case fields.ThreadPID:
return kevt.Kparams.GetUint32(kparams.ProcessID)
case fields.ThreadTEB:
return kevt.GetParamAsString(kparams.TEB), nil
case fields.ThreadAccessMask:
if kevt.Type != ktypes.OpenThread {
return nil, nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/filter/fields/fields_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ const (
ThreadStartAddress Field = "thread.start_address"
// ThreadPID is the process identifier where the thread is created
ThreadPID Field = "thread.pid"
// ThreadTEB is the thread environment block base address
ThreadTEB Field = "thread.teb_address"
// ThreadAccessMask represents the thread access rights field
ThreadAccessMask Field = "thread.access.mask"
// ThreadAccessMaskNames represents the thread access rights list field
Expand Down Expand Up @@ -701,6 +703,7 @@ var fields = map[Field]FieldInfo{
ThreadEntrypoint: {ThreadEntrypoint, "starting address of the function to be executed by the thread", kparams.Address, []string{"thread.entrypoint = '7efe0000'"}, &Deprecation{Since: "2.3.0", Fields: []Field{ThreadStartAddress}}},
ThreadStartAddress: {ThreadStartAddress, "thread start address", kparams.Address, []string{"thread.start_address = '7efe0000'"}, nil},
ThreadPID: {ThreadPID, "the process identifier where the thread is created", kparams.Uint32, []string{"kevt.pid != thread.pid"}, nil},
ThreadTEB: {ThreadTEB, "the base address of the thread environment block", kparams.Address, []string{"thread.teb_address = '8f30893000'"}, nil},
ThreadAccessMask: {ThreadAccessMask, "thread desired access rights", kparams.AnsiString, []string{"thread.access.mask = '0x1fffff'"}, nil},
ThreadAccessMaskNames: {ThreadAccessMaskNames, "thread desired access rights as a string list", kparams.Slice, []string{"thread.access.mask.names in ('IMPERSONATE')"}, nil},
ThreadAccessStatus: {ThreadAccessStatus, "thread access status", kparams.UnicodeString, []string{"thread.access.status = 'success'"}, nil},
Expand Down
2 changes: 2 additions & 0 deletions pkg/filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func TestThreadFilter(t *testing.T) {
kparams.ThreadID: {Name: kparams.ThreadID, Type: kparams.TID, Value: uint32(3453)},
kparams.BasePrio: {Name: kparams.BasePrio, Type: kparams.Uint8, Value: uint8(13)},
kparams.StartAddress: {Name: kparams.StartAddress, Type: kparams.Address, Value: uint64(140729524944768)},
kparams.TEB: {Name: kparams.TEB, Type: kparams.Address, Value: uint64(614994620416)},
kparams.IOPrio: {Name: kparams.IOPrio, Type: kparams.Uint8, Value: uint8(2)},
kparams.KstackBase: {Name: kparams.KstackBase, Type: kparams.Address, Value: uint64(18446677035730165760)},
kparams.KstackLimit: {Name: kparams.KstackLimit, Type: kparams.Address, Value: uint64(18446677035730137088)},
Expand Down Expand Up @@ -343,6 +344,7 @@ func TestThreadFilter(t *testing.T) {
{`thread.kstack.base = 'ffffc307810d6000'`, true},
{`thread.kstack.limit = 'ffffc307810cf000'`, true},
{`thread.start_address = '7ffe2557ff80'`, true},
{`thread.teb_address = '8f30893000'`, true},
{`thread.callstack.summary = 'KERNELBASE.dll|KERNEL32.DLL|java.dll|unbacked'`, true},
{`thread.callstack.detail icontains 'C:\\WINDOWS\\System32\\KERNELBASE.dll!CreateProcessW+0x66'`, true},
{`thread.callstack.modules in ('C:\\WINDOWS\\System32\\KERNELBASE.dll', 'C:\\Program Files\\JetBrains\\GoLand 2021.2.3\\jbr\\bin\\java.dll')`, true},
Expand Down
3 changes: 3 additions & 0 deletions pkg/kevent/kparam_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (e *Kevent) produceParams(evt *etw.EventRecord) {
kstack, klimit uint64
ustack, ulimit uint64
startAddress uint64
teb uint64
basePrio uint8
pagePrio uint8
ioPrio uint8
Expand All @@ -295,6 +296,7 @@ func (e *Kevent) produceParams(evt *etw.EventRecord) {
ustack = evt.ReadUint64(24)
ulimit = evt.ReadUint64(32)
startAddress = evt.ReadUint64(48)
teb = evt.ReadUint64(56)
}
if evt.Version() >= 3 {
basePrio = evt.ReadByte(69)
Expand All @@ -308,6 +310,7 @@ func (e *Kevent) produceParams(evt *etw.EventRecord) {
e.AppendParam(kparams.UstackBase, kparams.Address, ustack)
e.AppendParam(kparams.UstackLimit, kparams.Address, ulimit)
e.AppendParam(kparams.StartAddress, kparams.Address, startAddress)
e.AppendParam(kparams.TEB, kparams.Address, teb)
e.AppendParam(kparams.BasePrio, kparams.Uint8, basePrio)
e.AppendParam(kparams.PagePrio, kparams.Uint8, pagePrio)
e.AppendParam(kparams.IOPrio, kparams.Uint8, ioPrio)
Expand Down
2 changes: 2 additions & 0 deletions pkg/kevent/kparams/fields_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const (
UstackLimit = "ustack_limit"
// StartAddress field is the thread start address.
StartAddress = "start_address"
// TEB field is the address of the Thread Environment Block (TEB)
TEB = "teb"

// FileObject determines the field name for the file object pointer.
FileObject = "file_object"
Expand Down
Loading