Skip to content

Commit

Permalink
fix: Add Microsoft Defender AV support on Windows Server
Browse files Browse the repository at this point in the history
Closes #857
  • Loading branch information
g-bougard committed Feb 14, 2025
1 parent 2330ad6 commit 4895a6b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ inventory:
ip address or network.
* Add "itemtype" configuration support to handle requirement for servers supporting genericity
like GLPI 11+. Remark: This option is shared with remoteinventory task.
* fix #857: Support Microsoft Defender AV detection on Windows Server

remoteinventory:
* Add "itemtype" configuration support to handle requirement for servers supporting genericity
Expand Down
77 changes: 47 additions & 30 deletions lib/GLPI/Agent/Task/Inventory/Win32/AntiVirus.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,8 @@ sub doInventory {

# Also support WMI access to Windows Defender
if (!$antivirus->{VERSION} && $antivirus->{NAME} =~ /Windows Defender/i) {
my $defender;
# Don't try to access Windows Defender class if not enabled as
# WMI call can fail after a too long time while another antivirus
# is installed
if ($antivirus->{ENABLED}) {
($defender) = getWMIObjects(
moniker => 'winmgmts://./root/microsoft/windows/defender',
class => "MSFT_MpComputerStatus",
properties => [ qw/AMProductVersion AntivirusEnabled
AntivirusSignatureVersion/ ]
);
}
if ($defender) {
$antivirus->{VERSION} = $defender->{AMProductVersion}
if $defender->{AMProductVersion};
$antivirus->{ENABLED} = 1
if defined($defender->{AntivirusEnabled}) && $defender->{AntivirusEnabled} =~ /^1|true$/;
$antivirus->{BASE_VERSION} = $defender->{AntivirusSignatureVersion}
if $defender->{AntivirusSignatureVersion};
}
&_setWinDefenderInfos($antivirus, $logger, "");
$found_enabled++ if $antivirus->{ENABLED};
$antivirus->{COMPANY} = "Microsoft Corporation";
# Finally try registry for base version
if (!$antivirus->{BASE_VERSION}) {
$defender = _getSoftwareRegistryKeys(
'Microsoft/Windows Defender/Signature Updates',
[ 'AVSignatureVersion' ]
);
$antivirus->{BASE_VERSION} = $defender->{'/AVSignatureVersion'}
if $defender && $defender->{'/AVSignatureVersion'};
}
}

# Finally try to get version from software installation in registry
Expand Down Expand Up @@ -159,6 +130,12 @@ sub doInventory {
my $services = getServices(logger => $logger);

foreach my $support ({
# Windows Defender support, path key is not set as it depends on installed version string
name => "Windows Defender",
service => "WinDefend",
command => "MsMpEng.exe",
func => \&_setWinDefenderInfos,
}, {
# Cortex XDR support
name => "Cortex XDR",
service => "cyserver",
Expand Down Expand Up @@ -250,6 +227,46 @@ sub _getAntivirusUninstall {
);
}

sub _setWinDefenderInfos {
my ($antivirus, $logger, $command) = @_;

my $defender;
# Don't try to access Windows Defender class if not enabled as
# WMI call can fail after a too long time while another antivirus
# is installed
if ($antivirus->{ENABLED}) {
($defender) = getWMIObjects(
moniker => 'winmgmts://./root/microsoft/windows/defender',
class => "MSFT_MpComputerStatus",
properties => [ qw/AMProductVersion AntivirusEnabled
AntivirusSignatureVersion/ ]
);
}
if ($defender) {
$antivirus->{VERSION} = $defender->{AMProductVersion}
if $defender->{AMProductVersion};
$antivirus->{ENABLED} = 1
if defined($defender->{AntivirusEnabled}) && $defender->{AntivirusEnabled} =~ /^1|true$/i;
$antivirus->{BASE_VERSION} = $defender->{AntivirusSignatureVersion}
if $defender->{AntivirusSignatureVersion};
}
unless ($antivirus->{VERSION} || empty($command)) {
my ($version) = $command =~ m{/([0-9.]+)[-/]};
$antivirus->{VERSION} = $version
unless empty($version);
}
$antivirus->{COMPANY} = "Microsoft Corporation";
# Finally try registry for base version
if (!$antivirus->{BASE_VERSION}) {
$defender = _getSoftwareRegistryKeys(
'Microsoft/Windows Defender/Signature Updates',
[ 'AVSignatureVersion' ]
);
$antivirus->{BASE_VERSION} = $defender->{'/AVSignatureVersion'}
if $defender && $defender->{'/AVSignatureVersion'};
}
}

sub _setMcAfeeInfos {
my ($antivirus, $logger, $command) = @_;

Expand Down

0 comments on commit 4895a6b

Please sign in to comment.