CWE
Home > CWE List > COMPOSITE SLICE: CWE-426: Untrusted Search Path (1.6)  

CWE-426: Untrusted Search Path

 
Untrusted Search Path
Definition in a New Window Definition in a New Window
Compound Element ID: 426 (Compound Element Base: Composite)Status: Draft
+ Description

Description Summary

The application searches for critical resources using an externally-supplied search path that can point to resources that are not under the application's direct control.

Extended Description

This might allow attackers to execute their own programs, access unauthorized data files, or modify configuration in unexpected ways. If the application 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 application would then execute. The problem extends to any type of critical resource that the application trusts.

+ Alternate Terms
Untrusted Path
+ Time of Introduction
  • Architecture and Design
  • Implementation
+ Applicable Platforms

Languages

All

Operating Systems

All

+ Common Consequences
ScopeEffect
Authorization
Integrity

There is the potential for arbitrary code execution with privileges of the vulnerable program.

Availability

The program could be redirected to the wrong files, potentially triggering a crash or hang when the targeted file is too large or does not have the expected format.

Confidentiality

The program could send the output of unauthorized files to the attacker.

+ Likelihood of Exploit

High

+ Demonstrative Examples

Example 1

This program is intended to execute a command that lists the contents of a restricted directory, then performs other actions. Assume that it runs with setuid privileges in order to bypass the permissions check by the operating system.

(Bad Code)
C
#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(...);
...

This code may look harmless at first, since both the directory and the command are set to fixed values that the attacker can't control. The attacker can only see the contents for DIR, which is the intended program behavior. Finally, the programmer is also careful to limit the code that executes with raised privileges.

However, because the program does not modify the PATH environment variable, the following attack would work:

The user sets the PATH to reference a directory under that user's control, such as "/my/dir/".

The user 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 malicious program, "/my/dir/ls". It doesn't find "/bin/ls" because PATH does not contain "/bin/".

The program executes the malicious program with the raised privileges.

+ Observed Examples
ReferenceDescription
CVE-1999-1120Application relies on its PATH environment variable to find and execute program.
CVE-2008-1810Database application relies on its PATH environment variable to find and execute program.
CVE-2007-2027Chain: untrusted search path enabling resultant format string by loading malicious internationalization messages.
CVE-2008-3485Untrusted search path using malicious .EXE in Windows environment.
CVE-2008-2613setuid program allows compromise using path that finds and loads a malicious library.
CVE-2008-1319Server allows client to specify the search path, which can be modified to point to a program that the client has uploaded.
+ Potential Mitigations
PhaseDescription
Architecture and Design

Hard-code your search path to a set of known-safe values, or 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-427 and CWE-428.

Implementation

When invoking other programs, specify those programs using fully-qualified pathnames.

Implementation

Sanitize your environment 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.

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 it, while execl() and execv() require a full path.

Testing

Use automated static analysis tools that target this type of weakness. Many modern techniques use data flow analysis to minimize the number of false positives. This is not a perfect solution, since 100% accuracy and coverage are not feasible.

Testing

Use dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.

Testing

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 that are related to design and business rules.

Testing

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 weaknesses. Examples include debuggers that directly attach to the running process; system-call tracing utilities such as truss (Solaris) and strace (Linux); system activity monitors such as FileMon, RegMon, Process Monitor, and other Sysinternals utilities (Windows); and sniffers and protocol analyzers that monitor network traffic.

Attach the monitor to the process and look for library functions and system calls that suggest when a search path is being used. One pattern is when the program performs multiple accesses of the same file but in different directories, with repeated failures until the proper filename is found. Library calls such as getenv() or their equivalent can be checked to see if any path-related variables are being accessed.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
RequiresWeakness ClassWeakness Class216Containment Errors (Container Errors)
Research Concepts1000
RequiresCategoryCategory275Permission Issues
Research Concepts1000
ChildOfCategoryCategory417Channel and Path Errors
Development Concepts (primary)699
RequiresWeakness BaseWeakness Base471Modification of Assumed-Immutable Data (MAID)
Research Concepts1000
ChildOfCategoryCategory634Weaknesses that Affect System Processes
Resource-specific Weaknesses (primary)631
ChildOfWeakness ClassWeakness Class642External Control of Critical State Data
Research Concepts (primary)1000
ChildOfWeakness ClassWeakness Class673External Influence of Sphere Definition
Research Concepts1000
ChildOfCategoryCategory744CERT C Secure Coding Section 10 - Environment (ENV)
Weaknesses Addressed by the CERT C Secure Coding Standard (primary)734
ChildOfCategoryCategory752Risky Resource Management
Weaknesses in the 2009 CWE/SANS Top 25 Most Dangerous Programming Errors (primary)750
CanAlsoBeCompound Element: CompositeCompound Element: Composite98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Research Concepts1000
+ Research Gaps

