diff --git a/apps/gpclient/src/hip.rs b/apps/gpclient/src/hip.rs index 08b9f8f..3c9ddd2 100644 --- a/apps/gpclient/src/hip.rs +++ b/apps/gpclient/src/hip.rs @@ -40,6 +40,19 @@ struct RealTimeProtection { value: bool, } +#[derive(Debug, Clone)] +struct UfwInfo { + version: String, + is_enabled: bool, +} + +#[derive(Debug, Clone)] +struct ClamAvInfo { + version: String, + definitions_version: Option, + real_time_protection: bool, +} + /// Host information for HIP reporting struct HostInfo { /// Common for all OSes, e.g., "Apple", "Microsoft", "Linux" @@ -55,6 +68,8 @@ struct HostInfo { domain: String, network_interfaces: Vec, defender: Option, + clamav: Option, + ufw: Option, } impl HostInfo { @@ -286,6 +301,8 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> { domain: self.domain_for_profile(), network_interfaces: interfaces, defender: self.defender_for_profile(), + clamav: self.clamav_for_profile(), + ufw: self.ufw_for_profile(), } } @@ -339,6 +356,108 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> { ClientOs::Mac | ClientOs::Windows => None, } } + + fn clamav_for_profile(&self) -> Option { + match self.profile.client_os() { + ClientOs::Linux => detect_clamav(), + ClientOs::Mac | ClientOs::Windows => None, + } + } + + fn ufw_for_profile(&self) -> Option { + match self.profile.client_os() { + ClientOs::Linux => detect_ufw(), + ClientOs::Mac | ClientOs::Windows => None, + } + } +} + +fn detect_clamav() -> Option { + let version_out = Command::new("clamscan").arg("--version").output().ok()?; + if !version_out.status.success() { + debug!("clamscan not found or failed"); + return None; + } + + let version_str = String::from_utf8(version_out.stdout).ok()?; + let (version, definitions_version) = parse_clamav_version(&version_str)?; + + let rtp_out = Command::new("systemctl") + .args(["is-active", "clamav-onaccess.service"]) + .output() + .ok()?; + + let real_time_protection = rtp_out.status.success(); + + Some(ClamAvInfo { + version, + definitions_version, + real_time_protection, + }) +} + +fn detect_ufw() -> Option { + let version_out = Command::new("ufw").arg("version").output().ok()?; + if !version_out.status.success() { + debug!("ufw not found or failed"); + return None; + } + + let version_str = String::from_utf8(version_out.stdout).ok()?; + let version = parse_ufw_version(&version_str)?; + + let status_out = Command::new("ufw").arg("status").env("LC_ALL", "C").output().ok()?; + if !status_out.status.success() { + log::warn!("ufw status failed"); + return None; + } + + let status_str = String::from_utf8(status_out.stdout).ok()?; + let is_enabled = parse_ufw_status(&status_str)?; + + Some(UfwInfo { version, is_enabled }) +} + +fn parse_clamav_version(output: &str) -> Option<(String, Option)> { + let mut output_parts = output.split_whitespace(); + if output_parts.next()? != "ClamAV" { + return None; + } + + let mut version_parts = output_parts.next()?.split('/'); + let version = version_parts.next()?; + if version.is_empty() { + return None; + } + + let definitions_version = version_parts + .next() + .filter(|definitions_version| !definitions_version.is_empty()) + .map(str::to_string); + + Some((version.to_string(), definitions_version)) +} + +fn parse_ufw_version(output: &str) -> Option { + let mut output_parts = output.split_whitespace(); + if output_parts.next()? != "ufw" { + return None; + } + + output_parts.next().map(str::to_string) +} + +fn parse_ufw_status(output: &str) -> Option { + let status = output + .lines() + .find_map(|line| line.trim().strip_prefix("Status:"))? + .trim(); + + match status { + "active" => Some(true), + "inactive" => Some(false), + _ => None, + } } fn detect_microsoft_defender_blocking() -> Option { @@ -577,4 +696,30 @@ mod tests { fn rejects_invalid_microsoft_defender_health_json() { assert!(parse_defender_info("{}").is_none()); } + + #[test] + fn parses_clamav_version() { + let version = + parse_clamav_version("ClamAV 1.4.3/27562/Sun Aug 31 10:23:42 2026").expect("ClamAV version should parse"); + + assert_eq!(version, ("1.4.3".to_string(), Some("27562".to_string()))); + } + + #[test] + fn parses_clamav_version_without_definitions_version() { + assert_eq!(parse_clamav_version("ClamAV 1.4.3"), Some(("1.4.3".to_string(), None))); + } + + #[test] + fn parses_ufw_version() { + assert_eq!(parse_ufw_version("ufw 0.36.2\n"), Some("0.36.2".to_string())); + assert_eq!(parse_ufw_version("unexpected output\n"), None); + } + + #[test] + fn parses_ufw_status() { + assert_eq!(parse_ufw_status("Status: active\n"), Some(true)); + assert_eq!(parse_ufw_status("Status: inactive\n"), Some(false)); + assert_eq!(parse_ufw_status("Status: unknown\n"), None); + } } diff --git a/apps/gpclient/templates/hip_report.xml b/apps/gpclient/templates/hip_report.xml index d4501e9..82a0051 100644 --- a/apps/gpclient/templates/hip_report.xml +++ b/apps/gpclient/templates/hip_report.xml @@ -218,8 +218,8 @@ {% elif host_info.os_vendor == "Linux" -%} - {% if let Some(defender) = &host_info.defender -%} + {% if let Some(defender) = &host_info.defender %} @@ -228,10 +228,17 @@ n/a - - {% else -%} - {% endif -%} + {% if let Some(clamav) = &host_info.clamav %} + + + + {% if clamav.real_time_protection %}yes{% else %}no{% endif %} + n/a + + + {% endif -%} + @@ -254,6 +261,14 @@ + {% if let Some(ufw) = &host_info.ufw %} + + + + {% if ufw.is_enabled %}yes{% else %}no{% endif %} + + + {% endif -%}