279
char* lib=(char*)malloc(strlen(home)+strlen(INITLIB));
if (lib) {
strcpy(lib,home);
strcat(lib,INITCMD);
LoadLibrary(lib);
}
...
The code in this example allows an attacker to load an arbitrary library, from which code will be
executed with the elevated privilege of the application, by modifying a registry key to specify a
different path containing a malicious version of INITLIB. Because the program does not validate the
value read from the environment, if an attacker can control the value of APPHOME, they can fool
the application into running malicious code.
Example 3:
The following code is from a web-based administration utility that allows users access to an
interface through which they can update their profile on the system. The utility makes use of a
library named liberty.dll, which is normally found in a standard system directory.
Example Language: C (Bad)
LoadLibrary("liberty.dll");
The problem is that the program does not specify an absolute path for liberty.dll. If an attacker is
able to place a malicious library named liberty.dll higher in the search order than file the application
intends to load, then the application will load the malicious copy instead of the intended file.
Because of the nature of the application, it runs with elevated privileges, which means the contents
of the attacker's liberty.dll will now be run with elevated privileges, possibly giving the attacker
complete control of the system. The type of attack seen in this example is made possible because
of the search order used by LoadLibrary() when an absolute path is not specified. If the current
directory is searched before system directories, as was the case up until the most recent versions
of Windows, then this type of attack becomes trivial if the attacker can execute the program locally.
The search order is operating system version dependent, and is controlled on newer operating
systems by the value of the registry key: HKLM\System\CurrentControlSet\Control\Session
Manager\SafeDllSearchMode
Affected Resources
• System Process
MemberOf Relationships
This MemberOf relationships table shows additional CWE Catgeories and Views that reference this
weakness as a member. This information is often useful in understanding where a weakness fits
within the context of external information sources.
Nature Type ID Name Page
MemberOf 991 SFP Secondary Cluster: Tainted Input to Environment 888 2416
MemberOf 1403 Comprehensive Categorization: Exposed Resource 1400 2528
Notes
Maintenance
CWE-114 is a Class, but it is listed a child of CWE-73 in view 1000. This suggests some
abstraction problems that should be resolved in future versions.
Maintenance
This entry seems to have close relationships with CWE-426/CWE-427. It seems more attackoriented.
Taxonomy Mappings
CWE Version 4.14
CWE-115: Misinterpretation of Input
CWE-115: Misinterpretation of Input