Search path issues on Windows are under-studied and possibly under-reported.

+ Affected Resources
  • System Process
+ Functional Areas
  • Program invocation
  • Code libraries
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERUntrusted Search Path
CLASPRelative path library search
CERT C Secure CodingENV03-CSanitize the environment when invoking external programs
+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Common Consequences, Relationships, Taxonomy Mappings
2008-11-24CWE Content TeamMITREInternal
updated Relationships, Taxonomy Mappings
2009-01-12CWE Content TeamMITREInternal
updated Applicable Platforms, Common Consequences, Demonstrative Examples, Description, Observed Examples, Potential Mitigations, Relationships, Time of Introduction
2009-03-10CWE Content TeamMITREInternal
updated Demonstrative Examples, Potential Mitigations
Composite Components
Composite Components
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
 
Containment Errors (Container Errors)
Definition in a New Window Definition in a New Window
Weakness ID: 216 (Weakness Class)Status: Incomplete
+ Description

Description Summary

This tries to cover various problems in which improper data are included within a "container."
+ Time of Introduction
  • Architecture and Design
  • Implementation
+ Applicable Platforms

Languages

All

+ Potential Mitigations
PhaseDescription

Compartmentalize your system to have "safe" areas where trust boundaries can be unambiguously drawn. Do not allow sensitive data to go outside of the trust boundary and always be careful when interfacing with a compartment outside of the safe area.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory199Information Management Errors
Development Concepts (primary)699
ChildOfWeakness ClassWeakness Class485Insufficient Encapsulation
Research Concepts (primary)1000
RequiredByCompound Element: CompositeCompound Element: Composite61UNIX Symbolic Link (Symlink) Following
Research Concepts1000
RequiredByCompound Element: CompositeCompound Element: Composite98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
Research Concepts1000
ParentOfWeakness VariantWeakness Variant219Sensitive Data Under Web Root
Development Concepts (primary)699
Research Concepts1000
ParentOfWeakness VariantWeakness Variant220Sensitive Data Under FTP Root
Development Concepts (primary)699
RequiredByCompound Element: CompositeCompound Element: Composite426Untrusted Search Path
Research Concepts1000
PeerOfCompound Element: CompositeCompound Element: Composite434Unrestricted File Upload
Research Concepts1000
ParentOfWeakness VariantWeakness Variant493Critical Public Variable Without Final Modifier
Research Concepts1000
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERContainment errors (container errors)
+ Maintenance Notes

This entry is closely associated with others related to encapsulation and permissions, and might ultimately prove to be a duplicate.

+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Maintenance Notes, Relationships, Taxonomy Mappings
2009-05-27CWE Content TeamMITREInternal
updated Relationships
 
Modification of Assumed-Immutable Data (MAID)
Definition in a New Window Definition in a New Window
Weakness ID: 471 (Weakness Base)Status: Draft
+ Description

Description Summary

The software does not properly protect an assumed-immutable element from being modified by an attacker.
+ Time of Introduction
  • Implementation
+ Applicable Platforms

Languages

All

+ Demonstrative Examples

Example 1

In the code excerpt below, an array returned by a Java method is modified despite the fact that arrays are mutable.

(Bad Code)
Java
String[] colors = car.getAllPossibleColors();
colors[0] = "Red";
+ Observed Examples
ReferenceDescription
CVE-2002-1757Relies on $PHP SELF variable for authentication.
CVE-2005-1905Gain privileges by modifying assumed-immutable code addresses that are accessed by a driver.
+ Potential Mitigations
PhaseDescription

Implement proper protection for immutable data (e.g. environment variable, hidden form fields, etc.)

+ Other Notes

Factors: MAID issues can be primary to many other weaknesses, and they are a major factor in languages such as PHP.

This happens when a particular input is critical enough to the functioning of the application that it should not be modifiable at all, but it is. A common programmer assumption is that certain variables are immutable; especially consider hidden form fields in web applications. So there are many examples where the MUTABILITY property is a major factor in a vulnerability.

