Service crashes on Windows Server 2016: "panic: sub-authority index out of range" in RidToString

Aperta Adatta ai principianti
#761 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Inizia in pkg/sys/rid.go a RidToString: aggiungi la guardia per SubAuthorityCount zero/SID non valido che restituisce UNKNOWN, con un unit test per un SID senza subauthority. Segui lo stack in pkg/ps/snapshotter_windows.go (newProcState) e pkg/event/param_windows.go per vedere come viene decodificato ProcessTokenIntegrityLevel; indaga la versione dell'evento Kernel-Process su 14393 solo se correggi la causa radice. Fatto significa nessun panic e livello di integrità UNKNOWN su Server 2016.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type: bug

Describe the bug

On Windows Server 2016 (build 14393), the Fibratus 3.1.1 service crashes a few seconds after start, as soon as the first process events are processed. The service control manager restarts it and it crashes again each time. The same version runs normally on Windows 10 22H2.

level=info msg=starting [Security Telemetry Logger] trace processing source=etw/source.go:271
level=info msg=starting [NT Kernel Logger] trace processing source=etw/source.go:271
panic: sub-authority index out of range

goroutine 29 [running]:
golang.org/x/sys/windows.(*SID).SubAuthority(..., 0xff)
	golang.org/x/[email protected]/windows/security_windows.go:272
github.com/rabbitstack/fibratus/pkg/sys.RidToString(...)
	pkg/sys/rid.go:63
github.com/rabbitstack/fibratus/pkg/event.Param.String(...)
	pkg/event/param_windows.go:80
github.com/rabbitstack/fibratus/pkg/event.(*Event).GetParamAsString(...)
	pkg/event/event.go:349
github.com/rabbitstack/fibratus/pkg/ps.(*snapshotter).newProcState(...)
	pkg/ps/snapshotter_windows.go:385
github.com/rabbitstack/fibratus/pkg/ps.(*snapshotter).Write(...)
	pkg/ps/snapshotter_windows.go:161
github.com/rabbitstack/fibratus/internal/etw/processors.psProcessor.ProcessEvent(...)
	internal/etw/processors/ps_windows.go:51
github.com/rabbitstack/fibratus/internal/etw/processors.(*Chain).ProcessEvent(...)
	internal/etw/processors/chain.go:46
github.com/rabbitstack/fibratus/internal/etw.(*Consumer).ProcessEvent(...)
	internal/etw/consumer.go:110
github.com/rabbitstack/fibratus/internal/etw.(*Trace).processEventCallback(...)
	internal/etw/trace.go:414

newProcState reads ProcessTokenIntegrityLevel from the Microsoft-Windows-Kernel-Process process events (CreateProcessInternal / ProcessRundownInternal). On build 14393 the SID in that parameter has a SubAuthorityCount() of 0, so in RidToString

switch sid.SubAuthority(uint32(sid.SubAuthorityCount() - 1)) {

SubAuthorityCount() - 1 wraps around to 255 (0xff in the trace) and SubAuthority panics. A likely cause is that the event payload layout on this build differs from the one the parser expects, so the SID is read from the wrong offset.

How to reproduce it

  1. Install Fibratus 3.1.1 (MSI) on Windows Server 2016 Standard, build 14393.
  2. Start the fibratus service, or run fibratus run.
  3. The service terminates within seconds with the panic above (System event log: Service Control Manager 7031, "The Fibratus service terminated unexpectedly").

Reproduced on two separate Server 2016 VMs.

Expected behavior

Fibratus keeps running. If the integrity-level SID can't be decoded, the integrity level should be reported as UNKNOWN (as RidToString already does for a nil SID) instead of crashing the service. A minimal guard:

func RidToString(sid *windows.SID) string {
	if sid == nil || !sid.IsValid() || sid.SubAuthorityCount() == 0 {
		return "UNKNOWN"
	}
	switch sid.SubAuthority(uint32(sid.SubAuthorityCount() - 1)) {

It may also be worth checking the Kernel-Process event version on 14393 so the SID is decoded correctly there.

Screenshots

N/A

Environment

  • Fibratus version: 3.1.1 (MSI). The same code path is present in 3.0.0, 3.1.0 and on master (pkg/sys/rid.go). 2.4.0 does not read the integrity level and is not affected. The code was introduced with "feat(process): Enrich processes with integrity level and token elevation info".
  • Configuration: the 3.1.1 default configuration, with the eventsource section unchanged. Only the rule paths and the output (HTTP instead of console) differ. The crash happens in the process snapshotter, before any rule is evaluated.
  • OS: Windows Server 2016 Standard, version 10.0.14393, x64 (VMware VMs). Not affected: Windows 10 22H2 (Pro and Education).

Additional context

Happy to test a build with a fix on Server 2016.

Lingua principale
Go
Stelle
2.6k
Fork
222
Merge medio
16h 23m
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rabbitstack/fibratus

Tutte le issue di rabbitstack/fibratus

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.