From b5b5297350a82461e2921964f4e0069624fb5073 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 22 Nov 2020 22:56:38 -0800 Subject: [PATCH] software and rebootnow nats --- agent/rpc_windows.go | 18 +++++++++++++++++ agent/software_windows_386.go | 34 +++++++++++++++++++++++++++++++++ agent/software_windows_amd64.go | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/agent/rpc_windows.go b/agent/rpc_windows.go index c3735ef..313aec7 100644 --- a/agent/rpc_windows.go +++ b/agent/rpc_windows.go @@ -163,6 +163,24 @@ func (a *WindowsAgent) RunRPC() { msg.Respond(resp) }() + case "softwarelist": + go func() { + var resp []byte + ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) + sw := a.GetInstalledSoftware() + ret.Encode(sw) + msg.Respond(resp) + }() + + case "rebootnow": + go func() { + var resp []byte + ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) + ret.Encode("ok") + msg.Respond(resp) + _, _ = CMD("shutdown.exe", []string{"/r", "/t", "5", "/f"}, 15, false) + }() + case "uninstall": go func() { var resp []byte diff --git a/agent/software_windows_386.go b/agent/software_windows_386.go index 6d9e5fd..d9d7b9d 100644 --- a/agent/software_windows_386.go +++ b/agent/software_windows_386.go @@ -7,6 +7,17 @@ import ( wapf "github.com/wh1te909/go-win64api" ) +type SoftwareList struct { + Name string `json:"name"` + Version string `json:"version"` + Publisher string `json:"publisher"` + InstallDate string `json:"install_date"` + Size string `json:"size"` + Source string `json:"source"` + Location string `json:"location"` + Uninstall string `json:"uninstall"` +} + // GetProgramVersion loops through the registry for software // and if found, returns its version func (a *WindowsAgent) GetProgramVersion(name string) string { @@ -34,3 +45,26 @@ func installedSoftwareList() ([]so.Software, error) { return sw32, nil } + +func (a *WindowsAgent) GetInstalledSoftware() []SoftwareList { + ret := make([]SoftwareList, 0) + + sw, err := installedSoftwareList() + if err != nil { + return ret + } + + for _, s := range sw { + ret = append(ret, SoftwareList{ + Name: s.Name(), + Version: s.Version(), + Publisher: s.Publisher, + InstallDate: s.InstallDate.String(), + Size: ByteCountSI(s.EstimatedSize * 1024), + Source: s.InstallSource, + Location: s.InstallLocation, + Uninstall: s.UninstallString, + }) + } + return ret +} diff --git a/agent/software_windows_amd64.go b/agent/software_windows_amd64.go index 1b4dae0..6696091 100644 --- a/agent/software_windows_amd64.go +++ b/agent/software_windows_amd64.go @@ -6,6 +6,17 @@ import ( wapi "github.com/iamacarpet/go-win64api" ) +type SoftwareList struct { + Name string `json:"name"` + Version string `json:"version"` + Publisher string `json:"publisher"` + InstallDate string `json:"install_date"` + Size string `json:"size"` + Source string `json:"source"` + Location string `json:"location"` + Uninstall string `json:"uninstall"` +} + // GetProgramVersion loops through the registry for software // and if found, returns its version func (a *WindowsAgent) GetProgramVersion(name string) string { @@ -24,3 +35,26 @@ func (a *WindowsAgent) GetProgramVersion(name string) string { } return "0.0.0" } + +func (a *WindowsAgent) GetInstalledSoftware() []SoftwareList { + ret := make([]SoftwareList, 0) + + sw, err := wapi.InstalledSoftwareList() + if err != nil { + return ret + } + + for _, s := range sw { + ret = append(ret, SoftwareList{ + Name: s.Name(), + Version: s.Version(), + Publisher: s.Publisher, + InstallDate: s.InstallDate.String(), + Size: ByteCountSI(s.EstimatedSize * 1024), + Source: s.InstallSource, + Location: s.InstallLocation, + Uninstall: s.UninstallString, + }) + } + return ret +}