用户工具

站点工具


cwe:cn:definition:494

CWE-494:下载代码缺少完整性检查

Description Summary

The product downloads source code or an executable from a remote location and executes the code without sufficiently verifying the origin and integrity of the code.

Extended Description

An attacker can execute malicious code by compromising the host server, performing DNS spoofing, or modifying the code in transit.

Likelihood of Exploit

Medium

Common Consequences

Scope Technical Impace Note
Integrity
Availability
Confidentiality
Other
Execute unauthorized code or commands
Alter execution logic
Other
Executing untrusted code could compromise the control flow of the program. The untrusted code could execute attacker-controlled commands, read or modify sensitive resources, or prevent the software from functioning correctly for legitimate users.

Detection Methods

Detection Method - 1

Manual Analysis

This weakness can be detected using 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.

Specifically, manual static analysis is typically required to find the behavior that triggers the download of code, and to determine whether integrity-checking methods are in use.

These may be more effective than strictly automated techniques. This is especially the case with weaknesses that are related to design and business rules.
2013/05/30 09:37

Detection Method - 2

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

2013/05/30 09:37

Potential Mitigations

Mitigation - 1

Implementation

Perform proper forward and reverse DNS lookups to detect DNS spoofing.

2013/05/30 13:23

Mitigation - 2

Architecture and Design Operation

Encrypt the code with a reliable encryption scheme before transmitting.

This will only be a partial solution, since it will not detect DNS spoofing and it will not prevent your code from being modified on the hosting site.

Mitigation - 3

Architecture and Design

Strategy:Libraries or Frameworks

Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.

For example, use anti-CSRF packages such as the OWASP CSRFGuard. [R.352.3]

Another example is the ESAPI Session Management control, which includes a component for CSRF. [R.352.9]

2013/05/30 09:36

Mitigation - 4

Architecture and Design Operation

Strategy:Environment Hardening

Run your code using the lowest privileges that are required to accomplish the necessary tasks [R.98.2]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.

2013/05/30 09:37

Mitigation - 5

Architecture and Design Operation

Strategy:Sandbox or Jail

Run the code in a “jail” or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software.

OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations.

This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise.

Be careful to avoid CWE-243 and other weaknesses related to jails.

2013/05/30 09:37

Demonstrative Examples

Example - 1

This example loads an external class from a local subdirectory.

URL[] classURLs= new URL[]{ 
new URL("file:subdir/") 
 
}; 
URLClassLoader loader = new URLClassLoader(classURLs); 
Class loadedClass = Class.forName("loadMe", true, loader); 

This code does not ensure that the class loaded is the intended one, for example by verifying the class's checksum. An attacker may be able to modify the class file to execute malicious code.

Example - 2

This code includes an external script to get database credentials, then authenticates a user against the database, allowing access to the application.

//assume the password is already encrypted, avoiding CWE-312 
function authenticate($username,$password){ 
include("http://external.example.com/dbInfo.php"); 
//dbInfo.php makes $dbhost, $dbuser, $dbpass, $dbname available 
mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); 
mysql_select_db($dbname); 
$query = 'Select * from users where username='.$username.' And password='.$password; 
$result = mysql_query($query); 
if(mysql_numrows($result) == 1){ 
mysql_close(); 
return true; 
 
} 
else{ 
mysql_close(); 
return false; 
 
} 
} 
 

This code does not verify that the external domain accessed is the intended one. An attacker may somehow cause the external domain name to resolve to an attack server, which would provide the information for a false database. The attacker may then steal the usernames and encrypted passwords from real user login attempts, or simply allow himself to access the application without a real user account.

This example is also vulnerable to a Man in the Middle (CWE-300) attack.

Observed Examples

Reference Description
CVE-2008-3438OS does not verify authenticity of its own updates.
CVE-2008-3324online poker client does not verify authenticity of its own updates.
CVE-2001-1125anti-virus product does not verify automatic updates for itself.
CVE-2002-0671VOIP phone downloads applications from web sites without verifying integrity.
cwe/cn/definition/494.txt · 最后更改: 2014/09/04 14:39 (外部编辑)