In this blog post, we'll discuss the recent hot topic over a week: the Backdoor XZ attack.
In Unix-like operating systems, "XZ Utils" is a notable open-source tool utilized for compressing and decompressing files using the LZMA (Lempel–Ziv–Markov chain algorithm) compression algorithm. It offers high compression ratios and fast decompression speeds, and serves as a popular choice in Linux distributions.
There are two main components of XZ Utils include
XZ: A command-line tool for compressing and decompressing files, similar to gzip.
liblzma: A software library featuring an API similar to zlib, used for compression and decompression operations in applications.
Vulnerability Details
Vulnerability Background
How does the backdoors work?
A backdoor typically operates by exploiting vulnerabilities within a system's security infrastructure to enable unauthorized access. Once established, it allows attackers to bypass standard authentication methods, granting them remote control over the system. This control can be utilized for executing commands, exfiltrating sensitive data, deploying malware, or conducting other malicious actions without the legitimate users' awareness. Backdoors are often concealed or obfuscated to evade detection by security measures.
Attack Sequence
This attack involves multiple components within the backdoor. Release tarballs from upstream and GitHub contain different code, a common practice in C projects for user convenience. Notably, the version of build-to-host.m4 differs significantly between the release tarballs and the upstream GitHub repository.
The Git repositories, there are two crafted files in the tests/ folder. Here's the commit Path:
These files are referenced by a script invoked by build-to-host.m4, which modifies the build process using the test data.
In the above mentioned 2nd line of script tr "\t \-_" " \t_\-", which represents the following substitution in bytes streamed from the tests/files/bad-3-corrupt_lzma2.xz file:
Eventually, the malicious code hooks the Procedure Linkage Table (PLT), targeting the "RSA_public_decrypt@....plt" function to redirect it to its own code.
The Procedure Linkage Table (PLT) is a data structure found in executable files on Unix-like systems, especially in shared libraries. It contains function addresses, enabling dynamic linking at runtime. When a program invokes a function from a shared library, the PLT redirects the call to the correct function address, facilitating dynamic linking without prior knowledge of memory addresses.
IFUNC, a feature within glibc enabling indirect function calls, is leveraged to redirect OpenSSH's authentication routines at runtime, constituting a form of runtime hooking. Although typically utilized for legitimate purposes, IFUNC is exploited in this context for malicious activities. Furthermore, the release tarballs issued by upstream differ from those generated automatically on GitHub. These modified tarballs incorporate a malicious build-to-host.m4 version, executing a script during the build process.
The exploit requires several runtime conditions
The TERM environment variable must be unset, indicating that SSH client-server communication hasn't begun, which aligns with the exploit’s targeted stage.
The process executing the malicious code must have a binary path of /usr/sbin/sshd, ensuring the activation of sshd which uses the libzlma library.
LD_DEBUG and LD_PROFILE environment variables must be unset.
The exploit relies on the LANG environment variable being set, as it aligns with the behavior of the SSH daemon (sshd) which sets LANG.
The exploit employs an anti-debugging technique by detecting debugging tools like rr and gdb. If these tools are found, the exploit refrains from execution.
Impact of Vulnerability on SSH Daemon Service
When authenticating with the SSH service, the user exchanges RSA keys with the server. The malicious code is triggered during the verification process in the server-side code:
Then, the backdoor initiates a call back into libcrypto, likely to execute typical authentication processes:
It appears that the same function hooked during the liblzma build process is involved. The malicious code seems to function as a backdoor, enabling attackers to bypass authentication and execute Remote Code Execution (RCE).
Affected Distributions
Conclusion:
The critical backdoor vulnerability found in XZ Utils poses a serious threat, especially for SSH-dependent systems. Exploitation could result in unauthorized access and data compromise. To mitigate risks, prompt patching is essential, along with proactive security measures and vigilant monitoring. By staying informed and taking proactive steps, organizations can effectively safeguard their systems and data.
Happy Hunting !!!