Description
The product searches for critical resources using an externally-supplied search path that can point to resources that are not under the product's direct control.
This might allow attackers to execute their own programs, access unauthorized data files, or modify configuration in unexpected ways. If the product uses a search path to locate critical resources such as programs, then an attacker could modify that search path to point to a malicious program, which the targeted product would then execute. The problem extends to any type of critical resource that the product trusts. Some of the most common variants of untrusted search path are:
Potential Impact
Integrity, Confidentiality, Availability, Access Control
Gain Privileges or Assume Identity, Execute Unauthorized Code or Commands
Availability
DoS: Crash, Exit, or Restart
Confidentiality
Read Files or Directories
Demonstrative Examples
#define DIR "/restricted/directory"
char cmd[500];sprintf(cmd, "ls -l %480s", DIR);
/* Raise privileges to those needed for accessing DIR. */
RaisePrivileges(...);system(cmd);DropPrivileges(...);...The user sets the PATH to reference a directory under the attacker's control, such as "/my/dir/".
The attacker creates a malicious program called "ls", and puts that program in /my/dir
The user executes the program.
When system() is executed, the shell consults the PATH to find the ls program
The program finds the attacker's malicious program, "/my/dir/ls". It doesn't find "/bin/ls" because PATH does not contain "/bin/".
The program executes the attacker's malicious program with the raised privileges....String home = System.getProperty("APPHOME");String cmd = home + INITCMD;java.lang.Runtime.getRuntime().exec(cmd);...//assume getCurrentUser() returns a username that is guaranteed to be alphanumeric (avoiding CWE-78)
$userName = getCurrentUser();$command = 'ps aux | grep ' . $userName;system($command);...System.Runtime.getRuntime().exec("make");...Mitigations & Prevention
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.
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.
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.
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.
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 it, while execl() and execv() require a full path.
Detection Methods
- Black Box — Use monitoring tools that examine the software's process as it interacts with the operating system and the network. This technique is useful in cases when source code is unavailable, if the software was not developed by you, or if you want to verify that the build phase did not introduce any new wea
- Automated Static Analysis High — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
- Manual Analysis — Use tools and techniques that require manual (human) analysis, such as penetration testing, threat modeling, and interactive tools that allow the tester to record and modify an active session. These may be more effective than strictly automated techniques. This is especially the case with weaknesses
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-1999-1120 | Application relies on its PATH environment variable to find and execute program. |
| CVE-2008-1810 | Database application relies on its PATH environment variable to find and execute program. |
| CVE-2007-2027 | Chain: untrusted search path enabling resultant format string by loading malicious internationalization messages. |
| CVE-2008-3485 | Untrusted search path using malicious .EXE in Windows environment. |
| CVE-2008-2613 | setuid program allows compromise using path that finds and loads a malicious library. |
| CVE-2008-1319 | Server allows client to specify the search path, which can be modified to point to a program that the client has uploaded. |
Related Weaknesses
Taxonomy Mappings
- PLOVER: — Untrusted Search Path
- CLASP: — Relative path library search
- CERT C Secure Coding: ENV03-C — Sanitize the environment when invoking external programs
Frequently Asked Questions
What is CWE-426?
CWE-426 (Untrusted Search Path) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product searches for critical resources using an externally-supplied search path that can point to resources that are not under the product's direct control.
How can CWE-426 be exploited?
Attackers can exploit CWE-426 (Untrusted Search Path) to gain privileges or assume identity, execute unauthorized code or commands. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-426?
Key mitigations include: 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
What is the severity of CWE-426?
CWE-426 is classified as a Base-level weakness (Medium abstraction). It has been observed in 6 real-world CVEs.