CWE

Common Weakness Enumeration

A Community-Developed Dictionary of Software Weakness Types

Common Weakness Scoring System
Common Weakness Risk Analysis Framework
Home > CWE List > CWE- Individual Dictionary Definition (2.9)  

Presentation Filter:

CWE-427: Uncontrolled Search Path Element

 
Uncontrolled Search Path Element
Weakness ID: 427 (Weakness Base)Status: Draft
+ Description

Description Summary

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.

Extended Description

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.

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.

+ Alternate Terms
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.

+ Time of Introduction
  • Implementation
+ Applicable Platforms

Languages

Language-independent

Operating Systems

OS-independent

+ Common Consequences
ScopeEffect
Confidentiality
Integrity
Availability

Technical Impact: Execute unauthorized code or commands

+ Demonstrative Examples

Example 1

The following code is from a web application that allows users access to an interface through which they can update their password on the system. In this environment, user passwords can be managed using the Network Information System (NIS), which is commonly used on UNIX systems. When performing NIS updates, part of the process for updating passwords is to run a make command in the /var/yp directory. Performing NIS updates requires extra privileges.

(Bad Code)
Example Language: Java 
...
System.Runtime.getRuntime().exec("make");
...

The problem here is that the program does not specify an absolute path for make and does not clean its environment prior to executing the call to Runtime.exec(). If an attacker can modify the $PATH variable to point to a malicious binary called make and cause the program to be executed in their environment, then the malicious binary will be loaded instead of the one intended. Because of the nature of the application, it runs with the privileges necessary to perform system operations, which means the attacker's make will now be run with these privileges, possibly giving the attacker complete control of the system.

+ Observed Examples
ReferenceDescription
"DLL hijacking" issue in document editor.
"DLL hijacking" issue in encryption software.
"DLL hijacking" issue in library used by multiple media players.
"DLL hijacking" issue in illustration program.
"DLL hijacking" issue in address book.
"DLL hijacking" issue in network monitoring software.
"DLL hijacking" issue in web browser.
"DLL hijacking" issue in music player/organizer.
Product uses the current working directory to find and execute a program, which allows local users to gain privileges by creating a symlink that points to a malicious version of the program.
Product trusts the PATH environmental variable to find and execute a program, which allows local users to obtain root access by modifying the PATH to point to a malicous version of that program.
Software uses a search path that includes the current working directory (.), which allows local users to gain privileges via malicious programs.
Admin software trusts the user-supplied -uv.install command line option to find and execute the uv.install program, which allows local users to gain privileges by providing a pathname that is under control of the user.
When a document is opened, the directory of that document is first used to locate DLLs , which could allow an attacker to execute arbitrary commands by inserting malicious DLLs into the same directory as the document.
Database trusts the PATH environment variable to find and execute programs, which allows local users to modify the PATH to point to malicious programs.
Database uses an environment variable to find and execute a program, which allows local users to execute arbitrary programs by changing the environment variable.
Server uses relative paths to find system files that will run in-process, which allows local users to gain privileges via a malicious file.
Product allows local users to execute arbitrary code by setting an environment variable to reference a malicious program.
Product includes the current directory in root's PATH variable.
Error during packaging causes product to include a hard-coded, non-standard directory in search path.
Product searches current working directory for configuration file.
Product searches current working directory for configuration file.
Product executable other program from current working directory.
Untrusted path.
Modification of trusted environment variable leads to untrusted path vulnerability.
Product searches /tmp for modules before other paths.
+ Potential Mitigations

Phases: Architecture and Design; Implementation

Strategy: Identify and Reduce Attack Surface

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.

Phase: Implementation

Strategy: Identify and Reduce Attack Surface

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.

Phase: Implementation

Strategy: Identify and Reduce Attack Surface

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.

Phase: 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 blacklist approach, it might not be a complete solution.

Phase: 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.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory417Channel and Path Errors
Development Concepts (primary)699
Weaknesses for Simplified Mapping of Published Vulnerabilities (primary)1003
ChildOfWeakness ClassWeakness Class668Exposure of Resource to Wrong Sphere
Research Concepts (primary)1000
ChildOfCategoryCategory991SFP Secondary Cluster: Tainted Input to Environment
Software Fault Pattern (SFP) Clusters (primary)888
PeerOfCompound Element: CompositeCompound Element: Composite426Untrusted Search Path
Research Concepts1000
+ Relationship Notes

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).

+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERUncontrolled Search Path Element
+ References
Georgi Guninski. "Double clicking on MS Office documents from Windows Explorer may execute arbitrary programs in some cases". Bugtraq. 2000-09-18.
Mitja Kolsek. "ACROS Security: Remote Binary Planting in Apple iTunes for Windows (ASPR #2010-08-18-1)". Bugtraq. 2010-08-18.
Taeho Kwon and Zhendong Su. "Automatic Detection of Vulnerable Dynamic Component Loadings". <http://www.cs.ucdavis.edu/research/tech-reports/2010/CSE-2010-2.pdf >.
"Dynamic-Link Library Search Order". Microsoft. 2010-09-02. <http://msdn.microsoft.com/en-us/library/ms682586%28v=VS.85%29.aspx>.
"Dynamic-Link Library Security". Microsoft. 2010-09-02. <http://msdn.microsoft.com/en-us/library/ff919712%28VS.85%29.aspx>.
"An update on the DLL-preloading remote attack vector". Microsoft. 2010-08-31. <http://blogs.technet.com/b/srd/archive/2010/08/23/an-update-on-the-dll-preloading-remote-attack-vector.aspx>.
"Insecure Library Loading Could Allow Remote Code Execution". Microsoft. 2010-08-23. <http://www.microsoft.com/technet/security/advisory/2269637.mspx>.
HD Moore. "Application DLL Load Hijacking". 2010-08-23. <http://blog.rapid7.com/?p=5325>.
Oliver Lavery. "DLL Hijacking: Facts and Fiction". 2010-08-26. <http://threatpost.com/en_us/blogs/dll-hijacking-facts-and-fiction-082610>.
+ Maintenance Notes

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.

+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Potential_Mitigations, Time_of_Introduction
2008-09-08CWE Content TeamMITREInternal
updated Relationships, Observed_Example, Other_Notes, Taxonomy_Mappings
2009-07-27CWE Content TeamMITREInternal
updated Description, Maintenance_Notes, Observed_Examples, Other_Notes, Potential_Mitigations, Relationships
2010-09-27CWE Content TeamMITREInternal
updated Alternate_Terms, Applicable_Platforms, Description, Maintenance_Notes, Observed_Examples, References, Relationship_Notes, Relationships
2011-03-29CWE Content TeamMITREInternal
updated Potential_Mitigations
2011-06-01CWE Content TeamMITREInternal
updated Common_Consequences
2012-05-11CWE Content TeamMITREInternal
updated Observed_Examples, Related_Attack_Patterns, Relationships
2014-02-18CWE Content TeamMITREInternal
updated Demonstrative_Examples, Observed_Examples, Potential_Mitigations
2014-07-30CWE Content TeamMITREInternal
updated Relationships
2015-12-07CWE Content TeamMITREInternal
updated Relationships
Page Last Updated: December 08, 2015