Updated windows update, so that it will attempt to kill any zombie processes

Bryan Roe committed Feb 5, 2021 at 14:45 UTC ee3c60a6bd646003e2b6ff86519ea638491a8051
2 files changed +12 -7
agents/meshcore.js
+9 -5
@@ -4012,13 +4012,16 @@ function bsd_execv(name, agentfilename, sessionid) {
4012 sendAgentMessage('Self Update failed because execv() failed', 3);
4013 }
4014
4015 -function windows_execve(name, agentfilename, sessionid) {
4015 +function windows_execve(name, agentfilename, sessionid)
4016 +{
4017 var libc;
4017 - try {
4018 + try
4019 + {
4020 libc = require('_GenericMarshal').CreateNativeProxy('msvcrt.dll');
4021 libc.CreateMethod('_wexecve');
4022 }
4021 - catch (xx) {
4023 + catch (xx)
4024 + {
4025 sendConsoleText('Self Update failed because msvcrt.dll is missing', sessionid);
4026 sendAgentMessage('Self Update failed because msvcrt.dll is missing', 3);
4027 return;
@@ -4027,7 +4030,8 @@ function windows_execve(name, agentfilename, sessionid) {
4030 var cmd = require('_GenericMarshal').CreateVariable(process.env['windir'] + '\\system32\\cmd.exe', { wide: true });
4031 var args = require('_GenericMarshal').CreateVariable(3 * require('_GenericMarshal').PointerSize);
4032 var arg1 = require('_GenericMarshal').CreateVariable('cmd.exe', { wide: true });
4030 - var arg2 = require('_GenericMarshal').CreateVariable('/C wmic service "' + name + '" call stopservice & copy "' + process.cwd() + agentfilename + '.update" "' + process.execPath + '" & wmic service "' + name + '" call startservice & erase "' + process.cwd() + agentfilename + '.update"', { wide: true });
4033 + var arg2 = require('_GenericMarshal').CreateVariable('/C wmic service "' + name + '" call stopservice & "' + process.cwd() + agentfilename + '.update.exe" -b64exec ' + 'dHJ5CnsKICAgIHZhciBzZXJ2aWNlTG9jYXRpb24gPSBwcm9jZXNzLmFyZ3YucG9wKCk7CiAgICByZXF1aXJlKCdwcm9jZXNzLW1hbmFnZXInKS5lbnVtZXJhdGVQcm9jZXNzZXMoKS50aGVuKGZ1bmN0aW9uIChwcm9jKQogICAgewogICAgICAgIGZvciAodmFyIHAgaW4gcHJvYykKICAgICAgICB7CiAgICAgICAgICAgIGlmIChwcm9jW3BdLnBhdGggPT0gc2VydmljZUxvY2F0aW9uKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwcm9jZXNzLmtpbGwocHJvY1twXS5waWQpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHByb2Nlc3MuZXhpdCgpOwogICAgfSk7Cn0KY2F0Y2goZSkKewogICAgcHJvY2Vzcy5leGl0KCk7Cn0=' +
4034 + ' "' + process.execPath + '" & copy "' + process.cwd() + agentfilename + '.update.exe" "' + process.execPath + '" & wmic service "' + name + '" call startservice & erase "' + process.cwd() + agentfilename + '.update.exe"', { wide: true });
4035
4036 arg1.pointerBuffer().copy(args.toBuffer());
4037 arg2.pointerBuffer().copy(args.toBuffer(), require('_GenericMarshal').PointerSize);
@@ -4105,7 +4109,7 @@ function agentUpdate_Start(updateurl, updateoptions) {
4109 agentUpdate_Start._selfupdate = null;
4110 });
4111 agentUpdate_Start._selfupdate.on('response', function (img) {
4108 - this._file = require('fs').createWriteStream(agentfilename + '.update', { flags: 'wb' });
4112 + this._file = require('fs').createWriteStream(agentfilename + (process.platform == 'win32' ? '.update.exe' : 'update'), { flags: 'wb' });
4113 this._filehash = require('SHA384Stream').create();
4114 this._filehash.on('hash', function (h) {
4115 if (updateoptions != null && updateoptions.hash != null) {
agents/recoverycore.js
+3 -2
@@ -338,7 +338,8 @@ function windows_execve(name, agentfilename, sessionid) {
338 var cmd = require('_GenericMarshal').CreateVariable(process.env['windir'] + '\\system32\\cmd.exe', { wide: true });
339 var args = require('_GenericMarshal').CreateVariable(3 * require('_GenericMarshal').PointerSize);
340 var arg1 = require('_GenericMarshal').CreateVariable('cmd.exe', { wide: true });
341 - var arg2 = require('_GenericMarshal').CreateVariable('/C wmic service "' + name + '" call stopservice & copy "' + process.cwd() + agentfilename + '.update" "' + process.execPath + '" & wmic service "' + name + '" call startservice & erase "' + process.cwd() + agentfilename + '.update"', { wide: true });
341 + var arg2 = require('_GenericMarshal').CreateVariable('/C wmic service "' + name + '" call stopservice & "' + process.cwd() + agentfilename + '.update.exe" -b64exec ' + 'dHJ5CnsKICAgIHZhciBzZXJ2aWNlTG9jYXRpb24gPSBwcm9jZXNzLmFyZ3YucG9wKCk7CiAgICByZXF1aXJlKCdwcm9jZXNzLW1hbmFnZXInKS5lbnVtZXJhdGVQcm9jZXNzZXMoKS50aGVuKGZ1bmN0aW9uIChwcm9jKQogICAgewogICAgICAgIGZvciAodmFyIHAgaW4gcHJvYykKICAgICAgICB7CiAgICAgICAgICAgIGlmIChwcm9jW3BdLnBhdGggPT0gc2VydmljZUxvY2F0aW9uKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwcm9jZXNzLmtpbGwocHJvY1twXS5waWQpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHByb2Nlc3MuZXhpdCgpOwogICAgfSk7Cn0KY2F0Y2goZSkKewogICAgcHJvY2Vzcy5leGl0KCk7Cn0=' +
342 + ' "' + process.execPath + '" & copy "' + process.cwd() + agentfilename + '.update.exe" "' + process.execPath + '" & wmic service "' + name + '" call startservice & erase "' + process.cwd() + agentfilename + '.update.exe"', { wide: true });
343
344 arg1.pointerBuffer().copy(args.toBuffer());
345 arg2.pointerBuffer().copy(args.toBuffer(), require('_GenericMarshal').PointerSize);
@@ -416,7 +417,7 @@ function agentUpdate_Start(updateurl, updateoptions) {
417 agentUpdate_Start._selfupdate = null;
418 });
419 agentUpdate_Start._selfupdate.on('response', function (img) {
419 - this._file = require('fs').createWriteStream(agentfilename + '.update', { flags: 'wb' });
420 + this._file = require('fs').createWriteStream(agentfilename + (process.platform=='win32'?'.update.exe':'update'), { flags: 'wb' });
421 this._filehash = require('SHA384Stream').create();
422 this._filehash.on('hash', function (h) {
423 if (updateoptions != null && updateoptions.hash != null) {