
Ansible role and Python script that detect backdoored liblzma (xz 5.6.0/5.6.1, CVE-2024-3094), back up affected libraries, upgrade packages, and re-scan hosts.
This Ansible role deploys a Python-based script that finds backdoored liblzma (xz 5.6.0 and 5.6.1, CVE-2024-3094) on a host and replaces it with the distribution's fixed package.
It is designed to be run via Ansible, but you can also execute the script manually if you wish.
Read more about the xz backdoor here:
The upstream release tarballs for xz 5.6.0 and 5.6.1 contain build-time code that modifies liblzma. sshd does not use liblzma directly, but Debian and several other distributions patch openssh for systemd notification, and libsystemd depends on liblzma. That is the path to ssh server compromise described in the oss-security report of 2024-03-29.
Exposure by distribution, as stated in the advisories above:
| Distribution | Affected | Fixed package |
|---|---|---|
| Debian | testing, unstable and experimental, 5.5.1alpha-0.1 up to and including 5.6.1-1. No stable release known to be affected | 5.6.1+really5.4.5-1 |
| Fedora | Rawhide (5.6.0, 5.6.1) and Fedora 40 (xz-libs-5.6.0-1.fc40, 5.6.0-2.fc40) | xz-5.4.6-3.fc40 (FEDORA-2024-d02c7bb266), epoch bumped |
| Red Hat Enterprise Linux | No version affected | — |
| Ubuntu | No released version affected; the package reached only noble-proposed and was removed | — |
dpkg-query (liblzma5,
xz-utils) and rpm (xz, xz-libs), whichever is presentliblzma.so.5*, resolves symlinks so each
real file is counted once, and reads the version from the file name, or
from the version string inside the library when the name carries none+really versions correctly: 5.6.1+really5.4.5-1 is the
fix, not 5.6.1sshd links liblzma, using ldd--apply--apply: backs up every affected library file, mirroring its full
path under the backup directory, upgrades the xz packages with
apt-get, dnf or yum, and scans again/usr/local, or shipped inside an application) after the
upgrade, rather than reporting the host cleanPyYAML, only for a run that reads a YAML config file (the installed
apply). The role installs it from the distribution (python3-yaml,
py3-yaml or python3-pyyaml), never from PyPI. The detection entry
needs only the standard library: its config goes in as JSON on stdin--apply and --backup-only. Detection runs as any userldd for the sshd check (part of glibc; the check is skipped without it)Everything else is the standard library. The package managers are the distribution's own.
The script is configured via a YAML file, templated automatically by the role.
Example config.yaml:
scan_paths:
- /lib
- /lib64
- /usr/lib
- /usr/lib64
- /usr/local/lib
backup_directory: /opt/backups/xz
log_file: /var/log/xz_backdoor_mitigation.log
check_packages: true
check_sshd: true
sshd_path: /usr/sbin/sshd
scan_paths: directories to search for liblzma.so.5*backup_directory: where to keep copies of affected librarieslog_file: path to a log file for operation trackingcheck_packages: query dpkg-query/rpm for package versionscheck_sshd: report whether sshd links liblzmasshd_path: the sshd binary to checkRole variables (defaults/main.yml) carry the same names with an
xz_backdoor_ prefix, plus:
xz_backdoor_apply (default true): back up and upgrade when something is
found. Set false to report onlyxz_backdoor_restart_sshd (default false): restart sshd after the upgrade
when it links liblzma. Off by default: the restart is the operator's to
schedule, and until it happens the running sshd keeps the old libraryxz_backdoor_script_dest: defaults to
/usr/local/lib/xz_backdoor_mitigation/, a directory of its own, so its
config.yaml does not overwrite another role's in /usr/local/binAdd this role to your playbook:
- name: Mitigate xz backdoor CVE-2024-3094
hosts: all
become: true
roles:
- xz_backdoor_mitigation
The role runs the script to detect, and only when something is found:
backs up the affected files, upgrades liblzma5/xz-utils (apt) or
xz/xz-libs (dnf, yum) to the latest version in the distribution's
repositories, restarts sshd if it links liblzma and xz_backdoor_restart_sshd
is true, and runs the script again.
The host fails if anything is still affected. Debian's and Fedora's fixed
packages both sort above the bad versions, so an ordinary upgrade installs
them.
To report only:
ansible-playbook site.yml -e xz_backdoor_apply=false
If you wish to run the script manually, you can do so:
Copy the script and the shared library beside it to your target machine:
files/xz_backdoor_mitigator.py
files/samp_common.py
Create your own config.yaml in the same directory.
Run it:
python3 xz_backdoor_mitigator.py # dry run, config.yaml beside the script
python3 xz_backdoor_mitigator.py --config /path/to/config.yaml
python3 xz_backdoor_mitigator.py --scan-path /srv/chroot/lib # repeatable; replaces scan_paths
sudo python3 xz_backdoor_mitigator.py --apply # back up, upgrade, re-scan
sudo python3 xz_backdoor_mitigator.py --backup-only # back up, change nothing else
scanned=N vulnerable=N backed_up=N upgraded=N failed=N sshd_links_liblzma=N undetermined=N
to stdout. Warnings naming each affected package or file go to stderr.0 nothing affected, 2 something affected remains or a
library's version could not be read (undetermined=N), 1 a backup,
upgrade or refusal failed, 130 interrupted./var/log/xz_backdoor_mitigation.log) for every package and library
examined and its versiondpkg-query -W liblzma5 or rpm -q xz-libssshd_links_liblzma=1 on a host that had 5.6.0 or 5.6.1, confirm sshd
has restarted since the upgrade
Open-source XDR and SIEM platform for threat detection, log analysis, file integrity monitoring, vulnerability assessment, and compliance management across endpoints and cloud workloads.

Open-source network IDS/IPS/NSM engine for real-time traffic inspection, intrusion detection and prevention, protocol analysis, and rule-based threat hunting.

Zeek is a powerful network analysis framework that is much different from the typical IDS you may know.