diff --git a/lib/agent/actions/wipe/runner.js b/lib/agent/actions/wipe/runner.js index 17d301e77..1064316c7 100644 --- a/lib/agent/actions/wipe/runner.js +++ b/lib/agent/actions/wipe/runner.js @@ -1,25 +1,18 @@ -#!/usr/bin/env node - var wipe = require('./wipe'), what = process.argv; - // variable to store last error var last_err; - // pad node binary and script path what.shift(); what.shift(); - // Get the cloud config dirs and processes var to_erase = what.pop().split(','), // 'Google Drive', 'Dropbox' to_kill = what.pop().split(','); what.pop(); what.pop(); - // process each of the requested items to wipe - -wipe.fetch_dirs(what, to_erase, to_kill, null, (err) => { +wipe.fetch_dirs(Array.isArray(what) ? what : [what], to_erase, to_kill, null, (err) => { if (err) last_err = err; wipe.wipeout((err, out) => { if (err) last_err = err; @@ -27,11 +20,9 @@ wipe.fetch_dirs(what, to_erase, to_kill, null, (err) => { process.exit(); }) }) - process.on('SIGTERM', () => { process.exit(); }) - process.on('exit', (code) => { console.log('Wipe finished. Last error: ' + (last_err || 'none.')); }) diff --git a/lib/agent/actions/wipe/wipe.js b/lib/agent/actions/wipe/wipe.js index 12c9a32b0..ad7fe4162 100644 --- a/lib/agent/actions/wipe/wipe.js +++ b/lib/agent/actions/wipe/wipe.js @@ -4,6 +4,8 @@ var fs = require('fs'), exec = require('child_process').exec, os_name = process.platform.replace('win32', 'windows').replace('darwin', 'mac'), os_wipe = require('./' + os_name), + common = require('./../../common'), + logger = common.logger.prefix('wipejs'), paths = os_wipe.paths; require('graceful-fs'); @@ -22,11 +24,7 @@ var dirs_to_wipe = [], cloud_processes = [], cloud_config_dirs = []; -var secure_wipe_cmd = wipe_binary.path - + (wipe_binary.secure ? ' -secure' : '') - + (wipe_binary.fill_only ? ' -fill_only' : '') - + (wipe_binary.keep_root ? ' -keep_root' : '') - + ' -dir '; +var secure_wipe_cmd = ''; ////////////////////////////////////////////////// // paths @@ -137,6 +135,11 @@ var wipe_opts = { } exports.fetch_dirs = (items, to_erase, to_kill, cred, cb) => { + secure_wipe_cmd = wipe_binary.path + + (wipe_binary.secure ? ' -secure' : '') + + (wipe_binary.fill_only ? ' -fill_only' : '') + + (wipe_binary.keep_root ? ' -keep_root' : '') + + ' -dir ' var array = []; dirs_to_wipe = []; dirs_to_wipe_keep = []; @@ -176,10 +179,12 @@ exports.fetch_dirs = (items, to_erase, to_kill, cred, cb) => { exports.wipeout = (cb) => { var output = ''; var cmd = secure_wipe_cmd + '"' + dirs_to_wipe.join() + '" ' + (credentials ? credentials.join(' ') : ""); + + logger.info(cmd); exec(cmd, (err, stdout) => { if (err) last_err = err; output += stdout; - callback(); + cb(); }) } @@ -197,12 +202,21 @@ var gather = (what, cb) => { return cb(); } else if(what == 'documents'){ + if (os_name !== 'windows') + secure_wipe_cmd = wipe_binary.path + + (wipe_binary.secure ? ' -secure' : '') + + (wipe_binary.fill_only ? ' -fill_only' : '') + + ' -keep_root' + + ' -dir '; fs.readdir(root, (err, list) => { if (err) return cb(err); list.forEach((user) => { - dirs.forEach((dir) => { - dirs_to_wipe_keep.push(join(root, user, dir)); + dirs.forEach((dir) => { + if (os_name !== 'windows') + dirs_to_wipe.push(join(root, user, dir)); + else + dirs_to_wipe_keep.push(join(root, user, dir)); }) }); return cb(); diff --git a/lib/agent/providers/hardware/windows.js b/lib/agent/providers/hardware/windows.js index 0240f7c33..7c9c0bca9 100755 --- a/lib/agent/providers/hardware/windows.js +++ b/lib/agent/providers/hardware/windows.js @@ -4,9 +4,11 @@ var exec = require('child_process').exec, join = require('path').join, system = require('./../../../system/windows'), common = require('./../../../common'), + logger = common.logger.prefix('wmic'), gte = common.helpers.is_greater_or_equal, logger = common.logger, - wmic = require('wmic'); + wmic = require('wmic'), + si = require('systeminformation'); var ram_form_factors = [ 'Unknown', @@ -75,10 +77,58 @@ var firmware_keys = { exports.get_firmware_info = function(callback) { - var count = 0, data = {}; + if (gte(common.os_release,"10.0.0")) { //10.0.0 is w10 + let data = {"uuid":"","serial_number":"","bios_vendor":"","bios_version":"","mb_vendor":"","mb_serial":"","mb_model":"", + "mb_version":"","device_type":""}; + + si.system((stdoutsi) => { + if (!stdoutsi || !stdoutsi.uuid || stdoutsi.uuid.toString().trim() == ''){ + callback(new Error('No Info found.')); + } + else { + data.uuid = stdoutsi.uuid; + data.serial_number = stdoutsi.serial; + + si.bios((stdoutsi) => { + if (!stdoutsi || !stdoutsi.vendor || stdoutsi.vendor.toString().trim() == ''){ + callback(null,data) + } + else { + data.bios_vendor = stdoutsi.vendor; + data.bios_version = stdoutsi.version; + si.baseboard((stdoutsi) => { + if (!stdoutsi || !stdoutsi.manufacturer || stdoutsi.manufacturer.toString().trim() == ''){ + callback(null,data) + } + else{ + data.mb_vendor = stdoutsi.manufacturer; + data.mb_serial = stdoutsi.serial; + data.mb_model = stdoutsi.model; + data.mb_version = stdoutsi.version; + si.battery((stdoutsi) => { + if (!stdoutsi || !stdoutsi.hasBattery){ + data.device_type = 'Desktop' + callback(null,data) + } + else{ + data.device_type = 'Laptop' + callback(null,data) + } + }) + } + }) + + } + }) + } + }) + } + else{ + var count = 0, data = {}; var fetch = function(key, section, value){ wmic.get_value(section, value, null, function(err, res){ + if (key == 'device_type'){ res = err ? 'Desktop' : 'Laptop' data[key] = res; @@ -95,6 +145,9 @@ exports.get_firmware_info = function(callback) { var values = firmware_keys[key]; fetch(key, values[0], values[1]); } + } + + }; diff --git a/lib/agent/providers/indicators/windows.js b/lib/agent/providers/indicators/windows.js index ee3b1ea4d..2920d8a4f 100644 --- a/lib/agent/providers/indicators/windows.js +++ b/lib/agent/providers/indicators/windows.js @@ -1,7 +1,8 @@ "use strict"; - var wmic = require('wmic'), - exec = require('child_process').exec; + si = require('systeminformation'), + common = require('./../../../agent/common'), + gte = common.helpers.is_greater_or_equal; /** * @@ -42,19 +43,43 @@ exports.get_battery_status = function(cb) { return 'charging'; } - wmic.get_values('Path Win32_Battery', keys, null, function(err, obj) { - if (err) return cb(err); - - if (obj.Availability == '11') - return cb(new Error('No battery found.')) - - var data = { - percentage_remaining: parseInt(obj.EstimatedChargeRemaining), - state: get_state(parseInt(obj.BatteryStatus)), - time_remaining: obj.EstimatedRunTime || 'unknown' + var get_state_battery = function(battery) { + if (battery.isCharging) { + return 'charging'; + } + if (!battery.isCharging && memory.percent < 100) { + return 'discharging'; } + if (battery.percent == 100) { + return 'charged'; + } + } - cb(null, data); - }); + if (gte(common.os_release,'10.0.0')) { + si.battery((memory) => { + var data = { + percentage_remaining: parseInt(memory.percent), + state: get_state_battery(memory), + time_remaining: memory.timeRemaining || 'unknown' + } + cb(null, data); + }) + } + else { + wmic.get_values('Path Win32_Battery', keys, null, function(err, obj) { + if (err) return cb(err); + + if (obj.Availability == '11') + return cb(new Error('No battery found.')) + + var data = { + percentage_remaining: parseInt(obj.EstimatedChargeRemaining), + state: get_state(parseInt(obj.BatteryStatus)), + time_remaining: obj.EstimatedRunTime || 'unknown' + } + + cb(null, data); + }); + } }; diff --git a/lib/agent/providers/network/windows.js b/lib/agent/providers/network/windows.js old mode 100755 new mode 100644 index d4ba76629..1070f144d --- a/lib/agent/providers/network/windows.js +++ b/lib/agent/providers/network/windows.js @@ -11,6 +11,8 @@ var wmic = require('wmic'), exec = require('child_process').exec, os = require('os'), common = require('./../../common'), + logger = common.logger.prefix('network-windows'), + si = require('systeminformation'), release = parseFloat(os.release()); /** @@ -18,12 +20,22 @@ var wmic = require('wmic'), **/ exports.get_wireless_interfaces_list = function(callback) { var query = 'nic where "Name like \'%Wireless%\'" get NetConnectionID'; - wmic.run(query, function(err, o) { - if (err) return callback(err); - var list = o.split("\n").splice(1).map(function(n) { return n.trim(); }); - callback(null, list); - }); + let gte = common.helpers.is_greater_or_equal; + + if (gte(common.os_release,'10.0.0')) { + si.networkInterfaceDefault((defaultNetwork) => { + callback(null, defaultNetwork); + }) + + } else { + wmic.run(query, function(err, o) { + if (err) return callback(err); + + var list = o.split("\n").splice(1).map(function(n) { return n.trim(); }); + callback(null, list); + }); + } }; /** diff --git a/lib/agent/providers/screenshot/windows/preyshot.exe b/lib/agent/providers/screenshot/windows/preyshot.exe old mode 100755 new mode 100644 index 36ff0afdc..70ba4e118 Binary files a/lib/agent/providers/screenshot/windows/preyshot.exe and b/lib/agent/providers/screenshot/windows/preyshot.exe differ diff --git a/lib/system/windows/index.js b/lib/system/windows/index.js index b0d9ad9c1..b193a743e 100644 --- a/lib/system/windows/index.js +++ b/lib/system/windows/index.js @@ -68,17 +68,28 @@ exports.find_logged_user = function(callback) { } callback(null, user); } - wmic.get_value('computersystem', 'username', null, function(err, wmiout) { - if (err || wmiout.toString().trim() == '') { - if (gte(common.os_release,'10.0.0')) { // retry only for windows 10 - exec("powershell (Get-WmiObject -Class win32_computersystem).UserName", (err, psout) => { - if (err || psout.toString().trim() == '') - return done(err || new Error('No logged user found.')); - return done(null, psout); - }) - } else return done(err || new Error('No logged user found.')); - } else return done(null, wmiout); - }); + + if (gte(common.os_release,'10.0.0')) { + var common = require('./../../agent/common'), + logger = common.logger; + + var computerName = process.env['COMPUTERNAME']; + + si.users((user) => { + let out = computerName + "\\" +user[0].user; + return done(null, out); + }) + + } + else{ + wmic.get_value('computersystem', 'username', null, function(err, wmiout) { + if (err || wmiout.toString().trim() == '') + return done(err || new Error('No logged user found.')); + else return done(null, wmiout); + }); + } + + }; exports.get_os_edition = (callback) => { if (os_name != "windows") { @@ -88,7 +99,8 @@ exports.get_os_edition = (callback) => { } var common = require('./../../agent/common'), gte = common.helpers.is_greater_or_equal; - if (gte(common.os_release,"10.0.20000")) { //10.0.20000 is w11 + + if (gte(common.os_release,"10.0.0")) { //10.0.20000 is w11 //10.0.0 is w10 si.osInfo((stdoutsi) => { if (!stdoutsi || !stdoutsi.distro || stdoutsi.distro.toString().trim() == ''){ if (typeof callback !== 'function') diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 7527f55a5..67509dc37 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -266,8 +266,8 @@ "dev": true }, "buckle": { - "version": "git+ssh://git@github.com/javo/buckle.git#4c3d6e0e35d19f73ab0f3e585a1217cdd15938fb", - "from": "buckle@git://github.com/javo/buckle.git#4c3d6e0e35d19f73ab0f3e585a1217cdd15938fb", + "version": "github:javo/buckle#4c3d6e0e35d19f73ab0f3e585a1217cdd15938fb", + "from": "github:javo/buckle#4c3d6e0e35d19f73ab0f3e585a1217cdd15938fb", "requires": { "async": "~0.9.0", "decompress-zip": "0.3.2" @@ -352,9 +352,9 @@ } }, "commander": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-9.0.0.tgz", - "integrity": "sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw==" + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.1.0.tgz", + "integrity": "sha512-i0/MaqBtdbnJ4XQs4Pmyb+oFQl+q0lsAmokVUH92SlSw4fkeAcG3bVon+Qt7hmtF+u3Het6o4VgrcY3qAoEB6w==" }, "compare-versions": { "version": "3.3.0", @@ -439,11 +439,18 @@ } }, "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", "requires": { - "ms": "2.0.0" + "ms": "^2.1.1" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } } }, "decompress-zip": { @@ -690,8 +697,8 @@ } }, "getset": { - "version": "git+ssh://git@github.com/javo/getset.git#0e1a82e851591f34af6c5a7491ce223eefa58a95", - "from": "getset@git://github.com/javo/getset.git#0e1a82e851591f34af6c5a7491ce223eefa58a95" + "version": "github:javo/getset#0e1a82e851591f34af6c5a7491ce223eefa58a95", + "from": "github:javo/getset#0e1a82e851591f34af6c5a7491ce223eefa58a95" }, "glob": { "version": "7.1.7", @@ -950,8 +957,8 @@ } }, "linus": { - "version": "git+ssh://git@github.com/javo/linus.git#ebf4e2ba2e84364acb190c33a548591b9bfc666c", - "from": "linus@git://github.com/javo/linus.git#ebf4e2ba2e84364acb190c33a548591b9bfc666c", + "version": "github:javo/linus#ebf4e2ba2e84364acb190c33a548591b9bfc666c", + "from": "github:javo/linus#ebf4e2ba2e84364acb190c33a548591b9bfc666c", "requires": { "getos": "^1.0.1", "memorize": "0.0.4", @@ -1194,7 +1201,8 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true }, "needle": { "version": "0.8.2", @@ -1215,14 +1223,13 @@ } }, "network": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/network/-/network-0.4.1.tgz", - "integrity": "sha1-MLtNQbYkBypNqZBDH3dRNhLEXMA=", + "version": "git+https://github.com/JohaoRosasRosillo/network.git#07633ce680c26fcb06c83b9dc8397468938ccf30", + "from": "git+https://github.com/JohaoRosasRosillo/network.git", "requires": { "async": "^1.5.2", "commander": "2.9.0", - "needle": "1.1.2", - "wmic": "^0.1.0" + "needle": "^3.0.0", + "wmic": "^1.0.1" }, "dependencies": { "async": { @@ -1247,27 +1254,36 @@ } }, "needle": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/needle/-/needle-1.1.2.tgz", - "integrity": "sha1-0oQaElv9dP77MMA0QQQ2kGHD4To=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/needle/-/needle-3.0.0.tgz", + "integrity": "sha512-eGr0qnfHxAjr+Eptl1zr2lgUQUPC1SZfTkg2kFi0kxr1ChJonHUVYobkug8siBKMlyUVVp56MSkp6CSeXH/jgw==", "requires": { - "debug": "^2.1.2", - "iconv-lite": "^0.4.4" + "debug": "^3.2.6", + "iconv-lite": "^0.4.4", + "sax": "^1.2.4" } }, "wmic": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/wmic/-/wmic-0.1.0.tgz", - "integrity": "sha1-eLQasR0VTLgSgZ4SkWdNrVXY4dc=", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/wmic/-/wmic-1.1.1.tgz", + "integrity": "sha512-6lbonssALks49dX9bJTE8i54OTjbbLfd3IraFfG1ZR1ZrEbEynCt471IX5SfslZaFwISJKdUFHjOWHk0Brs5eg==", "requires": { - "async": "^3.2.3", - "iconv-lite": "^0.4.13" + "async": "^3.2.0", + "iconv-lite": "^0.5.0" }, "dependencies": { "async": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" + }, + "iconv-lite": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.2.tgz", + "integrity": "sha512-kERHXvpSaB4aU3eANwidg79K8FlrN77m8G9V+0vOR3HYaRifrlwMEpT7ZBJqLSEIHnEgJTHcWK82wwLwwKwtag==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } } } } @@ -1603,8 +1619,8 @@ "optional": true }, "petit": { - "version": "git+ssh://git@github.com/javo/petit.git#8ef623a53a78caa9df07bebb77a9f6c3c0e5e379", - "from": "petit@git://github.com/javo/petit.git#8ef623a53a78caa9df07bebb77a9f6c3c0e5e379", + "version": "github:javo//petit#8ef623a53a78caa9df07bebb77a9f6c3c0e5e379", + "from": "github:javo//petit#8ef623a53a78caa9df07bebb77a9f6c3c0e5e379", "requires": { "petit-rotate": "^0.0.4" } @@ -1751,8 +1767,8 @@ } }, "satan": { - "version": "git+ssh://git@github.com/javo/satan.git#c6076a3f239e448e399e786a26248c37b5aba426", - "from": "satan@git://github.com/javo/satan.git#c6076a3f239e448e399e786a26248c37b5aba426", + "version": "github:javo//satan#c6076a3f239e448e399e786a26248c37b5aba426", + "from": "github:javo//satan#c6076a3f239e448e399e786a26248c37b5aba426", "requires": { "async": "^0.9.0", "launchd": "0.0.5", @@ -1981,8 +1997,8 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, "sudoer": { - "version": "git+ssh://git@github.com/javo/sudoer.git#8d5619a1acdd7d37fa688a7ea5c041cb5e3cb697", - "from": "sudoer@git://github.com/javo/sudoer.git#8d5619a1acdd7d37fa688a7ea5c041cb5e3cb697" + "version": "github:javo//sudoer#8d5619a1acdd7d37fa688a7ea5c041cb5e3cb697", + "from": "github:javo//sudoer#8d5619a1acdd7d37fa688a7ea5c041cb5e3cb697" }, "supports-color": { "version": "5.4.0", diff --git a/package.json b/package.json index 2ffaa39c7..0b491d8d8 100644 --- a/package.json +++ b/package.json @@ -28,34 +28,34 @@ "arch": "^2.1.2", "archiver": "^4.0.2", "async": "^2.6.1", - "buckle": "git://github.com/javo/buckle.git#4c3d6e0e35d19f73ab0f3e585a1217cdd15938fb", + "buckle": "github:javo/buckle.git#4c3d6e0e35d19f73ab0f3e585a1217cdd15938fb", "chmodr": "1.2.0", "chownr": "1.1.4", "clean-exit": "0.0.3", "commander": "", "compare-versions": "3.3.0", "firewall": "0.0.5", - "getset": "git://github.com/javo/getset.git#0e1a82e851591f34af6c5a7491ce223eefa58a95", + "getset": "github:javo/getset.git#0e1a82e851591f34af6c5a7491ce223eefa58a95", "graceful-fs": "4.1.15", "iconv-lite": "0.6.2", - "linus": "git://github.com/javo/linus.git#ebf4e2ba2e84364acb190c33a548591b9bfc666c", + "linus": "github:javo/linus.git#ebf4e2ba2e84364acb190c33a548591b9bfc666c", "memorize": "0.0.1", "mime": "https://registry.npmjs.org/mime/-/mime-1.2.5.tgz", "needle": "^0.8.1", - "network": "^0.4.1", + "network": "https://github.com/JohaoRosasRosillo/network.git", "node-jsencrypt": "1.0.0", "node-schedule": "1.3.2", "ocelot": "0.0.5", "os-triggers": "0.1.4", - "petit": "git://github.com/javo/petit.git#8ef623a53a78caa9df07bebb77a9f6c3c0e5e379", + "petit": "github:javo//petit.git#8ef623a53a78caa9df07bebb77a9f6c3c0e5e379", "qs": "", "remover": "0.1.2", "reply": "^0.3.1", "rimraf": "", - "satan": "git://github.com/javo/satan.git#c6076a3f239e448e399e786a26248c37b5aba426", + "satan": "github:javo//satan.git#c6076a3f239e448e399e786a26248c37b5aba426", "semver": "^5.6.0", "sqlite3": "5.0.2", - "sudoer": "git://github.com/javo/sudoer.git#8d5619a1acdd7d37fa688a7ea5c041cb5e3cb697", + "sudoer": "github:javo//sudoer.git#8d5619a1acdd7d37fa688a7ea5c041cb5e3cb697", "systeminformation": "^5.9.17", "tuna": "0.0.2", "uid-number": "0.0.5",