Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Adversaries may execute their own malicious payloads by hijacking environment variables the dynamic linker uses to load shared libraries.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-23 | ✗→✓ | ▲ Improved | -50% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 43% | 0% |
| case-04 | ✗→✓ | ▲ Improved | -28% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 46% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 62% | 0% |
> Sub-technique of: T1574
Adversaries may execute their own malicious payloads by hijacking environment variables the dynamic linker uses to load shared libraries. During the execution preparation phase of a program, the dynamic linker loads specified absolute paths of shared libraries from various environment variables and files, such as <code>LD_PRELOAD</code> on Linux or <code>DYLD_INSERT_LIBRARIES</code> on macOS. Libraries specified in environment variables are loaded first, taking precedence over system libraries with the same function name. Each platform's linker uses an extensive list of environment variables at different points in execution. These variables are often used by developers to debug binaries without needing to recompile, deconflict mapped symbols, and implement custom functions in the original library.
Hijacking dynamic linker variables may grant access to the victim process's memory, system/network resources, and possibly elevated privileges. On Linux, adversaries may set <code>LD_PRELOAD</code> to point to malicious libraries that match the name of legitimate libraries which are requested by a victim program, causing the operating system to load the adversary's malicious code upon execution of the victim program. For example, adversaries have used LD_PRELOAD to inject a malicious library into every descendant process of the sshd daemon, resulting in execution under a legitimate process. When the executing sub-process calls the execve function, for example, the malicious library’s execve function is executed rather than the system function execve contained in the system library on disk. This allows adversaries to Hide Artifacts from detection, as hooking system functions such as execve and readdir enables malware to scrub its own artifacts from the results of commands such as ls, ldd, iptables, and dmesg.
Hijacking dynamic linker variables may grant access to the victim process's memory, system/network resources, and possibly elevated privileges.
Platforms: Linux, macOS
The following tests are from Atomic Red Team and provide actionable ways to test this technique:
This test adds a shared library to the ld.so.preload list to execute and intercept API calls. This technique was used by threat actor Rocke during the exploitation of Linux web servers. This requires the glibc package.
Upon successful execution, bash will echo ../bin/T1574.006.so to /etc/ld.so.preload.
Supported Platforms: linux Elevation Required: Yes
bashsudo sh -c 'echo #{path_to_shared_library} > /etc/ld.so.preload'
Dependencies:
This test injects a shared object library via the LD_PRELOAD environment variable to execute. This technique was used by threat actor Rocke during the exploitation of Linux web servers. This requires the glibc package.
Upon successful execution, bash will utilize LD_PRELOAD to load the shared object library /etc/ld.so.preload. Output will be via stdout.
Supported Platforms: linux
bashLD_PRELOAD=#{path_to_shared_library} ls
Dependencies:
injects a dylib that opens calculator via env variable
Supported Platforms: macos
bashDYLD_INSERT_LIBRARIES=#{dylib_file} #{file_to_inject}
Dependencies:
If Atomic Red Team tests are not applicable, manually verify the technique by:
When System Integrity Protection (SIP) is enabled in macOS, the aforementioned environment variables are ignored when executing protected binaries. Third-party applications can also leverage Apple’s Hardened Runtime, ensuring these environment variables are subject to imposed restrictions. Admins can add restrictions to applications by setting the setuid and/or setgid bits, use entitlements, or have a \_\_RESTRICT segment in the Mach-O binary.
Adversaries may use new payloads to execute this technique. Identify and block potentially malicious software executed through hijacking by using application control solutions also capable of blocking libraries loaded by legitimate software.
| Finding | Severity | Impact | | --------------------------------------------- | -------- | ----------- | | Dynamic Linker Hijacking technique applicable | High | Persistence |
| CWE ID | Title | | ------- | ----------------------------- | | CWE-276 | Incorrect Default Permissions |
Other measured skills in the registry, with their headline benchmark lift.