Skip to content

Commit dfc2761

Browse files
committed
feat: SCA-6 windows patch scan
1 parent 3f3a62d commit dfc2761

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

api/sbom_commit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"bufio"
55
"context"
66
"encoding/json"
7+
"os"
8+
79
"github.com/murphysecurity/murphysec/env"
810
"github.com/murphysecurity/murphysec/model"
911
"github.com/murphysecurity/murphysec/scanerr"
1012
"github.com/murphysecurity/murphysec/utils"
1113
"github.com/murphysecurity/murphysec/utils/must"
12-
"os"
1314
)
1415

1516
func SubmitSBOM(ctx context.Context, client *Client, subtaskId string, modules []model.Module, codeFragments []model.ComponentCodeFragment) error {

envinspection/inspection.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/iseki0/osname"
8-
"github.com/murphysecurity/murphysec/infra/logctx"
9-
"github.com/murphysecurity/murphysec/model"
10-
"github.com/murphysecurity/murphysec/scanerr"
117
"io/fs"
128
"os/exec"
139
"reflect"
1410
"runtime"
1511
"strings"
12+
13+
"github.com/iseki0/osname"
14+
"github.com/murphysecurity/murphysec/infra/logctx"
15+
"github.com/murphysecurity/murphysec/model"
16+
"github.com/murphysecurity/murphysec/scanerr"
1617
)
1718

1819
func InspectEnv(ctx context.Context, scanProcess bool) error {
@@ -25,6 +26,15 @@ func InspectEnv(ctx context.Context, scanProcess bool) error {
2526
var osn, _ = osname.OsName()
2627
if runtime.GOOS == "linux" {
2728
packageManager = getOsInfo()
29+
} else if runtime.GOOS == "windows" {
30+
version := getWindowsVersion()
31+
var m = model.Module{
32+
ModuleName: "5ec239b6-715c-4d36-a3b8-a5a629b898a9",
33+
Dependencies: []model.DependencyItem{{Component: version}},
34+
Patches: listPendingPatch(ctx),
35+
ModulePath: "/Windows",
36+
}
37+
task.Modules = append(task.Modules, m)
2838
}
2939
if s, ok := processByRule(osn); ok {
3040
packageManager = s

envinspection/installed_software_all.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ package envinspection
44

55
import (
66
"context"
7+
78
"github.com/murphysecurity/murphysec/model"
89
)
910

1011
func listInstalledSoftwareWindows(ctx context.Context) ([]model.DependencyItem, error) {
1112
return nil, nil
1213
}
14+
func listPendingPatch(ctx context.Context) []string {
15+
return nil
16+
}
17+
func getWindowsVersion() model.Component {
18+
return model.Component{}
19+
}

envinspection/installed_software_windows.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ package envinspection
55
import (
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

1419
type 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+
4860
func 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+
}

model/module.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Module struct {
1212
MD5Hashes []MD5Hash `json:"md5_hashes,omitempty"` // MD5哈希列表
1313
SHA1Hashes []SHA1Hash `json:"sha1_hashes,omitempty"`
1414
SHA256Hashes []SHA256Hash `json:"sha256_hashes,omitempty"` // SHA256哈希列表
15+
Patches []string `json:"patches,omitempty"`
1516
}
1617

1718
func (m Module) String() string {

0 commit comments

Comments
 (0)