用户工具

站点工具


cwe:cn:definition:807

CWE-807:在安全决策中依赖未经信任的输入

Description Summary

The application uses a protection mechanism that relies on the existence or values of an input, but the input can be modified by an untrusted actor in a way that bypasses the protection mechanism.

Extended Description

Developers may assume that inputs such as cookies, environment variables, and hidden form fields cannot be modified. However, an attacker could change these inputs using customized clients or other attacks. This change might not be detected. When security decisions such as authentication and authorization are made based on the values of these inputs, attackers can bypass the security of the software.

Without sufficient encryption, integrity checking, or other mechanism, any input that originates from an outsider cannot be trusted.

Likelihood of Exploit

Medium to High

Common Consequences

Scope Technical Impace Note
Confidentiality
Access_Control
Availability
Other
Bypass protection mechanism
Gain privileges / assume identity
Varies by context
Attackers can bypass the security decision to access whatever is being protected. The consequences will depend on the associated functionality, but they can range from granting additional privileges to untrusted users to bypassing important security checks. Ultimately, this weakness may lead to exposure or modification of sensitive data, system crash, or execution of arbitrary code.

Detection Methods

Detection Method - 1

Manual Static Analysis

Since this weakness does not typically appear frequently within a single software package, manual white box techniques may be able to provide sufficient code coverage and reduction of false positives if all potentially-vulnerable operations can be assessed within limited time constraints.

The effectiveness and speed of manual analysis will be reduced if the there is not a centralized security mechanism, and the security logic is widely distributed throughout the software.
2013/05/30 09:37

Detection Method - 2

Automated Static Analysis - Binary / Bytecode

According to SOAR, the following detection techniques may be useful:

Detection Method - 3

Manual Static Analysis - Binary / Bytecode

According to SOAR, the following detection techniques may be useful:

Detection Method - 4

=== Dynamic Analysis with automated results interpretation === According to SOAR, the following detection techniques may be useful:

Detection Method - 5

Dynamic Analysis with manual results interpretation

According to SOAR, the following detection techniques may be useful:

Detection Method - 6

Manual Static Analysis - Source Code

According to SOAR, the following detection techniques may be useful:

Detection Method - 7

Automated Static Analysis - Source Code

According to SOAR, the following detection techniques may be useful:

Detection Method - 8

Architecture / Design Review

According to SOAR, the following detection techniques may be useful:

Potential Mitigations

Mitigation - 1

Architecture and Design

Strategy:Identify and Reduce Attack Surface

Store state information and sensitive data on the server side only.

Ensure that the system definitively and unambiguously keeps track of its own state and user state and has rules defined for legitimate state transitions. Do not allow any application user to affect state directly in any way other than through legitimate actions leading to state transitions.

If information must be stored on the client, do not do so without encryption and integrity checking, or otherwise having a mechanism on the server side to catch tampering. Use a message authentication code (MAC) algorithm, such as Hash Message Authentication Code (HMAC) [R.807.2]. Apply this against the state or sensitive data that you has to be exposed, which can guarantee the integrity of the data - i.e., that the data has not been modified. Ensure that a strong hash function is used (CWE-328).

2013/05/30 09:37

Mitigation - 2

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.

With a stateless protocol such as HTTP, use a framework that maintains the state for you.

Examples include ASP.NET View State [R.807.3] and the OWASP ESAPI Session Management feature [R.807.4].

Be careful of language features that provide state support, since these might be provided as a convenience to the programmer and may not be considering security.

2013/05/30 09:37

Mitigation - 3

Architecture and Design

For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.

2013/05/30 09:37

Mitigation - 4

Operation Implementation

Strategy:Environment Hardening

When using PHP, configure the application so that it does not use register_globals. During implementation, develop the application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues.

Often, programmers do not protect direct access to files intended only to be included by core programs. These include files may assume that critical variables have already been initialized by the calling program. As a result, the use of register_globals combined with the ability to directly access the include file may allow attackers to conduct file inclusion attacks. This remains an extremely common pattern as of 2009.

2013/05/30 09:37

Mitigation - 5

Architecture and Design Implementation

Strategy:Identify and Reduce Attack Surface

