@@ -5,10 +5,15 @@ package envinspection
55import (
66 "context"
77 "fmt"
8+ "os/exec"
9+ "path/filepath"
10+ "strings"
11+
12+ "github.com/murphysecurity/murphysec/infra/logctx"
813 "github.com/murphysecurity/murphysec/model"
14+ "github.com/repeale/fp-go"
915 "golang.org/x/sys/windows"
1016 "golang.org/x/sys/windows/registry"
11- "path/filepath"
1217)
1318
1419type listSubKeysError struct {
@@ -45,15 +50,16 @@ func listSubKeys(ctx context.Context, key registry.Key, path string) ([]string,
4550 return r , nil
4651}
4752
53+ func getWindowsVersion () model.Component {
54+ return model.Component {
55+ CompName : "Windows" ,
56+ CompVersion : fmt .Sprintf ("%d.%d.%d" , windows .RtlGetVersion ().MajorVersion , windows .RtlGetVersion ().MinorVersion , windows .RtlGetVersion ().BuildNumber ),
57+ }
58+ }
59+
4860func listInstalledSoftwareWindows (ctx context.Context ) ([]model.DependencyItem , error ) {
4961 var rKeys = []registry.Key {registry .CURRENT_USER , registry .LOCAL_MACHINE }
5062 var r []model.DependencyItem
51- r = append (r , model.DependencyItem {
52- Component : model.Component {
53- CompName : "Windows" ,
54- CompVersion : fmt .Sprintf ("%d.%d.%d" , windows .RtlGetVersion ().MajorVersion , windows .RtlGetVersion ().MinorVersion , windows .RtlGetVersion ().BuildNumber ),
55- },
56- })
5763 for _ , rKey := range rKeys {
5864 paths , e := listSubKeys (ctx , rKey , "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Uninstall" )
5965 if e != nil {
@@ -80,3 +86,13 @@ func listInstalledSoftwareWindows(ctx context.Context) ([]model.DependencyItem,
8086 }
8187 return r , nil
8288}
89+
90+ func listPendingPatch (ctx context.Context ) []string {
91+ var logger = logctx .Use (ctx ).Sugar ()
92+ data , e := exec .CommandContext (ctx , "wmic" , "qfe" , "get" , "HotFixID" ).Output ()
93+ if e != nil {
94+ logger .Warnf ("wmic qfe get HotFixID failed: %s" , e )
95+ }
96+ var isKB = func (s string ) bool { return strings .HasPrefix (s , "KB" ) }
97+ return fp .Pipe2 (fp .Map (strings .TrimSpace ), fp .Filter (isKB ))(strings .Split (string (data ), "\n " ))
98+ }
0 commit comments