17 Commits

Author SHA1 Message Date
wh1te909
14707d78c9 Release 2.3.0 2022-08-09 13:18:55 -07:00
wh1te909
89d7ec8242 bump versions 2022-08-09 13:17:02 -07:00
wh1te909
7b8d524a81 still need program files 2022-08-09 13:07:25 -07:00
wh1te909
662c41794b better cleanup 2022-08-09 12:41:07 -07:00
wh1te909
607a5283ac add helper func to get env 2022-08-09 12:40:42 -07:00
wh1te909
41597d7d26 standardize windows temp dir fixes amidaware/tacticalrmm#1238 2022-08-09 10:33:30 -07:00
wh1te909
381f9696eb fix agent update when selinux is enforcing fixes amidaware/tacticalrmm#1239 2022-08-08 23:07:34 +00:00
wh1te909
f6ec32a8d6 Release 2.2.1 2022-08-01 15:44:59 -07:00
wh1te909
adee74ffd0 bump version 2022-08-01 15:42:28 -07:00
wh1te909
0c536f13b0 fix wrong token type 2022-08-01 15:42:01 -07:00
wh1te909
1c1fb0af99 Release 2.2.0 2022-08-01 10:14:20 -07:00
wh1te909
5bf3ef5356 bump version 2022-08-01 10:13:58 -07:00
wh1te909
50cebb950d run as user 2022-07-31 15:14:05 -07:00
wh1te909
82ad6be3aa Merge branch 'develop' 2022-07-26 23:22:40 -07:00
wh1te909
ad1ae2a6a1 bump version 2022-07-26 23:20:39 -07:00
wh1te909
eb386a4ee2 update logrus 2022-07-25 21:33:13 -07:00
wh1te909
1fbf2be562 only log the url during debug 2022-07-25 21:31:52 -07:00
16 changed files with 144 additions and 108 deletions

View File