Common data types that are attacked are environment variables, web application parameters, and HTTP headers.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory19Data Handling
Development Concepts (primary)699
ChildOfWeakness ClassWeakness Class664Improper Control of a Resource Through its Lifetime
Research Concepts (primary)1000
RequiredByCompound Element: CompositeCompound Element: Composite291Trusting Self-reported IP Address
Research Concepts1000
CanFollowWeakness BaseWeakness Base425Direct Request ('Forced Browsing')
Research Concepts1000
RequiredByCompound Element: CompositeCompound Element: Composite426Untrusted Search Path
Research Concepts1000
ParentOfWeakness BaseWeakness Base472External Control of Assumed-Immutable Web Parameter
Development Concepts (primary)699
Research Concepts1000
ParentOfWeakness VariantWeakness Variant473PHP External Variable Modification
Development Concepts (primary)699
Research Concepts (primary)1000
CanFollowWeakness BaseWeakness Base602Client-Side Enforcement of Server-Side Security
Research Concepts1000
ParentOfWeakness VariantWeakness Variant607Public Static Final Field References Mutable Object
Development Concepts699
Research Concepts (primary)1000
PeerOfWeakness BaseWeakness Base621Variable Extraction Error
Research Concepts1000
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERModification of Assumed-Immutable Data
+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-07-01Sean EidemillerCigitalExternal
added/updated demonstrative examples
2008-07-01Eric DalciCigitalExternal
updated Potential Mitigations, Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Relationships, Other Notes, Taxonomy Mappings
2009-07-27CWE Content TeamMITREInternal
updated Other Notes
 
Permission Issues
Definition in a New Window Definition in a New Window
Category ID: 275 (Category)Status: Draft
+ Description

Description Summary

Weaknesses in this category are related to improper assignment or handling of permissions.
+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory264Permissions, Privileges, and Access Controls
Development Concepts (primary)699
ChildOfCategoryCategory632Weaknesses that Affect Files or Directories
Resource-specific Weaknesses (primary)631
ChildOfCategoryCategory723OWASP Top Ten 2004 Category A2 - Broken Access Control
Weaknesses in OWASP Top Ten (2004) (primary)711
ChildOfCategoryCategory731OWASP Top Ten 2004 Category A10 - Insecure Configuration Management
Weaknesses in OWASP Top Ten (2004)711
RequiredByCompound Element: CompositeCompound Element: Composite61UNIX Symbolic Link (Symlink) Following
Research Concepts1000
ParentOfWeakness VariantWeakness Variant276Incorrect Default Permissions
Development Concepts (primary)699
ParentOfWeakness VariantWeakness Variant277Insecure Inherited Permissions
Development Concepts (primary)699
ParentOfWeakness VariantWeakness Variant278Insecure Preserved Inherited Permissions
Development Concepts (primary)699
ParentOfWeakness VariantWeakness Variant279Incorrect Execution-Assigned Permissions
Development Concepts (primary)699
ParentOfWeakness BaseWeakness Base280Improper Handling of Insufficient Permissions or Privileges
Development Concepts (primary)699
ParentOfWeakness BaseWeakness Base281Improper Preservation of Permissions
Development Concepts (primary)699
RequiredByCompound Element: CompositeCompound Element: Composite426Untrusted Search Path
Research Concepts1000
ParentOfWeakness BaseWeakness Base618Exposed Unsafe ActiveX Method
Development Concepts (primary)699
ParentOfCompound Element: CompositeCompound Element: Composite689Permission Race Condition During Resource Copy
Development Concepts (primary)699
ParentOfWeakness ClassWeakness Class732Incorrect Permission Assignment for Critical Resource
Development Concepts (primary)699
+ Affected Resources
  • File/Directory
+ Functional Areas
  • File processing, non-specific.
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
PLOVERPermission errors
OWASP Top Ten 2004A2CWE More SpecificBroken Access Control
OWASP Top Ten 2004A10CWE More SpecificInsecure Configuration Management
+ Content History
Submissions
Submission DateSubmitterOrganizationSource
PLOVERExternally Mined
Modifications
Modification DateModifierOrganizationSource
2008-09-08CWE Content TeamMITREInternal
updated Relationships, Taxonomy Mappings
2009-01-12CWE Content TeamMITREInternal
updated Relationships
Page Last Updated: October 29, 2009