MeshCentral/agents/meshcmd.js

1980 lines
2.4 MiB
JavaScript
Raw Normal View History

2018-01-30 21:23:57 -05:00
/*
2019-01-03 19:22:15 -05:00
Copyright 2018-2019 Intel Corporation
2018-01-30 21:23:57 -05:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @description MeshCmd, command line tool for Intel AMT and MeshCentral.
* @author Ylian Saint-Hilaire
* @version v0.2.0
*/
2018-08-06 21:57:30 -04:00
// Debug Stuff
//console.displayFinalizerMessages = 1; // Display objects that have event listeners that are disposed.
//console.displayStreamPipeMessages = 1; // Display stream pipe and un-pipes
//var __gc = setInterval(function () { console.log('GC'); _debugGC() }, 2000); //
2018-03-06 20:50:44 -05:00
2017-10-31 19:19:58 -04:00
var fs = require('fs');
var os = require('os');
var net = require('net');
var http = require('http');
var dgram = require('dgram');
var httpHeaders = require('http-headers');
var tcpserver = null;
var broadcastSockets = {};
var multicastSockets = {};
var discoveryInterval = null;
var membershipIPv4 = '239.255.255.235';
var membershipIPv6 = 'FF02:0:0:0:0:0:0:FE';
var settings = null;
2018-01-30 21:23:57 -05:00
var meshCmdVersion = '***Mesh*Cmd*Version***'; // Dynamically replaced with MeshCentral version
var amtLms = null, amtMei = null, amtMeiState = null;
2018-02-07 21:45:14 -05:00
var wsstack = null, amtstack = null;
var oswsstack = null, osamtstack = null;
2018-03-06 20:50:44 -05:00
var amtMeiTmpState = null;
var SMBiosTables = null;
var globalDebugFlags = 0; // 1 = IDER Debug
2019-06-13 12:12:11 -04:00
const RCSMessageProtocolVersion = 1; // RCS Message Protocol Version. Needs to be less than or equal to RCS server Message Protocol Version
2018-02-07 21:45:14 -05:00
2019-04-17 20:08:01 -04:00
// Me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OvuX4MYbEIMt0DYWzWvhgkNwLG2cesYuMlSfW5r/YE8XeBwx5ZAepwGpHmmsXaccvVekJl+1tCzEc0Rqk5I+IbnKRUmlVE2jh8ODtVTmryNQrR1Xovc4O5hM1jUXi6U28SUd8lHNsyPF2niXYAv+T6jDx/I+dVnckfDKMP3XMs04yTNyKffrsh9LjiJGBGzhzNmuF4Z1zsiYo7oNghPCU1gCIn4cU2ccTrvrd7b9Jlm51L6/zUaRlMrwwWoMEk5WYKsNBTy68qLGFtR4ucjCCZXxxUNYvJB4xjFOLPkN3iekH/TvW0pr6XIrt1hWessBen1+Fp8R/3rz2x
2017-10-31 19:19:58 -04:00
// Check the server certificate fingerprint
function onVerifyServer(clientName, certs) {
2018-01-26 20:01:38 -05:00
if (certs == null) { certs = clientName; } // Temporary thing until we fix duktape
2019-03-26 18:18:07 -04:00
try { for (var i in certs) { if (certs[i].fingerprint.replace(/:/g, '') == settings.serverhttpshash) { return; } } } catch (e) { }
if (serverhash != null) { console.log('Error: Failed to verify server certificate.'); throw 'Invalid server certificate'; }
2017-10-31 19:19:58 -04:00
}
2018-03-06 20:50:44 -05:00
// Various utility functions
2019-03-26 18:18:07 -04:00
function debug(level, message) { if ((settings.debuglevel != null) && (settings.debuglevel >= level)) { console.log(message); } }
function exit(status) { if (status == null) { status = 0; } try { process.exit(status); } catch (e) { } }
2018-03-06 20:50:44 -05:00
function getInstance(x, y) { for (var i in x) { if (x[i]["InstanceID"] == y) return x[i]; } return null; }
function md5hex(str) { return require('MD5Stream').create().syncHash(str).toString('hex'); }
function guidToStr(g) { return g.substring(6, 8) + g.substring(4, 6) + g.substring(2, 4) + g.substring(0, 2) + "-" + g.substring(10, 12) + g.substring(8, 10) + "-" + g.substring(14, 16) + g.substring(12, 14) + "-" + g.substring(16, 20) + "-" + g.substring(20); }
function parceArguments(argv) { var r = {}; for (var i in argv) { i = parseInt(i); if (argv[i].startsWith('--') == true) { var key = argv[i].substring(2).toLowerCase(), val = true; if (((i + 1) < argv.length) && (argv[i + 1].startsWith('--') == false)) { val = argv[i + 1]; } r[key] = val; } } return r; }
2017-11-02 21:44:27 -04:00
// Convert an object to string with all functions
function objToString(x, p, ret) {
if (ret == undefined) ret = '';
if (p == undefined) p = 0;
if (x == null) { return '[null]'; }
if (p > 8) { return '[...]'; }
if (x == undefined) { return '[undefined]'; }
if (typeof x == 'string') { if (p == 0) return x; return '"' + (x.split('\0')[0]) + '"'; }
if (typeof x == 'buffer') { return '[buffer]'; }
if (typeof x != 'object') { return x; }
var r = '{' + (ret ? '\r\n' : ' ');
for (var i in x) {
if (i != '_ObjectID') { r += (addPad(p + 2, ret) + i + ': ' + objToString(x[i], p + 2, ret) + (ret ? '\r\n' : ' ')); }
}
return r + addPad(p, ret) + '}';
}
// Return p number of spaces
function addPad(p, ret) { var r = ''; for (var i = 0; i < p; i++) { r += ' '; } return r; }
2018-01-30 21:23:57 -05:00
// Parse the incoming arguments
function run(argv) {
if (meshCmdVersion[0] == '*') { meshCmdVersion = ''; } else { meshCmdVersion = ' v' + meshCmdVersion; }
2017-11-02 21:44:27 -04:00
var args = parceArguments(argv);
//console.log(JSON.stringify(argv));
//console.log('addedModules = ' + JSON.stringify(addedModules));
2017-10-31 19:19:58 -04:00
var actionpath = 'meshaction.txt';
2017-11-02 21:44:27 -04:00
if (args.actionfile != null) { actionpath = args.actionfile; }
var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTPRESENCE'];
2017-10-31 19:19:58 -04:00
// Load the action file
var actionfile = null;
try { actionfile = fs.readFileSync(actionpath); } catch (e) { }
if ((actionpath != 'meshaction.txt') && (actionfile == null)) { console.log('Unable to load \"' + actionpath + '\". Create this file or specify the location using --actionfile [filename].'); exit(1); return; }
if (actionfile != null) { try { settings = JSON.parse(actionfile); } catch (e) { console.log(actionpath, e); exit(1); return; } } else { if (argv.length >= 2) { settings = { action: argv[1] } } }
2017-12-15 16:43:04 -05:00
if (settings == null) { settings = {}; }
2019-03-26 18:18:07 -04:00
var settings2 = {}; for (var i in settings) { settings2[i.toLowerCase()] = settings[i]; } settings = settings2;
2017-10-31 19:19:58 -04:00
2017-11-02 21:44:27 -04:00
// Set the arguments
2017-12-15 16:43:04 -05:00
if ((typeof args.action) == 'string') { settings.action = args.action; }
2017-11-02 21:44:27 -04:00
if ((typeof args.localport) == 'string') { settings.localport = parseInt(args.localport); }
2019-03-26 18:18:07 -04:00
if ((typeof args.remotenodeid) == 'string') { settings.remotenodeid = args.remotenodeid; }
2017-11-02 21:44:27 -04:00
if ((typeof args.username) == 'string') { settings.username = args.username; }
if ((typeof args.password) == 'string') { settings.password = args.password; }
if ((typeof args.wss) == 'string') { settings.wss = args.wss; }
2019-06-13 12:12:11 -04:00
if ((typeof args.profile) == 'string') { settings.profile = args.profile; }
if ((typeof args.type) == 'string') { settings.type = args.type; }
2017-11-02 21:44:27 -04:00
if ((typeof args.user) == 'string') { settings.username = args.user; }
if ((typeof args.pass) == 'string') { settings.password = args.pass; }
if ((typeof args.host) == 'string') { settings.hostname = args.host; }
if ((typeof args.hostname) == 'string') { settings.hostname = args.hostname; }
2019-03-26 18:18:07 -04:00
if ((typeof args.serverid) == 'string') { settings.serverid = args.serverid; }
if ((typeof args.serverhttpshash) == 'string') { settings.serverhttpshash = args.serverhttpshash; }
if ((typeof args.remoteport) == 'string') { settings.remoteport = parseInt(args.remoteport); }
2018-01-25 19:12:53 -05:00
if ((typeof args.out) == 'string') { settings.output = args.out; }
if ((typeof args.output) == 'string') { settings.output = args.output; }
2019-03-26 18:18:07 -04:00
if ((typeof args.debug) == 'string') { settings.debuglevel = parseInt(args.debug); }
if ((typeof args.debugflags) == 'string') { globalDebugFlags = parseInt(args.debugflags); }
if ((typeof args.script) == 'string') { settings.script = args.script; }
if ((typeof args.agent) == 'string') { settings.agent = args.agent; }
2019-03-27 15:55:31 -04:00
if ((typeof args.proxy) == 'string') { settings.proxy = args.proxy; }
if ((typeof args.floppy) == 'string') { settings.floppy = args.floppy; }
if ((typeof args.cdrom) == 'string') { settings.cdrom = args.cdrom; }
if ((typeof args.timeout) == 'string') { settings.timeout = parseInt(args.timeout); }
if (args.debug === true) { settings.debuglevel = 1; }
2018-08-06 21:57:30 -04:00
if (args.debug) { try { waitForDebugger(); } catch (e) { } }
2018-01-25 19:28:52 -05:00
if (args.noconsole) { settings.noconsole = true; }
if (args.nocommander) { settings.noconsole = true; }
2018-01-25 19:12:53 -05:00
if (args.lmsdebug) { settings.lmsdebug = true; }
if (args.tls) { settings.tls = true; }
2017-12-15 16:43:04 -05:00
if ((argv.length > 1) && (actions.indexOf(argv[1].toUpperCase()) >= 0)) { settings.action = argv[1]; }
2017-11-02 21:44:27 -04:00
2017-10-31 19:19:58 -04:00
// Validate meshaction.txt
if (settings.action == null) {
console.log('MeshCentral Command (MeshCmd) ' + meshCmdVersion);
console.log('No action specified, use MeshCmd like this:\r\n');
console.log(' meshcmd [action] [arguments...]\r\n');
console.log('Valid MeshCentral actions:');
console.log(' Route - Map a local TCP port to a remote computer.');
console.log('\r\nValid local actions:');
console.log(' SMBios - Display System Management BIOS tables for this computer.');
console.log(' RawSMBios - Display RAW System Management BIOS tables for this computer.');
console.log(' MicroLMS - Run MicroLMS, allowing local access to Intel AMT.');
console.log(' AmtInfo - Show Intel AMT version and activation state.');
console.log(' AmtVersions - Show all Intel ME version information.');
console.log(' AmtHashes - Show all Intel AMT trusted activation hashes.');
console.log(' AmtCCM - Activate Intel AMT into Client Control Mode.');
2019-06-13 12:12:11 -04:00
//console.log(' AmtACM - Activate Intel AMT into Admin Control Mode.'); // Not correcly implemented so not making this visible yet.
console.log(' AmtDeactivate - Deactivate Intel AMT if activated in Client Control mode.');
console.log(' AmtAcmDeactivate - Deactivate Intel AMT if activated in Admin Control mode.');
console.log('\r\nValid local or remote actions:');
console.log(' MeshCommander - Launch a local MeshCommander web server.');
console.log(' AmtUUID - Show Intel AMT unique identifier.');
console.log(' AmtAuditLog - Show the Intel AMT audit log.');
console.log(' AmtLoadWebApp - Load MeshCommander in Intel AMT 11.6+ firmware.');
console.log(' AmtClearWebApp - Clear everything from Intel AMT web storage.');
console.log(' AmtStorageState - Show contents of the Intel AMT web storage.');
console.log(' AmtSaveState - Save all Intel AMT WSMAN object to file.');
console.log(' AmtPresence - Heartbeat a local Intel AMT watchdog agent.');
console.log(' AmtScript - Run .mescript on Intel AMT.');
console.log(' AmtIDER - Mount local disk image to remote computer.');
console.log('\r\nHelp on a specific action using:\r\n');
console.log(' meshcmd help [action]');
exit(1); return;
}
if (settings.action == 'help') {
if (argv.length <= 2) {
actions.shift();
console.log('Help usage:\r\n\r\n MeshCmd help [action]\r\n\r\nValid actions are: ' + actions.join(', ') + '.');
exit(1); return;
}
var action = argv[2].toLowerCase();
if (action == 'route') {
console.log("The route action is used along with a MeshCentral account to map a local TCP port to a remote port on any computer on your MeshCentral account. This action requires many arguments, to avoid specifying them all it's best to download the meshaction.txt file from the web site and place it in the current folder. Example usage:\r\n\r\n (Place meshaction.txt file in current folder)\r\n meshcmd route --pass myAccountPassword");
} else if (action == 'smbios') {
console.log("SMBios action will display this computer's system management BIOS information. Example usage:\r\n\r\n meshcmd smbios --out smbios.txt\r\n");
console.log('\r\Optional arguments:\r\n');
console.log(' --output [filename] Optional filename to write the results to.');
} else if (action == 'rawsmbios') {
console.log("RawSMBios action will display this computer's system management BIOS information in raw hexdecimal form. Example usage:\r\n\r\n meshcmd rawsmbios --out smbios.txt\r\n");
console.log('\r\Optional arguments:\r\n');
console.log(' --output [filename] Optional filename to write the results to.');
} else if (action == 'amtinfo') {
console.log('AmtInfo action will get the version and activation state of Intel AMT on this computer. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Example usage:\r\n\r\n meshcmd amtinfo');
} else if ((action == 'amtversion') || (action == 'amtversions')) {
console.log('AmtVersions will display all version information about Intel AMT on this computer. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Example usage:\r\n\r\n meshcmd amtversions');
} else if (action == 'amthashes') {
console.log('Amthashes will display all trusted activations hashes for Intel AMT on this computer. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. These certificates hashes are used by Intel AMT when performing activation into ACM mode. Example usage:\r\n\r\n meshcmd amthashes');
} else if ((action == 'microlms') || (action == 'lms') || (action == 'amtlms')) {
console.log('Starts MicroLMS on this computer, allowing local access to Intel AMT on TCP ports 16992 and 16993 when applicable. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. These certificates hashes are used by Intel AMT when performing activation into ACM mode. Example usage:\r\n\r\n meshcmd microlms');
2018-03-19 20:31:54 -04:00
console.log('\r\nPossible arguments:\r\n');
console.log(' --noconsole MeshCommander for LMS will no be available on port 16994.');
console.log('\r\nRun as a background service:\r\n');
console.log(' microlms install/uninstall/start/stop.');
} else if (action == 'amtccm') {
console.log('AmtCCM will attempt to activate Intel AMT on this computer into client control mode (CCM). The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Intel AMT must be in "pre-provisioning" state for this command to work and a administrator password must be provided. Example usage:\r\n\r\n meshcmd amtccm --pass mypassword');
} else if (action == 'amtacm') {
console.log('AmtACM will attempt to activate Intel AMT on this computer into admin control mode (ACM). The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Intel AMT must be in "pre-provisioning" state for this command to work and a administrator password and provisioning certificate must be provided via RCS. Example usage:\r\n\r\n meshcmd amtacm --wss servername:port');
console.log('\r\nPossible arguments:\r\n');
console.log(' --wss [server:port] The address of the AMT remote configuration server.');
2019-06-13 12:12:11 -04:00
console.log(' --profile [name] The name of the AMT profile stored on the AMT remote configuration server.');
} else if (action == 'amtdeactivate') {
console.log('AmtDeactivate will attempt to deactivate Intel AMT on this computer when in client control mode (CCM). The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Intel AMT must be activated in client control mode for this command to work. Example usage:\r\n\r\n meshcmd amtdeactivate');
} else if (action == 'amtacmdeactivate') {
console.log('AmtACMDeactivate will attempt to deactivate Intel AMT on this computer when in admin control mode (ACM). The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Intel AMT must be activated in admin control mode for this command to work. Example usage:\r\n\r\n meshcmd amtacmdeactivate');
console.log('\r\nPossible arguments:\r\n');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --type [partial/full] Specifies to perform partial or full unprovision.');
} else if (action == 'amtuuid') {
console.log('AmtUUID action will get the unique identifier of the local or remote Intel AMT computer. By default, the local UUID is obtained unless a host is specified. Intel AMT must be activated for this command to work. Example usage:\r\n\r\n meshcmd amtuuid --host 1.2.3.4 --user admin --pass mypassword --tls');
2018-03-19 20:31:54 -04:00
console.log('\r\nPossible arguments:\r\n');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
} else if ((action == 'amtloadwebapp') || (action == 'amtloadsmallwebapp') || (action == 'amtloadlargewebapp') || (action == 'amtclearwebapp') || (action == 'amtstoragestate')) {
console.log('AmtLoadWebApp action will load MeshCommander into Intel AMT 11.6 or higher. If the computer is in ACM mode, MeshCommander will replace the default index.htm on HTTP/16992 or HTTPS/16993. If Intel AMT is in CCM mode, MeshCommander will be installed alongside the default web page and will be accessible in the "Web Applications" section. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtloadwebapp --host 1.2.3.4 --user admin --pass mypassword --tls');
2018-03-19 20:31:54 -04:00
console.log('\r\nPossible arguments:\r\n');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
} else if (action == 'amtclearwebstorage') {
console.log('AmtClearWebStorage will clear the web storage of Intel AMT, removing any loaded firmware version of MeshCommander. This command can clear the local or a remote Intel AMT computer. By default, the local computer storage is cleared unless a host is specified. Intel AMT must be activated for this command to work. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtclearwebstorage --host 1.2.3.4 --user admin --pass mypassword --tls');
2018-03-19 20:31:54 -04:00
console.log('\r\nPossible arguments:\r\n');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
} else if (action == 'amtstoragestate') {
console.log('AmtStorageState will display the content of the web storage of Intel AMT including any loaded firmware version of MeshCommander. This command can read the storage state of a local or remote Intel AMT computer. By default, the local computer storage state is displayed unless a host is specified. Intel AMT must be activated for this command to work. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtstoragestate --host 1.2.3.4 --user admin --pass mypassword --tls');
2018-03-19 20:31:54 -04:00
console.log('\r\nPossible arguments:\r\n');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
} else if (action == 'amtsavestate') {
console.log('AmtSaveState action will fetch all the entire state of Intel AMT and save it as a JSON file. This action will take multiple minutes to perform. The command will fetch the local computer state unless host is specified. Intel AMT must be ativated for this command to work. Example usage:\r\n\r\n meshcmd amtsavestate --host 1.2.3.4 --user admin --pass mypassword --tls --output state.json');
2018-03-19 20:31:54 -04:00
console.log('\r\nPossible arguments:\r\n');
console.log(' --output [filename] The output file for the Intel AMT state in JSON format.');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
} else if (action == 'amtpresence') {
console.log('AmtPresence will heartbeat a local Intel AMT watchdog agent. Example usage:\r\n\r\n meshcmd amtpresence --agent B4B6A24C-255E-A75C-F5E8-B00B4D946AA7');
console.log('\r\nPossible arguments:\r\n');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --agent [uuid] The unique identifier of the watchdog agent.');
} else if (action == 'amtscript') {
console.log('AmtScript will run a .mescript file on the local or remote Intel AMT. Script files can be built using the MeshCommander script editor and be used to setup or perform actions on Intel AMT. Example usage:\r\n\r\n meshcmd amtscript --script myscript.mescript --host 1.2.3.4 --user admin --pass mypassword --tls');
2018-03-19 20:31:54 -04:00
console.log('\r\nPossible arguments:\r\n');
console.log(' --script [filename] The script file to run on Intel AMT.');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
2018-03-19 20:31:54 -04:00
} else if (action == 'meshcommander') {
console.log('This action launched a local web server that hosts MeshCommander, a Intel AMT management console.');
console.log('\r\nPossible arguments:\r\n');
console.log(' --localport [port] Local port used for the web server, 3000 is default.');
console.log('\r\nRun as a background service:\r\n');
console.log(' meshcommander install/uninstall/start/stop.');
} else if (action == 'amtauditlog') {
console.log('AmtAuditLog action will fetch the local or remote audit log. If used localy, no username/password is required. Example usage:\r\n\r\n meshcmd amtauditlog --host 1.2.3.4 --user admin --pass mypassword --tls --output audit.json');
console.log('\r\nPossible arguments:\r\n');
console.log(' --output [filename] The output file for the Intel AMT state in JSON format.');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
} else if (action == 'amtider') {
console.log('AmtIDER will mount a local disk images to a remote Intel AMT computer. Example usage:\r\n\r\n meshcmd amtider --host 1.2.3.4 --user admin --pass mypassword --tls --floppy disk.img --cdrom disk.iso');
console.log('\r\nPossible arguments:\r\n');
console.log(' --host [hostname] The IP address or DNS name of Intel AMT.');
console.log(' --user [username] The Intel AMT login username, admin is default.');
console.log(' --pass [password] The Intel AMT login password.');
console.log(' --tls Specifies that TLS must be used.');
console.log(' --floppy [file] Specifies .img file to be mounted as a flppy disk.');
console.log(' --cdrom [file] Specifies .img file to be mounted as a CDROM disk.');
console.log(' --timeout [seconds] Optional, disconnect after number of seconds without disk read.');
} else {
actions.shift();
console.log('Invalid action, usage:\r\n\r\n meshcmd help [action]\r\n\r\nValid actions are: ' + actions.join(', ') + '.');
}
exit(1); return;
}
2017-10-31 19:19:58 -04:00
settings.action = settings.action.toLowerCase();
debug(1, "Settings: " + JSON.stringify(settings));
2019-03-27 15:55:31 -04:00
// Setup the proxy if needed
if ((typeof settings.proxy) == 'string') {
var proxy = settings.proxy.split(':'), proxyport = (proxy.length == 2) ? parseInt(proxy[1]) : 0;
if ((proxy.length != 2) || (proxy[0].length < 1) || (proxyport < 1) || (proxyport > 65535)) { console.log('Invalid \"proxy\" specified, use --proxy [hostname]:[port].'); exit(1); return; }
try { require('global-tunnel').initialize({ host: proxy[0], port: proxyport }); } catch (ex) { console.log(ex); exit(1); return; }
console.log('Proxy set to ' + proxy[0] + ':' + proxyport);
}
if (settings.action == 'smbios') {
// Display SM BIOS tables in raw form
SMBiosTables = require('smbios');
SMBiosTables.get(function (data) {
var r = SMBiosTables.parse(data);
var out = objToString(r, 0, '\r\n');
if (settings.output == null) { console.log(out); } else { var file = fs.openSync(settings.output, 'w'); fs.writeSync(file, Buffer.from(out, 'utf8')); fs.closeSync(file); }
exit(1);
});
} else if (settings.action == 'rawsmbios') {
// Display SM BIOS tables in raw form
SMBiosTables = require('smbios');
SMBiosTables.get(function (data) {
var out = '';
for (var i in data) { var header = false; for (var j in data[i]) { if (data[i][j].length > 0) { if (header == false) { out += ('Table type #' + i + ((SMBiosTables.smTableTypes[i] == null) ? '' : (', ' + SMBiosTables.smTableTypes[i]))) + '\r\n'; header = true; } out += (' ' + data[i][j].toString('hex')) + '\r\n'; } } }
if (settings.output == null) { console.log(out); } else { var file = fs.openSync(settings.output, 'w'); fs.writeSync(file, Buffer.from(out, 'utf8')); fs.closeSync(file); }
exit(1);
});
} else if (settings.action == 'route') {
2018-01-30 21:23:57 -05:00
// MeshCentral Router, port map local TCP port to a remote computer
2019-03-26 18:18:07 -04:00
if ((settings.localport == null) || (typeof settings.localport != 'number') || (settings.localport < 0) || (settings.localport > 65535)) { console.log('No or invalid \"localPort\" specified, use --localport [localport].'); exit(1); return; }
if ((settings.remotenodeid == null) || (typeof settings.remotenodeid != 'string')) { console.log('No or invalid \"remoteNodeId\" specified.'); exit(1); return; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { console.log('No or invalid \"username\" specified, use --username [username].'); exit(1); return; }
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
2019-03-26 18:18:07 -04:00
if ((settings.serverid == null) || (typeof settings.serverid != 'string') || (settings.serverid.length != 96)) { console.log('No or invalid \"serverId\" specified.'); exit(1); return; }
if ((settings.serverhttpshash == null) || (typeof settings.serverhttpshash != 'string') || (settings.serverhttpshash.length != 96)) { console.log('No or invalid \"serverHttpsHash\" specified.'); exit(1); return; }
if ((settings.remoteport == null) || (typeof settings.remoteport != 'number') || (settings.remoteport < 0) || (settings.remoteport > 65535)) { console.log('No or invalid \"remotePort\" specified, use --remoteport [remoteport].'); exit(1); return; }
if (settings.serverurl != null) { startRouter(); } else { discoverMeshServer(); } // Start MeshCentral Router
} else if ((settings.action == 'amtloadwebapp') || (settings.action == 'amtloadsmallwebapp') || (settings.action == 'amtloadlargewebapp') || (settings.action == 'amtclearwebapp') || (settings.action == 'amtstoragestate')) { // Intel AMT Web Application Actions
2018-01-30 21:23:57 -05:00
// Intel AMT 11.6+ Load MeshCommander into firmware
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { settings.hostname = '127.0.0.1'; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
settings.protocol = 'http:';
settings.localport = 16992;
debug(1, "Settings: " + JSON.stringify(settings));
digest = require('http-digest').create(settings.username, settings.password);
digest.http = require('http');
2017-12-15 16:43:04 -05:00
if (settings.action == 'amtstoragestate') {
getAmtStorage(function (statusCode, data) { if (statusCode == 200) { console.log("Storage State: " + JSON.stringify(data, null, 2)); exit(); return; } else { console.log("Unable to read storage state."); exit(); return; } });
} else {
2017-12-15 16:43:04 -05:00
if (settings.action == 'amtloadwebapp') { settings.webapp = Medium_IntelAmtWebApp; }
else if (settings.action == 'amtloadsmallwebapp') { settings.webapp = Small_IntelAmtWebApp; }
else if (settings.action == 'amtloadlargewebapp') { settings.webapp = Large_IntelAmtWebApp; }
else if (settings.action == 'amtclearwebapp') { settings.webapp = null; }
nextStepStorageUpload();
}
} else if ((settings.action == 'amtversion') || (settings.action == 'amtversions') || (settings.action == 'amtver')) {
2018-01-30 21:23:57 -05:00
// Display Intel AMT versions
2019-03-01 20:13:11 -05:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
2018-01-25 19:28:52 -05:00
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
2018-03-19 20:31:54 -04:00
amtMei.getVersion(function (val) {
console.log("MEI Version = " + val.BiosVersion.toString());
for (var version in val.Versions) { console.log(val.Versions[version].Description + " = " + val.Versions[version].Version); }
exit(1); return;
});
} else if (settings.action == 'amthashes') {
2018-01-30 21:23:57 -05:00
// Display Intel AMT list of trusted hashes
2019-03-01 20:13:11 -05:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
2018-01-25 19:28:52 -05:00
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
2018-03-19 20:31:54 -04:00
amtMei.getHashHandles(function (handles) {
exitOnCount = handles.length;
for (var i = 0; i < handles.length; ++i) {
this.getCertHashEntry(handles[i], function (result) {
console.log(result.name + ', (' + (result.isDefault ? 'Default' : '') + (result.isActive ? ', Active' : ', Disabled') + ')\r\n ' + result.hashAlgorithmStr + ': ' + result.certificateHash);
if (--exitOnCount == 0) { exit(1); }
});
}
});
} else if (settings.action == 'amtinfo') {
2018-01-30 21:23:57 -05:00
// Display Intel AMT version and activation state
2018-03-19 20:31:54 -04:00
mestate = {};
2019-03-01 20:13:11 -05:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
2018-01-25 19:28:52 -05:00
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
2018-10-11 16:29:50 -04:00
amtMei.getVersion(function (result) { if (result) { for (var version in result.Versions) { if (result.Versions[version].Description == 'AMT') { mestate.ver = result.Versions[version].Version; } } } });
amtMei.getProvisioningState(function (result) { if (result) { mestate.ProvisioningState = result; } });
amtMei.getProvisioningMode(function (result) { if (result) { mestate.ProvisioningMode = result; } });
amtMei.getEHBCState(function (result) { if (result) { mestate.ehbc = result; } });
amtMei.getControlMode(function (result) { if (result) { mestate.controlmode = result; } });
amtMei.getMACAddresses(function (result) { if (result) { mestate.mac = result; } });
amtMei.getLanInterfaceSettings(0, function (result) { if (result) { mestate.net0 = result; } });
amtMei.getLanInterfaceSettings(1, function (result) { if (result) { mestate.net1 = result; } });
amtMei.getUuid(function (result) { if ((result != null) && (result.uuid != null)) { mestate.uuid = result.uuid; } });
2018-03-19 20:31:54 -04:00
amtMei.getDnsSuffix(function (result) {
2018-10-11 16:29:50 -04:00
if (result) { mestate.dns = result; }
if (mestate.ver && mestate.ProvisioningState && mestate.ProvisioningMode) {
var str = 'Intel AMT v' + mestate.ver;
if (mestate.ProvisioningState.stateStr == 'PRE') { str += ', pre-provisioning state'; }
else if (mestate.ProvisioningState.stateStr == 'IN') { str += ', in-provisioning state'; }
else if (mestate.ProvisioningState.stateStr == 'POST') {
if (mestate.ProvisioningMode) {
if (mestate.controlmode) {
if (mestate.ProvisioningMode.modeStr == 'ENTERPRISE') { str += ', activated in ' + ["none", "client control mode", "admin control mode", "remote assistance mode"][mestate.controlmode.controlMode]; } else { str += ', activated in ' + mestate.ProvisioningMode.modeStr; }
} else {
str += ', activated in ' + mestate.ProvisioningMode.modeStr;
}
}
}
2018-10-11 16:29:50 -04:00
if ((mestate.ehbc) && (mestate.ehbc.EHBC == true)) { str += ', EHBC enabled'; }
str += '.';
if (mestate.net0 != null) { str += '\r\nWired ' + ((mestate.net0.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net0.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net0.mac + (mestate.net0.address == '0.0.0.0' ? '' : (', ' + mestate.net0.address)); }
if (mestate.net1 != null) { str += '\r\nWireless ' + ((mestate.net1.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net1.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net1.mac + (mestate.net1.address == '0.0.0.0' ? '' : (', ' + mestate.net1.address)); }
if ((mestate.ProvisioningState.stateStr != 'POST') && (mestate.net0 != null) && (mestate.net0.enabled == 1)) {
if (mestate.dns != null) {
// Intel AMT has a trusted DNS suffix set, use that one.
str += '\r\nTrusted DNS suffix: ' + mestate.dns;
} else {
// Look for the DNS suffix for the Intel AMT Ethernet interface
var fqdn = null, interfaces = require('os').networkInterfaces();
for (var i in interfaces) {
for (var j in interfaces[i]) {
if ((interfaces[i][j].mac == mestate.net0.mac) && (interfaces[i][j].fqdn != null) && (interfaces[i][j].fqdn != '')) { fqdn = interfaces[i][j].fqdn; }
}
}
if (fqdn != null) { str += '\r\nDNS suffix: ' + fqdn; }
}
}
2018-10-11 16:29:50 -04:00
console.log(str + '.');
} else {
console.log('Intel(R) AMT not supported.');
}
2018-03-19 20:31:54 -04:00
exit(1);
});
2018-09-20 14:45:12 -04:00
} else if (settings.action == 'amtinfodebug') {
// Display Intel AMT version and activation state
mestate = {};
2019-03-01 20:13:11 -05:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
2018-09-20 14:45:12 -04:00
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
amtMei.getVersion(function (result) { console.log('getVersion: ' + JSON.stringify(result)); });
amtMei.getProvisioningState(function (result) { console.log('getProvisioningState: ' + JSON.stringify(result)); });
amtMei.getProvisioningMode(function (result) { console.log('getProvisioningMode: ' + JSON.stringify(result)); });
amtMei.getEHBCState(function (result) { if (result) { console.log('getEHBCState: ' + JSON.stringify(result)); } });
amtMei.getControlMode(function (result) { if (result) { console.log('getControlMode: ' + JSON.stringify(result)); } });
amtMei.getMACAddresses(function (result) { if (result) { console.log('getMACAddresses: ' + JSON.stringify(result)); } });
amtMei.getLanInterfaceSettings(0, function (result) { console.log('getLanInterfaceSettings0: ' + JSON.stringify(result)); });
amtMei.getLanInterfaceSettings(1, function (result) { console.log('getLanInterfaceSettings1: ' + JSON.stringify(result)); });
amtMei.getUuid(function (result) { console.log('getUuid: ' + JSON.stringify(result)); });
amtMei.getDnsSuffix(function (result) { console.log('getDnsSuffix: ' + JSON.stringify(result)); exit(1);});
2018-01-02 19:52:49 -05:00
} else if (settings.action == 'amtsavestate') {
2018-01-30 21:23:57 -05:00
// Save the entire state of Intel AMT info a JSON file
2018-01-25 19:12:53 -05:00
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { settings.hostname = '127.0.0.1'; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
if ((settings.output == null) || (typeof settings.output != 'string') || (settings.output == '')) { console.log('No or invalid \"output\" file specified, use --output [filename].'); exit(1); return; }
settings.protocol = 'http:';
settings.localport = 16992;
debug(1, "Settings: " + JSON.stringify(settings));
2018-01-02 19:52:49 -05:00
saveEntireAmtState();
} else if ((settings.action == 'microlms') || (settings.action == 'amtlms') || (settings.action == 'lms')) {
2018-01-30 21:23:57 -05:00
// Start Intel AMT MicroLMS
2018-03-19 20:31:54 -04:00
startLms(function (state) {
console.log(['MicroLMS did not start. Must run as administrator or LMS already active.', 'MicroLMS started.', 'MicroLMS started, MeshCommander on HTTP/16994.', 'MEI error'][state]);
if (((state == 0) || (state == 3)) && (settings.noconsole === true)) { exit(0); } else { console.log('Press ctrl-c to exit.'); }
}, settings.noconsole !== true);
} else if (settings.action == 'amtpresence') {
// Heartbeat a Intel AMT watchdog
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
if ((settings.agent == null) || (typeof settings.agent != 'string') || (settings.agent == '')) { console.log('No or invalid \"agent\" specified, use --agent [agent].'); exit(1); return; }
performAmtAgentPresence();
} else if (settings.action == 'amtscript') {
// Start running a MEScript
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { settings.hostname = '127.0.0.1'; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
2019-03-26 18:18:07 -04:00
if ((settings.script == null) || (typeof settings.script != 'string') || (settings.script == '')) { if (mescriptJSON != '') { settings.scriptjson = mescriptJSON; } else { console.log('No or invalid \"script\" file specified, use --script [filename].'); exit(1); return; } }
startMeScript();
2018-03-06 20:50:44 -05:00
} else if (settings.action == 'amtuuid') {
// Start running
if (settings.hostname != null) {
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
}
2018-03-06 20:50:44 -05:00
settings.protocol = 'http:';
settings.localport = 16992;
debug(1, "Settings: " + JSON.stringify(settings));
getAmtUuid();
} else if (settings.action == 'amtccm') {
// Start activation to CCM
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
settings.protocol = 'http:';
settings.localport = 16992;
debug(1, "Settings: " + JSON.stringify(settings));
activeToCCM();
} else if (settings.action == 'amtacm') {
// Start activation to ACM
if ((settings.wss == null) || (typeof settings.wss != 'string') || (settings.wss == '')) { console.log('No or invalid \"server name\" specified, use --wss [servername:port].'); exit(1); return; }
2019-06-13 12:12:11 -04:00
if ((settings.profile == null) || (typeof settings.profile != 'string') || (settings.profile == '')) { console.log('No or invalid \"profile name\" specified, use --profile [name].'); exit(1); return; }
settings.protocol = 'http:';
settings.localport = 16992;
debug(1, "Settings: " + JSON.stringify(settings));
activeToACM();
2018-03-06 20:50:44 -05:00
} else if (settings.action == 'amtdeactivate') {
// Deactivate CCM
debug(1, "Settings: " + JSON.stringify(settings));
deactivateCCM();
} else if (settings.action == 'amtacmdeactivate') {
// Deactivate ACM
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.type == null) || (typeof settings.type != 'string') || (settings.type == '')) { console.log('Unprovisioning \"type\" must be specified, use --type [partial/full].'); exit(1); return; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
if (settings.hostname == null) { settings.hostname = '127.0.0.1'; }
if (settings.tls == null) { settings.tls = false; }
debug(1, "Settings: " + JSON.stringify(settings));
deactivateACM();
} else if (settings.action == 'meshcommander') { // Start MeshCommander
2018-03-19 20:31:54 -04:00
startMeshCommander();
} else if (settings.action == 'amtauditlog') { // Read the Intel AMT audit log
if (settings.hostname != null) {
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
} else { settings.hostname = '127.0.0.1'; }
readAmtAuditLog();
} else if (settings.action == 'amtider') { // Remote mount IDER image
if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { console.log('No or invalid \"hostname\" specified, use --hostname [password].'); exit(1); return; }
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
if ((settings.floppy == null) || (typeof settings.floppy != 'string') || (settings.floppy == '')) { settings.floppy = null; }
if ((settings.cdrom == null) || (typeof settings.cdrom != 'string') || (settings.cdrom == '')) { settings.cdrom = null; }
if ((settings.floppy == null) && (settings.cdrom == null)) { console.log('No or invalid \"floppy\" or \"cdrom\" specified, use --floppy [file] or --cdrom [file].'); exit(1); return; }
performIder();
2017-10-31 19:19:58 -04:00
} else {
console.log('Invalid \"action\" specified.'); exit(1); return;
2017-10-31 19:19:58 -04:00
}
}
2017-10-31 19:19:58 -04:00
//
// Intel AMT Agent Presence
//
function performAmtAgentPresence() { startLms(function () { tempWatchdogTimer = setTimeout(performAmtAgentPresenceRegister, 3000); }); }
function performAmtAgentPresenceRegister() {
// Setup the Intel AMT WSMAN stack
tempWatchdogTimer = null;
var transport = require('amt-wsman-duk');
var wsman = require('amt-wsman');
var amt = require('amt');
wsstack = new wsman(transport, '127.0.0.1', settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls);
amtstack = new amt(wsstack);
// Register the watchdog
watchdog = { DeviceID: Buffer.from(guidToStr(settings.agent.split('-').join('')).split('-').join(''), 'hex').toString('base64'), Retry: 0 };
amtstack.AMT_AgentPresenceWatchdog_RegisterAgent(performAmtAgentPresenceRegisterRetry, watchdog, watchdog.Seq, { 'DeviceID': watchdog.DeviceID });
}
// Called after the agent is registered
function performAmtAgentPresenceRegisterRetry(stack, name, response, status, watchdog) {
if ((status == 200) && (response.Body.SessionSequenceNumber) && (response.Body.TimeoutInterval)) {
console.log('Asserting presence of the watchdog...');
watchdog.Seq = response.Body.SessionSequenceNumber;
watchdog.Interval = response.Body.TimeoutInterval * 800;
watchdog.Retry = 0;
tempWatchdogTimer = setTimeout(performAmtAgentPresenceAssert, watchdog.Interval);
} else {
debug(1, 'Failed to register, status = ' + status);
watchdog.Retry++;
if (watchdog.Retry < 5) {
tempWatchdogTimer = setTimeout(function () { amtstack.AMT_AgentPresenceWatchdog_RegisterAgent(performAmtAgentPresenceRegisterRetry, watchdog, watchdog.Seq, { 'DeviceID': watchdog.DeviceID }); }, 1000);
} else {
console.log('Failed to register this watchdog.');
process.exit(0);
}
}
}
// Start a new agent assert
function performAmtAgentPresenceAssert() {
watchdog.Seq++;
amtstack.AMT_AgentPresenceWatchdog_AssertPresence(watchdog.Seq, performAmtAgentPresenceAssertRetry, watchdog, 0, { 'DeviceID': watchdog.DeviceID });
}
// Called after the agent is asserted
function performAmtAgentPresenceAssertRetry(stack, name, response, status, watchdog) {
if (status == 200) {
debug(1, 'Succesful assert, sequence = ' + watchdog.Seq);
watchdog.Retry = 0;
tempWatchdogTimer = setTimeout(performAmtAgentPresenceAssert, watchdog.Interval);
} else {
debug(1, 'Failed to assert, status = ' + status);
watchdog.Retry++;
if (watchdog.Retry < 5) {
amtstack.AMT_AgentPresenceWatchdog_AssertPresence(watchdog.Seq, performAmtAgentPresenceAssertRetry, watchdog, 0, { 'DeviceID': watchdog.DeviceID });
} else {
console.log('Failed to assert presence on this watchdog.');
process.exit(0);
}
}
}
function performAmtAgentPresenceEx5(stack, name, response, status, watchdog) {
console.log('b', status, watchdog);
if (status == 200) {
watchdog.Retry = 0;
} else {
watchdog.Retry++;
if (watchdog.Retry < 5) {
amtstack.AMT_AgentPresenceWatchdog_AssertPresence(watchdog.Seq, performAmtAgentPresenceEx4, watchdog, 0, { 'DeviceID': watchdog.DeviceID });
} else {
console.log('Failed to assert presence on this watchdog.');
process.exit(0);
}
}
}
//
// Intel AMT Audit Log
//
function readAmtAuditLog() {
// See if MicroLMS needs to be started
if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) {
settings.noconsole = true; startLms(readAmtAuditLogEx);
} else {
readAmtAuditLogEx(9999);
}
}
function readAmtAuditLogEx(x) {
if (x == 9999) {
var transport = require('amt-wsman-duk');
var wsman = require('amt-wsman');
var amt = require('amt');
wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls);
amtstack = new amt(wsstack);
amtstack.GetAuditLog(readAmtAuditLogEx2);
} else {
osamtstack.GetAuditLog(readAmtAuditLogEx2);
}
}
function readAmtAuditLogEx2(stack, response, status) {
if (status != 200) {
console.log('Unable to get audit log, status = ' + status + '.');
} else {
var out = '';
for (var i in response) {
var name = ((response[i].Initiator != '') ? (response[i].Initiator + ': ') : '')
out += (response[i].Time + ' - ' + name + response[i].Event + '\r\n');
}
if (settings.output == null) { console.log(out); } else { var file = fs.openSync(settings.output, 'w'); fs.writeSync(file, Buffer.from(out, 'utf8')); fs.closeSync(file); }
}
exit(1);
}
2018-03-19 20:31:54 -04:00
//
// MeshCommander local web server
//
function startMeshCommander() {
2019-04-17 20:08:01 -04:00
// MeshCommander Local v0.7.5
2019-04-29 00:23:49 -04:00
var _IntelAmtLocalWebApp_etag = "2yqTVWrrXNG95TGphPSo";
var _IntelAmtLocalWebApp = "H4sIAAAAAAAEAMQ5h3ajOtOvwu/ckpyNN4CNa7znYOwUJ07i1PU9VYAAJQIREC7xyYv9X3uk7xU+yUAMwdldX9/iKo00fTTSiP/+4z+H/9e71G7HV33BoS7+csh/hZDOMew4ENkObUmi+DODQ2B+OXQhBWwi9cvwOUKTztfynVrWiOsDinQMBYN4FHq0Uzrtd6Bpw1KMsoJTOKMHnEfbcEAQQtqJqFVulLJEtXhy+XbuwwTfAy7sWCRwAS2bkEKDIuJlqWLoO8SDHY8wlhh5T0IAcaeE2JSSQBmhDnKBDQ98zxacAFqdkgkoaL0B2zoIYa26j+67l9dT8ezYJh1GaWmILzox54uMNdoumJWzfTKBgYXJtOUg04Re2yJMfAu4CM9bIEAA7wsOxBNIkQH2hRB4YTmEAbLiiSF6ga2mT9sGwSRo6RgYT22d/dgBiTyzNXUQhYxnYCOvTInfEtMOhhZd9QImEO+Wp1B/QpRNjQynbACMSURbHjPP21DE2DMRMDTSgSfulDVwl7ysg4ZFYAHwitEiFo0J5QPTRJ7dEhkY6BAvTBT6GMyZusR4SlSfIs8kUx4jGf3L2bH2GoJTZFIndkRMu+VwhywKJBxmIMyN1H7XX3J8Ba0JChGF5oL1eZwZJAA80GJ1YpwdsWrxqTzGfmBeIkoCUxSl/epIi5XbJcmncRRM43jSCTZzgZB1teLPsnEgiau+TiglbqvGIK+OnOHQ3IRBLc+gVqDP3OcvvoFRLWLkw1PmAlIzLyCDOEVIarsoCJmwPkEehUF2YewAANqvn3lqYvN8EqKlFyw0g2Y7XijJCkmXRrJoa3V/liMkVmpt4fWzHxA7gGGog3XkYrT1FOUiQSYZ8nK2qjJ/MSgm9iI7V9d1oCvxgPThiEB5GhJo0PIoW9UOwuYuMc29HAJsQGhBhmBFGBsQ47VqNJk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m2sOTfkWq1pPDv1KpCMing/VIiZxKzohAGxg88xF3e7dzcOf07m7XOxuyne6Sp/L+nPgwkXeWQY7N7e9dX1fPjS+uKXj9NGVDrPt4cDS5Y46TH+o9qQ1WvpBs+MGLD1v+ILItEWYE1CS+IAW5D3N2Z4VC4y+r73Lb3V+Ep8aVG3DOMNep/txTuMIxUPJ+thOi/Wqxo4B2YdTKJhnLUnHOUabzA5BWZfXMkXXIpYBjhJ09pioaiH4tzbV9xScwFdDODJqHb9adaJXsYF5O0SROu4fmfAe2e1DGtKLrq3HkiLzSm6KhiKuwuE4Q6I6tMMxtuK4bcc7lHpm/rS9Gg/gKAtecA8tHkRJI6akdtwfRrcQ14IXm35LytfTffWxCu5AaxvzMKw8ojx2gOa4R9RsQkS3Isr74UIk6d+DIDJTA1S0T6zRWm7RgYa7EgUC/itNSKPI8M446kgUve7YpYg6nB6ehbbndLkw3vM0pcOF5dywrFqVqR5PL+nyxd+43muNh6pjz+OO2wnSYnFlJ5aihBLXQaoHCfhU/c7aKP9rjzfA/e1ZmAnoQM9jE3E3jRHRdipyq/xDWSvhZOp8POgMGERo1RuQjfr0mZSxhQVfUosC0ew2Njpxw6soTNNXPquk+18GYZnWe4ZBuLYYJg1AsOK73YmxFPkIp8vUMOVXTzBDryDDJ55zMuZA1sGqYQWkPNQ6zaCTujwtlqQCczkILamUmMV802++te5ORm3tIdXkHro4O+hmk0b84fNL7I2fb9++oclT1n5CnCNBpaKb4/xRNBxwYDQL4I6brGordPwqYOtrRq0UiSldFXLNdeaPCLbkoJ54vcl8BSQAZYSganoGJ7qagYor4fU2yVcfwZhy7oUf4AiXZKPWUtNTrhG8ZTNrAYES7OkwewopNgLwPLwerI5MG+jSZ4vAt
2018-03-19 20:31:54 -04:00
if (settings.localport == null) { settings.localport = 3000; }
// Start the web server
var http = require('http');
webServer = http.createServer();
webServer.listen(settings.localport);
webServer.wsList = {};
webServer.wsListIndex = 0;
2018-03-19 20:31:54 -04:00
webServer.on('upgrade', function (req, socket, head) {
//console.log("WebSocket for " + req.url.split('?')[0]);
switch (req.url.split('?')[0]) {
case '/webrelay.ashx': // MeshCommander relay channel
var ws = socket.upgradeWebSocket();
socket.ws = ws;
ws.wsIndex = ++webServer.wsListIndex;
2018-03-21 18:39:16 -04:00
webServer.wsList[ws.wsIndex] = ws; // Keep a reference so the websocket and forwarder don't get disposed.
2018-03-19 20:31:54 -04:00
ws.pause();
// We got a new web socket connection, initiate a TCP connection to the target Intel AMT host/port.
var webargs = parseUrlArguments(req.url);
if (webargs.p) { webargs.p = parseInt(webargs.p); }
if (webargs.tls) { webargs.tls = parseInt(webargs.tls); }
if (webargs.tls1only) { webargs.tls1only = parseInt(webargs.tls1only); }
if (webargs.port) { webargs.port = parseInt(webargs.port); }
2019-04-29 00:23:49 -04:00
debug(1, 'Opening web socket connection to ' + webargs.host + ':' + webargs.port + '.');
2018-03-19 20:31:54 -04:00
//console.log('Opening web socket connection to ' + webargs.host + ':' + webargs.port + '.');
if (webargs.tls == 0) {
// If this is TCP (without TLS) set a normal TCP socket
var net = require('net');
ws.forwardclient = net.connect({ host: webargs.host, port: webargs.port })
2019-04-29 00:23:49 -04:00
ws.forwardclient.on('connect', function () { debug(1, 'Connected TCP to ' + webargs.host + ':' + webargs.port + '.'); this.pipe(this.ws, { end: false }); this.ws.pipe(this, { end: false }); });
ws.forwardclient.on('error', function () { debug(1, 'TCP connection error to ' + webargs.host + ':' + webargs.port + '.'); try { this.ws.end(); } catch (e) { } });
2018-03-19 20:31:54 -04:00
ws.forwardclient.ws = ws;
} else {
// If TLS is going to be used, setup a TLS socket
var tls = require('tls');
var tlsoptions = { host: webargs.host, port: webargs.port, secureProtocol: ((webargs.tls1only == 1) ? 'TLSv1_method' : 'SSLv23_method'), rejectUnauthorized: false };
2019-04-29 00:23:49 -04:00
ws.forwardclient = tls.connect(tlsoptions, function () { debug(1, 'Connected TLS to ' + webargs.host + ':' + webargs.port + '.'); this.pipe(this.ws, { end: false }); this.ws.pipe(this, { end: false }); });
ws.forwardclient.on('error', function () { debug(1, 'TLS connection error to ' + webargs.host + ':' + webargs.port + '.'); try { this.ws.end(); } catch (e) { } });
2018-03-19 20:31:54 -04:00
ws.forwardclient.ws = ws;
}
2018-03-21 18:39:16 -04:00
// Handle pipe closure
2019-04-29 00:23:49 -04:00
ws.on('end', function () { debug(1, 'Disconnected from ' + webargs.host + ':' + webargs.port + '.'); try { this.forwardclient.end(); } catch (e) { } delete webServer.wsList[this.wsIndex]; });
2018-03-21 18:39:16 -04:00
ws.forwardclient.on('end', function () { try { this.ws.end(); } catch (e) { } });
2018-03-19 20:31:54 -04:00
break;
default:
socket.end();
break;
}
});
webServer.on('request', function (req, rsp) {
//console.log("WebRequest for " + req.url.split('?')[0]);
switch (req.url.split('?')[0]) {
case '/': // Serve MeshCommander Web Application
var meshcommander = null;
try { meshcommander = fs.readFileSync('meshcommander.htm'); } catch (e) { }
if (meshcommander != null) {
rsp.writeHead(200, 'OK', { Server: 'JSLMS', 'Cache-Control': 'max-age=0, no-cache', 'X-Frame-Options': 'DENY', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked' });
rsp.end(meshcommander);
} else {
rsp.writeHead(200, 'OK', { Server: 'JSLMS', 'Cache-Control': 'max-age=0, no-cache', 'X-Frame-Options': 'DENY', 'Content-Type': 'text/html', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', ETag: _IntelAmtLocalWebApp_etag });
rsp.end(Buffer.from(_IntelAmtLocalWebApp, 'base64'));
}
break;
default: // Unknown request
rsp.statusCode = 404;
rsp.statusMessage = "Not Found";
rsp.end();
break;
}
});
console.log('MeshCommander running on HTTP port ' + settings.localport + '.');
console.log('Press ctrl-c to exit.');
}
2018-03-06 20:50:44 -05:00
//
// Deactivate Intel AMT CCM
//
// When called, this will use MEI to deactivate Intel AMT when it's in CCM mode. Simply calls "unprovision" on MEI and checks the return code.
function deactivateCCM() {
2019-03-01 20:13:11 -05:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
2018-03-06 20:50:44 -05:00
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
2018-03-19 20:31:54 -04:00
amtMei.unprovision(1, function (status) { if (status == 0) { console.log('Success'); } else { console.log('Error ' + status); } exit(1); });
2018-03-06 20:50:44 -05:00
}
//
// Activate Intel AMT to CCM
//
function activeToCCM() {
// See if MicroLMS needs to be started and setup the $$OsAdmin wsman stack
settings.noconsole = true;
startLms(activeToCCMEx); // TODO: Fix this so that it works even if LMS already running.
}
function activeToCCMEx(state) {
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToCCMEx2);
}
function activeToCCMEx2(stack, name, responses, status) {
if (status != 200) { console.log('Failed to fetch activation status, status ' + status); exit(1); }
else if (responses['IPS_HostBasedSetupService'].response['AllowedControlModes'].length != 2) { console.log('Client control mode activation not allowed'); exit(1); }
else { osamtstack.IPS_HostBasedSetupService_Setup(2, md5hex('admin:' + responses['AMT_GeneralSettings'].response['DigestRealm'] + ':' + settings.password).substring(0, 32), null, null, null, null, activeToCCMEx3); }
2018-03-06 20:50:44 -05:00
}
function activeToCCMEx3(stack, name, responses, status) {
if (status != 200) { console.log('Failed to activate, status ' + status); }
else if (responses.Body.ReturnValue != 0) { console.log('Client control mode activation failed: ' + responses.Body.ReturnValueStr); }
else { console.log('Success'); exit(0); }
exit(1);
}
//
// Deactivate Intel AMT ACM
//
// When called, this will use MEI to deactivate Intel AMT when it's in ACM mode. Calls "unprovision" on MEI and checks the return code.
function deactivateACM() {
settings.noconsole = true;
startLms(deactivateACMEx);
}
function deactivateACMEx() {
var transport = require('amt-wsman-duk');
var wsman = require('amt-wsman');
var amt = require('amt');
wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls);
amtstack = new amt(wsstack);
amtstack.Get("AMT_SetupAndConfigurationService", function (stack, name, responses, status) {
if (status !== 200) {
console.log('Command not allowed. Status: ' + status);
exit(1);
} else {
var sacs = responses.Body;
if (sacs.ZeroTouchConfigurationEnabled == true) { sacs.ZeroTouchConfigurationEnabled = true; }
amtstack.Put("AMT_SetupAndConfigurationService", sacs, function (stack, name, responses, status) {
if (settings.type == 'full') {
amtstack.AMT_SetupAndConfigurationService_Unprovision(2, function (stack, name, responses, status) {
if (status != 200) { console.log('Failed to fully unconfigure AMT, status ' + status); exit(1); }
else if (responses.Body.ReturnValue != 0) { console.log('Unprovision failed: ' + responses.Body.ReturnValueStr); exit(1); }
else { console.log('AMT fully unprovisioned.'); exit(0); }
});
} else {
console.log('Only full unprovision is currently supported.');
exit(0);
}
//} else if (settings.type == 'partial') {
// amtstack.AMT_SetupAndConfigurationService_PartialUnprovision(null, function (stack, name, responses, status) {
// if (status != 200) { console.log('Failed to partially unconfigure AMT, status ' + status); exit(1); }
// else if (responses.Body.ReturnValue != 0) { console.log('Unprovision failed: ' + responses.Body.ReturnValueStr); exit(1); }
// else { console.log('AMT partially unprovisioned.'); exit(0); }
// });
//}
});
}
});
}
//
// Activate Intel AMT to ACM
//
function activeToACM() {
// See if MicroLMS needs to be started and setup the $$OsAdmin wsman stack
console.log('Starting AMT Provisioning to Admin Control Mode.');
settings.noconsole = true;
// Display Intel AMT version and activation state
mestate = {};
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
amtMei.getProvisioningState(function (result) {
if (result) {
mestate.ProvisioningState = result;
startLms(getFwNonce); // TODO: Fix this so that it works even if LMS already running.
}
});
}
// Gets the FWNonce from AMT and saves it to a file.
function getFwNonce() {
osamtstack.Get("IPS_HostBasedSetupService", function (obj, name, responses, status) {
var fwNonce = Buffer.from(responses["Body"]['ConfigurationNonce'], 'base64');
2019-06-13 12:12:11 -04:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
amtMei.getDnsSuffix(function (result) {
activeToACMEx(fwNonce, result);
});
});
}
// Sends a message to RCS server using RCS Message Protocol
function sendRCSMessage(socket, status, event, message) {
//console.log('Status: ' + status + '. Event: ' + event + '. Message: ' + message);
if (socket !== null) { socket.write({"status": status, "event": event, "data": message}); }
}
2019-06-13 12:12:11 -04:00
function activeToACMEx(fwNonce, dnsSuffix) {
// open connection to RCS
console.log('Initializing WebSocket...');
// Establish WebSocket connection to RCS server
var connection = http.request(settings.wss);
connection.on('upgrade', function (response, socket) {
// WebSocket is up. Handle data on the duplex socket
socket.on('data', function (data) {
// All messages from RCS are JSON.stringify format and need to be parsed
var message = JSON.parse(data);
// Check RCS Message Protocol version. Exit if version not supported
if (message.version > RCSMessageProtocolVersion) { console.log('Unsupported RCS server.'); socket.end(); exit(0) }
// Handle the AMT provisioning certificate blob (contains provisioning certificate, mcnonce, digital signature and password hash)
if (message.data.provCertObj !== undefined) {
activeToACMEx1(message.data, function (stack, name, responses, status, message) {
if (status !== 200) {
2019-06-13 12:12:11 -04:00
if (status == 2) {
console.log('AMT already provisioned.Exiting ' + status);
sendRCSMessage(socket, "error", "finish", "failed with status: " + status);
2019-06-13 12:12:11 -04:00
}
else {
console.log('Failed to fetch activation status, status ' + status);
sendRCSMessage(socket, "error", "finish", "failed with status: " + status);
}
socket.end();
exit(status);
2019-06-13 12:12:11 -04:00
} else if (responses['IPS_HostBasedSetupService'].response['AllowedControlModes'].length != 2) {
console.log('Admin control mode activation not allowed');
2019-06-13 12:12:11 -04:00
sendRCSMessage(socket, "error", "finish", "failed with message: Admin control mode activation not allowed");
socket.end();
exit(status);
2019-06-13 12:12:11 -04:00
} else {
activeToACMEx2(message, responses, function (stack, name, responses, status, message) {
if (status != 200) {
console.log('Failed to activate, status ' + status);
sendRCSMessage(socket, "error", "finish", "failed to activate. Status: " + status);
} else if (responses.Body.ReturnValue != 0) {
console.log('Admin control mode activation failed: ' + responses.Body.ReturnValueStr);
sendRCSMessage(socket, "error", "finish", "failed to activate: " + responses.Body.ReturnValueStr);
} else {
2019-06-13 12:12:11 -04:00
if (message.profileScript !== '') {
console.log("Running MEScript...");
settings.scriptjson = message.profileScript;
settings.password = message.amtPassword
settings.username = 'admin';
startMeScriptEx(function () {
console.log('AMT Profile applied');
sendRCSMessage(socket, "ok", "finish", "success");
socket.end();
exit(0);
}, stack);
} else {
sendRCSMessage(socket, "ok", "finish", "success");
socket.end();
exit(0);
}
console.log('AMT Provisioning Success');
2019-06-13 12:12:11 -04:00
}
2019-06-13 12:12:11 -04:00
//socket.end();
//exit(status);
});
}
});
}
2019-06-13 12:12:11 -04:00
if (message.event.toString() == "cmd" && message.data.toString() == "acmready") {
sendRCSMessage(socket, "ok", "message", JSON.stringify(fwNonce));
}
});
2019-06-13 12:12:11 -04:00
socket.on('end', function () {
console.log('WebSocket closed');
});
sendRCSMessage(socket, "ok", "cmd", { "cmd": "acm", "dnssuffix": dnsSuffix, "profile": settings.profile });
});
}
// Detects AMT provisioning state and injects the certificate chain into AMT firmware
function activeToACMEx1(data, callback) {
if (mestate.ProvisioningState.state == 0) {
console.log('Performing ACM provisioning...');
// Perform full provisioning -- AMT was fully unprovisioned
injectCert(0, data, function (stack, name, responses, status, data) {
if (status !== 200) { exit(status); return; }
else if (responses['Body']['ReturnValue'] !== 0) { exit(responses['Body']['ReturnValueStr']); return; }
else if (responses['Body']['ReturnValue'] == 0) {
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], function (stack, name, responses, status) {
callback(stack, name, responses, status, data);
});
}
});
} else if (mestate.ProvisioningState.state == 1) {
// Perform partial provisioning -- AMT was partial unprovisioned
// Currently not functional due to limitations in the HW.
console.log('Partial provisioning flow currently not available.');
exit(0);
//osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToACMEx2);
} else {
// AMT already provisioned
callback(null, null, null, 2, 'AMT already provisioned. Exiting')
exit(0);
}
}
// Recursive function to inject the provisioning certificates into AMT in the proper order
function injectCert(index, cert, callback, stack, name, responses, status) {
var leaf = false;
var root = false;
if (index == 0) { leaf = true; }
if (index == cert.provCertObj.certChain.length - 1) { root = true; }
if (index < cert.provCertObj.certChain.length){
if (cert.provCertObj.certChain[index] !== undefined){
osamtstack.IPS_HostBasedSetupService_AddNextCertInChain(cert.provCertObj.certChain[index], leaf, root, function (stack, name, responses, status) {
if (status !== 200) { exit(status); return; }
else if (responses['Body']['ReturnValue'] !== 0) { exit(responses['Body']['ReturnValueStr']); return; }
else if (responses['Body']['ReturnValue'] == 0) {
index++;
injectCert(index, cert, callback, stack, name, responses, status);
}
});
}
} else { callback(stack, name, responses, status, cert); }
}
// Sends the password hash, mcnonce, and digital signature to complete the admin control mode provisioning
2019-06-13 12:12:11 -04:00
function activeToACMEx2(data, responses, callback) {
var passwordhash = md5hex('admin:' + responses['AMT_GeneralSettings'].response['DigestRealm'] + ':' + data.amtPassword).substring(0, 32);
//var debugreturn = {"Body": {"ReturnValue": 0}};
//console.log("DEBUG: Everything up to activation works"); callback(null, null, debugreturn, 200, data);
osamtstack.IPS_HostBasedSetupService_AdminSetup(2, passwordhash, data.mcNonce, 2, data.digitalSignature, function (stack, name, responses, status) { callback(stack, name, responses, status, data); });
}
2018-03-06 20:50:44 -05:00
//
// Get AMT UUID
//
// Called to get the UUID of Intel AMT, start by setting up MicroLMS if we are doing the operation on the local computer
function getAmtUuid() {
if (settings.hostname == null) {
2019-03-01 20:13:11 -05:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
amtMei.getUuid(function (result) { if ((result == null) || (result.uuid == null)) { console.log('Failed.'); } else { console.log(result.uuid); } exit(1); });
} else {
if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) { settings.noconsole = true; startLms(getAmtUuidEx); return; } else { getAmtUuidEx(); }
}
2018-03-06 20:50:44 -05:00
}
// Fetch the computer's UUID by fetching the CIM_ComputerSystemPackage WSMAN object.
function getAmtUuidEx() {
var transport = require('amt-wsman-duk');
var wsman = require('amt-wsman');
var amt = require('amt');
wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls);
amtstack = new amt(wsstack);
amtstack.Get("CIM_ComputerSystemPackage", function (obj, name, response, xstatus, tag) {
if (xstatus == 200) { console.log("GUID: " + guidToStr(response.Body.PlatformGUID.toLowerCase())); } else { console.log("Intel AMT is not available or not activated."); } exit(1);
});
}
//
// Run MESCRIPT
//
2018-03-06 20:50:44 -05:00
// Run a .mescript targeting local or remote Intel AMT.
function startMeScript() {
// See if MicroLMS needs to be started
if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) { settings.noconsole = true; startLms(startMeScriptEx); return; } else { startMeScriptEx(); }
}
2019-06-13 12:12:11 -04:00
function startMeScriptEx(callback, amtstack) {
2018-03-06 20:50:44 -05:00
//console.log('Running script...');
var transport = require('amt-wsman-duk');
var wsman = require('amt-wsman');
var amt = require('amt');
2019-06-13 12:12:11 -04:00
if (!wsstack) { wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls); }
if (!amtstack) { amtstack = new amt(wsstack); }
2018-02-07 21:45:14 -05:00
//IntelAmtEntireStateProgress = 101;
//amtstack.onProcessChanged = onWsmanProcessChanged;
var scriptData = null;
2018-03-06 20:50:44 -05:00
if (settings.script != null) {
try { scriptData = fs.readFileSync(settings.script); } catch (e) { console.log('Unable to read script file (1): ' + settings.script + '.'); exit(1); return; }
} else {
2019-03-26 18:18:07 -04:00
scriptData = settings.scriptjson;
}
if (scriptData == null) { console.log('Unable to read script file (2): ' + settings.script + '.'); exit(1); return; }
try { scriptData = JSON.parse(scriptData); } catch (e) { console.log('Unable to read script file (3): ' + settings.script + '.'); exit(1); return; }
if (scriptData.mescript == null) { console.log('Unable to read script file (4): ' + settings.script + '.'); exit(1); return; }
var scriptData = Buffer.from(scriptData.mescript, 'base64');
var scriptModule = require('amt-script');
var script = scriptModule.setup(scriptData, {})
script.amtstack = amtstack;
script.start();
2019-06-13 12:12:11 -04:00
script.onCompleted = function () { if (callback) { callback(); } exit(1); }
}
2018-01-30 21:23:57 -05:00
2018-03-06 20:50:44 -05:00
2018-01-30 21:23:57 -05:00
//
// FETCH ALL INTEL AMT STATE
//
2018-01-25 19:28:52 -05:00
2019-03-01 20:13:11 -05:00
function saveEntireAmtState2()
{
2018-01-25 19:12:53 -05:00
console.log('Fetching all Intel AMT state, this may take a few minutes...');
2018-01-30 21:23:57 -05:00
var transport = require('amt-wsman-duk');
var wsman = require('amt-wsman');
var amt = require('amt');
wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls);
2018-01-02 19:52:49 -05:00
amtstack = new amt(wsstack);
2018-01-25 19:28:52 -05:00
amtstack.onProcessChanged = onWsmanProcessChanged;
//var AllWsman = "AMT_GeneralSystemDefenseCapabilities".split(',');
2018-01-02 19:52:49 -05:00
var AllWsman = "AMT_8021xCredentialContext,AMT_8021XProfile,AMT_ActiveFilterStatistics,AMT_AgentPresenceCapabilities,AMT_AgentPresenceInterfacePolicy,AMT_AgentPresenceService,AMT_AgentPresenceWatchdog,AMT_AgentPresenceWatchdogAction,AMT_AlarmClockService,IPS_AlarmClockOccurrence,AMT_AssetTable,AMT_AssetTableService,AMT_AuditLog,AMT_AuditPolicyRule,AMT_AuthorizationService,AMT_BootCapabilities,AMT_BootSettingData,AMT_ComplexFilterEntryBase,AMT_CRL,AMT_CryptographicCapabilities,AMT_EACCredentialContext,AMT_EndpointAccessControlService,AMT_EnvironmentDetectionInterfacePolicy,AMT_EnvironmentDetectionSettingData,AMT_EthernetPortSettings,AMT_EventLogEntry,AMT_EventManagerService,AMT_EventSubscriber,AMT_FilterEntryBase,AMT_FilterInSystemDefensePolicy,AMT_GeneralSettings,AMT_GeneralSystemDefenseCapabilities,AMT_Hdr8021Filter,AMT_HeuristicPacketFilterInterfacePolicy,AMT_HeuristicPacketFilterSettings,AMT_HeuristicPacketFilterStatistics,AMT_InterfacePolicy,AMT_IPHeadersFilter,AMT_KerberosSettingData,AMT_ManagementPresenceRemoteSAP,AMT_MessageLog,AMT_MPSUsernamePassword,AMT_NetworkFilter,AMT_NetworkPortDefaultSystemDefensePolicy,AMT_NetworkPortSystemDefenseCapabilities,AMT_NetworkPortSystemDefensePolicy,AMT_PCIDevice,AMT_PETCapabilities,AMT_PETFilterForTarget,AMT_PETFilterSetting,AMT_ProvisioningCertificateHash,AMT_PublicKeyCertificate,AMT_PublicKeyManagementCapabilities,AMT_PublicKeyManagementService,AMT_PublicPrivateKeyPair,AMT_RedirectionService,AMT_RemoteAccessCapabilities,AMT_RemoteAccessCredentialContext,AMT_RemoteAccessPolicyAppliesToMPS,AMT_RemoteAccessPolicyRule,AMT_RemoteAccessService,AMT_SetupAndConfigurationService,AMT_SNMPEventSubscriber,AMT_StateTransitionCondition,AMT_SystemDefensePolicy,AMT_SystemDefensePolicyInService,AMT_SystemDefenseService,AMT_SystemPowerScheme,AMT_ThirdPartyDataStorageAdministrationService,AMT_ThirdPartyDataStorageService,AMT_TimeSynchronizationService,AMT_TLSCredentialContext,AMT_TLSProtocolEndpoint,AMT_TLSProtocolEndpointCollection,AMT_TLSSettingData,AMT_TrapTargetForService,AMT_UserInitiatedConnectionService,AMT_WebUIService,AMT_WiFiPortConfigurationService,CIM_AbstractIndicationSubscription,CIM_Account,CIM_AccountManagementCapabilities,CIM_AccountManagementService,CIM_AccountOnSystem,CIM_AdminDomain,CIM_AlertIndication,CIM_AssignedIdentity,CIM_AssociatedPowerManagementService,CIM_AuthenticationService,CIM_AuthorizationService,CIM_BIOSElement,CIM_BIOSFeature,CIM_BIOSFeatureBIOSElements,CIM_BootConfigSetting,CIM_BootService,CIM_BootSettingData,CIM_BootSourceSetting,CIM_Capabilities,CIM_Card,CIM_Chassis,CIM_Chip,CIM_Collection,CIM_Component,CIM_ComputerSystem,CIM_ComputerSystemPackage,CIM_ConcreteComponent,CIM_ConcreteDependency,CIM_Controller,CIM_CoolingDevice,CIM_Credential,CIM_CredentialContext,CIM_CredentialManagementService,CIM_Dependency,CIM_DeviceSAPImplementation,CIM_ElementCapabilities,CIM_ElementConformsToProfile,CIM_ElementLocation,CIM_ElementSettingData,CIM_ElementSoftwareIdentity,CIM_ElementStatisticalData,CIM_EnabledLogicalElement,CIM_EnabledLogicalElementCapabilities,CIM_EthernetPort,CIM_Fan,CIM_FilterCollection,CIM_FilterCollectionSubscription,CIM_HostedAccessPoint,CIM_HostedDependency,CIM_HostedService,CIM_Identity,CIM_IEEE8021xCapabilities,CIM_IEEE8021xSettings,CIM_Indication,CIM_IndicationService,CIM_InstalledSoftwareIdentity,CIM_KVMRedirectionSAP,CIM_LANEndpoint,CIM_ListenerDestination,CIM_ListenerDestinationWSManagement,CIM_Location,CIM_Log,CIM_LogEntry,CIM_LogicalDevice,CIM_LogicalElement,CIM_LogicalPort,CIM_LogicalPortCapabilities,CIM_LogManagesRecord,CIM_ManagedCredential,CIM_ManagedElement,CIM_ManagedSystemElement,CIM_MediaAccessDevice,CIM_MemberOfCollection,CIM_Memory,CIM_MessageLog,CIM_NetworkPort,CIM_NetworkPortCapabilities,CIM_NetworkPortConfigurationService,CIM_OrderedComponent,CIM_OwningCollectionElement,CIM_OwningJobElement,CIM_PCIController,CIM_PhysicalComponent,CIM_PhysicalElement,CIM_PhysicalElementLocation,CIM_PhysicalFrame,CIM_PhysicalMemory,CIM_PhysicalPackage,CIM_Policy,CIM_PolicyAction,CIM_PolicyCondition,CIM_PolicyInSystem,CIM_PolicyRule,CIM_PolicyR
2018-01-25 19:28:52 -05:00
IntelAmtEntireStateProgress = 101;
2018-01-02 19:52:49 -05:00
IntelAmtEntireStateCalls = 3;
IntelAmtEntireState = { 'localtime': Date(), 'utctime': new Date().toUTCString(), 'isotime': new Date().toISOString() };
amtstack.BatchEnum(null, AllWsman, saveEntireAmtStateOk2, null, true);
amtstack.GetAuditLog(saveEntireAmtStateOk3);
amtstack.GetMessageLog(saveEntireAmtStateOk4);
2019-03-01 20:13:11 -05:00
}
// Save the entire Intel AMT state
function saveEntireAmtState()
{
// See if MicroLMS needs to be started
if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost'))
{
settings.noconsole = true;
startLms().then(saveEntireAmtState2);
}
else
{
saveEntireAmtState2();
}
2018-01-02 19:52:49 -05:00
}
2018-01-25 19:28:52 -05:00
function onWsmanProcessChanged(a, b) { var x = Math.floor((a * 100) / b); if (x < IntelAmtEntireStateProgress) { IntelAmtEntireStateProgress = x; console.log((100 - x) + '%'); } }
function saveEntireAmtStateOk2(stack, name, responses, status) { if (status == 600) { console.log('ERROR: Unable to connect to Intel(R) AMT.'); exit(2); } IntelAmtEntireState['wsmanenums'] = responses; saveEntireAmtStateDone(); }
function saveEntireAmtStateOk3(stack, messages, status) { if (status == 600) { console.log('ERROR: Unable to connect to Intel(R) AMT.'); exit(2); } IntelAmtEntireState['auditlog'] = messages; saveEntireAmtStateDone(); }
function saveEntireAmtStateOk4(stack, messages, tag, status) { if (status == 600) { console.log('ERROR: Unable to connect to Intel(R) AMT.'); exit(2); } IntelAmtEntireState['eventlog'] = messages; saveEntireAmtStateDone(); }
2018-01-02 19:52:49 -05:00
2018-01-30 21:23:57 -05:00
// Called when the entire state of Intel AMT is fetched.
2018-01-02 19:52:49 -05:00
function saveEntireAmtStateDone() {
if (--IntelAmtEntireStateCalls != 0) return;
2018-01-25 19:12:53 -05:00
var out = fs.openSync(settings.output, 'w');
2019-03-01 20:13:11 -05:00
fs.writeSync(out, Buffer.from(JSON.stringify(IntelAmtEntireState)));
2018-01-25 19:12:53 -05:00
fs.closeSync(out);
console.log('Done, results written to ' + settings.output + '.');
2018-01-02 19:52:49 -05:00
exit(1);
}
2018-01-30 21:23:57 -05:00
//
// FETCH ALL INTEL AMT MEI STATE
//
// Get Intel AMT information using MEI
2018-03-06 20:50:44 -05:00
// TODO: If this call is called many time at once, it's going to cause issues.
var getAmtInfoFetching = null;
var getAmtInfoFetchingTimer = null;
function getAmtInfo(func, tag) {
if (amtMei == null) { if (func != null) { func(null, tag); } return; }
if (getAmtInfoFetching != null) { getAmtInfoFetching.push({ f: func, t: tag }); return; }
getAmtInfoFetching = [{ f: func, t: tag }];
2018-03-06 20:50:44 -05:00
amtMeiTmpState = { Flags: 0, TrustedHashes: [] }; // Flags: 1=EHBC, 2=CCM, 4=ACM
getAmtInfoFetchingTimer = setTimeout(function () {
// MEI failed to respond, break out and reset everthing.
for (var i in getAmtInfoFetching) { if (getAmtInfoFetching[i].f != null) { getAmtInfoFetching[i].f(amtMeiTmpState, getAmtInfoFetching[i].t); } }
getAmtInfoFetching = null;
getAmtInfoFetchingTimer = null;
2019-03-01 20:13:11 -05:00
var amtMeiModule, amtMei;
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
}, 3000);
amtMei.getProtocolVersion(function (result) { if (result != null) { amtMeiTmpState.MeiVersion = result; } });
amtMei.getVersion(function (val) {
amtMeiTmpState.Versions = {};
if (val != null) {
for (var version in val.Versions) { amtMeiTmpState.Versions[val.Versions[version].Description] = val.Versions[version].Version; }
amtMei.getProvisioningMode(function (result) { if (result != null) { amtMeiTmpState.ProvisioningMode = result.mode; } });
amtMei.getProvisioningState(function (result) { if (result != null) { amtMeiTmpState.ProvisioningState = result.state; } });
amtMei.getEHBCState(function (result) { if ((result != null) && (result.EHBC == true)) { amtMeiTmpState.Flags += 1; } });
amtMei.getControlMode(function (result) { if (result != null) { if (result.controlMode == 1) { amtMeiTmpState.Flags += 2; } if (result.controlMode == 2) { amtMeiTmpState.Flags += 4; } } });
//amtMei.getMACAddresses(function (result) { if (result != null) { amtMeiTmpState.mac = result; } });
amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.dns = result; } });
amtMei.getHashHandles(function (handles) {
exitOnCount = handles.length;
for (var i = 0; i < handles.length; ++i) {
amtMei.getCertHashEntry(handles[i], function (result) {
amtMeiTmpState.TrustedHashes.push({ Active: result.isActive, Default: result.isDefault, HashAlgorithm: result.hashAlgorithm, Name: result.name, Hash: result.certificateHash });
2018-03-06 20:50:44 -05:00
if (--exitOnCount == 0) {
amtMeiTmpState.Notifications = lmsNotifications; amtMeiState = amtMeiTmpState;
for (var i in getAmtInfoFetching) { if (getAmtInfoFetching[i].f != null) { getAmtInfoFetching[i].f(amtMeiTmpState, getAmtInfoFetching[i].t); } }
getAmtInfoFetching = null;
clearTimeout(getAmtInfoFetchingTimer);
getAmtInfoFetchingTimer = null;
2018-03-06 20:50:44 -05:00
}
});
}
});
} else {
amtMeiState = amtMeiTmpState;
amtMeiState.ProvisioningMode = -858993460;
amtMeiState.TrustedHashes = {};
amtMeiState.Notifications = lmsNotifications;
2018-03-06 20:50:44 -05:00
//console.log('getAmtInfo3', JSON.stringify(amtMeiState));
if (func != null) { func(amtMeiState, tag); }
}
});
}
2018-01-30 21:23:57 -05:00
//
// MicroLMS
//
var lmsControlSockets = {};
var lmsControlSocketsNextId = 1;
var lmsNotifications = [];
2018-03-06 20:50:44 -05:00
var amtLms = null;
2019-03-01 20:13:11 -05:00
var promise = require('promise');
function startLms(func, lmscommander)
2019-03-01 20:13:11 -05:00
{
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
var lme_heci = null
try { lme_heci = require('amt-lme'); } catch (ex) { }
if (lme_heci == null) { if (func != null) { func(func, 0); } this.promise._res(); return; }
2018-03-06 20:50:44 -05:00
//var amtLms = null;
var http = require('http');
2019-03-01 20:13:11 -05:00
console.log('Setting up MEI...');
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
2018-01-25 19:28:52 -05:00
amtMei.on('error', function (e) { console.log('ERROR: ' + e); exit(1); return; });
2018-03-19 20:31:54 -04:00
//console.log("PTHI Connected.");
2019-03-01 20:13:11 -05:00
console.log('Setting up LME...');
2018-03-19 20:31:54 -04:00
amtLms = new lme_heci({ debug: settings.lmsdebug });
2019-03-01 20:13:11 -05:00
amtLms.promise = ret;
2018-03-19 20:31:54 -04:00
amtLms.on('error', function (e) {
//console.log('LME connection failed', e);
if (lmscommander === true) { //settings.noconsole !== true) {
startMeshCommanderLms();
//console.log("LMS started, MeshCommander on HTTP/16994.");
tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2); }, 100);
} else {
//console.log('LME connection failed: ' + JSON.stringify(e));
tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 0); }, 100);
}
2019-03-01 20:13:11 -05:00
this.promise._res();
2018-03-19 20:31:54 -04:00
});
amtLms.on('notify', function (data, options, str, code) {
if (code == 'iAMT0052-3') {
kvmGetData();
2018-03-19 20:31:54 -04:00
} else if (str != null) {
var notify = { date: Date.now(), str: str, code: code };
lmsNotifications.push(notify);
while (lmsNotifications.length > 100) { lmsNotifications.shift(); }
var notifyBuf = Buffer.concat([Buffer.from('0900', 'hex'), Buffer.from(JSON.stringify(notify))]) // Add a notification
for (var i in lmsControlSockets) { lmsControlSockets[i].write(notifyBuf); }
}
});
//console.log('LME Connecting...');
2019-03-01 20:13:11 -05:00
amtLms.on('bind', function (mapping) {
if (mapping[16992]) { this.removeAllListeners('bind'); } else { return; }
//console.log('LMS Bounded');
2018-03-19 20:31:54 -04:00
amtLms.connected = true;
2019-03-01 20:13:11 -05:00
this.promise._res();
2018-03-19 20:31:54 -04:00
//console.log("LME Connected.");
if (settings.noconsole !== true) {
startMeshCommanderLms();
2018-03-19 20:31:54 -04:00
//console.log("LMS started, MeshCommander on HTTP/16994.");
tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2); }, 100);
//console.logReferenceCount(tempTimer);
} else {
//console.log("LMS started.");
tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 1); }, 100);
//console.logReferenceCount(tempTimer);
}
});
2019-03-01 20:13:11 -05:00
return (ret);
}
function startMeshCommanderLms() {
2019-04-17 20:08:01 -04:00
// MeshCommander LMS v0.7.5
var _IntelAmtWebApp_etag = "C2ZfnIbUEl7w4c1S1Xbd";
var _IntelAmtWebApp = "77u/PCFET0NUWVBFIGh0bWw+DQo8aHRtbCBzdHlsZT0iaGVpZ2h0OjEwMCUiPg0KPGhlYWQ+DQogICAgPG1ldGEgaHR0cC1lcXVpdj0iWC1VQS1Db21wYXRpYmxlIiBjb250ZW50PSJJRT1lZGdlIj4gDQogICAgPG1ldGEgY29udGVudD0idGV4dC9odG1sO2NoYXJzZXQ9dXRmLTgiIGh0dHAtZXF1aXY9IkNvbnRlbnQtVHlwZSI+DQogICAgPG1ldGEgbmFtZT0iZm9ybWF0LWRldGVjdGlvbiIgY29udGVudD0idGVsZXBob25lPW5vIj4NCiAgICA8bGluayByZWw9Imljb24iIHR5cGU9ImltYWdlL3BuZyIgaHJlZj0iZGF0YTppbWFnZS9wbmc7YmFzZTY0LGlWQk9SdzBLR2dvPSI+IDwhLS0gU3RvcCBmYXZpY29uLmljbyBmcm9tIGxvYWRpbmcgLS0+DQogICAgPHN0eWxlPmJvZHkgew0KICAgIGhlaWdodDogMTAwJTsNCiAgICBtYXgtaGVpZ2h0OiAxMDAlOw0KICAgIG92ZXJmbG93OiBoaWRkZW47DQogICAgZm9udC1mYW1pbHk6IGFyaWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWY7DQogICAgZm9udC1zaXplOiA5cHQ7DQogICAgY29sb3I6IGJsYWNrOw0KICAgIGJhY2tncm91bmQ6IHdoaXRlOw0KICAgIG1hcmdpbi10b3A6IDA7DQogICAgbWFyZ2luLWxlZnQ6IDA7DQogICAgbWFyZ2luLXJpZ2h0OiAwOw0KICAgIC13ZWJraXQtdG91Y2gtY2FsbG91dDogbm9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ICAgcG9zaXRpb246IGZpeGVkOw0KICAgIHRvcDogNjlweDsNCiAgICByaWdodDogMDsNCiAgICBib3R0b206IDA7DQogICAgbGVmdDogMHB4Ow0KICAgIG92ZXJmbG93OiBoaWRkZW47DQp9DQoNCi5tYWluY2VsbCB7DQogICAgcG9zaXRpb246IGZpeGVkOw0KICAgIHRvcDogNjlweDsNCiAgICByaWdodDogMDsNCiAgICBib3R0b206IDA7DQogICAgbGVmdDogMTU2cHg7DQogICAgb3ZlcmZsb3c6IGhpZGRlbjsNCiAgICBwYWRkaW5nLWxlZnQ6IDJweDsNCiAgICB2ZXJ0aWNhbC1hbGlnbjogdG9wOw0KfQ0KDQoubmF2YmFyIHsNCiAgICBwb3NpdGlvbjogZml4ZWQ7DQogICAgdG9wOiA2OXB4Ow0KICAgIGxlZnQ6IDA7DQogICAgYm90dG9tOiAwOw0KICAgIHdpZHRoOiAxNTZweDsNCiAgICBib3JkZXItcmlnaHQ6IDJweCBzb2xpZCAjQjBDNkZDOw0KICAgIHZlcnRpY2FsLWFsaWduOiB0b3A7DQogICAgYmFja2dyb3VuZDogIzAzNjsNCiAgICBiYWNrZ3JvdW5kOiBsaW5lYXItZ3JhZGllbnQodG8gYm90dG9tLCAjYmZkMWZjIDAlLCNlOGVlZmUgMTAwJSk7DQp9DQoNCi5uYXYxIHsNCiAgICBwYWRkaW5nOiAxcHggMHB4IDFweCA4cHg7DQogICAgbWFyZ2luOiAwcHg7DQogICAgZm9udC13ZWlnaHQ6IGJvbGQ7DQogICAgY29sb3I6IGJsYWNrOw0KICAgIHdoaXRlLXNwYWNlOiBub3dyYXA7DQogICAgY3Vyc29yOiBwb2ludGVyOw0KfQ0KDQoubmF2MiB7DQogICAgbWFyZ2luLWxlZnQ6IDMycHg7DQogICAgbWFyZ2luLXRv
amtLms.meshCommander = http.createServer();
amtLms.meshCommander.listen(16994);
amtLms.meshCommander.on('upgrade', function (req, socket, head) {
//console.log("WebSocket for " + req.url.split('?')[0]);
switch (req.url.split('?')[0]) {
case '/lms.ashx': // MeshCommander control channel (PTHI)
socket.ws = socket.upgradeWebSocket();
socket.ws.on('data', processLmsControlData);
socket.ws.on('end', function () { if (lmsControlSockets[this.id]) { delete lmsControlSockets[this.id]; /*console.log('removeControl', JSON.stringify(lmsControlSockets));*/ } });
var id = lmsControlSocketsNextId++;
lmsControlSockets[id] = socket.ws;
socket.ws.id = id;
//socket.ws.write(Buffer.concat([Buffer.from('0900', 'hex'), Buffer.from(JSON.stringify(lmsNotifications))])); // Send out full list of notifications
//console.log('addControl', JSON.stringify(lmsControlSockets));
break;
case '/webrelay.ashx': // MeshCommander data channel (LME)
socket.ws = socket.upgradeWebSocket();
if (amtLms.connected == true) {
// Route traffic directly into MicroLMS
amtLms.bindDuplexStream(socket.ws, 'IPv4', 16992);
} else {
// Route traffic to real LMS service
var net = require('net');
socket.relay = net.connect({ host: '127.0.0.1', port: 16992 })
socket.relay.on('connect', function () {
socket.ws.on('data', function (data) { socket.relay.write(data); });
socket.ws.on('end', function () { socket.relay.end(); });
});
socket.relay.on('data', function (data) { socket.ws.write(data); });
socket.relay.on('close', function () { socket.ws.end(); });
}
break;
default:
socket.end();
break;
}
});
amtLms.meshCommander.on('request', function (req, rsp) {
//console.log("WebRequest for " + req.url.split('?')[0]);
switch (req.url.split('?')[0]) {
case '/': // Serve MeshCommander Web Application for LMS
var lmscommander = null;
try { lmscommander = fs.readFileSync('lmscommander.htm'); } catch (e) { }
if (lmscommander != null) {
rsp.writeHead(200, 'OK', { Server: 'JSLMS', 'Cache-Control': 'max-age=0, no-cache', 'X-Frame-Options': 'DENY', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked' });
rsp.end(lmscommander);
} else {
rsp.writeHead(200, 'OK', { Server: 'JSLMS', 'Cache-Control': 'max-age=0, no-cache', 'X-Frame-Options': 'DENY', 'Content-Type': 'text/html', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', ETag: _IntelAmtWebApp_etag });
rsp.end(Buffer.from(_IntelAmtWebApp, 'base64'));
}
break;
default: // Unknown request
rsp.statusCode = 404;
rsp.statusMessage = "Not Found";
rsp.end();
break;
}
});
}
2018-03-06 20:50:44 -05:00
function setupMeiOsAdmin(func, state) {
2019-03-01 20:13:11 -05:00
if (amtMei == null) {
2018-03-06 20:50:44 -05:00
if (func) { func(state); }
2019-03-01 20:13:11 -05:00
} else {
amtMei.getLocalSystemAccount(function (x) {
var transport = require('amt-wsman-duk');
var wsman = require('amt-wsman');
var amt = require('amt');
oswsstack = new wsman(transport, '127.0.0.1', 16992, x.user, x.pass, false);
osamtstack = new amt(oswsstack);
if (func) { func(state); }
2019-03-01 20:13:11 -05:00
//var AllWsman = "CIM_SoftwareIdentity,IPS_SecIOService,IPS_ScreenSettingData,IPS_ProvisioningRecordLog,IPS_HostBasedSetupService,IPS_HostIPSettings,IPS_IPv6PortSettings".split(',');
//osamtstack.BatchEnum(null, AllWsman, startLmsWsmanResponse, null, true);
//*************************************
// Setup KVM data channel if this is Intel AMT 12 or above
amtMei.getVersion(function (x) {
var amtver = null;
try { for (var i in x.Versions) { if (x.Versions[i].Description == 'AMT') amtver = parseInt(x.Versions[i].Version.split('.')[0]); } } catch (e) { }
if ((amtver != null) && (amtver >= 12)) {
kvmGetData('skip'); // Clear any previous data, this is a dummy read to about handling old data.
tempTimer = setInterval(function () { kvmGetData(); }, 2000); // Start polling for KVM data.
kvmSetData(JSON.stringify({ action: 'restart', ver: 1 })); // Send a restart command to advise the console if present that MicroLMS just started.
}
});
});
}
2018-03-06 20:50:44 -05:00
}
2018-03-08 20:58:22 -05:00
function kvmGetData(tag) {
osamtstack.IPS_KVMRedirectionSettingData_DataChannelRead(kvmDataGetResponse, tag);
}
function kvmDataGetResponse(stack, name, response, status, tag) {
if ((tag != 'skip') && (status == 200) && (response.Body.ReturnValue == 0)) {
2018-03-08 20:58:22 -05:00
var val = null;
try { val = Buffer.from(response.Body.DataMessage, 'base64').toString(); } catch (e) { return }
if (val != null) { kvmProcessData(response.Body.RealmsBitmap, response.Body.MessageId, val); }
2018-03-08 20:58:22 -05:00
}
}
var webRtcDesktop = null;
function kvmProcessData(realms, messageId, val) {
var data = null;
try { data = JSON.parse(val) } catch (e) { }
if ((data != null) && (data.action)) {
if (data.action == 'present') { kvmSetData(JSON.stringify({ action: 'present', ver: 1, platform: process.platform })); }
2018-03-08 20:58:22 -05:00
if (data.action == 'offer') {
webRtcDesktop = {};
var rtc = require('ILibWebRTC');
webRtcDesktop.webrtc = rtc.createConnection();
webRtcDesktop.webrtc.on('connected', function () { });
webRtcDesktop.webrtc.on('disconnected', function () { webRtcCleanUp(); });
webRtcDesktop.webrtc.on('dataChannel', function (rtcchannel) {
webRtcDesktop.rtcchannel = rtcchannel;
var kvmmodule = require('meshDesktop');
webRtcDesktop.kvm = kvmmodule.getRemoteDesktopStream();
webRtcDesktop.kvm.pipe(webRtcDesktop.rtcchannel, { dataTypeSkip: 1, end: false });
2018-03-08 20:58:22 -05:00
webRtcDesktop.rtcchannel.on('end', function () { webRtcCleanUp(); });
webRtcDesktop.rtcchannel.on('data', function (x) { kvmCtrlData(this, x); });
webRtcDesktop.rtcchannel.pipe(webRtcDesktop.kvm, { dataTypeSkip: 1, end: false });
2018-03-08 20:58:22 -05:00
//webRtcDesktop.kvm.on('end', function () { console.log('WebRTC DataChannel closed2'); webRtcCleanUp(); });
//webRtcDesktop.rtcchannel.on('data', function (data) { console.log('WebRTC data: ' + data); });
});
kvmSetData(JSON.stringify({ action: 'answer', ver: 1, sdp: webRtcDesktop.webrtc.setOffer(data.sdp) }));
}
}
}
// Polyfill path.join
var path = {
join: function () {
var x = [];
for (var i in arguments) {
var w = arguments[i];
if (w != null) {
while (w.endsWith('/') || w.endsWith('\\')) { w = w.substring(0, w.length - 1); }
if (i != 0) {
while (w.startsWith('/') || w.startsWith('\\')) { w = w.substring(1); }
}
x.push(w);
}
}
if (x.length == 0) return '/';
return x.join('/');
}
};
// Get a formated response for a given directory path
function getDirectoryInfo(reqpath) {
var response = { path: reqpath, dir: [] };
if (((reqpath == undefined) || (reqpath == '')) && (process.platform == 'win32')) {
// List all the drives in the root, or the root itself
var results = null;
try { results = fs.readDrivesSync(); } catch (e) { } // TODO: Anyway to get drive total size and free space? Could draw a progress bar.
//console.log('a', objToString(results, 0, ' '));
if (results != null) {
for (var i = 0; i < results.length; ++i) {
var drive = { n: results[i].name, t: 1 };
if (results[i].type == 'REMOVABLE') { drive.dt = 'removable'; } // TODO: See if this is USB/CDROM or something else, we can draw icons.
response.dir.push(drive);
}
}
} else {
// List all the files and folders in this path
if (reqpath == '') { reqpath = '/'; }
var xpath = path.join(reqpath, '*');
var results = null;
try { results = fs.readdirSync(xpath); } catch (e) { }
if (results != null) {
for (var i = 0; i < results.length; ++i) {
if ((results[i] != '.') && (results[i] != '..')) {
var stat = null, p = path.join(reqpath, results[i]);
try { stat = fs.statSync(p); } catch (e) { } // TODO: Get file size/date
if ((stat != null) && (stat != undefined)) {
if (stat.isDirectory() == true) {
response.dir.push({ n: results[i], t: 2, d: stat.mtime });
} else {
response.dir.push({ n: results[i], t: 3, s: stat.size, d: stat.mtime });
}
}
}
}
}
}
return response;
}
// Process KVM control channel data
function kvmCtrlData(channel, cmd) {
if (cmd.length > 0 && cmd.charCodeAt(0) != 123) {
// This is upload data
if (this.fileupload != null) {
cmd = Buffer.from(cmd, 'base64');
var header = cmd.readUInt32BE(0);
if ((header == 0x01000000) || (header == 0x01000001)) {
fs.writeSync(this.fileupload.fp, cmd.slice(4));
channel.write({ action: 'upload', sub: 'ack', reqid: this.fileupload.reqid });
if (header == 0x01000001) { fs.closeSync(this.fileupload.fp); this.fileupload = null; } // Close the file
}
}
return;
}
//console.log('KVM Ctrl Data', cmd);
try { cmd = JSON.parse(cmd); } catch (ex) { console.error('Invalid JSON: ' + cmd); return; }
if ((cmd.path != null) && (process.platform != 'win32') && (cmd.path[0] != '/')) { cmd.path = '/' + cmd.path; } // Add '/' to paths on non-windows
switch (cmd.action) {
2018-07-13 22:18:43 -04:00
case 'ping': {
// This is a keep alive
channel.write({ action: 'pong' });
break;
}
case 'ls': {
/*
// Close the watcher if required
var samepath = ((this.httprequest.watcher != undefined) && (cmd.path == this.httprequest.watcher.path));
if ((this.httprequest.watcher != undefined) && (samepath == false)) {
//console.log('Closing watcher: ' + this.httprequest.watcher.path);
//this.httprequest.watcher.close(); // TODO: This line causes the agent to crash!!!!
delete this.httprequest.watcher;
}
*/
// Send the folder content to the browser
var response = getDirectoryInfo(cmd.path);
if (cmd.reqid != undefined) { response.reqid = cmd.reqid; }
channel.write(response);
/*
// Start the directory watcher
if ((cmd.path != '') && (samepath == false)) {
var watcher = fs.watch(cmd.path, onFileWatcher);
watcher.tunnel = this.httprequest;
watcher.path = cmd.path;
this.httprequest.watcher = watcher;
//console.log('Starting watcher: ' + this.httprequest.watcher.path);
}
*/
break;
}
case 'mkdir': {
// Create a new empty folder
fs.mkdirSync(cmd.path);
break;
}
case 'rm': {
// Remove many files or folders
for (var i in cmd.delfiles) {
var fullpath = path.join(cmd.path, cmd.delfiles[i]);
try { fs.unlinkSync(fullpath); } catch (e) { console.log(e); }
}
break;
}
case 'rename': {
// Rename a file or folder
var oldfullpath = path.join(cmd.path, cmd.oldname);
var newfullpath = path.join(cmd.path, cmd.newname);
try { fs.renameSync(oldfullpath, newfullpath); } catch (e) { console.log(e); }
break;
}
case 'download': {
// Download a file, to browser
var sendNextBlock = 0;
if (cmd.sub == 'start') { // Setup the download
if (this.filedownload != null) { channel.write({ action: 'download', sub: 'cancel', id: this.filedownload.id }); delete this.filedownload; }
this.filedownload = { id: cmd.id, path: cmd.path, ptr: 0 }
try { this.filedownload.f = fs.openSync(this.filedownload.path, 'rbN'); } catch (e) { channel.write({ action: 'download', sub: 'cancel', id: this.filedownload.id }); delete this.filedownload; }
if (this.filedownload) { channel.write({ action: 'download', sub: 'start', id: cmd.id }); }
} else if ((this.filedownload != null) && (cmd.id == this.filedownload.id)) { // Download commands
if (cmd.sub == 'startack') { sendNextBlock = 8; } else if (cmd.sub == 'stop') { delete this.filedownload; } else if (cmd.sub == 'ack') { sendNextBlock = 1; }
}
// Send the next download block(s)
while (sendNextBlock > 0) {
sendNextBlock--;
var buf = Buffer.alloc(4096);
var len = fs.readSync(this.filedownload.f, buf, 4, 4092, null);
this.filedownload.ptr += len;
if (len < 4092) { buf.writeInt32BE(0x01000001, 0); fs.closeSync(this.filedownload.f); delete this.filedownload; sendNextBlock = 0; } else { buf.writeInt32BE(0x01000000, 0); }
channel.write(buf.slice(0, len + 4).toString('base64')); // Write as Base64
}
break;
}
case 'upload': {
// Upload a file, from browser
if (cmd.sub == 'start') { // Start the upload
if (this.fileupload != null) { fs.closeSync(this.fileupload.fp); }
if (!cmd.path || !cmd.name) break;
this.fileupload = { reqid: cmd.reqid };
var filepath = path.join(cmd.path, cmd.name);
try { this.fileupload.fp = fs.openSync(filepath, 'wbN'); } catch (e) { }
if (this.fileupload.fp) { channel.write({ action: 'upload', sub: 'start', reqid: this.fileupload.reqid }); } else { this.fileupload = null; channel.write({ action: 'upload', sub: 'error', reqid: this.fileupload.reqid }); }
}
else if (cmd.sub == 'cancel') { // Stop the upload
if (this.fileupload != null) { fs.closeSync(this.fileupload.fp); this.fileupload = null; }
}
break;
}
case 'copy': {
// Copy a bunch of files from scpath to dspath
for (var i in cmd.names) {
var sc = path.join(cmd.scpath, cmd.names[i]), ds = path.join(cmd.dspath, cmd.names[i]);
if (sc != ds) { try { fs.copyFileSync(sc, ds); } catch (e) { } }
}
break;
}
case 'move': {
// Move a bunch of files from scpath to dspath
for (var i in cmd.names) {
var sc = path.join(cmd.scpath, cmd.names[i]), ds = path.join(cmd.dspath, cmd.names[i]);
if (sc != ds) { try { fs.copyFileSync(sc, ds); fs.unlinkSync(sc); } catch (e) { } }
}
break;
}
2019-01-04 20:59:13 -05:00
default:
// Unknown action, ignore it.
break;
}
}
2018-03-08 20:58:22 -05:00
function webRtcCleanUp() {
if (webRtcDesktop == null) return;
if (webRtcDesktop.rtcchannel) {
try { webRtcDesktop.rtcchannel.close(); } catch (e) { }
try { webRtcDesktop.rtcchannel.removeAllListeners('data'); } catch (e) { }
try { webRtcDesktop.rtcchannel.removeAllListeners('end'); } catch (e) { }
delete webRtcDesktop.rtcchannel;
}
if (webRtcDesktop.webrtc) {
try { webRtcDesktop.webrtc.close(); } catch (e) { }
try { webRtcDesktop.webrtc.removeAllListeners('connected'); } catch (e) { }
try { webRtcDesktop.webrtc.removeAllListeners('disconnected'); } catch (e) { }
try { webRtcDesktop.webrtc.removeAllListeners('dataChannel'); } catch (e) { }
delete webRtcDesktop.webrtc;
}
if (webRtcDesktop.kvm) {
try { webRtcDesktop.kvm.end(); } catch (e) { }
delete webRtcDesktop.kvm;
}
webRtcDesktop = null;
}
function kvmSetData(x) {
osamtstack.IPS_KVMRedirectionSettingData_DataChannelWrite(Buffer.from(x).toString('base64'), function () { });
}
2018-02-07 21:45:14 -05:00
function startLmsWsmanResponse(stack, name, responses, status) {
if (status == 600) { console.log('ERROR: Unable to connect to Intel(R) AMT.'); }
else if (status != 200) { console.log('ERROR: Unable to get object from Intel(R) AMT, status = ' + status + '.'); }
2018-03-06 20:50:44 -05:00
else {
//console.log(JSON.stringify(responses), status);
var amtlogicalelements = responses["CIM_SoftwareIdentity"].responses;
if (amtlogicalelements.length > 0) {
var v = getInstance(amtlogicalelements, "AMT")["VersionString"];
amtversion = parseInt(v.split('.')[0]);
amtversionmin = parseInt(v.split('.')[1]);
//console.log(amtversion, amtversionmin);
}
}
2018-02-07 21:45:14 -05:00
}
2018-01-30 21:23:57 -05:00
// Process commands in the LMS control channel
// Command 9 is add a notification.
function processLmsControlData(data) {
if (data.length < 2) return;
var cmdid = data.readUInt16LE(0);
switch (cmdid) {
case 1: // Request basic Intel AMT information (CMD = 1)
2018-01-30 21:23:57 -05:00
{ getAmtInfo(function (meinfo, socket) { meinfo.LoginMode = 2; socket.write(Buffer.concat([Buffer.from('0100', 'hex'), Buffer.from(JSON.stringify(meinfo))])); }, this); break; }
case 2: // Intel AMT MEI Unprovision (CMD = 2)
{ if (data.length < 6) break; amtMei.unprovision(data.readUInt32LE(2), function (status, socket) { var data = Buffer.alloc(6); data.writeUInt16LE(2, 0); data.writeUInt32LE(status, 2); socket.write(data); }, this); break; }
case 3: // Intel AMT MEI GetLocalSystemAccount (CMD = 3)
{ amtMei.getLocalSystemAccount(function (account, socket) { socket.write(Buffer.concat([Buffer.from('030000000000', 'hex'), account.raw])); }, this); break; }
case 4: // Instruct Intel AMT to start remote configuration (CMD = 4)
{ amtMei.startConfiguration(function (status, socket) { var data = Buffer.alloc(6); data.writeUInt16LE(7, 0); data.writeUInt32LE(status, 2); socket.write(data); }, this); break; }
case 5: // Instruct Intel AMT to stop remote configuration (CMD = 5)
{ amtMei.stopConfiguration(function (status, socket) { var data = Buffer.alloc(6); data.writeUInt16LE(7, 0); data.writeUInt32LE(status, 2); socket.write(data); }, this); break; }
case 6: // Instruct Intel AMT connect CIRA (CMD = 6)
{ amtMei.openUserInitiatedConnection(function (status, socket) { var data = Buffer.alloc(6); data.writeUInt16LE(7, 0); data.writeUInt32LE(status, 2); socket.write(data); }, this); break; }
case 7: // Instruct Intel AMT disconnect CIRA (CMD = 7)
{ amtMei.closeUserInitiatedConnection(function (status, socket) { var data = Buffer.alloc(6); data.writeUInt16LE(7, 0); data.writeUInt32LE(status, 2); socket.write(data); }, this); break; }
case 8: // Get Intel AMT CIRA State (CMD = 8)
{ amtMei.getRemoteAccessConnectionStatus(function (state, socket) { var data = Buffer.alloc(6); data.writeUInt16LE(8, 0); data.writeUInt32LE(state.status, 2); socket.write(Buffer.concat([data, state.raw])); }, this); break; }
2019-01-04 20:59:13 -05:00
default:
// Unknown action, ignore it.
break;
}
2017-10-31 19:19:58 -04:00
}
2018-01-30 21:23:57 -05:00
//
// MeshCentral TCP port router
//
2017-10-31 19:19:58 -04:00
function startRouter() {
tcpserver = net.createServer(OnTcpClientConnected);
2018-03-08 20:58:22 -05:00
tcpserver.on('error', function (e) { console.log('ERROR: ' + JSON.stringify(e)); exit(0); return; });
2019-03-26 18:18:07 -04:00
tcpserver.listen(settings.localport, function () {
2017-10-31 19:19:58 -04:00
// We started listening.
2019-03-26 18:18:07 -04:00
if (settings.remotename == null) {
console.log('Redirecting local port ' + settings.localport + ' to remote port ' + settings.remoteport + '.');
2017-10-31 19:19:58 -04:00
} else {
2019-03-26 18:18:07 -04:00
console.log('Redirecting local port ' + settings.localport + ' to ' + settings.remotename + ':' + settings.remoteport + '.');
2017-10-31 19:19:58 -04:00
}
2018-03-19 20:31:54 -04:00
console.log('Press ctrl-c to exit.');
2017-10-31 19:19:58 -04:00
// If settings has a "cmd", run it now.
//process.exec("notepad.exe");
});
}
// Called when a TCP connect is received on the local port. Launch a tunnel.
function OnTcpClientConnected(c) {
try {
// 'connection' listener
debug(1, 'Client connected');
c.on('end', function () { disconnectTunnel(this, this.websocket, 'Client closed'); });
c.pause();
try {
2019-03-26 18:18:07 -04:00
options = http.parseUri(settings.serverurl + '?user=' + settings.username + '&pass=' + settings.password + '&nodeid=' + settings.remotenodeid + '&tcpport=' + settings.remoteport);
} catch (e) { console.log('Unable to parse \"serverUrl\".'); process.exit(1); return; }
2017-10-31 19:19:58 -04:00
options.checkServerIdentity = onVerifyServer;
2018-01-26 20:01:38 -05:00
options.rejectUnauthorized = false;
2017-10-31 19:19:58 -04:00
c.websocket = http.request(options);
c.websocket.tcp = c;
c.websocket.tunneling = false;
c.websocket.upgrade = OnWebSocket;
2018-01-26 20:01:38 -05:00
c.websocket.on('error', function (e) { console.log('ERROR: ' + JSON.stringify(e)); });
2017-10-31 19:19:58 -04:00
c.websocket.end();
} catch (e) { debug(2, e); }
}
// Disconnect both TCP & WebSocket connections and display a message.
function disconnectTunnel(tcp, ws, msg) {
if (ws != null) { try { ws.end(); } catch (e) { debug(2, e); } }
if (tcp != null) { try { tcp.end(); } catch (e) { debug(2, e); } }
debug(1, 'Tunnel disconnected: ' + msg);
}
// Called when the web socket gets connected
function OnWebSocket(msg, s, head) {
debug(1, 'Websocket connected');
s.on('data', function (msg) {
if (this.parent.tunneling == false) {
msg = msg.toString();
if (msg == 'c') {
this.parent.tunneling = true; this.pipe(this.parent.tcp); this.parent.tcp.pipe(this); debug(1, 'Tunnel active');
} else if ((msg.length > 6) && (msg.substring(0, 6) == 'error:')) {
console.log(msg.substring(6));
disconnectTunnel(this.tcp, this, msg.substring(6));
}
}
});
s.on('error', function (msg) { disconnectTunnel(this.tcp, this, 'Websocket error'); });
s.on('close', function (msg) { disconnectTunnel(this.tcp, this, 'Websocket closed'); });
s.parent = this;
}
// Try to discover the location of the mesh server
function discoverMeshServer() { console.log('Looking for server...'); discoveryInterval = setInterval(discoverMeshServerOnce, 5000); discoverMeshServerOnce(); }
// Try to discover the location of the mesh server only once
function discoverMeshServerOnce() {
var interfaces = os.networkInterfaces();
for (var adapter in interfaces) {
if (interfaces.hasOwnProperty(adapter)) {
for (var i = 0; i < interfaces[adapter].length; ++i) {
2017-10-31 19:19:58 -04:00
var addr = interfaces[adapter][i];
multicastSockets[i] = dgram.createSocket({ type: (addr.family == "IPv4" ? "udp4" : "udp6") });
multicastSockets[i].bind({ address: addr.address, exclusive: false });
if (addr.family == "IPv4") {
try {
multicastSockets[i].addMembership(membershipIPv4);
//multicastSockets[i].setMulticastLoopback(true);
multicastSockets[i].once('message', OnMulticastMessage);
2019-03-26 18:18:07 -04:00
multicastSockets[i].send(settings.serverid, 16989, membershipIPv4);
} catch (e) { }
2017-10-31 19:19:58 -04:00
}
}
}
}
}
// Called when a multicast packet is received
function OnMulticastMessage(msg, rinfo) {
var m = msg.toString().split('|');
2019-03-26 18:18:07 -04:00
if ((m.length == 3) && (m[0] == 'MeshCentral2') && (m[1] == settings.serverid)) {
settings.serverurl = m[2].replace('%s', rinfo.address).replace('/agent.ashx', '/meshrelay.ashx');
console.log('Found server at ' + settings.serverurl + '.');
2017-10-31 19:19:58 -04:00
if (discoveryInterval != null) { clearInterval(discoveryInterval); discoveryInterval = null; }
startRouter();
}
}
2018-01-30 21:23:57 -05:00
//
// PUSH MESHCOMMANDER INTO FIRMWARE
//
function nextStepStorageUpload() {
debug(3, "nextStepStorageUpload");
getAmtStorage(function (statusCode, data) {
if (statusCode == 200) {
debug(2, "getAmtStorage: " + JSON.stringify(data, null, 2));
if ((data['content'] != null) && (data['content']['index.htm'] != null)) { nextStepStorageUpload3('index.htm'); }
else if ((data['content'] != null) && (data['content']['logon.htm'] != null)) { nextStepStorageUpload3('logon.htm'); }
else if ((data['content'] != null) && (data['content']['logon.htm'] != null)) { nextStepStorageUpload3('logon.htm'); }
else { nextStepStorageUpload2('index.htm', null); }
} else {
console.log("Unable to read storage state.");
exit();
return;
}
});
}
function nextStepStorageUpload2(uploadName, linkName) {
debug(3, "nextStepStorageUpload2");
if (settings.webapp == null) { console.log("Done."); exit(); return; } else {
console.log("Uploading MeshCommander...");
pushToStorage(uploadName, linkName, Buffer.from(settings.webapp, 'base64'), function (statusCode) {
if (statusCode == 500) { console.log("Error, check that computer is powered on."); exit(); return; }
if (statusCode != 200) {
if (uploadName == 'index.htm') {
nextStepStorageUpload2('mesh/commander/console', 'MeshCommander');
} else {
console.log("Unable to upload MeshCommander, status = " + statusCode + "."); exit(); return;
}
} else {
console.log("Verifying MeshCommander...");
verifyStorage(uploadName, Buffer.from(settings.webapp, 'base64'), function (verified) {
if (verified == true) { console.log('Done.'); } else { console.log('MeshCommander verification failed.'); }
exit(); return;
});
}
});
}
}
function nextStepStorageUpload3(deleteName) {
console.log("Deleting " + deleteName + " from storage...");
deleteStorage(deleteName, function (statusCode) {
if (statusCode == 500) { console.log("Error, check that computer is powered on."); exit(); return; }
if (statusCode == 200) { nextStepStorageUpload(); } else { console.log("Unable to delete " + deleteName + "."); exit(); return; }
});
}
// Fetch the Intel AMT storage document
function getAmtStorage(func, noretry) {
var req = digest.request({ protocol: settings.protocol, method: "GET", host: settings.hostname, path: "/amt-storage/", port: settings.localport },
function (response) {
if (response.statusCode != 200) { console.log("Unable to connect to Intel(R) AMT."); func(response.statusCode, null); }
response.on('data', function (chunk) { if (response.acc == null) { response.acc = chunk; } else { response.acc += chunk; } });
response.on('end', function () {
var data = response.acc.toString(), len, data2, amtstorage = null;
2019-04-17 20:08:01 -04:00
data = data.split('\t').join('').split('\r').join('').split('\n').join('');
try {
2019-04-17 20:08:01 -04:00
do { len = data.length; data2 = data; data = data2.replace('": ', '":'); } while (data != data2); // Remove all zero's, this is needed because firmware sometimes returns garbage we must fix.
do { len = data.length; data2 = data; data = data2.replace('\x00', ''); } while (data != data2); // Remove all zero's, this is needed because firmware sometimes returns garbage we must fix.
do { len = data.length; data2 = data; data = data2.replace('\x22\x01\x22', '\x22\x22'); } while (data != data2); // "\x01", this is needed because firmware sometimes returns garbage we must fix.
2019-04-17 20:08:01 -04:00
var xopen = data.split("{").length, xclose = data.split("}").length, xadd = '';
while (xopen > xclose) { data += '}'; xclose++; } // Close any missing close brackets
amtstorage = JSON.parse(data);
2019-04-17 20:08:01 -04:00
} catch (e) { console.log("Error: Unable to parse Intel AMT response: " + data, e); func(null); }
if (func != null) { func(response.statusCode, amtstorage); }
});
});
req.on('error', function (e) { console.log("Error occured: " + JSON.stringify(e)); if (noretry == true) { if (func != null) { func(null); } } else { getAmtStorage(func, true); } });
req.end();
}
// Fetch the Intel AMT storage document
function pushToStorage(name, linkname, data, func, ptr) {
if (ptr == null) { ptr = 0; }
var req = digest.request({ protocol: settings.protocol, method: "PUT", host: settings.hostname, path: ("/amt-storage/" + name + ((ptr != 0) ? '?append=' : '')), port: settings.localport });
req.on('error', function (e) { console.log("Error occured: " + JSON.stringify(e)); if (func != null) { func(null); } });
2018-01-25 19:12:53 -05:00
req.on('response', function (response) {
debug(1, 'Chunk Done', data.length, ptr);
if ((response.statusCode == 200) && (ptr < data.length)) { pushToStorage(name, linkname, data, func, ptr); } else { if (func != null) { func(response.statusCode); } }
});
var header = (ptr > 0) ? '<metadata></metadata>' : '<metadata><headers><h>Content-Encoding:gzip</h><h>Content-Type:text/html</h></headers>' + ((linkname != null) ? ('<link>' + linkname + '</link>') : '') + '</metadata>';
var blocklen = ((data.length - ptr) > (7000 - header.length)) ? (7000 - header.length) : (data.length - ptr);
req.write(Buffer.concat([new Buffer(header), data.slice(ptr, ptr + blocklen)]));
ptr += blocklen;
req.end();
}
// Fetch the Intel AMT storage document
function verifyStorage(name, data, func) {
2018-01-25 19:12:53 -05:00
var req = digest.request({ protocol: settings.protocol, method: "GET", host: settings.hostname, path: ("/amt-storage/" + name), port: settings.localport });
req.on('error', function (e) { console.log("Verify error occured: " + JSON.stringify(e)); if (func != null) { func(null); } });
2018-01-25 19:12:53 -05:00
req.on('response', function (response) {
response.ptr = 0;
response.ok = true;
2018-01-26 20:01:38 -05:00
response.on('data', function (data2) { if (data2.toString('hex') != data.slice(response.ptr, response.ptr + data2.length).toString('hex')) { response.ok = false; console.log('Verifiy failed (' + response.ptr + ', ' + data2.length + ').'); } response.ptr += data2.length; });
2018-01-25 19:12:53 -05:00
response.on('end', function () { if (func != null) { func(response.ok); } });
});
req.end();
}
// Fetch the Intel AMT storage document
function deleteStorage(name, func, noretry) {
var req = digest.request({ protocol: settings.protocol, method: "DELETE", host: settings.hostname, path: "/amt-storage/" + name, port: settings.localport });
req.on('error', function (e) { if ((e == 'Error: Socket was unexpectedly closed') && (noretry != true)) { deleteStorage(name, func, true); } else { if (func != null) { if (e.statusCode) { func(e.statusCode); } else { func(null); } } } });
2018-01-25 19:12:53 -05:00
req.on('response', function (response) { if (func != null) { func(response.statusCode); } });
req.end();
}
//
// IDER
//
ider = null;
iderIdleTimer = null;
// Perform IDER
function performIder() {
if ((settings.floppy != null) && fs.existsSync(settings.floppy) == false) { console.log("Unable to floppy image file: " + settings.floppy); process.exit(); return; }
if ((settings.cdrom != null) && fs.existsSync(settings.cdrom) == false) { console.log("Unable to CDROM image file: " + settings.cdrom); process.exit(); return; }
try {
var sfloppy = null, scdrom = null;
if (settings.floppy) { try { if (sfloppy = fs.statSync(settings.floppy)) { sfloppy.file = fs.openSync(settings.floppy, 'rbN'); } } catch (ex) { console.log(ex); process.exit(1); return; } }
if (settings.cdrom) { try { scdrom = fs.statSync(settings.cdrom); if (scdrom) { scdrom.file = fs.openSync(settings.cdrom, 'rbN'); } } catch (ex) { console.log(ex); process.exit(1); return; } }
ider = require('amt-redir-duk')(require('amt-ider')());
ider.onStateChanged = onIderStateChange;
ider.m.floppy = sfloppy;
ider.m.cdrom = scdrom;
ider.m.iderStart = 1; // OnReboot = 0, Graceful = 1, Now = 2
ider.m.debug = (settings.debuglevel > 0);
if (settings.timeout > 0) { ider.m.sectorStats = iderSectorStats; }
//ider.digestRealmMatch = wsstack.comm.digestRealm;
//ider.tlsv1only = amtstack.wsman.comm.tlsv1only;
ider.Start(settings.hostname, (settings.tls == true)?16995:16994, settings.username ? 'admin' : settings.username, settings.password, settings.tls);
} catch (ex) { console.log(ex); }
}
function onIderStateChange(stack, state) { console.log(['Disconnected', 'Connecting...', 'Connected...', 'Started IDER...'][state]);}
function iderSectorStats(mode, dev, mediaBlocks, lba, len) {
if (iderIdleTimer != null) { clearTimeout(iderIdleTimer); }
iderIdleTimer = setTimeout(function () { console.log('Idle timeout'); process.exit(1); }, 1000 * settings.timeout);
}
//
// Startup
//
2018-03-19 20:31:54 -04:00
// Parse URL arguments
function parseUrlArguments(url) {
var r = {}, x = url.split('?');
if (x.length < 2) return r;
x = x[1].split('&');
for (var i in x) { var j = x[i].indexOf('='); if (j > 0) { r[x[i].substring(0, j).toLowerCase()] = x[i].substring(j + 1); } }
return r;
}
// Remove a element from a array
function removeItemFromArray(array, element) {
2018-12-29 18:24:33 -05:00
var index = array.indexOf(element);
if (index !== -1) { array.splice(index, 1); }
}
// Run MeshCmd, but before we do, we need to see if what type of service we are going to be
var serviceName = null;
var serviceOpSpecified = 0;
var serviceInstall = 0;
for (var i in process.argv) {
if (process.argv[i].toLowerCase() == 'install') { serviceInstall = 1 } else if (process.argv[i].toLowerCase() == 'uninstall') { serviceInstall = -1 }
if ((process.argv[i].toLowerCase() == 'microlms') || (process.argv[i].toLowerCase() == 'amtlms') || (process.argv[i].toLowerCase() == 'lms')) { serviceName = 'MicroLMS'; break; }
if ((process.argv[i].toLowerCase() == 'meshcommander') || (process.argv[i].toLowerCase() == 'commander')) { serviceName = 'MeshCommander'; break; }
}
if (serviceName == null) {
for (var i in process.argv) {
if ((process.argv[i].toLowerCase() == 'install') || (process.argv[i].toLowerCase() == 'uninstall')) {
console.log('In order to install/uninstall, a service type must be specified.');
process.exit();
}
}
if (process.execPath.includes('MicroLMS')) { serviceName = 'MicroLMS'; }
else if (process.execPath.includes('MeshCommander')) { serviceName = 'MeshCommander'; }
else { serviceName = 'not_a_service'; }
}
if (serviceInstall == 0) {
run(process.argv);
} else {
var serviceHost = require('service-host');
var meshcmdService = new serviceHost({ name: serviceName, startType: 'AUTO_START' });
// Called when the background service is started.
meshcmdService.on('serviceStart', function onStart() {
console.setDestination(console.Destinations.DISABLED); // Disable console.log().
if (process.execPath.includes('MicroLMS')) { run([process.execPath, 'microlms']); } //
else if (process.execPath.includes('MeshCommander')) { run([process.execPath, 'meshcommander']); }
else { console.log('Aborting Service Start, because unknown binary: ' + process.execPath); process.exit(1); }
});
// Called when the background service is stopping
meshcmdService.on('serviceStop', function onStop() { console.log('Stopping service'); process.exit(); }); // The console.log() is for debugging, will be ignored unless "console.setDestination()" is set.
// Called when the executable is not running as a service, run normally.
meshcmdService.on('normalStart', function onNormalStart() { try { run(process.argv); } catch (e) { console.log('ERROR: ' + e); } });
meshcmdService.run();
}