Release 2.3.0

This commit is contained in:
wh1te909 2022-08-09 13:18:55 -07:00
commit 14707d78c9
9 changed files with 81 additions and 70 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*"}
for _, glob := range globs {
files, err := filepath.Glob(glob)
if err == nil { if err == nil {
for _, f := range files { for _, f := range files {
a.Logger.Debugln("CleanupAgentUpdates() Removing file:", f)
os.Remove(f) os.Remove(f)
} }
} }
agents, err := filepath.Glob("tacticalagent-v*.exe")
if err == nil {
for _, f := range agents {
os.Remove(f)
} }
} }
cderr = os.Chdir(os.Getenv("TMP")) err := os.Chdir(os.Getenv("TMP"))
if cderr != nil {
a.Logger.Errorln(cderr)
return
}
folders, err := filepath.Glob("tacticalrmm*")
if err == nil { if err == nil {
for _, f := range folders { dirs, err := filepath.Glob("tacticalrmm*")
if err == nil {
for _, f := range dirs {
os.RemoveAll(f) 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

@ -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()
@ -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"

View File

@ -86,9 +86,10 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int,
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
@ -110,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
@ -576,13 +577,15 @@ 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.Debugln("Downloading agent update from", url) a.Logger.Debugln("Downloading agent update from", url)
@ -605,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...)
@ -658,12 +654,11 @@ 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, false)
if err != nil { if err != nil {
a.Logger.Debugln(err) a.Logger.Debugln(err)

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

@ -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

@ -3,7 +3,7 @@
<assemblyIdentity <assemblyIdentity
type="win32" type="win32"
name="TacticalRMM" name="TacticalRMM"
version="2.2.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.2.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"

View File

@ -25,7 +25,7 @@ import (
) )
var ( var (
version = "2.2.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

@ -2,14 +2,14 @@
"FixedFileInfo": { "FixedFileInfo": {
"FileVersion": { "FileVersion": {
"Major": 2, "Major": 2,
"Minor": 2, "Minor": 3,
"Patch": 1, "Patch": 0,
"Build": 0 "Build": 0
}, },
"ProductVersion": { "ProductVersion": {
"Major": 2, "Major": 2,
"Minor": 2, "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.2.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.2.1.0", "ProductVersion": "v2.3.0.0",
"SpecialBuild": "" "SpecialBuild": ""
}, },
"VarFileInfo": { "VarFileInfo": {