Skip to content

Commit fe98381

Browse files
committed
tests(ps): Verify process token retrieval from OS
1 parent c5c8f97 commit fe98381

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

pkg/ps/snapshotter_windows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,11 @@ func (s *snapshotter) Find(pid uint32) (bool, *pstypes.PS) {
628628
}
629629

630630
// get process token attributes
631-
var token windows.Token
632-
var tokenUser *windows.Tokenuser
633-
var tokenMandatoryLabel *windows.Tokenmandatorylabel
631+
var (
632+
token windows.Token
633+
tokenUser *windows.Tokenuser
634+
tokenMandatoryLabel *windows.Tokenmandatorylabel
635+
)
634636

635637
err = windows.OpenProcessToken(process, windows.TOKEN_QUERY, &token)
636638
if err != nil {

pkg/ps/snapshotter_windows_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,29 @@ func TestWriteInternalEventsEnrichment(t *testing.T) {
295295
assert.Equal(t, uint32(1), proc.SessionID)
296296
},
297297
},
298+
{"consult process token integrity level from OS",
299+
[]*event.Event{
300+
{
301+
Type: event.CreateProcess,
302+
Params: event.Params{
303+
params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(os.Getpid())},
304+
params.ProcessParentID: {Name: params.ProcessParentID, Type: params.PID, Value: uint32(444)},
305+
params.Exe: {Name: params.Exe, Type: params.UnicodeString, Value: `svchost.exe`},
306+
params.Cmdline: {Name: params.Cmdline, Type: params.UnicodeString, Value: `svchost.exe -k LocalSystemNetworkRestricted -p -s NcbService`},
307+
params.UserSID: {Name: params.UserSID, Type: params.WbemSID, Value: []byte{224, 8, 226, 31, 15, 167, 255, 255, 0, 0, 0, 0, 15, 167, 255, 255, 1, 1, 0, 0, 0, 0, 0, 5, 18, 0, 0, 0}},
308+
params.SessionID: {Name: params.SessionID, Type: params.Uint32, Value: uint32(1)},
309+
params.ProcessFlags: {Name: params.ProcessFlags, Type: params.Flags, Value: uint32(0x00000010)},
310+
},
311+
},
312+
},
313+
NewSnapshotter(hsnap, &config.Config{}),
314+
func(t *testing.T, psnap Snapshotter) {
315+
ok, proc := psnap.Find(uint32(os.Getpid()))
316+
assert.True(t, ok)
317+
assert.Equal(t, "HIGH", proc.TokenIntegrityLevel)
318+
assert.Equal(t, true, proc.IsTokenElevated)
319+
},
320+
},
298321
}
299322

300323
for _, tt := range tests {

0 commit comments

Comments
 (0)