From 2750b6e39f60671bbb1336a7079c6fad33040ad3 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 1 Oct 2019 16:53:10 -0700 Subject: [PATCH] Fixed ScanAmt in agent and added AmtScan to MeshCmd --- MeshCentralServer.njsproj | 1 + agents/MeshCmd-signed.exe | Bin 4486216 -> 4488128 bytes agents/MeshCmd64-signed.exe | Bin 4101192 -> 4103104 bytes agents/meshcmd.js | 33 ++++++++++++++++-- agents/meshcmd.min.js | 33 ++++++++++++++++-- agents/modules_meshcmd/amt-scanner.js | 10 ++++-- agents/modules_meshcmd_min/amt-scanner.min.js | 2 +- .../modules_meshcore_min/amt-scanner.min.js | 2 +- package.json | 2 +- 9 files changed, 73 insertions(+), 10 deletions(-) diff --git a/MeshCentralServer.njsproj b/MeshCentralServer.njsproj index 92bf34ee..f88334e0 100644 --- a/MeshCentralServer.njsproj +++ b/MeshCentralServer.njsproj @@ -137,6 +137,7 @@ + diff --git a/agents/MeshCmd-signed.exe b/agents/MeshCmd-signed.exe index d9271f25a136a850525df7ee35077c8706511a8d..e2a53826dad674c7ad45d06ff0049150c99c2626 100644 GIT binary patch delta 2590 zcmaKr3se->8Gu<>f-4}32=1zIL2+ha8J5Qa>$)JbOCm`HVO4yQy6g_i!tM;tEC_Ot zDjd+pqN2?;AwH58tJPFArE6`hXg1M2sz4q+^~Ct9T9Z>-jTT>({>Z*{>yXY_!Y4=__X&U}34#S0*M>4GTRr(b+gFcsIF*hAJ76BKqim{=zv*(9+(XnfNUTKnB!?5$UUi%n~k{zp8Npj zXoy^@DV{KfQH_^Y$bc+@UG$X#TY?#tCty7DRS52lWCHbON#W_2gv_i(uvQ=^Z?!lP z$GTVXLKQ0K1(eUZStrV!w*cALT8EVtaeovO<2gT-*<65EtYE?eC1(Vd#WS(A6bxGB za5}*d|NQ%i=a9RCm3-i}T82{jVogf&{Ze$PbV^1RokDApQ`4~}fr-Tjix^#~PrA%e zjRbgi_}^JfluBB$$jzf_R)9cVKC3=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0LJl(=f*Ij!R5Lxov%$9%=tPL&t?C%W>U+?&@r zNw=3;Ueb3osAzF2`Xpeur?Yfzl2DkJuO_M%&25HvT<=EnXL^tMyOorxZn?uA9osJ0zp7--Ek3WOqN0m0jxuJw3abQ1&C1=Q`sJExwH5WMrozHI Ux+q`j5uYpZcsv-{qo=3$4`bY3&;S4c diff --git a/agents/meshcmd.js b/agents/meshcmd.js index daae5007..5f931899 100644 --- a/agents/meshcmd.js +++ b/agents/meshcmd.js @@ -114,7 +114,7 @@ function run(argv) { //console.log('addedModules = ' + JSON.stringify(addedModules)); var actionpath = 'meshaction.txt'; if (args.actionfile != null) { actionpath = args.actionfile; } - var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE']; + var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTSCAN', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE']; // Load the action file var actionfile = null; @@ -151,6 +151,7 @@ function run(argv) { if ((typeof args.floppy) == 'string') { settings.floppy = args.floppy; } if ((typeof args.cdrom) == 'string') { settings.cdrom = args.cdrom; } if ((typeof args.tag) == 'string') { settings.tag = args.tag; } + if ((typeof args.scan) == 'string') { settings.scan = args.scan; } if ((typeof args.timeout) == 'string') { settings.timeout = parseInt(args.timeout); } if (args.debug === true) { settings.debuglevel = 1; } if (args.debug) { try { waitForDebugger(); } catch (e) { } } @@ -194,6 +195,7 @@ function run(argv) { console.log(' AmtIDER - Mount local disk image to remote computer.'); console.log(' AmtFeatures - Intel AMT features & user consent.'); console.log(' AmtNetwork - Intel AMT network interface settings.'); + console.log(' AmtScan - Search local network for Intel AMT devices.'); console.log('\r\nHelp on a specific action using:\r\n'); console.log(' meshcmd help [action]'); exit(1); return; @@ -373,6 +375,10 @@ function run(argv) { 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 if (action == 'amtscan') { + console.log('AmtSCAN will look for Intel AMT device on the network. Example usage:\r\n\r\n meshcmd amtscan --scan 192.168.1.0/24'); + console.log('\r\Required arguments:\r\n'); + console.log(' --scan [ip range] The IP address range to perform the scan on.'); } else { actions.shift(); console.log('Invalid action, usage:\r\n\r\n meshcmd help [action]\r\n\r\nValid actions are: ' + actions.join(', ') + '.'); @@ -629,6 +635,29 @@ function run(argv) { startMeshCommander(); //} else if (settings.action == 'amtdisable') { // Disable AMT Network Interface // amtDisable(); + } else if (settings.action == 'amtscan') { + // Scan the network for Intel AMT devices + if ((settings.scan == null) || (typeof settings.scan != 'string') || (settings.scan == '')) { console.log('No or invalid \"scan\" specified, use --scan [ip range].'); exit(1); return; } + console.log('Scanning: ' + settings.scan + '...'); + var AMTScannerModule = require('amt-scanner'); + var amtscanner = new AMTScannerModule(), r = ''; + amtscanner.scan(settings.scan, 2000, function (data) { + if (data.length > 0) { + r = '', pstates = ['NotActivated', 'InActivation', 'Activated']; + for (var i in data) { + var x = data[i]; + if (r != '') { r += '\r\n'; } + r += x.address + ' - Intel AMT v' + x.majorVersion + '.' + x.minorVersion; + if (x.provisioningState < 3) { r += (', ' + pstates[x.provisioningState]); } + if (x.provisioningState == 2) { r += (', ' + x.openPorts.join(', ')); } + r += '.'; + } + } else { + r = 'No Intel AMT found.'; + } + console.log(r); + exit(1); + }); } 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; } @@ -1146,7 +1175,7 @@ function activeToACMEx(fwNonce, dnsSuffix, digestRealm, uuid, allowedModes) { var connection = http.request(options); connection.on('upgrade', function (response, socket) { settings.xxsocket = socket; - console.log('Connected, requesting activation...'); + if (settings.action == 'amtdiscover') { console.log('Connected, performing discovery...'); } else { console.log('Connected, requesting activation...'); } socket.on('end', function () { console.log('Connection closed'); exit(0); }); socket.on('error', function () { console.log('Connection error'); exit(100); }); socket.on('data', function (data) { diff --git a/agents/meshcmd.min.js b/agents/meshcmd.min.js index daae5007..5f931899 100644 --- a/agents/meshcmd.min.js +++ b/agents/meshcmd.min.js @@ -114,7 +114,7 @@ function run(argv) { //console.log('addedModules = ' + JSON.stringify(addedModules)); var actionpath = 'meshaction.txt'; if (args.actionfile != null) { actionpath = args.actionfile; } - var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE']; + var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTSCAN', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE']; // Load the action file var actionfile = null; @@ -151,6 +151,7 @@ function run(argv) { if ((typeof args.floppy) == 'string') { settings.floppy = args.floppy; } if ((typeof args.cdrom) == 'string') { settings.cdrom = args.cdrom; } if ((typeof args.tag) == 'string') { settings.tag = args.tag; } + if ((typeof args.scan) == 'string') { settings.scan = args.scan; } if ((typeof args.timeout) == 'string') { settings.timeout = parseInt(args.timeout); } if (args.debug === true) { settings.debuglevel = 1; } if (args.debug) { try { waitForDebugger(); } catch (e) { } } @@ -194,6 +195,7 @@ function run(argv) { console.log(' AmtIDER - Mount local disk image to remote computer.'); console.log(' AmtFeatures - Intel AMT features & user consent.'); console.log(' AmtNetwork - Intel AMT network interface settings.'); + console.log(' AmtScan - Search local network for Intel AMT devices.'); console.log('\r\nHelp on a specific action using:\r\n'); console.log(' meshcmd help [action]'); exit(1); return; @@ -373,6 +375,10 @@ function run(argv) { 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 if (action == 'amtscan') { + console.log('AmtSCAN will look for Intel AMT device on the network. Example usage:\r\n\r\n meshcmd amtscan --scan 192.168.1.0/24'); + console.log('\r\Required arguments:\r\n'); + console.log(' --scan [ip range] The IP address range to perform the scan on.'); } else { actions.shift(); console.log('Invalid action, usage:\r\n\r\n meshcmd help [action]\r\n\r\nValid actions are: ' + actions.join(', ') + '.'); @@ -629,6 +635,29 @@ function run(argv) { startMeshCommander(); //} else if (settings.action == 'amtdisable') { // Disable AMT Network Interface // amtDisable(); + } else if (settings.action == 'amtscan') { + // Scan the network for Intel AMT devices + if ((settings.scan == null) || (typeof settings.scan != 'string') || (settings.scan == '')) { console.log('No or invalid \"scan\" specified, use --scan [ip range].'); exit(1); return; } + console.log('Scanning: ' + settings.scan + '...'); + var AMTScannerModule = require('amt-scanner'); + var amtscanner = new AMTScannerModule(), r = ''; + amtscanner.scan(settings.scan, 2000, function (data) { + if (data.length > 0) { + r = '', pstates = ['NotActivated', 'InActivation', 'Activated']; + for (var i in data) { + var x = data[i]; + if (r != '') { r += '\r\n'; } + r += x.address + ' - Intel AMT v' + x.majorVersion + '.' + x.minorVersion; + if (x.provisioningState < 3) { r += (', ' + pstates[x.provisioningState]); } + if (x.provisioningState == 2) { r += (', ' + x.openPorts.join(', ')); } + r += '.'; + } + } else { + r = 'No Intel AMT found.'; + } + console.log(r); + exit(1); + }); } 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; } @@ -1146,7 +1175,7 @@ function activeToACMEx(fwNonce, dnsSuffix, digestRealm, uuid, allowedModes) { var connection = http.request(options); connection.on('upgrade', function (response, socket) { settings.xxsocket = socket; - console.log('Connected, requesting activation...'); + if (settings.action == 'amtdiscover') { console.log('Connected, performing discovery...'); } else { console.log('Connected, requesting activation...'); } socket.on('end', function () { console.log('Connection closed'); exit(0); }); socket.on('error', function () { console.log('Connection error'); exit(100); }); socket.on('data', function (data) { diff --git a/agents/modules_meshcmd/amt-scanner.js b/agents/modules_meshcmd/amt-scanner.js index c455b753..3de986d2 100644 --- a/agents/modules_meshcmd/amt-scanner.js +++ b/agents/modules_meshcmd/amt-scanner.js @@ -64,7 +64,7 @@ function AMTScanner() { if (masknum <= 16 || masknum > 32) return null; masknum = 32 - masknum; for (var i = 0; i < masknum; i++) { mask = (mask << 1); mask++; } - return { min: ip & (0xFFFFFFFF - mask), max: (ip & (0xFFFFFFFF - mask)) + mask }; + return { min: (ip & (0xFFFFFFFF - mask))+1, max: (ip & (0xFFFFFFFF - mask)) + mask -1 };//remove network and broadcast address to avoid irrecoverable socket error } x = this.parseIpv4Addr(range); if (x == null) return null; @@ -83,7 +83,7 @@ function AMTScanner() { return ((num >> 24) & 0xFF) + '.' + ((num >> 16) & 0xFF) + '.' + ((num >> 8) & 0xFF) + '.' + (num & 0xFF); } - this.scan = function (rangestr, timeout) { + this.scan = function (rangestr, timeout, callback) { var iprange = this.parseIPv4Range(rangestr); var rmcp = this.buildRmcpPing(0); var server = this.dgram.createSocket({ type: 'udp4' }); @@ -91,11 +91,15 @@ function AMTScanner() { server.scanResults = []; server.on('error', function (err) { console.log('Error:' + err); }); server.on('message', function (msg, rinfo) { if (rinfo.size > 4) { this.parent.parseRmcpPacket(this, msg, rinfo, function (s, res) { s.scanResults.push(res); }) }; }); - server.on('listening', function () { for (var i = iprange.min; i <= iprange.max; i++) { server.send(rmcp, 623, server.parent.IPv4NumToStr(i)); } }); + server.on('listening', function () { for (var i = iprange.min; i <= iprange.max; i++) { + server.send(rmcp, 623, server.parent.IPv4NumToStr(i)); } }); server.bind({ address: '0.0.0.0', port: 0, exclusive: true }); var tmout = setTimeout(function cb() { //console.log("Server closed"); server.close(); + if (callback) { + callback(server.scanResults); + } server.parent.emit('found', server.scanResults); delete server; }, timeout); diff --git a/agents/modules_meshcmd_min/amt-scanner.min.js b/agents/modules_meshcmd_min/amt-scanner.min.js index 9b755c70..0de77528 100644 --- a/agents/modules_meshcmd_min/amt-scanner.min.js +++ b/agents/modules_meshcmd_min/amt-scanner.min.js @@ -1 +1 @@ -function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(d,g){var c=this.parseIPv4Range(d);var e=this.buildRmcpPing(0);var f=this.dgram.createSocket({type:"udp4"});f.parent=this;f.scanResults=[];f.on("error",function(i){console.log("Error:"+i)});f.on("message",function(i,j){if(j.size>4){this.parent.parseRmcpPacket(this,i,j,function(l,k){l.scanResults.push(k)})}});f.on("listening",function(){for(var j=c.min;j<=c.max;j++){f.send(e,623,f.parent.IPv4NumToStr(j))}});f.bind({address:"0.0.0.0",port:0,exclusive:true});var h=setTimeout(function b(){f.close();f.parent.emit("found",f.scanResults);delete f},g)}}module.exports=AMTScanner; \ No newline at end of file +function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(e,h,b){var d=this.parseIPv4Range(e);var f=this.buildRmcpPing(0);var g=this.dgram.createSocket({type:"udp4"});g.parent=this;g.scanResults=[];g.on("error",function(j){console.log("Error:"+j)});g.on("message",function(j,k){if(k.size>4){this.parent.parseRmcpPacket(this,j,k,function(m,l){m.scanResults.push(l)})}});g.on("listening",function(){for(var j=d.min;j<=d.max;j++){g.send(f,623,g.parent.IPv4NumToStr(j))}});g.bind({address:"0.0.0.0",port:0,exclusive:true});var i=setTimeout(function c(){g.close();if(b){b(g.scanResults)}g.parent.emit("found",g.scanResults);delete g},h)}}module.exports=AMTScanner; \ No newline at end of file diff --git a/agents/modules_meshcore_min/amt-scanner.min.js b/agents/modules_meshcore_min/amt-scanner.min.js index 9b755c70..0de77528 100644 --- a/agents/modules_meshcore_min/amt-scanner.min.js +++ b/agents/modules_meshcore_min/amt-scanner.min.js @@ -1 +1 @@ -function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(d,g){var c=this.parseIPv4Range(d);var e=this.buildRmcpPing(0);var f=this.dgram.createSocket({type:"udp4"});f.parent=this;f.scanResults=[];f.on("error",function(i){console.log("Error:"+i)});f.on("message",function(i,j){if(j.size>4){this.parent.parseRmcpPacket(this,i,j,function(l,k){l.scanResults.push(k)})}});f.on("listening",function(){for(var j=c.min;j<=c.max;j++){f.send(e,623,f.parent.IPv4NumToStr(j))}});f.bind({address:"0.0.0.0",port:0,exclusive:true});var h=setTimeout(function b(){f.close();f.parent.emit("found",f.scanResults);delete f},g)}}module.exports=AMTScanner; \ No newline at end of file +function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(e,h,b){var d=this.parseIPv4Range(e);var f=this.buildRmcpPing(0);var g=this.dgram.createSocket({type:"udp4"});g.parent=this;g.scanResults=[];g.on("error",function(j){console.log("Error:"+j)});g.on("message",function(j,k){if(k.size>4){this.parent.parseRmcpPacket(this,j,k,function(m,l){m.scanResults.push(l)})}});g.on("listening",function(){for(var j=d.min;j<=d.max;j++){g.send(f,623,g.parent.IPv4NumToStr(j))}});g.bind({address:"0.0.0.0",port:0,exclusive:true});var i=setTimeout(function c(){g.close();if(b){b(g.scanResults)}g.parent.emit("found",g.scanResults);delete g},h)}}module.exports=AMTScanner; \ No newline at end of file diff --git a/package.json b/package.json index b59a4c2c..e5a6aa77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.4.1-o", + "version": "0.4.1-p", "keywords": [ "Remote Management", "Intel AMT",