From b167f2a7b73b35cfb2c790081ef9c8d9dfc56d75 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Sun, 5 Jun 2022 16:50:39 -0700 Subject: [PATCH] added domaininfo console command for windows --- agents/meshcore.js | 122 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index 00a62268..e8d3b723 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -56,6 +56,73 @@ function bcdOK() } return (true); } +function getDomainInfo() +{ + var hostname = require('os').hostname(); + var ret = { Name: hostname, Domain: "" }; + + switch (process.platform) + { + case 'win32': + try + { + ret = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_ComputerSystem', ['Name', 'Domain'])[0]; + } + catch (x) + { + } + break; + case 'linux': + var hasrealm = false; + + try + { + hasrealm = require('lib-finder').hasBinary('realm'); + } + catch(x) + { + } + if (hasrealm) + { + var child = require('child_process').execFile('/bin/sh', ['sh']); + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stdin.write("realm list | grep domain-name: | tr '\\n' '`' | "); + child.stdin.write("awk -F'`' '{ "); + child.stdin.write(' printf("[");'); + child.stdin.write(' ST="";'); + child.stdin.write(' for(i=1;i0) + { + if(hostname.endsWith('.' + names.peek())) + { + ret = { Name: hostname.substring(0, hostname.length - names.peek().length - 1), Domain: names.peek() }; + break; + } + names.pop(); + } + } + break; + } + return (ret); +} + try { @@ -3268,7 +3335,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) { var response = null; switch (cmd) { case 'help': { // Displays available commands - var fin = '', f = '', availcommands = 'translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task'; + var fin = '', f = '', availcommands = 'domain,translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task'; if (require('os').dns != null) { availcommands += ',dnsinfo'; } try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { } if (process.platform == 'win32') @@ -3290,6 +3357,59 @@ function processConsoleCommand(cmd, args, rights, sessionid) { response = "Available commands: \r\n" + fin + "."; break; } + case 'domain': + response = getDomainInfo(); + break; + case 'domaininfo': + { + if(process.platform != 'win32') + { + response = 'Unknown command "cs", type "help" for list of avaialble commands.'; + break; + } + if(global._domainQuery != null) + { + response = "There is already an outstanding Domain Controller Query... Please try again later..."; + break; + } + + sendConsoleText('Querying Domain Controller... This can take up to 60 seconds. Please wait...', sessionid); + global._domainQuery = require('win-wmi').queryAsync('ROOT\\CIMV2', 'SELECT * FROM Win32_NTDomain'); + global._domainQuery.session = sessionid; + global._domainQuery.then(function (v) + { + var results = []; + if (Array.isArray(v)) + { + var i; + var r; + for (i = 0; i < v.length; ++i) + { + r = {}; + if (v[i].DomainControllerAddress != null) { r.DomainControllerAddress = v[i].DomainControllerAddress.split('\\').pop(); } + if (r.DomainControllerName != null) { r.DomainControllerName = v[i].DomainControllerName.split('\\').pop(); } + r.DomainGuid = v[i].DomainGuid; + r.DomainName = v[i].DomainName; + if (r.DomainGuid != null) + { + results.push(r); + } + } + } + if (results.length > 0) + { + sendConsoleText('Domain Controller Results:', this.session); + sendConsoleText(JSON.stringify(results, null, 1), this.session); + sendConsoleText('End of results...', this.session); + } + else + { + sendConsoleText('Domain Controller: No results returned. Is the domain controller reachable?', this.session); + } + global._domainQuery = null; + }); + break; + } case 'translations': { response = JSON.stringify(coretranslations, null, 2); break;