From 7f0d7ec062892697296e12fbebe972cb687bcfb1 Mon Sep 17 00:00:00 2001 From: johaoRosasRosillo Date: Thu, 26 Jan 2023 10:29:20 -0300 Subject: [PATCH 1/7] send version prey-user to panel --- lib/agent/providers/hardware/index.js | 2 +- lib/agent/providers/hardware/mac.js | 21 +++++++++++++++++---- lib/agent/providers/hardware/windows.js | 1 - lib/agent/reports/specs.js | 1 + lib/system/mac/index.js | 10 ++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/agent/providers/hardware/index.js b/lib/agent/providers/hardware/index.js index 632273808..33f541755 100644 --- a/lib/agent/providers/hardware/index.js +++ b/lib/agent/providers/hardware/index.js @@ -78,7 +78,7 @@ exp.get_rp_module = os_functions.get_recovery_partition_status; exp.get_model_name = exp.get_model_name; exp.get_vendor_name = exp.get_vendor_name; exp.get_processor_info = (os_name == 'mac') ? os_functions.get_processor_info : exp.get_processor_info;/////////////// - +exp.get_prey_user_version = os_functions.get_prey_user_version; // even though these functions look like they belong in the network provider, // we put them here because MAC addresses are part of the network interfaces, // and are not subject to change (even though they can be spoofed) diff --git a/lib/agent/providers/hardware/mac.js b/lib/agent/providers/hardware/mac.js index 7a48edee1..83b43f519 100644 --- a/lib/agent/providers/hardware/mac.js +++ b/lib/agent/providers/hardware/mac.js @@ -1,6 +1,8 @@ var exec = require('child_process').exec, si = require('systeminformation'), - system = require('./../../../system/mac/index'); + system = require('./../../../system/mac/index'), + common = require('./../../../common'), + logger = common.logger.prefix('hardware-mac'); var ram_vendors = { '0x014F': 'Transcend Information', @@ -85,9 +87,7 @@ exports.get_ram_module_list = function(cb) { cb(null, list); }) - } - - + } } ///////////////////////////////////////////////////////////////// @@ -126,4 +126,17 @@ var get_system_profiler_data = function(type, cb) { cb(null, obj); }); +} + +exports.get_prey_user_version = function(cb) { + system.get_prey_user_version((err, prey_user_version) => { + if (err) return cb(err); + try { + logger.info("prey_user_version:"+ JSON.stringify(prey_user_version)) + } catch(e) { + return cb(new Error("Error get prey_user_version: " + e.message)); + } + return cb(null, prey_user_version); + }) + } \ No newline at end of file diff --git a/lib/agent/providers/hardware/windows.js b/lib/agent/providers/hardware/windows.js index 4a08de7b3..65487f2ae 100755 --- a/lib/agent/providers/hardware/windows.js +++ b/lib/agent/providers/hardware/windows.js @@ -6,7 +6,6 @@ var exec = require('child_process').exec, common = require('./../../../common'), logger = common.logger.prefix('wmic'), gte = common.helpers.is_greater_or_equal, - logger = common.logger, wmic = require('wmic'), si = require('systeminformation'); diff --git a/lib/agent/reports/specs.js b/lib/agent/reports/specs.js index 2036cc608..d71002669 100644 --- a/lib/agent/reports/specs.js +++ b/lib/agent/reports/specs.js @@ -9,4 +9,5 @@ exports.includes = [ ...(process.platform == 'win32' ? ['os_edition', 'winsvc_version', 'rp_module'] : []), + ...(process.platform == 'darwin'? ['prey_user_version']:[]) ]; diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 96b505b81..19e0335cd 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -132,4 +132,14 @@ exports.get_info_chip = function(){ var model = cpus[0].model.trim(); return model; +} + +exports.get_prey_user_version = function(cb) { + var prey_user_version; + try { + prey_user_version = cp.execSync('/usr/local/lib/prey/versions/prey-user -v'); + } catch (e) { + return cb(new Error("Unable to determine Mac OS version.")) + } + cb(null, prey_user_version.toString().trim()); } \ No newline at end of file From 7d36c25bfb6b087c809edd050cefb30a3d71b784 Mon Sep 17 00:00:00 2001 From: johaoRosasRosillo Date: Thu, 26 Jan 2023 10:31:07 -0300 Subject: [PATCH 2/7] message error prey-user-version --- lib/system/mac/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 19e0335cd..7302947db 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -139,7 +139,7 @@ exports.get_prey_user_version = function(cb) { try { prey_user_version = cp.execSync('/usr/local/lib/prey/versions/prey-user -v'); } catch (e) { - return cb(new Error("Unable to determine Mac OS version.")) + return cb(new Error("Unable to get prey-user-version.")) } cb(null, prey_user_version.toString().trim()); } \ No newline at end of file From f43824593cac635a907a3c25272a0882da0a746a Mon Sep 17 00:00:00 2001 From: johaoRosasRosillo Date: Thu, 26 Jan 2023 14:03:16 -0300 Subject: [PATCH 3/7] add paths version --- lib/system/mac/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 7302947db..5f77ba5db 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -7,7 +7,8 @@ var cp = require('child_process'), os_name = process.platform.replace('darwin', 'mac'), - os = require('os'); + os = require('os'), + paths = require('./../paths'); // var get_logged_user_cmd = "stat /dev/console | cut -d' ' -f5"; // var get_logged_user_pid_cmd = "ps ax | grep -v grep | grep loginwindow | awk '{print $1}'" @@ -135,9 +136,11 @@ exports.get_info_chip = function(){ } exports.get_prey_user_version = function(cb) { + + const path = (paths.versions) ? `${paths.versions}/prey-user -v` : '/usr/local/lib/prey/versions/prey-user -v' ; var prey_user_version; try { - prey_user_version = cp.execSync('/usr/local/lib/prey/versions/prey-user -v'); + prey_user_version = cp.execSync(path); } catch (e) { return cb(new Error("Unable to get prey-user-version.")) } From cce5ae8d757e6aae5ab38fbb1c963dc61b943c01 Mon Sep 17 00:00:00 2001 From: johaoRosasRosillo Date: Tue, 14 Feb 2023 17:01:40 -0300 Subject: [PATCH 4/7] add validation to prey-user file --- lib/agent/providers/hardware/mac.js | 6 +++--- lib/system/mac/index.js | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/agent/providers/hardware/mac.js b/lib/agent/providers/hardware/mac.js index 83b43f519..50e21cf16 100644 --- a/lib/agent/providers/hardware/mac.js +++ b/lib/agent/providers/hardware/mac.js @@ -2,7 +2,7 @@ var exec = require('child_process').exec, si = require('systeminformation'), system = require('./../../../system/mac/index'), common = require('./../../../common'), - logger = common.logger.prefix('hardware-mac'); + logger = common.logger.prefix('hardware-mac'); var ram_vendors = { '0x014F': 'Transcend Information', @@ -133,10 +133,10 @@ exports.get_prey_user_version = function(cb) { if (err) return cb(err); try { logger.info("prey_user_version:"+ JSON.stringify(prey_user_version)) + return cb(null, prey_user_version); } catch(e) { return cb(new Error("Error get prey_user_version: " + e.message)); - } - return cb(null, prey_user_version); + } }) } \ No newline at end of file diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 5f77ba5db..6674fd660 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -8,7 +8,9 @@ var cp = require('child_process'), os_name = process.platform.replace('darwin', 'mac'), os = require('os'), - paths = require('./../paths'); + paths = require('./../paths'), + join = require('path').join, + fs = require('fs'); // var get_logged_user_cmd = "stat /dev/console | cut -d' ' -f5"; // var get_logged_user_pid_cmd = "ps ax | grep -v grep | grep loginwindow | awk '{print $1}'" @@ -136,11 +138,21 @@ exports.get_info_chip = function(){ } exports.get_prey_user_version = function(cb) { - - const path = (paths.versions) ? `${paths.versions}/prey-user -v` : '/usr/local/lib/prey/versions/prey-user -v' ; + const file_prey_user = 'prey-user'; + let cmd = ''; + if (paths.current) { + cmd = join(paths.current,'bin',file_prey_user); + if (!fs.existsSync(cmd)) { + return cb(new Error("Unable to get prey-user-version,don't exist prey-user-version")) + } + cmd = cmd + ' -v'; + } + else{ + return cb(new Error("Unable to get prey-user-version,don't exist current")) + } var prey_user_version; try { - prey_user_version = cp.execSync(path); + prey_user_version = cp.execSync(cmd); } catch (e) { return cb(new Error("Unable to get prey-user-version.")) } From c8c4e8c51bc28a3956e70a54945cdcb5dd5d99f3 Mon Sep 17 00:00:00 2001 From: johaoRosasRosillo Date: Tue, 14 Feb 2023 17:07:58 -0300 Subject: [PATCH 5/7] validation send prey user only mac --- lib/agent/providers/hardware/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/agent/providers/hardware/index.js b/lib/agent/providers/hardware/index.js index 33f541755..dc99a1775 100644 --- a/lib/agent/providers/hardware/index.js +++ b/lib/agent/providers/hardware/index.js @@ -78,7 +78,7 @@ exp.get_rp_module = os_functions.get_recovery_partition_status; exp.get_model_name = exp.get_model_name; exp.get_vendor_name = exp.get_vendor_name; exp.get_processor_info = (os_name == 'mac') ? os_functions.get_processor_info : exp.get_processor_info;/////////////// -exp.get_prey_user_version = os_functions.get_prey_user_version; +exp.get_prey_user_version = (os_name == 'mac') ? os_functions.get_prey_user_version : null; // even though these functions look like they belong in the network provider, // we put them here because MAC addresses are part of the network interfaces, // and are not subject to change (even though they can be spoofed) From 33ac2f79ebf590f841727825dac1c2d69eac70e0 Mon Sep 17 00:00:00 2001 From: johaoRosasRosillo Date: Thu, 16 Feb 2023 14:29:39 -0300 Subject: [PATCH 6/7] fix , get prey-user in directory versions --- lib/system/mac/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 6674fd660..9b1f3ecf0 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -140,15 +140,15 @@ exports.get_info_chip = function(){ exports.get_prey_user_version = function(cb) { const file_prey_user = 'prey-user'; let cmd = ''; - if (paths.current) { - cmd = join(paths.current,'bin',file_prey_user); + if (paths.versions) { + cmd = join(paths.versions ,file_prey_user); if (!fs.existsSync(cmd)) { return cb(new Error("Unable to get prey-user-version,don't exist prey-user-version")) } cmd = cmd + ' -v'; } else{ - return cb(new Error("Unable to get prey-user-version,don't exist current")) + return cb(new Error("Unable to get prey-user-version,don't exist versions")) } var prey_user_version; try { From de9951b8d6dfe7b8817b9c37e0cba86d4bb9fb36 Mon Sep 17 00:00:00 2001 From: johaoRosasRosillo Date: Fri, 17 Feb 2023 11:52:57 -0300 Subject: [PATCH 7/7] validation for prey-user --- lib/agent/providers/hardware/mac.js | 2 +- lib/system/mac/index.js | 31 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/agent/providers/hardware/mac.js b/lib/agent/providers/hardware/mac.js index 50e21cf16..a48148895 100644 --- a/lib/agent/providers/hardware/mac.js +++ b/lib/agent/providers/hardware/mac.js @@ -135,7 +135,7 @@ exports.get_prey_user_version = function(cb) { logger.info("prey_user_version:"+ JSON.stringify(prey_user_version)) return cb(null, prey_user_version); } catch(e) { - return cb(new Error("Error get prey_user_version: " + e.message)); + return cb(new Error("Error:" + e.message)); } }) diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 9b1f3ecf0..59956e0ab 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -4,7 +4,6 @@ // By Tomas Pollak - http://forkhq.com // GPLv3 Licensed ////////////////////////////////////////// - var cp = require('child_process'), os_name = process.platform.replace('darwin', 'mac'), os = require('os'), @@ -138,23 +137,23 @@ exports.get_info_chip = function(){ } exports.get_prey_user_version = function(cb) { - const file_prey_user = 'prey-user'; - let cmd = ''; - if (paths.versions) { - cmd = join(paths.versions ,file_prey_user); - if (!fs.existsSync(cmd)) { - return cb(new Error("Unable to get prey-user-version,don't exist prey-user-version")) - } - cmd = cmd + ' -v'; - } - else{ - return cb(new Error("Unable to get prey-user-version,don't exist versions")) - } - var prey_user_version; try { + const file_prey_user = 'prey-user'; + let cmd = ''; + if (paths.versions) { + cmd = join(paths.versions, file_prey_user); + if (!fs.existsSync(cmd)) { + return cb(new Error("Don't exist file prey-user.")) + } + cmd = cmd + ' -v'; + } + else{ + return cb(new Error("don't exist directory versions")) + } + var prey_user_version; prey_user_version = cp.execSync(cmd); + cb(null, prey_user_version.toString().trim()); } catch (e) { - return cb(new Error("Unable to get prey-user-version.")) + return cb(new Error("Unable to get prey-user-version." +e.message )) } - cb(null, prey_user_version.toString().trim()); } \ No newline at end of file