mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 22:46:14 -05:00
feat: report SentinelOne status on macOS
This commit is contained in:
3 files changed
+212
No files matched your search
@@ -7,6 +7,9 @@ use std::collections::HashMap;
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use xmltree::Element;
|
use xmltree::Element;
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod sentinel_macos;
|
||||||
|
|
||||||
pub const MAX_EDITED_REPORT_BYTES: usize = 48 * 1024;
|
pub const MAX_EDITED_REPORT_BYTES: usize = 48 * 1024;
|
||||||
|
|
||||||
/// Validate an edited report before it is stored or used as a submission body.
|
/// Validate an edited report before it is stored or used as a submission body.
|
||||||
@@ -252,6 +255,12 @@ struct ClamAvInfo {
|
|||||||
real_time_protection: bool,
|
real_time_protection: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SentinelInfo {
|
||||||
|
version: String,
|
||||||
|
real_time_protection: bool,
|
||||||
|
firewall_enabled: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Host information for HIP reporting
|
/// Host information for HIP reporting
|
||||||
struct HostInfo {
|
struct HostInfo {
|
||||||
/// Common for all OSes, e.g., "Apple", "Microsoft", "Linux"
|
/// Common for all OSes, e.g., "Apple", "Microsoft", "Linux"
|
||||||
@@ -268,6 +277,7 @@ struct HostInfo {
|
|||||||
network_interfaces: Vec<NetworkInterface>,
|
network_interfaces: Vec<NetworkInterface>,
|
||||||
defender: Option<DefenderInfo>,
|
defender: Option<DefenderInfo>,
|
||||||
clamav: Option<ClamAvInfo>,
|
clamav: Option<ClamAvInfo>,
|
||||||
|
sentinel: Option<SentinelInfo>,
|
||||||
ufw: Option<UfwInfo>,
|
ufw: Option<UfwInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,6 +412,7 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
|
|||||||
network_interfaces: interfaces,
|
network_interfaces: interfaces,
|
||||||
defender: self.defender_for_profile(),
|
defender: self.defender_for_profile(),
|
||||||
clamav: self.clamav_for_profile(),
|
clamav: self.clamav_for_profile(),
|
||||||
|
sentinel: self.sentinel_for_profile(),
|
||||||
ufw: self.ufw_for_profile(),
|
ufw: self.ufw_for_profile(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,6 +481,14 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
|
|||||||
ClientOs::Mac | ClientOs::Windows => None,
|
ClientOs::Mac | ClientOs::Windows => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sentinel_for_profile(&self) -> Option<SentinelInfo> {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
if self.profile.client_os() == ClientOs::Mac && self.profile.is_native() {
|
||||||
|
return sentinel_macos::detect();
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detect_clamav() -> Option<ClamAvInfo> {
|
fn detect_clamav() -> Option<ClamAvInfo> {
|
||||||
@@ -771,6 +790,37 @@ mod tests {
|
|||||||
validate_edited_report(&report).unwrap();
|
validate_edited_report(&report).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mac_report_renders_detected_sentinel_products() {
|
||||||
|
let input = make_input(make_profile(ClientOs::Mac));
|
||||||
|
let cookie_params = HashMap::new();
|
||||||
|
let mut host_info = HostInfoCollector::new(&input.profile, &input, &cookie_params).collect();
|
||||||
|
host_info.sentinel = Some(SentinelInfo {
|
||||||
|
version: "25.3.4.8365".to_string(),
|
||||||
|
real_time_protection: true,
|
||||||
|
firewall_enabled: Some(false),
|
||||||
|
});
|
||||||
|
let (generate_time, day, month, year) = get_current_time_components();
|
||||||
|
let report = HipReportTemplate {
|
||||||
|
client_version: input.profile.client_version(),
|
||||||
|
generate_time,
|
||||||
|
day,
|
||||||
|
month,
|
||||||
|
year,
|
||||||
|
user_name: "test-user",
|
||||||
|
host_info,
|
||||||
|
md5: "test-digest",
|
||||||
|
}
|
||||||
|
.render()
|
||||||
|
.unwrap();
|
||||||
|
let report = format_xml(&report).unwrap();
|
||||||
|
validate_edited_report(&report).unwrap();
|
||||||
|
assert!(report.contains("vendor=\"SentinelOne\" name=\"Sentinel Agent\" version=\"25.3.4.8365\""));
|
||||||
|
assert!(report.contains("<real-time-protection>yes</real-time-protection>"));
|
||||||
|
assert!(report.contains("<is-enabled>no</is-enabled>"));
|
||||||
|
assert_eq!(report.matches("name=\"Sentinel Agent\"").count(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn preview_uses_explicit_pending_digest() {
|
fn preview_uses_explicit_pending_digest() {
|
||||||
let input = ReportInput {
|
let input = ReportInput {
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
os::unix::fs::{MetadataExt, PermissionsExt},
|
||||||
|
path::Path,
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::SentinelInfo;
|
||||||
|
|
||||||
|
const SENTINELCTL: &str = "/Library/Sentinel/sentinel-agent.bundle/Contents/MacOS/sentinelctl";
|
||||||
|
|
||||||
|
pub(super) fn detect() -> Option<SentinelInfo> {
|
||||||
|
if !trusted_cli(Path::new(SENTINELCTL)) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = run(&["status"])?;
|
||||||
|
let status = parse_status(&status)?;
|
||||||
|
let real_time_protection = if status.active {
|
||||||
|
let scan_status = run(&["scan-on-write"])?;
|
||||||
|
parse_yes_no(scan_status.trim().strip_prefix("scan-on-write:")?)?
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
let firewall_enabled = run(&["firewall", "enabled"]).as_deref().and_then(parse_yes_no);
|
||||||
|
|
||||||
|
Some(SentinelInfo {
|
||||||
|
version: status.version,
|
||||||
|
real_time_protection,
|
||||||
|
firewall_enabled,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trusted_cli(path: &Path) -> bool {
|
||||||
|
path.ancestors().take_while(|part| part.as_os_str() != "/").all(|part| {
|
||||||
|
let Ok(metadata) = fs::symlink_metadata(part) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
if metadata.uid() != 0 || metadata.permissions().mode() & 0o022 != 0 || metadata.file_type().is_symlink() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if part == path {
|
||||||
|
metadata.is_file()
|
||||||
|
} else {
|
||||||
|
metadata.is_dir()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(args: &[&str]) -> Option<String> {
|
||||||
|
let output = Command::new(SENTINELCTL)
|
||||||
|
.args(args)
|
||||||
|
.env("LC_ALL", "C")
|
||||||
|
.env_remove("SENTINEL_OUTPUT_JSON")
|
||||||
|
.output()
|
||||||
|
.ok()?;
|
||||||
|
if !output.status.success() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
String::from_utf8(output.stdout).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AgentStatus {
|
||||||
|
version: String,
|
||||||
|
active: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_status(output: &str) -> Option<AgentStatus> {
|
||||||
|
let version = status_value(output, "Version:")?;
|
||||||
|
if version.is_empty()
|
||||||
|
|| version.len() > 64
|
||||||
|
|| !version
|
||||||
|
.chars()
|
||||||
|
.all(|ch| ch.is_ascii_alphanumeric() || matches!(ch, '.' | '-' | '_'))
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let operational = parse_status_bool(output, "Agent Operational State:", "enabled", "disabled")?;
|
||||||
|
let ready = parse_status_bool(output, "Ready:", "yes", "no")?;
|
||||||
|
let protected = parse_status_bool(output, "Protection:", "enabled", "disabled")?;
|
||||||
|
Some(AgentStatus {
|
||||||
|
version: version.to_string(),
|
||||||
|
active: operational && ready && protected,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn status_value<'a>(output: &'a str, label: &str) -> Option<&'a str> {
|
||||||
|
output
|
||||||
|
.lines()
|
||||||
|
.find_map(|line| line.trim().strip_prefix(label).map(str::trim))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_status_bool(output: &str, label: &str, yes: &str, no: &str) -> Option<bool> {
|
||||||
|
match status_value(output, label)? {
|
||||||
|
value if value == yes => Some(true),
|
||||||
|
value if value == no => Some(false),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_yes_no(output: &str) -> Option<bool> {
|
||||||
|
match output.trim() {
|
||||||
|
"yes" => Some(true),
|
||||||
|
"no" => Some(false),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_running_agent_status() {
|
||||||
|
let status = parse_status(
|
||||||
|
"Agent\n Version: 25.3.4.8365\n Agent Operational State: enabled\n Ready: yes\n Protection: enabled\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(status.version, "25.3.4.8365");
|
||||||
|
assert!(status.active);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_unknown_agent_state() {
|
||||||
|
assert!(parse_status("Version: 25.3.4.8365\nProtection: maybe\n").is_none());
|
||||||
|
assert!(
|
||||||
|
!parse_status("Version: 25.3.4.8365\nAgent Operational State: disabled\nReady: yes\nProtection: enabled\n")
|
||||||
|
.unwrap()
|
||||||
|
.active
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_scan_and_firewall_states() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_yes_no("scan-on-write:\tyes\n".trim().strip_prefix("scan-on-write:").unwrap()),
|
||||||
|
Some(true)
|
||||||
|
);
|
||||||
|
assert_eq!(parse_yes_no("no\n"), Some(false));
|
||||||
|
assert_eq!(parse_yes_no("unknown\n"), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -139,6 +139,15 @@
|
|||||||
{% elif host_info.os_vendor == "Apple" -%}
|
{% elif host_info.os_vendor == "Apple" -%}
|
||||||
<entry name="anti-malware">
|
<entry name="anti-malware">
|
||||||
<list>
|
<list>
|
||||||
|
{% if let Some(sentinel) = &host_info.sentinel %}
|
||||||
|
<entry>
|
||||||
|
<ProductInfo>
|
||||||
|
<Prod vendor="SentinelOne" name="Sentinel Agent" version="{{ sentinel.version }}" engver="" datemon="{{ month }}" dateday="{{ day }}" dateyear="{{ year }}" prodType="3" osType="4"/>
|
||||||
|
<real-time-protection>{% if sentinel.real_time_protection %}yes{% else %}no{% endif %}</real-time-protection>
|
||||||
|
<last-full-scan-time>n/a</last-full-scan-time>
|
||||||
|
</ProductInfo>
|
||||||
|
</entry>
|
||||||
|
{% endif -%}
|
||||||
<entry>
|
<entry>
|
||||||
<ProductInfo>
|
<ProductInfo>
|
||||||
<Prod vendor="Apple Inc." name="Xprotect" version="2167" defver="235000000000000" engver="" datemon="{{ month }}" dateday="{{ day }}" dateyear="{{ year }}" prodType="3" osType="4"/>
|
<Prod vendor="Apple Inc." name="Xprotect" version="2167" defver="235000000000000" engver="" datemon="{{ month }}" dateday="{{ day }}" dateyear="{{ year }}" prodType="3" osType="4"/>
|
||||||
@@ -190,6 +199,16 @@
|
|||||||
</entry>
|
</entry>
|
||||||
<entry name="firewall">
|
<entry name="firewall">
|
||||||
<list>
|
<list>
|
||||||
|
{% if let Some(sentinel) = &host_info.sentinel %}
|
||||||
|
{% if let Some(firewall_enabled) = sentinel.firewall_enabled %}
|
||||||
|
<entry>
|
||||||
|
<ProductInfo>
|
||||||
|
<Prod vendor="SentinelOne" name="Sentinel Agent" version="{{ sentinel.version }}"/>
|
||||||
|
<is-enabled>{% if firewall_enabled %}yes{% else %}no{% endif %}</is-enabled>
|
||||||
|
</ProductInfo>
|
||||||
|
</entry>
|
||||||
|
{% endif -%}
|
||||||
|
{% endif -%}
|
||||||
<entry>
|
<entry>
|
||||||
<ProductInfo>
|
<ProductInfo>
|
||||||
<Prod vendor="Apple Inc." name="Mac OS X Builtin Firewall" version="{{ host_info.software_version }}"/>
|
<Prod vendor="Apple Inc." name="Mac OS X Builtin Firewall" version="{{ host_info.software_version }}"/>
|
||||||
|
|||||||
Reference in new issue
Block a user