Katalog CWE

CWE-427 · Słabość

Uncontrolled Search Path Element

Abstrakcja
Bazowa
Status
Szkic
Dodano
19 lipca 2006
Ostatnia zmiana
30 kwietnia 2026

Podatności CVE z tą słabościąPełny wpis na cwe.mitre.org ↗

Opis

The product uses a fixed or controlled search path to find resources, but one or more locations in that path can be under the control of unintended actors.

Although this weakness can occur with any type of resource, it is frequently introduced when a product uses a directory search path to find executables or code libraries, but the path contains a directory that can be modified by an attacker, such as "/tmp" or the current working directory.

In Windows-based systems, when the LoadLibrary or LoadLibraryEx function is called with a DLL name that does not contain a fully qualified path, the function follows a search order that includes two path elements that might be uncontrolled:

- the directory from which the program has been loaded

- the current working directory

In some cases, the attack can be conducted remotely, such as when SMB or WebDAV network shares are used.

One or more locations in that path could include the Windows drive root or its subdirectories. This often exists in Linux-based code assuming the controlled nature of the root directory (/) or its subdirectories (/etc, etc), or a code that recursively accesses the parent directory. In Windows, the drive root and some of its subdirectories have weak permissions by default, which makes them uncontrolled.

In some Unix-based systems, a PATH might be created that contains an empty element, e.g. by splicing an empty variable into the PATH. This empty element can be interpreted as equivalent to the current working directory, which might be an untrusted search element.

In software package management frameworks (e.g., npm, RubyGems, or PyPi), the framework may identify dependencies on third-party libraries or other packages, then consult a repository that contains the desired package. The framework may search a public repository before a private repository. This could be exploited by attackers by placing a malicious package in the public repository that has the same name as a package from the private repository. The search path might not be directly under control of the developer relying on the framework, but this search order effectively contains an untrusted element.

Inne nazwy

DLL preloading
This term is one of several that are used to describe exploitation of untrusted search path elements in Windows systems, which received wide attention in August 2010. From a weakness perspective, the term is imprecise because it can apply to both CWE-426 and CWE-427.
Binary planting
This term is one of several that are used to describe exploitation of untrusted search path elements in Windows systems, which received wide attention in August 2010. From a weakness perspective, the term is imprecise because it can apply to both CWE-426 and CWE-427.
Insecure library loading
This term is one of several that are used to describe exploitation of untrusted search path elements in Windows systems, which received wide attention in August 2010. From a weakness perspective, the term is imprecise because it can apply to both CWE-426 and CWE-427.
Dependency confusion
As of February 2021, this term is used to describe CWE-427 in the context of managing installation of software package dependencies, in which attackers release packages on public sites where the names are the same as package names used by private repositories, and the search for the dependent package tries the public site first, downloading untrusted code. It may also be referred to as a "substitution attack."

Skutki

  • Confidentiality, Integrity, Availability

    Execute Unauthorized Code or Commands

Zapobieganie

  • Architecture and Design, Implementation · Attack Surface Reduction

    Hard-code the search path to a set of known-safe values (such as system directories), or only allow them to be specified by the administrator in a configuration file. Do not allow these settings to be modified by an external party. Be careful to avoid related weaknesses such as CWE-426 and CWE-428.

  • Implementation · Attack Surface Reduction

    When invoking other programs, specify those programs using fully-qualified pathnames. While this is an effective approach, code that uses fully-qualified pathnames might not be portable to other systems that do not use the same pathnames. The portability can be improved by locating the full-qualified paths in a centralized, easily-modifiable location within the source code, and having the code refer to these paths.

  • Implementation · Attack Surface Reduction

    Remove or restrict all environment settings before invoking other programs. This includes the PATH environment variable, LD_LIBRARY_PATH, and other settings that identify the location of code libraries, and any application-specific search paths.

  • Implementation

    Check your search path before use and remove any elements that are likely to be unsafe, such as the current working directory or a temporary files directory. Since this is a denylist approach, it might not be a complete solution.

  • Implementation

    Use other functions that require explicit paths. Making use of any of the other readily available functions that require explicit paths is a safe way to avoid this problem. For example, system() in C does not require a full path since the shell can take care of finding the program using the PATH environment variable, while execl() and execv() require a full path.

Przykłady podatności

Słabość nadrzędna

Kiedy powstaje

Dotyczy

Not Language-Specific, Not OS-Specific, Not Technology-Specific

Uwagi

Unlike untrusted search path (CWE-426), which inherently involves control over the definition of a control sphere (i.e., modification of a search path), this entry concerns a fixed control sphere in which some part of the sphere may be under attacker control (i.e., the search path cannot be modified by an attacker, but one element of the path can be under attacker control).

This weakness is not a clean fit under CWE-668 or CWE-610, which suggests that the control sphere model might need enhancement or clarification.

Źródła

  1. Double clicking on MS Office documents from Windows Explorer may execute arbitrary programs in some cases — Georgi Guninski, Bugtraq, 2000
  2. ACROS Security: Remote Binary Planting in Apple iTunes for Windows (ASPR #2010-08-18-1) — Mitja Kolsek, Bugtraq, 2010
  3. Automatic Detection of Vulnerable Dynamic Component Loadings — Taeho Kwon, Zhendong Su
  4. Dynamic-Link Library Search Order — Microsoft, 2010
  5. Dynamic-Link Library Security — Microsoft, 2010
  6. An update on the DLL-preloading remote attack vector — Microsoft, 2010
  7. Insecure Library Loading Could Allow Remote Code Execution — Microsoft, 2010
  8. Application DLL Load Hijacking — H D Moore, 2010
  9. DLL Hijacking: Facts and Fiction — Oliver Lavery, 2010
  10. Microsoft warns enterprises of new 'dependency confusion' attack technique — Catalin Cimpanu, ZDNet, 2021
  11. Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Other Companies — Alex Birsan, 2021
  12. 3 Ways to Mitigate Risk When Using Private Package Feeds — Microsoft, 2021
  13. exec package - os/exec - Go Packages — 2023
  14. Git LFS Changelog — Brian M. Carlson, 2022

Wpis z katalogu CWE 4.20.