T07 · Tool Hijacking and Spoofing
- Location
scripts/office/soffice.py:24- Finding
Predictable Temporary LD_PRELOAD Library Enables Local Code Execution
- Content
View full analysis
dict: env = os.environ.copy() env["SAL_USE_VCLPLUGIN"] = "svp" if _needs_shim(): shim = _ensure_shim() env["LD_PRELOAD"] = str(shim) return env def run_soffice(args: list[str], **kwargs) -> subprocess.CompletedProcess: env = get_soffice_env() return subprocess.run(["soffice"] + args, env=env, **kwargs) _SHIM_SO = Path(tempfile.gettempdir()) / "lo_socket_shim.so" def _needs_shim() -> bool: try: s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.close() return False except OSError: return True def _ensure_shim() -> Path: if _SHIM_SO.exists(): return _SHIM_SO src = Path(tempfile.gettempdir()) / "lo_socket_shim.c" src.write_text(_SHIM_SOURCE) subprocess.run( ["gcc", "-shared", "-fPIC", "-o", str(_SHIM_SO), str(src), "-ldl"], check=True, capture_output=True, ) src.unlink() return _SHIM_SO ``` ### Technical Analysis The shared library and its C source are created at globally predictable paths under the system temporary directory: - `/tmp/lo_socket_shim.so` - `/tmp/lo_socket_shim.c` The implementation trusts any existing `lo_socket_shim.so` without checking its ownership, permissions, file type, content, or cryptographic digest. It also does not reject symbolic links or create the files atomically. When Unix-domain socket creation fails, the existing library is assigned to `LD_PRELOAD` and a LibreOffice subprocess is launched. The operating system consequently loads and executes initialization code from that library before LibreOffice starts. This creates both a pre-creation attack and a race condition. A local attacker who can write to the shared temporary dire ...[truncated 1404 chars]- Remediation
View remediation
