aboutsummaryrefslogtreecommitdiff
path: root/pkg/exec/scmr
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/exec/scmr')
-rw-r--r--pkg/exec/scmr/exec.go140
-rw-r--r--pkg/exec/scmr/module.go4
-rw-r--r--pkg/exec/scmr/scmr.go68
3 files changed, 107 insertions, 105 deletions
diff --git a/pkg/exec/scmr/exec.go b/pkg/exec/scmr/exec.go
index b3c1531..c2702a3 100644
--- a/pkg/exec/scmr/exec.go
+++ b/pkg/exec/scmr/exec.go
@@ -4,11 +4,11 @@ import (
"context"
"errors"
"fmt"
- "github.com/bryanmcnulty/adauth"
- "github.com/rs/zerolog"
"github.com/FalconOpsLLC/goexec/pkg/client/dcerpc"
"github.com/FalconOpsLLC/goexec/pkg/exec"
"github.com/FalconOpsLLC/goexec/pkg/windows"
+ "github.com/bryanmcnulty/adauth"
+ "github.com/rs/zerolog"
)
const (
@@ -20,94 +20,94 @@ const (
ServiceAllAccess uint32 = ServiceCreateAccess | ServiceModifyAccess
)
-func (executor *Executor) createClients(ctx context.Context) (cleanup func(cCtx context.Context), err error) {
+func (mod *Module) createClients(ctx context.Context) (cleanup func(cCtx context.Context), err error) {
cleanup = func(context.Context) {
- if executor.dce != nil {
- executor.log.Debug().Msg("Cleaning up clients")
- if err := executor.dce.Close(ctx); err != nil {
- executor.log.Error().Err(err).Msg("Failed to destroy DCE connection")
+ if mod.dce != nil {
+ mod.log.Debug().Msg("Cleaning up clients")
+ if err := mod.dce.Close(ctx); err != nil {
+ mod.log.Error().Err(err).Msg("Failed to destroy DCE connection")
}
}
}
cleanup(ctx)
- executor.dce = dcerpc.NewDCEClient(ctx, false, &dcerpc.SmbConfig{Port: 445})
+ mod.dce = dcerpc.NewDCEClient(ctx, false, &dcerpc.SmbConfig{Port: 445})
cleanup = func(context.Context) {}
- if err = executor.dce.Connect(ctx, executor.creds, executor.target); err != nil {
+ if err = mod.dce.Connect(ctx, mod.creds, mod.target); err != nil {
return nil, fmt.Errorf("connection to DCERPC failed: %w", err)
}
- executor.ctl, err = executor.dce.OpenSvcctl(ctx)
+ mod.ctl, err = mod.dce.OpenSvcctl(ctx)
return
}
-func (executor *Executor) Exec(ctx context.Context, creds *adauth.Credential, target *adauth.Target, ecfg *exec.ExecutionConfig) (err error) {
+func (mod *Module) Exec(ctx context.Context, creds *adauth.Credential, target *adauth.Target, ecfg *exec.ExecutionConfig) (err error) {
vctx := context.WithoutCancel(ctx)
- executor.log = zerolog.Ctx(ctx).With().
+ mod.log = zerolog.Ctx(ctx).With().
Str("module", "scmr").
Str("method", ecfg.ExecutionMethod).Logger()
- executor.creds = creds
- executor.target = target
+ mod.creds = creds
+ mod.target = target
if ecfg.ExecutionMethod == MethodCreate {
if cfg, ok := ecfg.ExecutionMethodConfig.(MethodCreateConfig); !ok || cfg.ServiceName == "" {
return errors.New("invalid configuration")
} else {
- if cleanup, err := executor.createClients(ctx); err != nil {
+ if cleanup, err := mod.createClients(ctx); err != nil {
return fmt.Errorf("failed to create client: %w", err)
} else {
- executor.log.Debug().Msg("Created clients")
+ mod.log.Debug().Msg("Created clients")
defer cleanup(ctx)
}
svc := &service{
createConfig: &cfg,
name: cfg.ServiceName,
}
- scm, code, err := executor.openSCM(ctx)
+ scm, code, err := mod.openSCM(ctx)
if err != nil {
return fmt.Errorf("failed to open SCM with code %d: %w", code, err)
}
- executor.log.Debug().Msg("Opened handle to SCM")
- code, err = executor.createService(ctx, scm, svc, ecfg)
+ mod.log.Debug().Msg("Opened handle to SCM")
+ code, err = mod.createService(ctx, scm, svc, ecfg)
if err != nil {
return fmt.Errorf("failed to create service with code %d: %w", code, err)
}
- executor.log.Info().Str("service", svc.name).Msg("Service created")
+ mod.log.Info().Str("service", svc.name).Msg("Service created")
// From here on out, make sure the service is properly deleted, even if the connection drops or something fails.
if !cfg.NoDelete {
defer func() {
// TODO: stop service?
- if code, err = executor.deleteService(ctx, scm, svc); err != nil {
- executor.log.Error().Err(err).Msg("Failed to delete service") // TODO
+ if code, err = mod.deleteService(ctx, scm, svc); err != nil {
+ mod.log.Error().Err(err).Msg("Failed to delete service") // TODO
}
- executor.log.Info().Str("service", svc.name).Msg("Service deleted successfully")
+ mod.log.Info().Str("service", svc.name).Msg("Service deleted successfully")
}()
}
- if code, err = executor.startService(ctx, scm, svc); err != nil {
+ if code, err = mod.startService(ctx, scm, svc); err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
// In case of timeout or cancel, try to reestablish a connection to restore the service
- executor.log.Info().Msg("Service start timeout/cancelled. Execution likely successful")
- executor.log.Info().Msg("Reconnecting for cleanup procedure")
+ mod.log.Info().Msg("Service start timeout/cancelled. Execution likely successful")
+ mod.log.Info().Msg("Reconnecting for cleanup procedure")
ctx = vctx
- if _, err = executor.createClients(ctx); err != nil {
- executor.log.Error().Err(err).Msg("Reconnect failed")
+ if _, err = mod.createClients(ctx); err != nil {
+ mod.log.Error().Err(err).Msg("Reconnect failed")
- } else if scm, code, err = executor.openSCM(ctx); err != nil {
- executor.log.Error().Err(err).Msg("Failed to reopen SCM")
+ } else if scm, code, err = mod.openSCM(ctx); err != nil {
+ mod.log.Error().Err(err).Msg("Failed to reopen SCM")
- } else if svc.handle, code, err = executor.openService(ctx, scm, svc.name); err != nil {
- executor.log.Error().Str("service", svc.name).Err(err).Msg("Failed to reopen service handle")
+ } else if svc.handle, code, err = mod.openService(ctx, scm, svc.name); err != nil {
+ mod.log.Error().Str("service", svc.name).Err(err).Msg("Failed to reopen service handle")
} else {
- executor.log.Debug().Str("service", svc.name).Msg("Reconnection successful")
+ mod.log.Debug().Str("service", svc.name).Msg("Reconnection successful")
}
} else {
- executor.log.Error().Err(err).Msg("Failed to start service")
+ mod.log.Error().Err(err).Msg("Failed to start service")
}
} else {
- executor.log.Info().Str("service", svc.name).Msg("Execution successful")
+ mod.log.Info().Str("service", svc.name).Msg("Execution successful")
}
}
} else if ecfg.ExecutionMethod == MethodModify {
@@ -123,102 +123,104 @@ func (executor *Executor) Exec(ctx context.Context, creds *adauth.Credential, ta
}
// Initialize protocol clients
- if cleanup, err := executor.createClients(ctx); err != nil {
+ if cleanup, err := mod.createClients(ctx); err != nil {
return fmt.Errorf("failed to create client: %w", err)
} else {
- executor.log.Debug().Msg("Created clients")
+ mod.log.Debug().Msg("Created clients")
defer cleanup(ctx)
}
svc := &service{modifyConfig: &cfg, name: cfg.ServiceName}
// Open SCM handle
- scm, code, err := executor.openSCM(ctx)
+ scm, code, err := mod.openSCM(ctx)
if err != nil {
return fmt.Errorf("failed to create service with code %d: %w", code, err)
}
- executor.log.Debug().Msg("Opened handle to SCM")
+ mod.log.Debug().Msg("Opened handle to SCM")
// Open service handle
- if svc.handle, code, err = executor.openService(ctx, scm, svc.name); err != nil {
+ if svc.handle, code, err = mod.openService(ctx, scm, svc.name); err != nil {
return fmt.Errorf("failed to open service with code %d: %w", code, err)
}
- executor.log.Debug().Str("service", svc.name).Msg("Opened service")
+ mod.log.Debug().Str("service", svc.name).Msg("Opened service")
// Stop service before editing
if !cfg.NoStart {
- if code, err = executor.stopService(ctx, scm, svc); err != nil {
- executor.log.Warn().Err(err).Msg("Failed to stop existing service")
+ if code, err = mod.stopService(ctx, scm, svc); err != nil {
+ mod.log.Warn().Err(err).Msg("Failed to stop existing service")
} else if code == windows.ERROR_SERVICE_NOT_ACTIVE {
- executor.log.Debug().Str("service", svc.name).Msg("Service is not running")
+ mod.log.Debug().Str("service", svc.name).Msg("Service is not running")
} else {
- executor.log.Info().Str("service", svc.name).Msg("Stopped existing service")
+ mod.log.Info().Str("service", svc.name).Msg("Stopped existing service")
defer func() {
- if code, err = executor.startService(ctx, scm, svc); err != nil {
- executor.log.Error().Err(err).Msg("Failed to restore service state to running")
+ if code, err = mod.startService(ctx, scm, svc); err != nil {
+ mod.log.Error().Err(err).Msg("Failed to restore service state to running")
}
}()
}
}
- if code, err = executor.queryServiceConfig(ctx, svc); err != nil {
+ if code, err = mod.queryServiceConfig(ctx, svc); err != nil {
return fmt.Errorf("failed to query service configuration with code %d: %w", code, err)
}
- executor.log.Debug().
+ mod.log.Debug().
Str("service", svc.name).
Str("command", svc.svcConfig.BinaryPathName).Msg("Fetched existing service configuration")
// Change service configuration
- if code, err = executor.changeServiceConfigBinary(ctx, svc, cmd); err != nil {
+ if code, err = mod.changeServiceConfigBinary(ctx, svc, cmd); err != nil {
return fmt.Errorf("failed to edit service configuration with code %d: %w", code, err)
}
defer func() {
// Revert configuration
- if code, err = executor.changeServiceConfigBinary(ctx, svc, svc.svcConfig.BinaryPathName); err != nil {
- executor.log.Error().Err(err).Msg("Failed to restore service configuration")
+ if code, err = mod.changeServiceConfigBinary(ctx, svc, svc.svcConfig.BinaryPathName); err != nil {
+ mod.log.Error().Err(err).Msg("Failed to restore service configuration")
} else {
- executor.log.Info().Str("service", svc.name).Msg("Restored service configuration")
+ mod.log.Info().Str("service", svc.name).Msg("Restored service configuration")
}
}()
- executor.log.Info().
+ mod.log.Info().
Str("service", svc.name).
Str("command", cmd).Msg("Changed service configuration")
// Start service
if !cfg.NoStart {
- if code, err = executor.startService(ctx, scm, svc); err != nil {
+ if code, err = mod.startService(ctx, scm, svc); err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
// In case of timeout or cancel, try to reestablish a connection to restore the service
- executor.log.Info().Msg("Service start timeout/cancelled. Execution likely successful")
- executor.log.Info().Msg("Reconnecting for cleanup procedure")
+ mod.log.Info().Msg("Service start timeout/cancelled. Execution likely successful")
+ mod.log.Info().Msg("Reconnecting for cleanup procedure")
ctx = vctx
- if _, err = executor.createClients(ctx); err != nil {
- executor.log.Error().Err(err).Msg("Reconnect failed")
+ if _, err = mod.createClients(ctx); err != nil {
+ mod.log.Error().Err(err).Msg("Reconnect failed")
- } else if scm, code, err = executor.openSCM(ctx); err != nil {
- executor.log.Error().Err(err).Msg("Failed to reopen SCM")
+ } else if scm, code, err = mod.openSCM(ctx); err != nil {
+ mod.log.Error().Err(err).Msg("Failed to reopen SCM")
- } else if svc.handle, code, err = executor.openService(ctx, scm, svc.name); err != nil {
- executor.log.Error().Str("service", svc.name).Err(err).Msg("Failed to reopen service handle")
+ } else if svc.handle, code, err = mod.openService(ctx, scm, svc.name); err != nil {
+ mod.log.Error().Str("service", svc.name).Err(err).Msg("Failed to reopen service handle")
} else {
- executor.log.Debug().Str("service", svc.name).Msg("Reconnection successful")
+ mod.log.Debug().Str("service", svc.name).Msg("Reconnection successful")
}
} else {
- executor.log.Error().Err(err).Msg("Failed to start service")
+ mod.log.Error().Err(err).Msg("Failed to start service")
}
} else {
- executor.log.Info().Str("service", svc.name).Msg("Started service")
+ mod.log.Info().Str("service", svc.name).Msg("Started service")
}
defer func() {
// Stop service
- if code, err = executor.stopService(ctx, scm, svc); err != nil {
- executor.log.Error().Err(err).Msg("Failed to stop service")
+ if code, err = mod.stopService(ctx, scm, svc); err != nil {
+ mod.log.Error().Err(err).Msg("Failed to stop service")
} else {
- executor.log.Info().Str("service", svc.name).Msg("Stopped service")
+ mod.log.Info().Str("service", svc.name).Msg("Stopped service")
}
}()
}
}
+ } else {
+ return fmt.Errorf("invalid method: %s", ecfg.ExecutionMethod)
}
return err
}
diff --git a/pkg/exec/scmr/module.go b/pkg/exec/scmr/module.go
index 1c855fb..b35c746 100644
--- a/pkg/exec/scmr/module.go
+++ b/pkg/exec/scmr/module.go
@@ -1,13 +1,13 @@
package scmrexec
import (
+ "github.com/FalconOpsLLC/goexec/pkg/client/dcerpc"
"github.com/bryanmcnulty/adauth"
"github.com/oiweiwei/go-msrpc/msrpc/scmr/svcctl/v2"
"github.com/rs/zerolog"
- "github.com/FalconOpsLLC/goexec/pkg/client/dcerpc"
)
-type Executor struct {
+type Module struct {
creds *adauth.Credential
target *adauth.Target
hostname string
diff --git a/pkg/exec/scmr/scmr.go b/pkg/exec/scmr/scmr.go
index fbbb108..e9ef53f 100644
--- a/pkg/exec/scmr/scmr.go
+++ b/pkg/exec/scmr/scmr.go
@@ -4,10 +4,10 @@ import (
"context"
"errors"
"fmt"
- "github.com/oiweiwei/go-msrpc/msrpc/scmr/svcctl/v2"
"github.com/FalconOpsLLC/goexec/internal/util"
"github.com/FalconOpsLLC/goexec/pkg/exec"
"github.com/FalconOpsLLC/goexec/pkg/windows"
+ "github.com/oiweiwei/go-msrpc/msrpc/scmr/svcctl/v2"
)
type service struct {
@@ -23,14 +23,14 @@ type service struct {
// openSCM opens a handle to SCM via ROpenSCManagerW
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/dc84adb3-d51d-48eb-820d-ba1c6ca5faf2
-func (executor *Executor) openSCM(ctx context.Context) (scm *svcctl.Handle, code uint32, err error) {
- if executor.ctl != nil {
+func (mod *Module) openSCM(ctx context.Context) (scm *svcctl.Handle, code uint32, err error) {
+ if mod.ctl != nil {
- hostname := executor.hostname
+ hostname := mod.hostname
if hostname == "" {
hostname = util.RandomHostname()
}
- if response, err := executor.ctl.OpenSCMW(ctx, &svcctl.OpenSCMWRequest{
+ if response, err := mod.ctl.OpenSCMW(ctx, &svcctl.OpenSCMWRequest{
MachineName: hostname + "\x00", // lpMachineName; The server's name (i.e. DC01, dc01.domain.local)
DatabaseName: "ServicesActive\x00", // lpDatabaseName; must be "ServicesActive" or "ServicesFailed"
DesiredAccess: ServiceModifyAccess, // dwDesiredAccess; requested access - appears to be ignored?
@@ -49,10 +49,10 @@ func (executor *Executor) openSCM(ctx context.Context) (scm *svcctl.Handle, code
// createService creates a service with the provided configuration via RCreateServiceW
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/6a8ca926-9477-4dd4-b766-692fab07227e
-func (executor *Executor) createService(ctx context.Context, scm *svcctl.Handle, scfg *service, ecfg *exec.ExecutionConfig) (code uint32, err error) {
- if executor.ctl != nil && scm != nil && scfg != nil && scfg.createConfig != nil {
+func (mod *Module) createService(ctx context.Context, scm *svcctl.Handle, scfg *service, ecfg *exec.ExecutionConfig) (code uint32, err error) {
+ if mod.ctl != nil && scm != nil && scfg != nil && scfg.createConfig != nil {
cfg := scfg.createConfig
- if response, err := executor.ctl.CreateServiceW(ctx, &svcctl.CreateServiceWRequest{
+ if response, err := mod.ctl.CreateServiceW(ctx, &svcctl.CreateServiceWRequest{
ServiceManager: scm,
ServiceName: cfg.ServiceName + "\x00",
DisplayName: cfg.DisplayName + "\x00",
@@ -76,9 +76,9 @@ func (executor *Executor) createService(ctx context.Context, scm *svcctl.Handle,
// openService opens a handle to a service given the service name (lpServiceName)
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/6d0a4225-451b-4132-894d-7cef7aecfd2d
-func (executor *Executor) openService(ctx context.Context, scm *svcctl.Handle, svcName string) (*svcctl.Handle, uint32, error) {
- if executor.ctl != nil && scm != nil {
- if openResponse, err := executor.ctl.OpenServiceW(ctx, &svcctl.OpenServiceWRequest{
+func (mod *Module) openService(ctx context.Context, scm *svcctl.Handle, svcName string) (*svcctl.Handle, uint32, error) {
+ if mod.ctl != nil && scm != nil {
+ if openResponse, err := mod.ctl.OpenServiceW(ctx, &svcctl.OpenServiceWRequest{
ServiceManager: scm,
ServiceName: svcName,
DesiredAccess: ServiceAllAccess,
@@ -99,9 +99,9 @@ func (executor *Executor) openService(ctx context.Context, scm *svcctl.Handle, s
// deleteService deletes an existing service with RDeleteService
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/6744cdb8-f162-4be0-bb31-98996b6495be
-func (executor *Executor) deleteService(ctx context.Context, scm *svcctl.Handle, svc *service) (code uint32, err error) {
- if executor.ctl != nil && scm != nil && svc != nil {
- if deleteResponse, err := executor.ctl.DeleteService(ctx, &svcctl.DeleteServiceRequest{Service: svc.handle}); err != nil {
+func (mod *Module) deleteService(ctx context.Context, scm *svcctl.Handle, svc *service) (code uint32, err error) {
+ if mod.ctl != nil && scm != nil && svc != nil {
+ if deleteResponse, err := mod.ctl.DeleteService(ctx, &svcctl.DeleteServiceRequest{Service: svc.handle}); err != nil {
defer func() {}()
if deleteResponse != nil {
return deleteResponse.Return, fmt.Errorf("delete service response: %w", err)
@@ -115,9 +115,9 @@ func (executor *Executor) deleteService(ctx context.Context, scm *svcctl.Handle,
// controlService sets the state of the provided process
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/e1c478be-117f-4512-9b67-17c20a48af97
-func (executor *Executor) controlService(ctx context.Context, scm *svcctl.Handle, svc *service, control uint32) (code uint32, err error) {
- if executor.ctl != nil && scm != nil && svc != nil {
- if controlResponse, err := executor.ctl.ControlService(ctx, &svcctl.ControlServiceRequest{
+func (mod *Module) controlService(ctx context.Context, scm *svcctl.Handle, svc *service, control uint32) (code uint32, err error) {
+ if mod.ctl != nil && scm != nil && svc != nil {
+ if controlResponse, err := mod.ctl.ControlService(ctx, &svcctl.ControlServiceRequest{
Service: svc.handle,
Control: control,
}); err != nil {
@@ -133,8 +133,8 @@ func (executor *Executor) controlService(ctx context.Context, scm *svcctl.Handle
// stopService sends stop signal to existing service using controlService
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/e1c478be-117f-4512-9b67-17c20a48af97
-func (executor *Executor) stopService(ctx context.Context, scm *svcctl.Handle, svc *service) (code uint32, err error) {
- if code, err = executor.controlService(ctx, scm, svc, windows.SERVICE_CONTROL_STOP); code == windows.ERROR_SERVICE_NOT_ACTIVE {
+func (mod *Module) stopService(ctx context.Context, scm *svcctl.Handle, svc *service) (code uint32, err error) {
+ if code, err = mod.controlService(ctx, scm, svc, windows.SERVICE_CONTROL_STOP); code == windows.ERROR_SERVICE_NOT_ACTIVE {
err = nil
}
return
@@ -142,9 +142,9 @@ func (executor *Executor) stopService(ctx context.Context, scm *svcctl.Handle, s
// startService starts the specified service with RStartServiceW
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/d9be95a2-cf01-4bdc-b30f-6fe4b37ada16
-func (executor *Executor) startService(ctx context.Context, scm *svcctl.Handle, svc *service) (code uint32, err error) {
- if executor.ctl != nil && scm != nil && svc != nil {
- if startResponse, err := executor.ctl.StartServiceW(ctx, &svcctl.StartServiceWRequest{Service: svc.handle}); err != nil {
+func (mod *Module) startService(ctx context.Context, scm *svcctl.Handle, svc *service) (code uint32, err error) {
+ if mod.ctl != nil && scm != nil && svc != nil {
+ if startResponse, err := mod.ctl.StartServiceW(ctx, &svcctl.StartServiceWRequest{Service: svc.handle}); err != nil {
if startResponse != nil {
// TODO: check if service is already running, return nil error if so
if startResponse.Return == windows.ERROR_SERVICE_REQUEST_TIMEOUT {
@@ -161,9 +161,9 @@ func (executor *Executor) startService(ctx context.Context, scm *svcctl.Handle,
// closeService closes the specified service handle using RCloseServiceHandle
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/a2a4e174-09fb-4e55-bad3-f77c4b13245c
-func (executor *Executor) closeService(ctx context.Context, svc *svcctl.Handle) (code uint32, err error) {
- if executor.ctl != nil && svc != nil {
- if closeResponse, err := executor.ctl.CloseService(ctx, &svcctl.CloseServiceRequest{ServiceObject: svc}); err != nil {
+func (mod *Module) closeService(ctx context.Context, svc *svcctl.Handle) (code uint32, err error) {
+ if mod.ctl != nil && svc != nil {
+ if closeResponse, err := mod.ctl.CloseService(ctx, &svcctl.CloseServiceRequest{ServiceObject: svc}); err != nil {
if closeResponse != nil {
return closeResponse.Return, fmt.Errorf("close service response: %w", err)
}
@@ -176,9 +176,9 @@ func (executor *Executor) closeService(ctx context.Context, svc *svcctl.Handle)
// getServiceConfig fetches the configuration details of a service given a handle passed in a service{} structure.
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/89e2d5b1-19cf-44ca-969f-38eea9fe7f3c
-func (executor *Executor) queryServiceConfig(ctx context.Context, svc *service) (code uint32, err error) {
- if executor.ctl != nil && svc != nil && svc.handle != nil {
- if getResponse, err := executor.ctl.QueryServiceConfigW(ctx, &svcctl.QueryServiceConfigWRequest{
+func (mod *Module) queryServiceConfig(ctx context.Context, svc *service) (code uint32, err error) {
+ if mod.ctl != nil && svc != nil && svc.handle != nil {
+ if getResponse, err := mod.ctl.QueryServiceConfigW(ctx, &svcctl.QueryServiceConfigWRequest{
Service: svc.handle,
BufferLength: 1024 * 8,
}); err != nil {
@@ -196,9 +196,9 @@ func (executor *Executor) queryServiceConfig(ctx context.Context, svc *service)
// queryServiceStatus fetches the state of the specified service
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/cf94d915-b4e1-40e5-872b-a9cb3ad09b46
-func (executor *Executor) queryServiceStatus(ctx context.Context, svc *service) (uint32, error) {
- if executor.ctl != nil && svc != nil {
- if queryResponse, err := executor.ctl.QueryServiceStatus(ctx, &svcctl.QueryServiceStatusRequest{Service: svc.handle}); err != nil {
+func (mod *Module) queryServiceStatus(ctx context.Context, svc *service) (uint32, error) {
+ if mod.ctl != nil && svc != nil {
+ if queryResponse, err := mod.ctl.QueryServiceStatus(ctx, &svcctl.QueryServiceStatusRequest{Service: svc.handle}); err != nil {
if queryResponse != nil {
return queryResponse.Return, fmt.Errorf("query service status response: %w", err)
}
@@ -213,9 +213,9 @@ func (executor *Executor) queryServiceStatus(ctx context.Context, svc *service)
// changeServiceConfigBinary edits the provided service's lpBinaryPathName
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/61ea7ed0-c49d-4152-a164-b4830f16c8a4
-func (executor *Executor) changeServiceConfigBinary(ctx context.Context, svc *service, bin string) (code uint32, err error) {
- if executor.ctl != nil && svc != nil && svc.handle != nil {
- if changeResponse, err := executor.ctl.ChangeServiceConfigW(ctx, &svcctl.ChangeServiceConfigWRequest{
+func (mod *Module) changeServiceConfigBinary(ctx context.Context, svc *service, bin string) (code uint32, err error) {
+ if mod.ctl != nil && svc != nil && svc.handle != nil {
+ if changeResponse, err := mod.ctl.ChangeServiceConfigW(ctx, &svcctl.ChangeServiceConfigWRequest{
Service: svc.handle,
ServiceType: svc.svcConfig.ServiceType,
StartType: svc.svcConfig.StartType,