Understand all the potential areas where untrusted inputs can enter your software: parameters or arguments, cookies, anything read from the network, environment variables, reverse DNS lookups, query results, request headers, URL components, e-mail, files, filenames, databases, and any external systems that provide data to the application. Remember that such inputs may be obtained indirectly through API calls.

Many file inclusion problems occur because the programmer assumed that certain inputs could not be modified, especially for cookies and URL components.

2013/05/30 09:37

Demonstrative Examples

Example - 1

The following code excerpt reads a value from a browser cookie to determine the role of the user.

Cookie[] cookies = request.getCookies(); 
for (int i =0; i< cookies.length; i++) { 
Cookie c = cookies[i]; 
if (c.getName().equals("role")) { 
userRole = c.getValue(); 
 
} 
 
} 
2013/05/30 13:23

Example - 2

The following code could be for a medical records application. It performs authentication by checking if a cookie has been set.

$auth = $_COOKIES['authenticated']; 
if (! $auth) { 
if (AuthenticateUser($_POST['user'], $_POST['password']) == "success") { 
// save the cookie to send out in future responses 
setcookie("authenticated", "1", time()+60*60*2); 
 
} 
else { 
ShowLoginScreen(); 
die("\n"); 
 
} 
 
} 
DisplayMedicalHistory($_POST['patient_ID']); 

The programmer expects that the AuthenticateUser() check will always be applied, and the “authenticated” cookie will only be set when authentication succeeds. The programmer even diligently specifies a 2-hour expiration for the cookie.

However, the attacker can set the “authenticated” cookie to a non-zero value such as 1. As a result, the $auth variable is 1, and the AuthenticateUser() check is not even performed. The attacker has bypassed the authentication.

2013/05/30 13:23

Example - 3

In the following example, an authentication flag is read from a browser cookie, thus allowing for external control of user state data.

Cookie[] cookies = request.getCookies(); 
for (int i =0; i< cookies.length; i++) { 
Cookie c = cookies[i]; 
if (c.getName().equals("authenticated") && Boolean.TRUE.equals(c.getValue())) { 
authenticated = true; 
 
} 
 
} 
2013/05/30 13:23

Example - 4

The following code samples use a DNS lookup in order to decide whether or not an inbound request is from a trusted host. If an attacker can poison the DNS cache, they can gain trusted status.

struct hostent *hp;struct in_addr myaddr; 
char* tHost = "trustme.example.com"; 
myaddr.s_addr=inet_addr(ip_addr_string); 
 
hp = gethostbyaddr((char *) &myaddr, sizeof(struct in_addr), AF_INET); 
if (hp && !strncmp(hp->h_name, tHost, sizeof(tHost))) { 
trusted = true; 
 
} else { 
trusted = false; 
 
} 
String ip = request.getRemoteAddr(); 
InetAddress addr = InetAddress.getByName(ip); 
if (addr.getCanonicalHostName().endsWith("trustme.com")) { 
trusted = true; 
 
} 
IPAddress hostIPAddress = IPAddress.Parse(RemoteIpAddress); 
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress); 
if (hostInfo.HostName.EndsWith("trustme.com")) { 
trusted = true; 
 
} 

IP addresses are more reliable than DNS names, but they can also be spoofed. Attackers can easily forge the source IP address of the packets they send, but response packets will return to the forged IP address. To see the response packets, the attacker has to sniff the traffic between the victim machine and the forged IP address. In order to accomplish the required sniffing, attackers typically attempt to locate themselves on the same subnet as the victim machine. Attackers may be able to circumvent this requirement by using source routing, but source routing is disabled across much of the Internet today. In summary, IP address verification can be a useful part of an authentication scheme, but it should not be the single factor required for authentication.

2013/05/30 13:23

Observed Examples

Reference Description
CVE-2009-1549Attacker can bypass authentication by setting a cookie to a specific value.
CVE-2009-1619Attacker can bypass authentication and gain admin privileges by setting an “admin” cookie to 1.
CVE-2009-0864Content management system allows admin privileges by setting a “login” cookie to “OK.”
CVE-2008-5784e-dating application allows admin privileges by setting the admin cookie to 1.
CVE-2008-6291Web-based email list manager allows attackers to gain admin privileges by setting a login cookie to “admin.”
cwe/cn/definition/807.txt · 最后更改: 2014/09/04 14:54 (外部编辑)