@@ -22,26 +22,64 @@ import (
2222 "github.com/rabbitstack/fibratus/pkg/kevent"
2323 "github.com/rabbitstack/fibratus/pkg/kevent/kparams"
2424 "github.com/rabbitstack/fibratus/pkg/ps"
25+ "github.com/rabbitstack/fibratus/pkg/util/signature"
2526)
2627
2728type imageProcessor struct {
28- psnap ps.Snapshotter
29+ psnap ps.Snapshotter
30+ signatures map [uint32 ]* signature.Signature
2931}
3032
3133func newImageProcessor (psnap ps.Snapshotter ) Processor {
32- return & imageProcessor {psnap : psnap }
34+ return & imageProcessor {psnap : psnap , signatures : make ( map [ uint32 ] * signature. Signature ) }
3335}
3436
3537func (imageProcessor ) Name () ProcessorType { return Image }
3638
37- func (i * imageProcessor ) ProcessEvent (e * kevent.Kevent ) (* kevent.Kevent , bool , error ) {
39+ func (m * imageProcessor ) ProcessEvent (e * kevent.Kevent ) (* kevent.Kevent , bool , error ) {
40+ if e .IsLoadImage () {
41+ // image signature parameters exhibit unreliable behaviour. Allegedly,
42+ // signature verification is not performed in certain circumstances
43+ // which leads to the core system DLL or binaries to be reported with
44+ // signature unchecked level.
45+ // To mitigate this situation, we have to manually check/verify the signature
46+ // for all unchecked signature levels
47+ level := e .Kparams .MustGetUint32 (kparams .ImageSignatureLevel )
48+ if level == signature .UncheckedLevel {
49+ m .checkSignature (e )
50+ }
51+ }
3852 if e .IsUnloadImage () {
39- return e , false , i .psnap .RemoveModule (e .Kparams .MustGetPid (), e .GetParamAsString (kparams .ImageFilename ))
53+ return e , false , m .psnap .RemoveModule (e .Kparams .MustGetPid (), e .GetParamAsString (kparams .ImageFilename ))
4054 }
4155 if e .IsLoadImage () {
42- return e , false , i .psnap .AddModule (e )
56+ return e , false , m .psnap .AddModule (e )
4357 }
4458 return e , true , nil
4559}
4660
4761func (imageProcessor ) Close () {}
62+
63+ // checkSignature consults the signature cache and if the signature
64+ // already exists for a particular image checksum, signature checking
65+ // is skipped. On the contrary, the signature verification is performed
66+ // and the cache is updated accordingly.
67+ func (m * imageProcessor ) checkSignature (e * kevent.Kevent ) {
68+ checksum := e .Kparams .MustGetUint32 (kparams .ImageCheckSum )
69+ sign , ok := m .signatures [checksum ]
70+ if ! ok {
71+ filename := e .GetParamAsString (kparams .FileName )
72+ sign = signature .Check (filename )
73+ if sign == nil {
74+ return
75+ }
76+ if sign .IsSigned () {
77+ sign .Verify ()
78+ }
79+ m .signatures [checksum ] = sign
80+ }
81+ if sign != nil {
82+ _ = e .Kparams .SetValue (kparams .ImageSignatureType , sign .Type )
83+ _ = e .Kparams .SetValue (kparams .ImageSignatureLevel , sign .Level )
84+ }
85+ }
0 commit comments