mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-20 06:56:17 -05:00
feat(gphip): report SentinelOne on Unix hosts
This commit is contained in:
3 files changed
+188
No files matched your search
@@ -9,6 +9,8 @@ use xmltree::Element;
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod sentinel_macos;
|
mod sentinel_macos;
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
|
mod sentinel_unix;
|
||||||
|
|
||||||
pub const MAX_EDITED_REPORT_BYTES: usize = 48 * 1024;
|
pub const MAX_EDITED_REPORT_BYTES: usize = 48 * 1024;
|
||||||
|
|
||||||
@@ -487,6 +489,10 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
|
|||||||
if self.profile.client_os() == ClientOs::Mac && self.profile.is_native() {
|
if self.profile.client_os() == ClientOs::Mac && self.profile.is_native() {
|
||||||
return sentinel_macos::detect();
|
return sentinel_macos::detect();
|
||||||
}
|
}
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
|
if self.profile.client_os() == ClientOs::Linux && self.profile.is_native() {
|
||||||
|
return sentinel_unix::detect();
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -821,6 +827,37 @@ mod tests {
|
|||||||
assert_eq!(report.matches("name=\"Sentinel Agent\"").count(), 2);
|
assert_eq!(report.matches("name=\"Sentinel Agent\"").count(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn linux_report_renders_detected_sentinel_antimalware() {
|
||||||
|
let input = make_input(make_profile(ClientOs::Linux));
|
||||||
|
let cookie_params = HashMap::new();
|
||||||
|
let mut host_info = HostInfoCollector::new(&input.profile, &input, &cookie_params).collect();
|
||||||
|
host_info.sentinel = Some(SentinelInfo {
|
||||||
|
version: "25.2.2.14".to_string(),
|
||||||
|
real_time_protection: true,
|
||||||
|
firewall_enabled: None,
|
||||||
|
});
|
||||||
|
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.2.2.14\""));
|
||||||
|
assert!(report.contains("osType=\"1\""));
|
||||||
|
assert!(report.contains("<real-time-protection>yes</real-time-protection>"));
|
||||||
|
assert_eq!(report.matches("name=\"Sentinel Agent\"").count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn preview_uses_explicit_pending_digest() {
|
fn preview_uses_explicit_pending_digest() {
|
||||||
let input = ReportInput {
|
let input = ReportInput {
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
os::unix::fs::{MetadataExt, PermissionsExt},
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::SentinelInfo;
|
||||||
|
|
||||||
|
const SENTINEL_DIR: &str = "/opt/sentinelone";
|
||||||
|
|
||||||
|
pub(super) fn detect() -> Option<SentinelInfo> {
|
||||||
|
let cli = trusted_cli()?;
|
||||||
|
|
||||||
|
let version = parse_version(&run(&cli, &["version"])?)?;
|
||||||
|
let agent_enabled = parse_enabled(&run(&cli, &["control", "status"])?, "Agent state")?;
|
||||||
|
let real_time_protection = if agent_enabled {
|
||||||
|
let policy = run(&cli, &["policy", "status"])?;
|
||||||
|
let on_write = parse_enabled(&policy, "On-Write:")?;
|
||||||
|
let on_execute = parse_enabled(&policy, "On-Execute:")?;
|
||||||
|
on_write || on_execute
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(SentinelInfo {
|
||||||
|
version,
|
||||||
|
real_time_protection,
|
||||||
|
firewall_enabled: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trusted_cli() -> Option<PathBuf> {
|
||||||
|
let agent_uid = uzers::get_user_by_name("sentinelone")?.uid();
|
||||||
|
let agent_dir = Path::new(SENTINEL_DIR);
|
||||||
|
if !trusted_dir(Path::new("/opt"), 0) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let link = fs::symlink_metadata(agent_dir).ok()?;
|
||||||
|
if link.file_type().is_symlink() && link.uid() != 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let resolved_dir = fs::canonicalize(agent_dir).ok()?;
|
||||||
|
for ancestor in resolved_dir.ancestors().skip(1) {
|
||||||
|
if !trusted_dir(ancestor, 0) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !(trusted_dir(&resolved_dir, 0) || trusted_dir(&resolved_dir, agent_uid))
|
||||||
|
|| !trusted_dir(&resolved_dir.join("bin"), 0)
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cli = resolved_dir.join("bin/sentinelctl");
|
||||||
|
let metadata = fs::symlink_metadata(&cli).ok()?;
|
||||||
|
if !metadata.is_file()
|
||||||
|
|| metadata.uid() != 0
|
||||||
|
|| metadata.permissions().mode() & 0o022 != 0
|
||||||
|
|| metadata.permissions().mode() & 0o111 == 0
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(cli)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trusted_dir(path: &Path, owner: u32) -> bool {
|
||||||
|
let Ok(metadata) = fs::symlink_metadata(path) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
metadata.is_dir() && metadata.uid() == owner && metadata.permissions().mode() & 0o022 == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(cli: &Path, args: &[&str]) -> Option<String> {
|
||||||
|
let output = Command::new(cli)
|
||||||
|
.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()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_version(output: &str) -> Option<String> {
|
||||||
|
let version = value(output, "Agent version:")?;
|
||||||
|
if version.is_empty()
|
||||||
|
|| version.len() > 64
|
||||||
|
|| !version
|
||||||
|
.chars()
|
||||||
|
.all(|ch| ch.is_ascii_alphanumeric() || matches!(ch, '.' | '-' | '_'))
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(version.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_enabled(output: &str, label: &str) -> Option<bool> {
|
||||||
|
match value(output, label)? {
|
||||||
|
"Enabled" => Some(true),
|
||||||
|
"Disabled" => Some(false),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn value<'a>(output: &'a str, label: &str) -> Option<&'a str> {
|
||||||
|
output
|
||||||
|
.lines()
|
||||||
|
.find_map(|line| line.trim().strip_prefix(label).map(str::trim))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_observed_agent_and_policy_status() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_version("Agent version: 25.2.2.14\nSentinelCTL version: 25.2.2.14\n"),
|
||||||
|
Some("25.2.2.14".into())
|
||||||
|
);
|
||||||
|
assert_eq!(parse_enabled("Agent state Enabled\n", "Agent state"), Some(true));
|
||||||
|
assert_eq!(
|
||||||
|
parse_enabled("On-Write: Enabled\nOn-Execute: Disabled\n", "On-Write:"),
|
||||||
|
Some(true)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_enabled("On-Write: Enabled\nOn-Execute: Disabled\n", "On-Execute:"),
|
||||||
|
Some(false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_unknown_or_invalid_status() {
|
||||||
|
assert_eq!(parse_version("Agent version: 25.2.2.14\"/>\n"), None);
|
||||||
|
assert_eq!(parse_enabled("Agent state Unknown\n", "Agent state"), None);
|
||||||
|
assert_eq!(parse_enabled("On-Write: Unknown\n", "On-Write:"), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -238,6 +238,15 @@
|
|||||||
{% elif host_info.os_vendor == "Linux" -%}
|
{% elif host_info.os_vendor == "Linux" -%}
|
||||||
<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="1"/>
|
||||||
|
<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 -%}
|
||||||
{% if let Some(defender) = &host_info.defender %}
|
{% if let Some(defender) = &host_info.defender %}
|
||||||
<entry>
|
<entry>
|
||||||
<ProductInfo>
|
<ProductInfo>
|
||||||
|
|||||||
Reference in new issue
Block a user