[RESOLVED] Package sharing update definition Microsoft Defender Zero Touch

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

January 30, 2025 - 4:41 PM

Good morning,

A package already exists on the Wapt store, but I modified it so that the update is completely automatic thanks to the audit function (eliminating the need for the update_package function). The goal is to deploy the update as quickly as possible and without human intervention.
The code is probably messy; this is my first time manipulating dates and times :lol:

Prerequisites:

Each WAPT agent will look for the mpam-fe.exe binary on its WAPT repo to avoid saturating the internet link.
On the WAPT server, you must therefore add, for example, the following line to crontab:
00 20 * * * wget --user-agent="Mozilla" -O /var/www/waptwua/mpam-fe.exe 'https://go.microsoft.com/fwlink/?LinkID=121721&arch=x64'
A brief summary of what the package audit does:

It checks by comparing the date of the binary available on the repository and the binary cached in c:\windows\temp\mpam-fe.xe to see if there is a new version of the binary available.
If the binary does not yet exist in "c:\windows\temp\mpam-fe.exe", it fakes the date in order to force the download.
If the date is different, it downloads the new binary and then checks the signature of the binary (it must be from 'Microsoft Corporation').
Then he installs the new binary.

All that's left is to configure the audit frequency ;)

setup.py:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
import requests
import os
from datetime import datetime, timedelta
import time
import waptlicences

r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()

"""
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls


def install():
    pass

def audit():
    # Declaring local variables
    osversion = get_os_version()
    repo_url = [r for r in WAPT.repositories if r.name == 'wapt'][0].repo_url
    repo_headers = WAPT.waptserver.head('waptwua/mpam-fe.exe')
    repo_last_modified = repo_headers.get('last-modified')
    repo_last_modified_pattern = "%a, %d %b %Y %H:%M:%S %Z"
    repo_last_modified_date = datetime.strptime(repo_last_modified, repo_last_modified_pattern)
    repo_last_modified_date_loc = repo_last_modified_date + timedelta(hours=1)
    if isfile(r'c:\windows\temp\mpam-fe.exe') :
        file_modTimesinceEpoc = os.path.getmtime(r'c:\windows\temp\mpam-fe.exe')
    else :
        # fake modification time if no bin
        file_modTimesinceEpoc =  int(float('1002387810.4883926'))
    file_modificationTime_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(file_modTimesinceEpoc))
    file_modificationTime_date = datetime.strptime(file_modificationTime_str, '%Y-%m-%d %H:%M:%S')

    # Downloading new bin
    if repo_last_modified_date_loc != file_modificationTime_date :
        with WAPT.waptserver.get_requests_session() as session:
            wget("%swua/mpam-fe.exe" % repo_url, r'c:\windows\temp\mpam-fe.exe', requests_session=session)

    # Check signature bin
    expected_issuer = 'Microsoft Corporation'
    sign_name = waptlicences.check_msi_signature(r'c:\windows\temp\mpam-fe.exe')[0]
    if sign_name != expected_issuer:
        error('Bad issuer %s != %s ' % (sign_name,expected_issuer))

    # Installing bin
    versionfile = get_file_properties(r'c:\windows\temp\mpam-fe.exe')['ProductVersion']

    if get_windows_defender_version() < versionfile:
        run(r'c:\windows\temp\mpam-fe.exe /s')
    if get_windows_defender_version() < versionfile:
        error('AntivirusSignatureVersion not in %s' % versionfile)
    print(r'OK: Definition Version is %s' % versionfile)
    return "OK"
                
def get_windows_defender_version():
    for i in get_antivirus_info():
        if not i["name"] == "Windows Defender":
            continue
        return Version(i['AntivirusSignatureVersion'])
    return Version('0')
Thanks to Simon for his help in putting together this package.
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
dcardon
WAPT Expert
Messages: 1929
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

February 7, 2025 - 12:28

Hi Olivier,

thanks for sharing :-) . For your information, we're currently working on integrating the SOAP MS-WUSP communication protocol between the Windows Update agent and a WSUS server into the WAPT agent and server. Microsoft has provided a reference implementation [1] in .NET that implements this protocol. It takes into account the updating of Windows Defender definitions. So there might be some interesting new features coming soon. :-)

I'm marking this topic as RESOLVED for now.

Best regards,

Denis

[1] https://github.com/microsoft/update-server-server-sync/
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
Locked