From f1db416d565dfce8c48534be35b9fb07b21457b7 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Thu, 24 Nov 2022 23:45:59 -0800 Subject: [PATCH 01/14] make checkin intervals configurable and remove extra nats conn --- agent/agent.go | 1 + agent/rpc.go | 9 ++++-- agent/svc.go | 84 +++++++++++++++++++++++++++++++++++++------------- agent/utils.go | 9 ++++++ 4 files changed, 79 insertions(+), 24 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index c9b9b04..daa3503 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -89,6 +89,7 @@ const ( var winTempDir = filepath.Join(os.Getenv("PROGRAMDATA"), "TacticalRMM") var winMeshDir = filepath.Join(os.Getenv("PROGRAMFILES"), "Mesh Agent") var natsCheckin = []string{"agent-hello", "agent-agentinfo", "agent-disks", "agent-winsvc", "agent-publicip", "agent-wmi"} +var limitNatsData = []string{"agent-winsvc", "agent-wmi"} func New(logger *logrus.Logger, version string) *Agent { host, _ := ps.Host() diff --git a/agent/rpc.go b/agent/rpc.go index b141be0..f5dc454 100644 --- a/agent/rpc.go +++ b/agent/rpc.go @@ -51,15 +51,18 @@ var ( func (a *Agent) RunRPC() { a.Logger.Infoln("Agent service started") - go a.RunAsService() - var wg sync.WaitGroup - wg.Add(1) + opts := a.setupNatsOptions() nc, err := nats.Connect(a.NatsServer, opts...) if err != nil { a.Logger.Fatalln("RunRPC() nats.Connect()", err) } + go a.RunAsService(nc) + + var wg sync.WaitGroup + wg.Add(1) + nc.Subscribe(a.AgentID, func(msg *nats.Msg) { var payload *NatsMsg var mh codec.MsgpackHandle diff --git a/agent/svc.go b/agent/svc.go index e695ffd..24d72d8 100644 --- a/agent/svc.go +++ b/agent/svc.go @@ -12,6 +12,7 @@ https://license.tacticalrmm.com package agent import ( + "fmt" "runtime" "sync" "time" @@ -19,15 +20,27 @@ import ( nats "github.com/nats-io/nats.go" ) -func (a *Agent) RunAsService() { +func (a *Agent) RunAsService(nc *nats.Conn) { var wg sync.WaitGroup wg.Add(1) - go a.AgentSvc() + go a.AgentSvc(nc) go a.CheckRunner() wg.Wait() } -func (a *Agent) AgentSvc() { +type AgentCheckInConfig struct { + Hello int `json:"checkin_hello"` + AgentInfo int `json:"checkin_agentinfo"` + WinSvc int `json:"checkin_winsvc"` + PubIP int `json:"checkin_pubip"` + Disks int `json:"checkin_disks"` + SW int `json:"checkin_sw"` + WMI int `json:"checkin_wmi"` + SyncMesh int `json:"checkin_syncmesh"` + LimitData bool `json:"limit_data"` +} + +func (a *Agent) AgentSvc(nc *nats.Conn) { if runtime.GOOS == "windows" { go a.GetPython(false) @@ -38,37 +51,36 @@ func (a *Agent) AgentSvc() { } a.RunMigrations() - sleepDelay := randRange(14, 22) + sleepDelay := randRange(7, 25) a.Logger.Debugf("AgentSvc() sleeping for %v seconds", sleepDelay) time.Sleep(time.Duration(sleepDelay) * time.Second) - opts := a.setupNatsOptions() - nc, err := nats.Connect(a.NatsServer, opts...) - if err != nil { - a.Logger.Fatalln("AgentSvc() nats.Connect()", err) - } - + conf := a.GetAgentCheckInConfig() for _, s := range natsCheckin { - a.NatsMessage(nc, s) - time.Sleep(time.Duration(randRange(100, 400)) * time.Millisecond) + if conf.LimitData && stringInSlice(s, limitNatsData) { + continue + } else { + a.NatsMessage(nc, s) + time.Sleep(time.Duration(randRange(100, 400)) * time.Millisecond) + } } go a.SyncMeshNodeID() time.Sleep(time.Duration(randRange(1, 3)) * time.Second) - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" && !conf.LimitData { a.AgentStartup() a.SendSoftware() } - checkInHelloTicker := time.NewTicker(time.Duration(randRange(30, 60)) * time.Second) - checkInAgentInfoTicker := time.NewTicker(time.Duration(randRange(200, 400)) * time.Second) - checkInWinSvcTicker := time.NewTicker(time.Duration(randRange(2400, 3000)) * time.Second) - checkInPubIPTicker := time.NewTicker(time.Duration(randRange(300, 500)) * time.Second) - checkInDisksTicker := time.NewTicker(time.Duration(randRange(1000, 2000)) * time.Second) - checkInSWTicker := time.NewTicker(time.Duration(randRange(2800, 3500)) * time.Second) - checkInWMITicker := time.NewTicker(time.Duration(randRange(3000, 4000)) * time.Second) - syncMeshTicker := time.NewTicker(time.Duration(randRange(800, 1200)) * time.Second) + checkInHelloTicker := time.NewTicker(time.Duration(conf.Hello) * time.Second) + checkInAgentInfoTicker := time.NewTicker(time.Duration(conf.AgentInfo) * time.Second) + checkInWinSvcTicker := time.NewTicker(time.Duration(conf.WinSvc) * time.Second) + checkInPubIPTicker := time.NewTicker(time.Duration(conf.PubIP) * time.Second) + checkInDisksTicker := time.NewTicker(time.Duration(conf.Disks) * time.Second) + checkInSWTicker := time.NewTicker(time.Duration(conf.SW) * time.Second) + checkInWMITicker := time.NewTicker(time.Duration(conf.WMI) * time.Second) + syncMeshTicker := time.NewTicker(time.Duration(conf.SyncMesh) * time.Second) for { select { @@ -100,3 +112,33 @@ func (a *Agent) AgentStartup() { a.Logger.Debugln("AgentStartup()", err) } } + +func (a *Agent) GetAgentCheckInConfig() AgentCheckInConfig { + ret := AgentCheckInConfig{} + url := fmt.Sprintf("/api/v3/%s/config/", a.AgentID) + r, err := a.rClient.R().SetResult(&AgentCheckInConfig{}).Get(url) + if err != nil { + a.Logger.Debugln("GetAgentCheckInConfig()", err) + ret.Hello = randRange(30, 60) + ret.AgentInfo = randRange(200, 400) + ret.WinSvc = randRange(2400, 3000) + ret.PubIP = randRange(300, 500) + ret.Disks = randRange(1000, 2000) + ret.SW = randRange(2800, 3500) + ret.WMI = randRange(3000, 4000) + ret.SyncMesh = randRange(800, 1200) + ret.LimitData = false + return ret + } + ret.Hello = r.Result().(*AgentCheckInConfig).Hello + ret.AgentInfo = r.Result().(*AgentCheckInConfig).AgentInfo + ret.WinSvc = r.Result().(*AgentCheckInConfig).WinSvc + ret.PubIP = r.Result().(*AgentCheckInConfig).PubIP + ret.Disks = r.Result().(*AgentCheckInConfig).Disks + ret.SW = r.Result().(*AgentCheckInConfig).SW + ret.WMI = r.Result().(*AgentCheckInConfig).WMI + ret.SyncMesh = r.Result().(*AgentCheckInConfig).SyncMesh + ret.LimitData = r.Result().(*AgentCheckInConfig).LimitData + a.Logger.Debugf("%+v\n", r) + return ret +} diff --git a/agent/utils.go b/agent/utils.go index f5916f8..ede7753 100644 --- a/agent/utils.go +++ b/agent/utils.go @@ -322,3 +322,12 @@ func createTmpFile() (*os.File, error) { } return f, nil } + +func stringInSlice(a string, list []string) bool { + for _, b := range list { + if b == a { + return true + } + } + return false +} From 79dba2f84c860b03cdb6b98f831d74b33c125eea Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Thu, 24 Nov 2022 23:48:27 -0800 Subject: [PATCH 02/14] add some debug callbacks --- agent/agent.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index daa3503..8a03e6a 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -400,13 +400,25 @@ func (a *Agent) SyncMeshNodeID() { func (a *Agent) setupNatsOptions() []nats.Option { opts := make([]nats.Option, 0) - opts = append(opts, nats.Name("TacticalRMM")) + opts = append(opts, nats.Name(a.AgentID)) opts = append(opts, nats.UserInfo(a.AgentID, a.Token)) opts = append(opts, nats.ReconnectWait(time.Second*5)) opts = append(opts, nats.RetryOnFailedConnect(true)) opts = append(opts, nats.MaxReconnects(-1)) opts = append(opts, nats.ReconnectBufSize(-1)) opts = append(opts, nats.ProxyPath(a.NatsProxyPath)) + opts = append(opts, nats.DisconnectErrHandler(func(nc *nats.Conn, err error) { + a.Logger.Debugln("NATS disconnected:", err) + a.Logger.Debugf("%+v\n", nc.Statistics) + })) + opts = append(opts, nats.ReconnectHandler(func(nc *nats.Conn) { + a.Logger.Debugln("NATS reconnected") + a.Logger.Debugf("%+v\n", nc.Statistics) + })) + opts = append(opts, nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, err error) { + a.Logger.Debugln("NATS error:", err) + a.Logger.Debugf("%+v\n", sub) + })) return opts } From 9565fea27cb72f1d2db4935d73c8dc06ccc89f4d Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Fri, 25 Nov 2022 00:22:28 -0800 Subject: [PATCH 03/14] update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9127efc..e31b3d0 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/go-resty/resty/v2 v2.7.0 github.com/gonutz/w32/v2 v2.4.0 github.com/iamacarpet/go-win64api v0.0.0-20220531131246-e84054eb584d - github.com/nats-io/nats-server/v2 v2.9.6 // indirect + github.com/nats-io/nats-server/v2 v2.9.8 // indirect github.com/nats-io/nats.go v1.20.0 github.com/rickb777/date v1.19.1 github.com/shirou/gopsutil/v3 v3.22.10 diff --git a/go.sum b/go.sum index ce32c18..75321c6 100644 --- a/go.sum +++ b/go.sum @@ -212,8 +212,8 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI= -github.com/nats-io/nats-server/v2 v2.9.6 h1:RTtK+rv/4CcliOuqGsy58g7MuWkBaWmF5TUNwuUo9Uw= -github.com/nats-io/nats-server/v2 v2.9.6/go.mod h1:AB6hAnGZDlYfqb7CTAm66ZKMZy9DpfierY1/PbpvI2g= +github.com/nats-io/nats-server/v2 v2.9.8 h1:jgxZsv+A3Reb3MgwxaINcNq/za8xZInKhDg9Q0cGN1o= +github.com/nats-io/nats-server/v2 v2.9.8/go.mod h1:AB6hAnGZDlYfqb7CTAm66ZKMZy9DpfierY1/PbpvI2g= github.com/nats-io/nats.go v1.20.0 h1:T8JJnQfVSdh1CzGiwAOv5hEobYCBho/0EupGznYw0oM= github.com/nats-io/nats.go v1.20.0/go.mod h1:tLqubohF7t4z3du1QDPYJIQQyhb4wl6DhjxEajSI7UA= github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= From 6ac14b6d6426bf66ec05d591e657cb66818cd138 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Fri, 25 Nov 2022 00:23:31 -0800 Subject: [PATCH 04/14] add env to scripts --- agent/agent_windows.go | 7 ++++++- agent/checks.go | 2 +- agent/choco_windows.go | 2 +- agent/rpc.go | 5 +++-- agent/tasks_windows.go | 2 +- shared/types.go | 8 +++++--- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/agent/agent_windows.go b/agent/agent_windows.go index 26cb7b6..c980ebd 100644 --- a/agent/agent_windows.go +++ b/agent/agent_windows.go @@ -82,7 +82,7 @@ func NewAgentConfig() *rmm.AgentConfig { } } -func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) { +func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool, envs []string) (stdout, stderr string, exitcode int, e error) { content := []byte(code) @@ -158,6 +158,11 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int, cmd.Stdout = &outb cmd.Stderr = &errb + if len(envs) > 0 { + cmd.Env = os.Environ() + cmd.Env = append(cmd.Env, envs...) + } + if cmdErr := cmd.Start(); cmdErr != nil { a.Logger.Debugln(cmdErr) return "", cmdErr.Error(), 65, cmdErr diff --git a/agent/checks.go b/agent/checks.go index 531bf74..a680917 100644 --- a/agent/checks.go +++ b/agent/checks.go @@ -169,7 +169,7 @@ type ScriptCheckResult struct { // ScriptCheck runs either bat, powershell or python script func (a *Agent) ScriptCheck(data rmm.Check, r *resty.Client) { start := time.Now() - stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser) + stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser, data.Script.Env) payload := ScriptCheckResult{ ID: data.CheckPK, diff --git a/agent/choco_windows.go b/agent/choco_windows.go index c37f025..1ba6058 100644 --- a/agent/choco_windows.go +++ b/agent/choco_windows.go @@ -42,7 +42,7 @@ func (a *Agent) InstallChoco() { return } - _, _, exitcode, err := a.RunScript(string(r.Body()), "powershell", []string{}, 900, false) + _, _, exitcode, err := a.RunScript(string(r.Body()), "powershell", []string{}, 900, false, []string{}) if err != nil { a.Logger.Debugln(err) a.rClient.R().SetBody(result).Post(url) diff --git a/agent/rpc.go b/agent/rpc.go index f5dc454..57f0987 100644 --- a/agent/rpc.go +++ b/agent/rpc.go @@ -41,6 +41,7 @@ type NatsMsg struct { ID int `json:"id"` Code string `json:"code"` RunAsUser bool `json:"run_as_user"` + Env []string `json:"env"` } var ( @@ -261,7 +262,7 @@ func (a *Agent) RunRPC() { var resultData rmm.RunScriptResp ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) start := time.Now() - stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser) + stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.Env) resultData.ExecTime = time.Since(start).Seconds() resultData.ID = p.ID @@ -291,7 +292,7 @@ func (a *Agent) RunRPC() { var retData rmm.RunScriptResp ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) start := time.Now() - stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser) + stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.Env) retData.ExecTime = time.Since(start).Seconds() if err != nil { diff --git a/agent/tasks_windows.go b/agent/tasks_windows.go index da3d7a2..3144c8f 100644 --- a/agent/tasks_windows.go +++ b/agent/tasks_windows.go @@ -59,7 +59,7 @@ func (a *Agent) RunTask(id int) error { action_start := time.Now() if action.ActionType == "script" { - stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout, action.RunAsUser) + stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout, action.RunAsUser, action.Env) if err != nil { a.Logger.Debugln(err) diff --git a/shared/types.go b/shared/types.go index b2cb258..90acdc5 100644 --- a/shared/types.go +++ b/shared/types.go @@ -141,9 +141,10 @@ type AssignedTask struct { } type Script struct { - Shell string `json:"shell"` - Code string `json:"code"` - RunAsUser bool `json:"run_as_user"` + Shell string `json:"shell"` + Code string `json:"code"` + RunAsUser bool `json:"run_as_user"` + Env []string `json:"env"` } type CheckInfo struct { @@ -190,6 +191,7 @@ type TaskAction struct { Args []string `json:"script_args"` Timeout int `json:"timeout"` RunAsUser bool `json:"run_as_user"` + Env []string `json:"env"` } type AutomatedTask struct { From 7358907b3c01f817155f8dc80c5ad0bf60380907 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 28 Nov 2022 23:18:22 -0800 Subject: [PATCH 05/14] add env --- agent/agent.go | 6 +++--- agent/agent_windows.go | 6 +++--- agent/checks.go | 2 +- agent/rpc.go | 6 +++--- agent/tasks_windows.go | 2 +- shared/types.go | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 8a03e6a..7374220 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -221,7 +221,7 @@ type CmdOptions struct { IsScript bool IsExecutable bool Detached bool - Env []string + EnvVars []string } func (a *Agent) NewCMDOpts() *CmdOptions { @@ -250,10 +250,10 @@ func (a *Agent) CmdV2(c *CmdOptions) CmdStatus { }) } - if len(c.Env) > 0 { + if len(c.EnvVars) > 0 { cmdOptions.BeforeExec = append(cmdOptions.BeforeExec, func(cmd *exec.Cmd) { cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, c.Env...) + cmd.Env = append(cmd.Env, c.EnvVars...) }) } diff --git a/agent/agent_windows.go b/agent/agent_windows.go index c980ebd..446ddd6 100644 --- a/agent/agent_windows.go +++ b/agent/agent_windows.go @@ -82,7 +82,7 @@ func NewAgentConfig() *rmm.AgentConfig { } } -func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool, envs []string) (stdout, stderr string, exitcode int, e error) { +func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool, envVars []string) (stdout, stderr string, exitcode int, e error) { content := []byte(code) @@ -158,9 +158,9 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int, cmd.Stdout = &outb cmd.Stderr = &errb - if len(envs) > 0 { + if len(envVars) > 0 { cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, envs...) + cmd.Env = append(cmd.Env, envVars...) } if cmdErr := cmd.Start(); cmdErr != nil { diff --git a/agent/checks.go b/agent/checks.go index a680917..ec44b04 100644 --- a/agent/checks.go +++ b/agent/checks.go @@ -169,7 +169,7 @@ type ScriptCheckResult struct { // ScriptCheck runs either bat, powershell or python script func (a *Agent) ScriptCheck(data rmm.Check, r *resty.Client) { start := time.Now() - stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser, data.Script.Env) + stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser, data.Script.EnvVars) payload := ScriptCheckResult{ ID: data.CheckPK, diff --git a/agent/rpc.go b/agent/rpc.go index 57f0987..b883ead 100644 --- a/agent/rpc.go +++ b/agent/rpc.go @@ -41,7 +41,7 @@ type NatsMsg struct { ID int `json:"id"` Code string `json:"code"` RunAsUser bool `json:"run_as_user"` - Env []string `json:"env"` + EnvVars []string `json:"env_vars"` } var ( @@ -262,7 +262,7 @@ func (a *Agent) RunRPC() { var resultData rmm.RunScriptResp ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) start := time.Now() - stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.Env) + stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.EnvVars) resultData.ExecTime = time.Since(start).Seconds() resultData.ID = p.ID @@ -292,7 +292,7 @@ func (a *Agent) RunRPC() { var retData rmm.RunScriptResp ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) start := time.Now() - stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.Env) + stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.EnvVars) retData.ExecTime = time.Since(start).Seconds() if err != nil { diff --git a/agent/tasks_windows.go b/agent/tasks_windows.go index 3144c8f..086b80e 100644 --- a/agent/tasks_windows.go +++ b/agent/tasks_windows.go @@ -59,7 +59,7 @@ func (a *Agent) RunTask(id int) error { action_start := time.Now() if action.ActionType == "script" { - stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout, action.RunAsUser, action.Env) + stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout, action.RunAsUser, action.EnvVars) if err != nil { a.Logger.Debugln(err) diff --git a/shared/types.go b/shared/types.go index 90acdc5..de7f2a9 100644 --- a/shared/types.go +++ b/shared/types.go @@ -144,7 +144,7 @@ type Script struct { Shell string `json:"shell"` Code string `json:"code"` RunAsUser bool `json:"run_as_user"` - Env []string `json:"env"` + EnvVars []string `json:"env_vars"` } type CheckInfo struct { @@ -191,7 +191,7 @@ type TaskAction struct { Args []string `json:"script_args"` Timeout int `json:"timeout"` RunAsUser bool `json:"run_as_user"` - Env []string `json:"env"` + EnvVars []string `json:"env_vars"` } type AutomatedTask struct { From 36e9065474ea8539e2f7225549cf73743551fbc7 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 28 Nov 2022 23:19:58 -0800 Subject: [PATCH 06/14] change logging level --- agent/agent.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 7374220..45c43b0 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -408,16 +408,16 @@ func (a *Agent) setupNatsOptions() []nats.Option { opts = append(opts, nats.ReconnectBufSize(-1)) opts = append(opts, nats.ProxyPath(a.NatsProxyPath)) opts = append(opts, nats.DisconnectErrHandler(func(nc *nats.Conn, err error) { - a.Logger.Debugln("NATS disconnected:", err) - a.Logger.Debugf("%+v\n", nc.Statistics) + a.Logger.Errorln("NATS disconnected:", err) + a.Logger.Errorf("%+v\n", nc.Statistics) })) opts = append(opts, nats.ReconnectHandler(func(nc *nats.Conn) { - a.Logger.Debugln("NATS reconnected") - a.Logger.Debugf("%+v\n", nc.Statistics) + a.Logger.Infoln("NATS reconnected") + a.Logger.Infof("%+v\n", nc.Statistics) })) opts = append(opts, nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, err error) { - a.Logger.Debugln("NATS error:", err) - a.Logger.Debugf("%+v\n", sub) + a.Logger.Errorln("NATS error:", err) + a.Logger.Errorf("%+v\n", sub) })) return opts } From 3ff004afa0327b52704e2c625d2d429c7752e956 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Tue, 29 Nov 2022 11:38:17 -0800 Subject: [PATCH 07/14] add more nats debug --- agent/agent.go | 129 +++++++++++++++++++++++------------------ agent/agent_unix.go | 1 + agent/agent_windows.go | 3 + agent/rpc.go | 2 + shared/types.go | 1 + 5 files changed, 80 insertions(+), 56 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 45c43b0..a5d36fb 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -40,35 +40,37 @@ import ( // Agent struct type Agent struct { - Hostname string - Arch string - AgentID string - BaseURL string - ApiURL string - Token string - AgentPK int - Cert string - ProgramDir string - EXE string - SystemDrive string - MeshInstaller string - MeshSystemEXE string - MeshSVC string - PyBin string - Headers map[string]string - Logger *logrus.Logger - Version string - Debug bool - rClient *resty.Client - Proxy string - LogTo string - LogFile *os.File - Platform string - GoArch string - ServiceConfig *service.Config - NatsServer string - NatsProxyPath string - NatsProxyPort string + Hostname string + Arch string + AgentID string + BaseURL string + ApiURL string + Token string + AgentPK int + Cert string + ProgramDir string + EXE string + SystemDrive string + MeshInstaller string + MeshSystemEXE string + MeshSVC string + PyBin string + Headers map[string]string + Logger *logrus.Logger + Version string + Debug bool + rClient *resty.Client + Proxy string + LogTo string + LogFile *os.File + Platform string + GoArch string + ServiceConfig *service.Config + NatsServer string + NatsProxyPath string + NatsProxyPort string + NatsPingInterval int + NatsWSCompression bool } const ( @@ -171,39 +173,50 @@ func New(logger *logrus.Logger, version string) *Agent { // check if using nats standard tcp, otherwise use nats websockets by default var natsServer string + var natsWsCompression bool if ac.NatsStandardPort != "" { natsServer = fmt.Sprintf("tls://%s:%s", ac.APIURL, ac.NatsStandardPort) } else { natsServer = fmt.Sprintf("wss://%s:%s", ac.APIURL, natsProxyPort) + natsWsCompression = true + } + + var natsPingInterval int + if ac.NatsPingInterval == 0 { + natsPingInterval = randRange(35, 45) + } else { + natsPingInterval = ac.NatsPingInterval } return &Agent{ - Hostname: info.Hostname, - BaseURL: ac.BaseURL, - AgentID: ac.AgentID, - ApiURL: ac.APIURL, - Token: ac.Token, - AgentPK: ac.PK, - Cert: ac.Cert, - ProgramDir: pd, - EXE: exe, - SystemDrive: sd, - MeshInstaller: "meshagent.exe", - MeshSystemEXE: MeshSysExe, - MeshSVC: meshSvcName, - PyBin: pybin, - Headers: headers, - Logger: logger, - Version: version, - Debug: logger.IsLevelEnabled(logrus.DebugLevel), - rClient: restyC, - Proxy: ac.Proxy, - Platform: runtime.GOOS, - GoArch: runtime.GOARCH, - ServiceConfig: svcConf, - NatsServer: natsServer, - NatsProxyPath: natsProxyPath, - NatsProxyPort: natsProxyPort, + Hostname: info.Hostname, + BaseURL: ac.BaseURL, + AgentID: ac.AgentID, + ApiURL: ac.APIURL, + Token: ac.Token, + AgentPK: ac.PK, + Cert: ac.Cert, + ProgramDir: pd, + EXE: exe, + SystemDrive: sd, + MeshInstaller: "meshagent.exe", + MeshSystemEXE: MeshSysExe, + MeshSVC: meshSvcName, + PyBin: pybin, + Headers: headers, + Logger: logger, + Version: version, + Debug: logger.IsLevelEnabled(logrus.DebugLevel), + rClient: restyC, + Proxy: ac.Proxy, + Platform: runtime.GOOS, + GoArch: runtime.GOARCH, + ServiceConfig: svcConf, + NatsServer: natsServer, + NatsProxyPath: natsProxyPath, + NatsProxyPort: natsProxyPort, + NatsPingInterval: natsPingInterval, + NatsWSCompression: natsWsCompression, } } @@ -399,14 +412,18 @@ func (a *Agent) SyncMeshNodeID() { } func (a *Agent) setupNatsOptions() []nats.Option { + reconnectWait := randRange(2, 8) opts := make([]nats.Option, 0) opts = append(opts, nats.Name(a.AgentID)) opts = append(opts, nats.UserInfo(a.AgentID, a.Token)) - opts = append(opts, nats.ReconnectWait(time.Second*5)) + opts = append(opts, nats.ReconnectWait(time.Duration(reconnectWait)*time.Second)) opts = append(opts, nats.RetryOnFailedConnect(true)) + opts = append(opts, nats.PingInterval(time.Duration(a.NatsPingInterval)*time.Second)) + opts = append(opts, nats.Compression(a.NatsWSCompression)) opts = append(opts, nats.MaxReconnects(-1)) opts = append(opts, nats.ReconnectBufSize(-1)) opts = append(opts, nats.ProxyPath(a.NatsProxyPath)) + opts = append(opts, nats.ReconnectJitter(500*time.Millisecond, 4*time.Second)) opts = append(opts, nats.DisconnectErrHandler(func(nc *nats.Conn, err error) { a.Logger.Errorln("NATS disconnected:", err) a.Logger.Errorf("%+v\n", nc.Statistics) diff --git a/agent/agent_unix.go b/agent/agent_unix.go index f33a307..a3b06f1 100644 --- a/agent/agent_unix.go +++ b/agent/agent_unix.go @@ -158,6 +158,7 @@ func NewAgentConfig() *rmm.AgentConfig { NatsProxyPath: viper.GetString("natsproxypath"), NatsProxyPort: viper.GetString("natsproxyport"), NatsStandardPort: viper.GetString("natsstandardport"), + NatsPingInterval: viper.GetInt("natspinginterval"), } return ret } diff --git a/agent/agent_windows.go b/agent/agent_windows.go index 446ddd6..263d1c1 100644 --- a/agent/agent_windows.go +++ b/agent/agent_windows.go @@ -65,6 +65,8 @@ func NewAgentConfig() *rmm.AgentConfig { natsProxyPath, _, _ := k.GetStringValue("NatsProxyPath") natsProxyPort, _, _ := k.GetStringValue("NatsProxyPort") natsStandardPort, _, _ := k.GetStringValue("NatsStandardPort") + natsPingInterval, _, _ := k.GetStringValue("NatsPingInterval") + npi, _ := strconv.Atoi(natsPingInterval) return &rmm.AgentConfig{ BaseURL: baseurl, @@ -79,6 +81,7 @@ func NewAgentConfig() *rmm.AgentConfig { NatsProxyPath: natsProxyPath, NatsProxyPort: natsProxyPort, NatsStandardPort: natsStandardPort, + NatsPingInterval: npi, } } diff --git a/agent/rpc.go b/agent/rpc.go index b883ead..5eaf456 100644 --- a/agent/rpc.go +++ b/agent/rpc.go @@ -55,6 +55,8 @@ func (a *Agent) RunRPC() { opts := a.setupNatsOptions() nc, err := nats.Connect(a.NatsServer, opts...) + a.Logger.Debugf("%+v\n", nc) + a.Logger.Debugf("%+v\n", nc.Opts) if err != nil { a.Logger.Fatalln("RunRPC() nats.Connect()", err) } diff --git a/shared/types.go b/shared/types.go index de7f2a9..f857ccb 100644 --- a/shared/types.go +++ b/shared/types.go @@ -45,6 +45,7 @@ type AgentConfig struct { NatsProxyPath string NatsProxyPort string NatsStandardPort string + NatsPingInterval int } type RunScriptResp struct { From 8d7dfeef25259af14d8c8fd010e27a353192a5aa Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Tue, 29 Nov 2022 19:50:52 +0000 Subject: [PATCH 08/14] fix unix --- agent/agent_unix.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agent/agent_unix.go b/agent/agent_unix.go index a3b06f1..b3af98e 100644 --- a/agent/agent_unix.go +++ b/agent/agent_unix.go @@ -163,7 +163,7 @@ func NewAgentConfig() *rmm.AgentConfig { return ret } -func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) { +func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool, envVars []string) (stdout, stderr string, exitcode int, e error) { code = removeWinNewLines(code) content := []byte(code) @@ -193,6 +193,7 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int, opts.IsScript = true opts.Shell = f.Name() opts.Args = args + opts.EnvVars = envVars opts.Timeout = time.Duration(timeout) out := a.CmdV2(opts) retError := "" From c71e495184cd6dbd5aebc457fba151bf0f0d995c Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Wed, 30 Nov 2022 16:28:06 -0800 Subject: [PATCH 09/14] update deps --- go.mod | 4 ++-- go.sum | 4 ++++ main.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e31b3d0..361ae4a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/StackExchange/wmi v1.2.1 - github.com/elastic/go-sysinfo v1.8.1 + github.com/elastic/go-sysinfo v1.9.0 github.com/go-ole/go-ole v1.2.6 github.com/go-ping/ping v1.1.0 github.com/go-resty/resty/v2 v2.7.0 @@ -55,7 +55,7 @@ require ( github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect - github.com/prometheus/procfs v0.7.3 // indirect + github.com/prometheus/procfs v0.8.0 // indirect github.com/rickb777/plural v1.4.1 // indirect github.com/rogpeppe/go-internal v1.8.1 // indirect github.com/scjalliance/comshim v0.0.0-20190308082608-cf06d2532c4e // indirect diff --git a/go.sum b/go.sum index 75321c6..d35e81e 100644 --- a/go.sum +++ b/go.sum @@ -59,6 +59,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/elastic/go-sysinfo v1.8.1 h1:4Yhj+HdV6WjbCRgGdZpPJ8lZQlXZLKDAeIkmQ/VRvi4= github.com/elastic/go-sysinfo v1.8.1/go.mod h1:JfllUnzoQV/JRYymbH3dO1yggI3mV2oTKSXsDHM+uIM= +github.com/elastic/go-sysinfo v1.9.0 h1:usICqY/Nw4Mpn9f4LdtpFrKxXroJDe81GaxxUlCckIo= +github.com/elastic/go-sysinfo v1.9.0/go.mod h1:eBD1wEGVaRnRLGecc9iG1z8eOv5HnEdz9+nWd8UAxcE= github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0= github.com/elastic/go-windows v1.0.1/go.mod h1:FoVvqWSun28vaDQPbj2Elfc0JahhPB7WQEGa3c814Ss= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -245,6 +247,8 @@ github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c/go.mod h1:Om github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= +github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= github.com/rickb777/date v1.14.2/go.mod h1:swmf05C+hN+m8/Xh7gEq3uB6QJDNc5pQBWojKdHetOs= github.com/rickb777/date v1.19.1 h1:IMcFlWY3PagAcc274tJAag84+dh4ihusPxhu4jaHMwY= github.com/rickb777/date v1.19.1/go.mod h1:NxzFOW9ZWNeOWWE2kUXLDN59GSuGMsu3E4YVVk+GcVU= diff --git a/main.go b/main.go index 36cc94a..52f95ce 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( ) var ( - version = "2.4.2" + version = "2.4.3-dev" log = logrus.New() logFile *os.File ) From de01fa5d80c31890e21ee243bf3b2bb03dc3f31b Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Wed, 30 Nov 2022 17:13:55 -0800 Subject: [PATCH 10/14] change logging levels --- agent/agent.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index a5d36fb..d9e573b 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -425,12 +425,12 @@ func (a *Agent) setupNatsOptions() []nats.Option { opts = append(opts, nats.ProxyPath(a.NatsProxyPath)) opts = append(opts, nats.ReconnectJitter(500*time.Millisecond, 4*time.Second)) opts = append(opts, nats.DisconnectErrHandler(func(nc *nats.Conn, err error) { - a.Logger.Errorln("NATS disconnected:", err) - a.Logger.Errorf("%+v\n", nc.Statistics) + a.Logger.Debugln("NATS disconnected:", err) + a.Logger.Debugf("%+v\n", nc.Statistics) })) opts = append(opts, nats.ReconnectHandler(func(nc *nats.Conn) { - a.Logger.Infoln("NATS reconnected") - a.Logger.Infof("%+v\n", nc.Statistics) + a.Logger.Debugln("NATS reconnected") + a.Logger.Debugf("%+v\n", nc.Statistics) })) opts = append(opts, nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, err error) { a.Logger.Errorln("NATS error:", err) From ec6ea9adedc28e7d44414760f59098067e469d73 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Fri, 2 Dec 2022 23:22:14 -0800 Subject: [PATCH 11/14] add local config --- agent/agent_unix.go | 3 +++ agent/agent_windows.go | 37 +++++++++++++++++++++++++++++++++++++ agent/svc.go | 26 +++++++++++++------------- agent/utils.go | 8 ++++++++ 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/agent/agent_unix.go b/agent/agent_unix.go index b3af98e..c0488d6 100644 --- a/agent/agent_unix.go +++ b/agent/agent_unix.go @@ -493,6 +493,9 @@ func (a *Agent) GetWMIInfo() map[string]interface{} { } // windows only below TODO add into stub file +func (a *Agent) GetAgentCheckInConfig(ret AgentCheckInConfig) AgentCheckInConfig { + return ret +} func (a *Agent) PlatVer() (string, error) { return "", nil } diff --git a/agent/agent_windows.go b/agent/agent_windows.go index 263d1c1..f211987 100644 --- a/agent/agent_windows.go +++ b/agent/agent_windows.go @@ -863,6 +863,43 @@ func (a *Agent) InstallService() error { return service.Control(s, "install") } +func (a *Agent) GetAgentCheckInConfig(ret AgentCheckInConfig) AgentCheckInConfig { + // if local config present, overwrite + k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS) + if err == nil { + if checkInHello, _, err := k.GetStringValue("CheckInHello"); err == nil { + ret.Hello = regRangeToInt(checkInHello) + } + if checkInAgentInfo, _, err := k.GetStringValue("CheckInAgentInfo"); err == nil { + ret.AgentInfo = regRangeToInt(checkInAgentInfo) + } + if checkInWinSvc, _, err := k.GetStringValue("CheckInWinSvc"); err == nil { + ret.WinSvc = regRangeToInt(checkInWinSvc) + } + if checkInPubIP, _, err := k.GetStringValue("CheckInPubIP"); err == nil { + ret.PubIP = regRangeToInt(checkInPubIP) + } + if checkInDisks, _, err := k.GetStringValue("CheckInDisks"); err == nil { + ret.Disks = regRangeToInt(checkInDisks) + } + if checkInSW, _, err := k.GetStringValue("CheckInSW"); err == nil { + ret.SW = regRangeToInt(checkInSW) + } + if checkInWMI, _, err := k.GetStringValue("CheckInWMI"); err == nil { + ret.WMI = regRangeToInt(checkInWMI) + } + if checkInSyncMesh, _, err := k.GetStringValue("CheckInSyncMesh"); err == nil { + ret.SyncMesh = regRangeToInt(checkInSyncMesh) + } + if checkInLimitData, _, err := k.GetStringValue("CheckInLimitData"); err == nil { + if checkInLimitData == "true" { + ret.LimitData = true + } + } + } + return ret +} + // TODO add to stub func (a *Agent) NixMeshNodeID() string { return "not implemented" diff --git a/agent/svc.go b/agent/svc.go index 24d72d8..cdaa11e 100644 --- a/agent/svc.go +++ b/agent/svc.go @@ -55,7 +55,8 @@ func (a *Agent) AgentSvc(nc *nats.Conn) { a.Logger.Debugf("AgentSvc() sleeping for %v seconds", sleepDelay) time.Sleep(time.Duration(sleepDelay) * time.Second) - conf := a.GetAgentCheckInConfig() + conf := a.GetAgentCheckInConfig(a.GetCheckInConfFromAPI()) + a.Logger.Debugf("+%v\n", conf) for _, s := range natsCheckin { if conf.LimitData && stringInSlice(s, limitNatsData) { continue @@ -113,7 +114,7 @@ func (a *Agent) AgentStartup() { } } -func (a *Agent) GetAgentCheckInConfig() AgentCheckInConfig { +func (a *Agent) GetCheckInConfFromAPI() AgentCheckInConfig { ret := AgentCheckInConfig{} url := fmt.Sprintf("/api/v3/%s/config/", a.AgentID) r, err := a.rClient.R().SetResult(&AgentCheckInConfig{}).Get(url) @@ -128,17 +129,16 @@ func (a *Agent) GetAgentCheckInConfig() AgentCheckInConfig { ret.WMI = randRange(3000, 4000) ret.SyncMesh = randRange(800, 1200) ret.LimitData = false - return ret + } else { + ret.Hello = r.Result().(*AgentCheckInConfig).Hello + ret.AgentInfo = r.Result().(*AgentCheckInConfig).AgentInfo + ret.WinSvc = r.Result().(*AgentCheckInConfig).WinSvc + ret.PubIP = r.Result().(*AgentCheckInConfig).PubIP + ret.Disks = r.Result().(*AgentCheckInConfig).Disks + ret.SW = r.Result().(*AgentCheckInConfig).SW + ret.WMI = r.Result().(*AgentCheckInConfig).WMI + ret.SyncMesh = r.Result().(*AgentCheckInConfig).SyncMesh + ret.LimitData = r.Result().(*AgentCheckInConfig).LimitData } - ret.Hello = r.Result().(*AgentCheckInConfig).Hello - ret.AgentInfo = r.Result().(*AgentCheckInConfig).AgentInfo - ret.WinSvc = r.Result().(*AgentCheckInConfig).WinSvc - ret.PubIP = r.Result().(*AgentCheckInConfig).PubIP - ret.Disks = r.Result().(*AgentCheckInConfig).Disks - ret.SW = r.Result().(*AgentCheckInConfig).SW - ret.WMI = r.Result().(*AgentCheckInConfig).WMI - ret.SyncMesh = r.Result().(*AgentCheckInConfig).SyncMesh - ret.LimitData = r.Result().(*AgentCheckInConfig).LimitData - a.Logger.Debugf("%+v\n", r) return ret } diff --git a/agent/utils.go b/agent/utils.go index ede7753..3e84288 100644 --- a/agent/utils.go +++ b/agent/utils.go @@ -23,6 +23,7 @@ import ( "path/filepath" "runtime" goDebug "runtime/debug" + "strconv" "strings" "time" @@ -331,3 +332,10 @@ func stringInSlice(a string, list []string) bool { } return false } + +func regRangeToInt(s string) int { + split := strings.Split(s, ",") + min, _ := strconv.Atoi(split[0]) + max, _ := strconv.Atoi(split[1]) + return randRange(min, max) +} From 3cb6b92a804f4ca4bcad67905844c4e6c43ca4a9 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Fri, 2 Dec 2022 23:34:09 -0800 Subject: [PATCH 12/14] tidy --- go.sum | 5 ----- 1 file changed, 5 deletions(-) diff --git a/go.sum b/go.sum index d35e81e..bc6b194 100644 --- a/go.sum +++ b/go.sum @@ -57,8 +57,6 @@ github.com/creachadair/staticfile v0.1.3/go.mod h1:a3qySzCIXEprDGxk6tSxSI+dBBdLz github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/elastic/go-sysinfo v1.8.1 h1:4Yhj+HdV6WjbCRgGdZpPJ8lZQlXZLKDAeIkmQ/VRvi4= -github.com/elastic/go-sysinfo v1.8.1/go.mod h1:JfllUnzoQV/JRYymbH3dO1yggI3mV2oTKSXsDHM+uIM= github.com/elastic/go-sysinfo v1.9.0 h1:usICqY/Nw4Mpn9f4LdtpFrKxXroJDe81GaxxUlCckIo= github.com/elastic/go-sysinfo v1.9.0/go.mod h1:eBD1wEGVaRnRLGecc9iG1z8eOv5HnEdz9+nWd8UAxcE= github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0= @@ -245,8 +243,6 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:Om github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c h1:NRoLoZvkBTKvR5gQLgA3e0hqjkY9u1wm+iOL45VN/qI= github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= -github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= github.com/rickb777/date v1.14.2/go.mod h1:swmf05C+hN+m8/Xh7gEq3uB6QJDNc5pQBWojKdHetOs= @@ -459,7 +455,6 @@ golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= From 524837627fbc7208078f32b0591c801a20303f78 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 3 Dec 2022 01:58:42 -0800 Subject: [PATCH 13/14] add env for script checks --- agent/checks.go | 2 +- shared/types.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/agent/checks.go b/agent/checks.go index ec44b04..00925d7 100644 --- a/agent/checks.go +++ b/agent/checks.go @@ -169,7 +169,7 @@ type ScriptCheckResult struct { // ScriptCheck runs either bat, powershell or python script func (a *Agent) ScriptCheck(data rmm.Check, r *resty.Client) { start := time.Now() - stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser, data.Script.EnvVars) + stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser, data.EnvVars) payload := ScriptCheckResult{ ID: data.CheckPK, diff --git a/shared/types.go b/shared/types.go index f857ccb..5ff983d 100644 --- a/shared/types.go +++ b/shared/types.go @@ -163,6 +163,7 @@ type Check struct { Disk string `json:"disk"` IP string `json:"ip"` ScriptArgs []string `json:"script_args"` + EnvVars []string `json:"env_vars"` Timeout int `json:"timeout"` ServiceName string `json:"svc_name"` PassStartPending bool `json:"pass_if_start_pending"` From 63fe3bcd73f0f9b9e89724ff4237885d200fb3d9 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 4 Dec 2022 15:09:48 -0800 Subject: [PATCH 14/14] bump versions --- build/rmm.exe.manifest | 2 +- build/setup.iss | 2 +- main.go | 2 +- versioninfo.json | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build/rmm.exe.manifest b/build/rmm.exe.manifest index c18eeec..56445b7 100644 --- a/build/rmm.exe.manifest +++ b/build/rmm.exe.manifest @@ -3,7 +3,7 @@ diff --git a/build/setup.iss b/build/setup.iss index 9f61bec..1c1b1e3 100644 --- a/build/setup.iss +++ b/build/setup.iss @@ -1,5 +1,5 @@ #define MyAppName "Tactical RMM Agent" -#define MyAppVersion "2.4.2" +#define MyAppVersion "2.4.3" #define MyAppPublisher "AmidaWare LLC" #define MyAppURL "https://github.com/amidaware" #define MyAppExeName "tacticalrmm.exe" diff --git a/main.go b/main.go index 52f95ce..1e2c402 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( ) var ( - version = "2.4.3-dev" + version = "2.4.3" log = logrus.New() logFile *os.File ) diff --git a/versioninfo.json b/versioninfo.json index 6cb8e61..695415b 100644 --- a/versioninfo.json +++ b/versioninfo.json @@ -3,13 +3,13 @@ "FileVersion": { "Major": 2, "Minor": 4, - "Patch": 2, + "Patch": 3, "Build": 0 }, "ProductVersion": { "Major": 2, "Minor": 4, - "Patch": 2, + "Patch": 3, "Build": 0 }, "FileFlagsMask": "3f", @@ -22,14 +22,14 @@ "Comments": "", "CompanyName": "AmidaWare LLC", "FileDescription": "Tactical RMM Agent", - "FileVersion": "v2.4.2.0", + "FileVersion": "v2.4.3.0", "InternalName": "tacticalrmm.exe", "LegalCopyright": "Copyright (c) 2022 AmidaWare LLC", "LegalTrademarks": "", "OriginalFilename": "tacticalrmm.exe", "PrivateBuild": "", "ProductName": "Tactical RMM Agent", - "ProductVersion": "v2.4.2.0", + "ProductVersion": "v2.4.3.0", "SpecialBuild": "" }, "VarFileInfo": {