Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

SV.DLLPRELOAD.NONABSOLUTE.EXE

Potential DLL-preload process-injection vector

When an application loads an external library, it's important for the code to use a fully qualified path. If an insufficiently qualified path is specified, a malicious attacker can gain control of the search path and use it as a vector for remotely executing arbitrary code. This type of threat is known as binary planting or DLL-preloading attacks.

The DLLPRELOAD.NONABSOLUTE.EXE checker flags code instances in which relative pathnames are used in system file-manipulation function calls CreateProcess, WinExec, LoadModule, _exec*, _wexec*, _spawn*, _wspawn*, and ShellExecute to .exe files.

Fore more information on DLL-preloading attacks, see Microsoft's Security Advisory 2269637.

Vulnerability and risk

An attacker can use relative pathnames to read, modify, or overwrite critical files, bypassing security mechanisms. For example, a malicious user can add a new account at the end of a password file to avoid authentication, or read the password file to break into an account on the system. In a worst-case scenario, users can be locked out of the system, software can be prevented from operating, or unauthorized commands or code can be executed.

Failure to use a fully qualified path can allow your application to load an executable file other than that intended. An exploiter can use this vulnerability to inject malicious executable code and run it on the user's machine.

Mitigation and prevention

To avoid relative path problems:

  • Make sure that external libraries are loaded securely, using fully qualified pathnames whenever possible
  • Include built-in path canonicalization functions such as realpath() or canonicalize_file_name() in the code
  • Store library, include, and utility files in separate directories where they can't be easily accessed
  • Make sure error messages don't disclose path information

For more suggestions for mitigation and prevention of DLL-preloading attacks, see Microsoft's Dynamic-Link Library Security article.

Vulnerable code example

1  BOOL createChild() {
2      return CreateProcess("child.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL); 
3  }

Klocwork produces an issue report at line 2 indicating that calling CreateProcess without a fully qualified path may allow the application to load an .exe file from an arbitrary location. Any call to a file-manipulation function that uses a relative path name can produce an unpredictable and possibly dangerous response. Special elements in a path like the parent directory shortcut (..) and filename separators (/) can make the path a vector for remotely executing arbitrary code.

Fixed code example

1  BOOL createChild() {
2      return CreateProcess("C:\\MyApp\\child.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL);  
3  }

In the fixed code example, a fully qualified path has been provided, eliminating the possibility of malicious access.