@@ -78,6 +78,8 @@ const (
meshSvcName = "mesh agent" meshSvcName = "mesh agent"
) )
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 natsCheckin = []string{"agent-hello", "agent-agentinfo", "agent-disks", "agent-winsvc", "agent-publicip", "agent-wmi"}
func New(logger *logrus.Logger, version string) *Agent { func New(logger *logrus.Logger, version string) *Agent {
@@ -402,54 +404,47 @@ func (a *Agent) GetUninstallExe() string {
} }
func (a *Agent) CleanupAgentUpdates() { func (a *Agent) CleanupAgentUpdates() {
cderr := os.Chdir(a.ProgramDir) // TODO remove a.ProgramDir, updates are now in winTempDir
if cderr != nil { dirs := [2]string{winTempDir, a.ProgramDir}
a.Logger.Errorln(cderr) for _, dir := range dirs {
return err := os.Chdir(dir)
} if err != nil {
a.Logger.Debugln("CleanupAgentUpdates()", dir, err)
continue
}
// winagent-v* is deprecated // TODO winagent-v* is deprecated
files, err := filepath.Glob("winagent-v*.exe") globs := [2]string{"tacticalagent-v*", "winagent-v*"}
if err == nil { for _, glob := range globs {
for _, f := range files { files, err := filepath.Glob(glob)
os.Remove(f) if err == nil {
for _, f := range files {
a.Logger.Debugln("CleanupAgentUpdates() Removing file:", f)
os.Remove(f)
}
}
} }
} }
agents, err := filepath.Glob("tacticalagent-v*.exe") err := os.Chdir(os.Getenv("TMP"))
if err == nil { if err == nil {
for _, f := range agents { dirs, err := filepath.Glob("tacticalrmm*")
os.Remove(f) if err == nil {
} for _, f := range dirs {
} os.RemoveAll(f)
}
cderr = os.Chdir(os.Getenv("TMP"))
if cderr != nil {
a.Logger.Errorln(cderr)
return
}
folders, err := filepath.Glob("tacticalrmm*")
if err == nil {
for _, f := range folders {
os.RemoveAll(f)
} }
} }
} }
func (a *Agent) RunPythonCode(code string, timeout int, args []string) (string, error) { func (a *Agent) RunPythonCode(code string, timeout int, args []string) (string, error) {
content := []byte(code) content := []byte(code)
dir, err := ioutil.TempDir("", "tacticalpy") tmpfn, _ := ioutil.TempFile(winTempDir, "*.py")
if err != nil {
a.Logger.Debugln(err)
return "", err
}
defer os.RemoveAll(dir)
tmpfn, _ := ioutil.TempFile(dir, "*.py")
if _, err := tmpfn.Write(content); err != nil { if _, err := tmpfn.Write(content); err != nil {
a.Logger.Debugln(err) a.Logger.Debugln(err)
return "", err return "", err
} }
defer os.Remove(tmpfn.Name())
if err := tmpfn.Close(); err != nil { if err := tmpfn.Close(); err != nil {
a.Logger.Debugln(err) a.Logger.Debugln(err)
return "", err return "", err
@@ -489,13 +484,12 @@ func (a *Agent) RunPythonCode(code string, timeout int, args []string) (string,
} }
func (a *Agent) CreateTRMMTempDir() { func createWinTempDir() error {
// create the temp dir for running scripts if !trmm.FileExists(winTempDir) {
dir := filepath.Join(os.TempDir(), "trmm") err := os.Mkdir(winTempDir, 0775)
if !trmm.FileExists(dir) {
err := os.Mkdir(dir, 0775)
if err != nil { if err != nil {
a.Logger.Errorln(err) return err
} }
} }
return nil
} }

View File

@@ -162,7 +162,7 @@ func NewAgentConfig() *rmm.AgentConfig {
return ret return ret
} }
func (a *Agent) RunScript(code string, shell string, args []string, timeout int) (stdout, stderr string, exitcode int, e error) { func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) {
code = removeWinNewLines(code) code = removeWinNewLines(code)
content := []byte(code) content := []byte(code)
@@ -209,6 +209,13 @@ func SetDetached() *syscall.SysProcAttr {
return &syscall.SysProcAttr{Setpgid: true} return &syscall.SysProcAttr{Setpgid: true}
} }
func (a *Agent) seEnforcing() bool {
opts := a.NewCMDOpts()
opts.Command = "getenforce"
out := a.CmdV2(opts)
return out.Status.Exit == 0 && strings.Contains(out.Stdout, "Enforcing")
}
func (a *Agent) AgentUpdate(url, inno, version string) { func (a *Agent) AgentUpdate(url, inno, version string) {
self, err := os.Executable() self, err := os.Executable()
@@ -225,7 +232,7 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
defer os.Remove(f.Name()) defer os.Remove(f.Name())
a.Logger.Infof("Agent updating from %s to %s", a.Version, version) a.Logger.Infof("Agent updating from %s to %s", a.Version, version)
a.Logger.Infoln("Downloading agent update from", url) a.Logger.Debugln("Downloading agent update from", url)
rClient := resty.New() rClient := resty.New()
rClient.SetCloseConnection(true) rClient.SetCloseConnection(true)
@@ -276,6 +283,13 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
} }
} }
if a.seEnforcing() {
se := a.NewCMDOpts()
se.Command = fmt.Sprintf("restorecon -rv %s", self)
out := a.CmdV2(se)
a.Logger.Debugln("%+v\n", out)
}
opts := a.NewCMDOpts() opts := a.NewCMDOpts()
opts.Detached = true opts.Detached = true
opts.Command = "systemctl restart tacticalagent.service" opts.Command = "systemctl restart tacticalagent.service"
@@ -507,7 +521,7 @@ func (a *Agent) installMesh(meshbin, exe, proxy string) (string, error) {
return "not implemented", nil return "not implemented", nil
} }
func CMDShell(shell string, cmdArgs []string, command string, timeout int, detached bool) (output [2]string, e error) { func CMDShell(shell string, cmdArgs []string, command string, timeout int, detached bool, runasuser bool) (output [2]string, e error) {
return [2]string{"", ""}, nil return [2]string{"", ""}, nil
} }

View File

