diff --git a/providers/os/resources/packages/windows_packages.go b/providers/os/resources/packages/windows_packages.go index 0d0891e737..f727d4568c 100644 --- a/providers/os/resources/packages/windows_packages.go +++ b/providers/os/resources/packages/windows_packages.go @@ -256,6 +256,15 @@ func (w *WinPkgManager) getInstalledApps() ([]Package, error) { if err != nil { return nil, fmt.Errorf("could not read app package list") } + + if cmd.ExitStatus != 0 { + stderr, err := io.ReadAll(cmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve installed apps: " + string(stderr)) + } + return ParseWindowsAppPackages(cmd.Stdout) } diff --git a/providers/os/resources/port.go b/providers/os/resources/port.go index c7b053630b..87af6a06f7 100644 --- a/providers/os/resources/port.go +++ b/providers/os/resources/port.go @@ -451,6 +451,14 @@ func (p *mqlPorts) listWindows() ([]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve network connections: " + string(stderr)) + } + list, err := p.parseWindowsPorts(executedCmd.Stdout, processes) if err != nil { return nil, err diff --git a/providers/os/resources/smbios/win.go b/providers/os/resources/smbios/win.go index 0d192a5fbf..f70292755f 100644 --- a/providers/os/resources/smbios/win.go +++ b/providers/os/resources/smbios/win.go @@ -5,6 +5,7 @@ package smbios import ( "encoding/json" + "errors" "io" "strconv" @@ -139,6 +140,14 @@ func (s *WindowsSmbiosManager) Info() (*SmBiosInfo, error) { return nil, err } + if c.ExitStatus != 0 { + stderr, err := io.ReadAll(c.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve smbios info: " + string(stderr)) + } + winBios, err := ParseWindowsSmbiosInfo(c.Stdout) if err != nil { return nil, err diff --git a/providers/os/resources/updates/win_updates.go b/providers/os/resources/updates/win_updates.go index 33e3c3f4bb..400607fd21 100644 --- a/providers/os/resources/updates/win_updates.go +++ b/providers/os/resources/updates/win_updates.go @@ -5,6 +5,7 @@ package updates import ( "encoding/json" + "errors" "fmt" "io" @@ -66,6 +67,13 @@ func (um *WindowsUpdateManager) List() ([]OperatingSystemUpdate, error) { if err != nil { return nil, fmt.Errorf("could not read package list") } + if c.ExitStatus != 0 { + stderr, err := io.ReadAll(c.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve updates: " + string(stderr)) + } return ParseWindowsUpdates(c.Stdout) } diff --git a/providers/os/resources/windows.go b/providers/os/resources/windows.go index 8cc67be957..061510718a 100644 --- a/providers/os/resources/windows.go +++ b/providers/os/resources/windows.go @@ -109,6 +109,14 @@ func (w *mqlWindows) hotfixes() ([]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve hotfixes: " + string(stderr)) + } + hotfixes, err := packages.ParseWindowsHotfixes(executedCmd.Stdout) if err != nil { return nil, err @@ -185,6 +193,14 @@ func (w *mqlWindows) features() ([]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve features: " + string(stderr)) + } + features, err := windows.ParseWindowsFeatures(executedCmd.Stdout) if err != nil { return nil, err @@ -263,6 +279,14 @@ func (w *mqlWindows) serverFeatures() ([]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve features: " + string(stderr)) + } + features, err := windows.ParseWindowsFeatures(executedCmd.Stdout) if err != nil { return nil, err @@ -341,6 +365,14 @@ func (w *mqlWindows) optionalFeatures() ([]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve optional features: " + string(stderr)) + } + features, err := windows.ParseWindowsOptionalFeatures(executedCmd.Stdout) if err != nil { return nil, err diff --git a/providers/os/resources/windows/bitlocker.go b/providers/os/resources/windows/bitlocker.go index d73f0dd77e..fcd113a82e 100644 --- a/providers/os/resources/windows/bitlocker.go +++ b/providers/os/resources/windows/bitlocker.go @@ -5,6 +5,7 @@ package windows import ( "encoding/json" + "errors" "io" "go.mondoo.com/cnquery/v11/providers/os/connection/shared" @@ -146,7 +147,13 @@ func GetBitLockerVolumes(p shared.Connection) ([]bitlockerVolumeStatus, error) { if err != nil { return nil, err } - + if c.ExitStatus != 0 { + stderr, err := io.ReadAll(c.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve bitlocker info: " + string(stderr)) + } return ParseWindowsBitlockerStatus(c.Stdout) } diff --git a/providers/os/resources/windows/security_health.go b/providers/os/resources/windows/security_health.go index 20fb5d2b4e..3be68751c9 100644 --- a/providers/os/resources/windows/security_health.go +++ b/providers/os/resources/windows/security_health.go @@ -5,6 +5,7 @@ package windows import ( "encoding/json" + "errors" "io" "go.mondoo.com/cnquery/v11/providers/os/connection/shared" @@ -89,6 +90,14 @@ func GetSecurityProviderHealth(p shared.Connection) (*windowsSecurityHealth, err return nil, err } + if c.ExitStatus != 0 { + stderr, err := io.ReadAll(c.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve security health: " + string(stderr)) + } + return ParseSecurityProviderHealth(c.Stdout) } diff --git a/providers/os/resources/windows/security_products.go b/providers/os/resources/windows/security_products.go index adaea4e24e..df7cdd4ce4 100644 --- a/providers/os/resources/windows/security_products.go +++ b/providers/os/resources/windows/security_products.go @@ -5,6 +5,7 @@ package windows import ( "encoding/json" + "errors" "io" "time" @@ -157,6 +158,14 @@ func GetSecurityProducts(p shared.Connection) ([]securityProduct, error) { return nil, err } + if c.ExitStatus != 0 { + stderr, err := io.ReadAll(c.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve security products: " + string(stderr)) + } + return ParseWindowsSecurityProducts(c.Stdout) } diff --git a/providers/os/resources/windows_firewall.go b/providers/os/resources/windows_firewall.go index 4dd641f04d..8e556c238e 100644 --- a/providers/os/resources/windows_firewall.go +++ b/providers/os/resources/windows_firewall.go @@ -4,6 +4,9 @@ package resources import ( + "errors" + "io" + "go.mondoo.com/cnquery/v11/llx" "go.mondoo.com/cnquery/v11/providers-sdk/v1/util/convert" "go.mondoo.com/cnquery/v11/providers/os/connection/shared" @@ -29,6 +32,14 @@ func (w *mqlWindowsFirewall) settings() (map[string]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve computer info: " + string(stderr)) + } + fwSettings, err := windows.ParseWindowsFirewallSettings(executedCmd.Stdout) if err != nil { return nil, err @@ -46,6 +57,14 @@ func (w *mqlWindowsFirewall) profiles() ([]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve firewall profiles: " + string(stderr)) + } + fwProfiles, err := windows.ParseWindowsFirewallProfiles(executedCmd.Stdout) if err != nil { return nil, err @@ -95,6 +114,14 @@ func (w *mqlWindowsFirewall) rules() ([]interface{}, error) { return nil, err } + if executedCmd.ExitStatus != 0 { + stderr, err := io.ReadAll(executedCmd.Stderr) + if err != nil { + return nil, err + } + return nil, errors.New("failed to retrieve firewall rules: " + string(stderr)) + } + fwRules, err := windows.ParseWindowsFirewallRules(executedCmd.Stdout) if err != nil { return nil, err