@@ -30,6 +30,7 @@ import (
rmm "github.com/amidaware/rmmagent/shared" rmm "github.com/amidaware/rmmagent/shared"
ps "github.com/elastic/go-sysinfo" ps "github.com/elastic/go-sysinfo"
"github.com/fourcorelabs/wintoken"
"github.com/go-ole/go-ole" "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil" "github.com/go-ole/go-ole/oleutil"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@@ -81,13 +82,14 @@ func NewAgentConfig() *rmm.AgentConfig {
} }
} }
func (a *Agent) RunScript(code string, shell string, args []string, timeout int) (stdout, stderr string, exitcode int, e error) { func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) {
content := []byte(code) content := []byte(code)
dir := filepath.Join(os.TempDir(), "trmm") err := createWinTempDir()
if !trmm.FileExists(dir) { if err != nil {
a.CreateTRMMTempDir() a.Logger.Errorln(err)
return "", err.Error(), 85, err
} }
const defaultExitCode = 1 const defaultExitCode = 1
@@ -109,7 +111,7 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int)
ext = "*.bat" ext = "*.bat"
} }
tmpfn, err := ioutil.TempFile(dir, ext) tmpfn, err := ioutil.TempFile(winTempDir, ext)
if err != nil { if err != nil {
a.Logger.Errorln(err) a.Logger.Errorln(err)
return "", err.Error(), 85, err return "", err.Error(), 85, err
@@ -143,8 +145,16 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
defer cancel() defer cancel()
var timedOut bool = false var timedOut = false
cmd := exec.Command(exe, cmdArgs...) cmd := exec.Command(exe, cmdArgs...)
if runasuser {
token, err := wintoken.GetInteractiveToken(wintoken.TokenImpersonation)
if err != nil {
return "", err.Error(), 66, err
}
defer token.Close()
cmd.SysProcAttr = &syscall.SysProcAttr{Token: syscall.Token(token.Token()), HideWindow: true}
}
cmd.Stdout = &outb cmd.Stdout = &outb
cmd.Stderr = &errb cmd.Stderr = &errb
@@ -230,7 +240,7 @@ func CMD(exe string, args []string, timeout int, detached bool) (output [2]strin
return [2]string{CleanString(outb.String()), CleanString(errb.String())}, nil return [2]string{CleanString(outb.String()), CleanString(errb.String())}, nil
} }
func CMDShell(shell string, cmdArgs []string, command string, timeout int, detached bool) (output [2]string, e error) { func CMDShell(shell string, cmdArgs []string, command string, timeout int, detached bool, runasuser bool) (output [2]string, e error) {
var ( var (
outb bytes.Buffer outb bytes.Buffer
errb bytes.Buffer errb bytes.Buffer
@@ -241,6 +251,8 @@ func CMDShell(shell string, cmdArgs []string, command string, timeout int, detac
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
defer cancel() defer cancel()
sysProcAttr := &windows.SysProcAttr{}
if len(cmdArgs) > 0 && command == "" { if len(cmdArgs) > 0 && command == "" {
switch shell { switch shell {
case "cmd": case "cmd":
@@ -254,9 +266,7 @@ func CMDShell(shell string, cmdArgs []string, command string, timeout int, detac
switch shell { switch shell {
case "cmd": case "cmd":
cmd = exec.Command("cmd.exe") cmd = exec.Command("cmd.exe")
cmd.SysProcAttr = &windows.SysProcAttr{ sysProcAttr.CmdLine = fmt.Sprintf("cmd.exe /C %s", command)
CmdLine: fmt.Sprintf("cmd.exe /C %s", command),
}
case "powershell": case "powershell":
cmd = exec.Command("Powershell", "-NonInteractive", "-NoProfile", command) cmd = exec.Command("Powershell", "-NonInteractive", "-NoProfile", command)
} }
@@ -264,10 +274,20 @@ func CMDShell(shell string, cmdArgs []string, command string, timeout int, detac
// https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags // https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
if detached { if detached {
cmd.SysProcAttr = &windows.SysProcAttr{ sysProcAttr.CreationFlags = windows.DETACHED_PROCESS | windows.CREATE_NEW_PROCESS_GROUP
CreationFlags: windows.DETACHED_PROCESS | windows.CREATE_NEW_PROCESS_GROUP,
}
} }
if runasuser {
token, err := wintoken.GetInteractiveToken(wintoken.TokenImpersonation)
if err != nil {
return [2]string{"", CleanString(err.Error())}, err
}
defer token.Close()
sysProcAttr.Token = syscall.Token(token.Token())
sysProcAttr.HideWindow = true
}
cmd.SysProcAttr = sysProcAttr
cmd.Stdout = &outb cmd.Stdout = &outb
cmd.Stderr = &errb cmd.Stderr = &errb
cmd.Start() cmd.Start()
@@ -449,7 +469,7 @@ func (a *Agent) PlatVer() (string, error) {
func EnablePing() { func EnablePing() {
args := make([]string, 0) args := make([]string, 0)
cmd := `netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow` cmd := `netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow`
_, err := CMDShell("cmd", args, cmd, 10, false) _, err := CMDShell("cmd", args, cmd, 10, false, false)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@@ -470,7 +490,7 @@ func EnableRDP() {
args := make([]string, 0) args := make([]string, 0)
cmd := `netsh advfirewall firewall set rule group="remote desktop" new enable=Yes` cmd := `netsh advfirewall firewall set rule group="remote desktop" new enable=Yes`
_, cerr := CMDShell("cmd", args, cmd, 10, false) _, cerr := CMDShell("cmd", args, cmd, 10, false, false)
if cerr != nil { if cerr != nil {
fmt.Println(cerr) fmt.Println(cerr)
} }
@@ -497,15 +517,15 @@ func DisableSleepHibernate() {
wg.Add(1) wg.Add(1)
go func(c string) { go func(c string) {
defer wg.Done() defer wg.Done()
_, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /set%svalueindex scheme_current sub_buttons lidaction 0", c), 5, false) _, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /set%svalueindex scheme_current sub_buttons lidaction 0", c), 5, false, false)
_, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -standby-timeout-%s 0", c), 5, false) _, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -standby-timeout-%s 0", c), 5, false, false)
_, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -hibernate-timeout-%s 0", c), 5, false) _, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -hibernate-timeout-%s 0", c), 5, false, false)
_, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -disk-timeout-%s 0", c), 5, false) _, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -disk-timeout-%s 0", c), 5, false, false)
_, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -monitor-timeout-%s 0", c), 5, false) _, _ = CMDShell("cmd", args, fmt.Sprintf("powercfg /x -monitor-timeout-%s 0", c), 5, false, false)
}(i) }(i)
} }
wg.Wait() wg.Wait()
_, _ = CMDShell("cmd", args, "powercfg -S SCHEME_CURRENT", 5, false) _, _ = CMDShell("cmd", args, "powercfg -S SCHEME_CURRENT", 5, false, false)
} }
// NewCOMObject creates a new COM object for the specifed ProgramID. // NewCOMObject creates a new COM object for the specifed ProgramID.
@@ -557,15 +577,17 @@ func (a *Agent) UninstallCleanup() {
a.PatchMgmnt(false) a.PatchMgmnt(false)
a.CleanupAgentUpdates() a.CleanupAgentUpdates()
CleanupSchedTasks() CleanupSchedTasks()
os.RemoveAll(winTempDir)
} }
func (a *Agent) AgentUpdate(url, inno, version string) { func (a *Agent) AgentUpdate(url, inno, version string) {
time.Sleep(time.Duration(randRange(1, 15)) * time.Second) time.Sleep(time.Duration(randRange(1, 15)) * time.Second)
a.KillHungUpdates() a.KillHungUpdates()
time.Sleep(1 * time.Second)
a.CleanupAgentUpdates() a.CleanupAgentUpdates()
updater := filepath.Join(a.ProgramDir, inno) updater := filepath.Join(winTempDir, inno)
a.Logger.Infof("Agent updating from %s to %s", a.Version, version) a.Logger.Infof("Agent updating from %s to %s", a.Version, version)
a.Logger.Infoln("Downloading agent update from", url) a.Logger.Debugln("Downloading agent update from", url)
rClient := resty.New() rClient := resty.New()
rClient.SetCloseConnection(true) rClient.SetCloseConnection(true)
@@ -586,14 +608,7 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
return return
} }
dir, err := ioutil.TempDir("", "tacticalrmm") innoLogFile := filepath.Join(winTempDir, fmt.Sprintf("tacticalagent_update_v%s.txt", version))
if err != nil {
a.Logger.Errorln("Agentupdate create tempdir:", err)
CMD("net", []string{"start", winSvcName}, 10, false)
return
}
innoLogFile := filepath.Join(dir, "tacticalrmm.txt")
args := []string{"/C", updater, "/VERYSILENT", fmt.Sprintf("/LOG=%s", innoLogFile)} args := []string{"/C", updater, "/VERYSILENT", fmt.Sprintf("/LOG=%s", innoLogFile)}
cmd := exec.Command("cmd.exe", args...) cmd := exec.Command("cmd.exe", args...)
@@ -639,13 +654,12 @@ func (a *Agent) AgentUninstall(code string) {
} }
func (a *Agent) addDefenderExlusions() { func (a *Agent) addDefenderExlusions() {
code := ` code := fmt.Sprintf(`
Add-MpPreference -ExclusionPath 'C:\Program Files\TacticalAgent\*' Add-MpPreference -ExclusionPath '%s\*'
Add-MpPreference -ExclusionPath 'C:\Windows\Temp\tacticalagent-v*.exe' Add-MpPreference -ExclusionPath '%s\*'
Add-MpPreference -ExclusionPath 'C:\Windows\Temp\trmm\*' Add-MpPreference -ExclusionPath '%s\*'
Add-MpPreference -ExclusionPath 'C:\Program Files\Mesh Agent\*' `, winTempDir, a.ProgramDir, winMeshDir)
` _, _, _, err := a.RunScript(code, "powershell", []string{}, 20, false)
_, _, _, err := a.RunScript(code, "powershell", []string{}, 20)
if err != nil { if err != nil {
a.Logger.Debugln(err) a.Logger.Debugln(err)
} }

View File

@@ -169,7 +169,7 @@ type ScriptCheckResult struct {
// ScriptCheck runs either bat, powershell or python script // ScriptCheck runs either bat, powershell or python script
func (a *Agent) ScriptCheck(data rmm.Check, r *resty.Client) { func (a *Agent) ScriptCheck(data rmm.Check, r *resty.Client) {
start := time.Now() start := time.Now()
stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout) stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser)
payload := ScriptCheckResult{ payload := ScriptCheckResult{
ID: data.CheckPK, ID: data.CheckPK,

View File

@@ -42,7 +42,7 @@ func (a *Agent) InstallChoco() {
return return
} }
_, _, exitcode, err := a.RunScript(string(r.Body()), "powershell", []string{}, 900) _, _, exitcode, err := a.RunScript(string(r.Body()), "powershell", []string{}, 900, false)
if err != nil { if err != nil {
a.Logger.Debugln(err) a.Logger.Debugln(err)
a.rClient.R().SetBody(result).Post(url) a.rClient.R().SetBody(result).Post(url)

View File

@@ -224,13 +224,16 @@ func (a *Agent) Install(i *Installer) {
a.SendSoftware() a.SendSoftware()
a.Logger.Debugln("Creating temp dir") a.Logger.Debugln("Creating temp dir")
a.CreateTRMMTempDir() err := createWinTempDir()
if err != nil {
a.Logger.Errorln("Install() createWinTempDir():", err)
}
a.Logger.Debugln("Disabling automatic windows updates") a.Logger.Debugln("Disabling automatic windows updates")
a.PatchMgmnt(true) a.PatchMgmnt(true)
a.Logger.Infoln("Installing service...") a.Logger.Infoln("Installing service...")
err := a.InstallService() err = a.InstallService()
if err != nil { if err != nil {
a.installerMsg(err.Error(), "error", i.Silent) a.installerMsg(err.Error(), "error", i.Silent)
} }

View File

@@ -40,6 +40,7 @@ type NatsMsg struct {
PatchMgmt bool `json:"patch_mgmt"` PatchMgmt bool `json:"patch_mgmt"`
ID int `json:"id"` ID int `json:"id"`
Code string `json:"code"` Code string `json:"code"`
RunAsUser bool `json:"run_as_user"`
} }
var ( var (
@@ -177,7 +178,7 @@ func (a *Agent) RunRPC() {
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
out, _ := CMDShell(p.Data["shell"], []string{}, p.Data["command"], p.Timeout, false) out, _ := CMDShell(p.Data["shell"], []string{}, p.Data["command"], p.Timeout, false, p.RunAsUser)
a.Logger.Debugln(out) a.Logger.Debugln(out)
if out[1] != "" { if out[1] != "" {
ret.Encode(out[1]) ret.Encode(out[1])
@@ -257,7 +258,7 @@ func (a *Agent) RunRPC() {
var resultData rmm.RunScriptResp var resultData rmm.RunScriptResp
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
start := time.Now() start := time.Now()
stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout) stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser)
resultData.ExecTime = time.Since(start).Seconds() resultData.ExecTime = time.Since(start).Seconds()
resultData.ID = p.ID resultData.ID = p.ID
@@ -287,7 +288,7 @@ func (a *Agent) RunRPC() {
var retData rmm.RunScriptResp var retData rmm.RunScriptResp
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle)) ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
start := time.Now() start := time.Now()
stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout) stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser)
retData.ExecTime = time.Since(start).Seconds() retData.ExecTime = time.Since(start).Seconds()
if err != nil { if err != nil {

View File

@@ -29,7 +29,10 @@ func (a *Agent) RunAsService() {
func (a *Agent) AgentSvc() { func (a *Agent) AgentSvc() {
go a.GetPython(false) go a.GetPython(false)
a.CreateTRMMTempDir() err := createWinTempDir()
if err != nil {
a.Logger.Errorln("AgentSvc() createWinTempDir():", err)
}
a.RunMigrations() a.RunMigrations()
sleepDelay := randRange(14, 22) sleepDelay := randRange(14, 22)

View File

@@ -59,7 +59,7 @@ func (a *Agent) RunTask(id int) error {
action_start := time.Now() action_start := time.Now()
if action.ActionType == "script" { if action.ActionType == "script" {
stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout) stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout, action.RunAsUser)
if err != nil { if err != nil {
a.Logger.Debugln(err) a.Logger.Debugln(err)
@@ -83,7 +83,7 @@ func (a *Agent) RunTask(id int) error {
} else if action.ActionType == "cmd" { } else if action.ActionType == "cmd" {
// out[0] == stdout, out[1] == stderr // out[0] == stdout, out[1] == stderr
out, err := CMDShell(action.Shell, []string{}, action.Command, action.Timeout, false) out, err := CMDShell(action.Shell, []string{}, action.Command, action.Timeout, false, action.RunAsUser)
if err != nil { if err != nil {
a.Logger.Debugln(err) a.Logger.Debugln(err)

View File

@@ -3,7 +3,7 @@
<assemblyIdentity <assemblyIdentity
type="win32" type="win32"
name="TacticalRMM" name="TacticalRMM"
version="2.1.1.0" version="2.3.0.0"
processorArchitecture="*"/> processorArchitecture="*"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security> <security>

View File

@@ -1,5 +1,5 @@
#define MyAppName "Tactical RMM Agent" #define MyAppName "Tactical RMM Agent"
#define MyAppVersion "2.1.1" #define MyAppVersion "2.3.0"
#define MyAppPublisher "AmidaWare LLC" #define MyAppPublisher "AmidaWare LLC"
#define MyAppURL "https://github.com/amidaware" #define MyAppURL "https://github.com/amidaware"
#define MyAppExeName "tacticalrmm.exe" #define MyAppExeName "tacticalrmm.exe"

5
go.mod
View File

@@ -14,12 +14,12 @@ require (
github.com/nats-io/nats.go v1.16.0 github.com/nats-io/nats.go v1.16.0
github.com/rickb777/date v1.19.1 github.com/rickb777/date v1.19.1
github.com/shirou/gopsutil/v3 v3.22.6 github.com/shirou/gopsutil/v3 v3.22.6
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.9.0
github.com/ugorji/go/codec v1.2.7 github.com/ugorji/go/codec v1.2.7
github.com/wh1te909/go-win64api v0.0.0-20210906074314-ab23795a6ae5 github.com/wh1te909/go-win64api v0.0.0-20210906074314-ab23795a6ae5
github.com/wh1te909/trmm-shared v0.0.0-20220227075846-f9f757361139 github.com/wh1te909/trmm-shared v0.0.0-20220227075846-f9f757361139
golang.org/x/net v0.0.0-20220706163947-c90051bbdb60 // indirect golang.org/x/net v0.0.0-20220706163947-c90051bbdb60 // indirect
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10
) )
require ( require (
@@ -28,6 +28,7 @@ require (
) )
require ( require (
github.com/fourcorelabs/wintoken v1.0.0
github.com/jaypipes/ghw v0.9.0 github.com/jaypipes/ghw v0.9.0
github.com/kardianos/service v1.2.1 github.com/kardianos/service v1.2.1
github.com/spf13/viper v1.12.0 github.com/spf13/viper v1.12.0

12
go.sum
View File

@@ -67,6 +67,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fourcorelabs/wintoken v1.0.0 h1:dskUYLAFHNy1cbS5MXsNFXauQzxieTrZlffQZ0Yu19I=
github.com/fourcorelabs/wintoken v1.0.0/go.mod h1:jKyXHt079W09KwEMbUC9g+R2KDs5kVvSKPUiF5p0ejs=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -257,8 +259,8 @@ github.com/scjalliance/comshim v0.0.0-20190308082608-cf06d2532c4e h1:+/AzLkOdIXE
github.com/scjalliance/comshim v0.0.0-20190308082608-cf06d2532c4e/go.mod h1:9Tc1SKnfACJb9N7cw2eyuI6xzy845G7uZONBsi5uPEA= github.com/scjalliance/comshim v0.0.0-20190308082608-cf06d2532c4e/go.mod h1:9Tc1SKnfACJb9N7cw2eyuI6xzy845G7uZONBsi5uPEA=
github.com/shirou/gopsutil/v3 v3.22.6 h1:FnHOFOh+cYAM0C30P+zysPISzlknLC5Z1G4EAElznfQ= github.com/shirou/gopsutil/v3 v3.22.6 h1:FnHOFOh+cYAM0C30P+zysPISzlknLC5Z1G4EAElznfQ=
github.com/shirou/gopsutil/v3 v3.22.6/go.mod h1:EdIubSnZhbAvBS1yJ7Xi+AShB/hxwLHOMz4MCYz7yMs= github.com/shirou/gopsutil/v3 v3.22.6/go.mod h1:EdIubSnZhbAvBS1yJ7Xi+AShB/hxwLHOMz4MCYz7yMs=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo= github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo=
github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo= github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
@@ -426,7 +428,6 @@ golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -467,8 +468,9 @@ golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e h1:CsOuNlbOuf0mzxJIefr6Q4uAUetRUwZE4qt7VfzP+xo= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@@ -25,7 +25,7 @@ import (
) )
var ( var (
version = "2.1.1" version = "2.3.0"
log = logrus.New() log = logrus.New()
logFile *os.File logFile *os.File
) )
@@ -85,6 +85,8 @@ func main() {
a.Logger.Debugf("%+v\n", a) a.Logger.Debugf("%+v\n", a)
switch *mode { switch *mode {
case "getenv":
fmt.Println(os.Getenv(flag.Arg(0)))
case "nixmeshnodeid": case "nixmeshnodeid":
fmt.Print(a.NixMeshNodeID()) fmt.Print(a.NixMeshNodeID())
case "installsvc": case "installsvc":

View File

@@ -141,8 +141,9 @@ type AssignedTask struct {
} }
type Script struct { type Script struct {
Shell string `json:"shell"` Shell string `json:"shell"`
Code string `json:"code"` Code string `json:"code"`
RunAsUser bool `json:"run_as_user"`
} }
type CheckInfo struct { type CheckInfo struct {
@@ -188,6 +189,7 @@ type TaskAction struct {
Code string `json:"code"` Code string `json:"code"`
Args []string `json:"script_args"` Args []string `json:"script_args"`
Timeout int `json:"timeout"` Timeout int `json:"timeout"`
RunAsUser bool `json:"run_as_user"`
} }
type AutomatedTask struct { type AutomatedTask struct {

View File

@@ -2,14 +2,14 @@
"FixedFileInfo": { "FixedFileInfo": {
"FileVersion": { "FileVersion": {
"Major": 2, "Major": 2,
"Minor": 1, "Minor": 3,
"Patch": 1, "Patch": 0,
"Build": 0 "Build": 0
}, },
"ProductVersion": { "ProductVersion": {
"Major": 2, "Major": 2,
"Minor": 1, "Minor": 3,
"Patch": 1, "Patch": 0,
"Build": 0 "Build": 0
}, },
"FileFlagsMask": "3f", "FileFlagsMask": "3f",
@@ -22,14 +22,14 @@
"Comments": "", "Comments": "",
"CompanyName": "AmidaWare LLC", "CompanyName": "AmidaWare LLC",
"FileDescription": "Tactical RMM Agent", "FileDescription": "Tactical RMM Agent",
"FileVersion": "v2.1.1.0", "FileVersion": "v2.3.0.0",
"InternalName": "tacticalrmm.exe", "InternalName": "tacticalrmm.exe",
"LegalCopyright": "Copyright (c) 2022 AmidaWare LLC", "LegalCopyright": "Copyright (c) 2022 AmidaWare LLC",
"LegalTrademarks": "", "LegalTrademarks": "",
"OriginalFilename": "tacticalrmm.exe", "OriginalFilename": "tacticalrmm.exe",
"PrivateBuild": "", "PrivateBuild": "",
"ProductName": "Tactical RMM Agent", "ProductName": "Tactical RMM Agent",
"ProductVersion": "v2.1.1.0", "ProductVersion": "v2.3.0.0",
"SpecialBuild": "" "SpecialBuild": ""
}, },
"VarFileInfo": { "VarFileInfo": {