结构: Simple
Abstraction: Class
状态: Draft
被利用可能性: High
The software does not properly control the allocation and maintenance of a limited resource thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources.
Limited resources include memory, file system storage, database connection pool entries, and CPU. If an attacker can trigger the allocation of these limited resources, but the number or size of the resources is not controlled, then the attacker could cause a denial of service that consumes all available resources. This would prevent valid users from accessing the software, and it could potentially have an impact on the surrounding environment. For example, a memory exhaustion attack against an application could slow down the application as well as its host operating system.
There are at least three distinct scenarios which can commonly lead to resource exhaustion:
Resource exhaustion problems are often result due to an incorrect implementation of the following situations:
Language: {'cwe_Class': 'Language-Independent', 'cwe_Prevalence': 'Undetermined'}
范围 | 影响 | 注释 |
---|---|---|
Availability | ['DoS: Crash, Exit, or Restart', 'DoS: Resource Consumption (CPU)', 'DoS: Resource Consumption (Memory)', 'DoS: Resource Consumption (Other)'] | The most common result of resource exhaustion is denial of service. The software may slow down, crash due to unhandled errors, or lock out legitimate users. |
['Access Control', 'Other'] | ['Bypass Protection Mechanism', 'Other'] | In some cases it may be possible to force the software to "fail open" in the event of resource exhaustion. The state of the software -- and possibly the security functionality - may then be compromised. |
Automated static analysis typically has limited utility in recognizing resource exhaustion problems, except for program-independent system resources such as files, sockets, and processes. For system resources, automated static analysis may be able to detect circumstances in which resources are not released after they have expired. Automated analysis of configuration files may be able to detect settings that do not specify a maximum value.
Automated static analysis tools will not be appropriate for detecting exhaustion of custom resources, such as an intended security policy in which a bulletin board user is only allowed to make a limited number of posts per day.
策略:
Design throttling mechanisms into the system architecture. The best protection is to limit the amount of resources that an unauthorized user can cause to be expended. A strong authentication and access control model will help prevent such attacks from occurring in the first place. The login application should be protected against DoS attacks as much as possible. Limiting the database access, perhaps by caching result sets, can help minimize the resources expended. To further limit the potential for a DoS attack, consider tracking the rate of requests received from users and blocking requests that exceed a defined rate threshold.
策略:
Mitigation of resource exhaustion attacks requires that the target system either: The first of these solutions is an issue in itself though, since it may allow attackers to prevent the use of the system by a particular valid user. If the attacker impersonates the valid user, they may be able to prevent the user from accessing the server in question. The second solution is simply difficult to effectively institute -- and even when properly done, it does not provide a full solution. It simply makes the attack require more resources on the part of the attacker.
策略:
Ensure that protocols have specific limits of scale placed on them.
策略:
Ensure that all failures in resource allocation place the system into a safe posture.
The following example demonstrates the weakness.
bad Java
There are no limits to runnables. Potentially an attacker could cause resource problems very quickly.
This code allocates a socket and forks each time it receives a new connection.
bad C
The program does not track how many connections have been made, and it does not limit the number of connections. Because forking is a relatively expensive operation, an attacker would be able to cause the system to run out of CPU, processes, or memory by making a large number of connections. Alternatively, an attacker could consume all available connections, preventing others from accessing the system remotely.
In the following example a server socket connection is used to accept a request to store data on the local file system using a specified filename. The method openSocketConnection establishes a server socket to accept requests from a client. When a client establishes a connection to this service the getNextMessage method is first used to retrieve from the socket the name of the file to store the data, the openFileToWrite method will validate the filename and open a file to write to on the local file system. The getNextMessage is then used within a while loop to continuously read data from the socket and output the data to the file until there is no longer any data from the socket.
bad C
This example creates a situation where data can be dumped to a file on the local file system without any limits on the size of the file. This could potentially exhaust file or disk resources and/or limit other clients' ability to access the service.
In the following example, the processMessage method receives a two dimensional character array containing the message to be processed. The two-dimensional character array contains the length of the message in the first character array and the message body in the second character array. The getMessageLength method retrieves the integer value of the length from the first character array. After validating that the message length is greater than zero, the body character array pointer points to the start of the second character array of the two-dimensional character array and memory is allocated for the new body character array.
bad C
This example creates a situation where the length of the body character array can be very large and will consume excessive memory, exhausting system resources. This can be avoided by restricting the length of the second character array with a maximum length check
Also, consider changing the type from 'int' to 'unsigned int', so that you are always guaranteed that the number is positive. This might not be possible if the protocol specifically requires allowing negative values, or if you cannot control the return value from getMessageLength(), but it could simplify the check to ensure the input is positive, and eliminate other errors such as signed-to-unsigned conversion errors (CWE-195) that may occur elsewhere in the code.
good C
In the following example, a server object creates a server socket and accepts client connections to the socket. For every client connection to the socket a separate thread object is generated using the ClientSocketThread class that handles request made by the client through the socket.
bad Java
In this example there is no limit to the number of client connections and client threads that are created. Allowing an unlimited number of client connections and threads could potentially overwhelm the system and system resources.
The server should limit the number of client connections and the client threads that are created. This can be easily done by creating a thread pool object that limits the number of threads that are generated.
good Java
标识 | 说明 | 链接 |
---|---|---|
CVE-2009-2874 | Product allows attackers to cause a crash via a large number of connections. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2874 |
CVE-2009-1928 | Malformed request triggers uncontrolled recursion, leading to stack exhaustion. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-1928 |
CVE-2009-2858 | Chain: memory leak (CWE-404) leads to resource exhaustion. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2858 |
CVE-2009-2726 | Driver does not use a maximum width when invoking sscanf style functions, causing stack consumption. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2726 |
CVE-2009-2540 | Large integer value for a length property in an object causes a large amount of memory allocation. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2540 |
CVE-2009-2299 | Web application firewall consumes excessive memory when an HTTP request contains a large Content-Length value but no POST data. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2299 |
CVE-2009-2054 | Product allows exhaustion of file descriptors when processing a large number of TCP packets. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2054 |
CVE-2008-5180 | Communication product allows memory consumption with a large number of SIP requests, which cause many sessions to be created. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5180 |
CVE-2008-2121 | TCP implementation allows attackers to consume CPU and prevent new connections using a TCP SYN flood attack. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-2121 |
CVE-2008-2122 | Port scan triggers CPU consumption with processes that attempt to read data from closed sockets. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-2122 |
CVE-2008-1700 | Product allows attackers to cause a denial of service via a large number of directives, each of which opens a separate window. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-1700 |
CVE-2007-4103 | Product allows resource exhaustion via a large number of calls that do not complete a 3-way handshake. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-4103 |
CVE-2006-1173 | Mail server does not properly handle deeply nested multipart MIME messages, leading to stack exhaustion. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-1173 |
CVE-2007-0897 | Chain: anti-virus product encounters a malformed file but returns from a function without closing a file descriptor (CWE-775) leading to file descriptor consumption (CWE-400) and failed scans. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0897 |
Theoretical Vulnerability theory is largely about how behaviors and resources interact. "Resource exhaustion" can be regarded as either a consequence or an attack, depending on the perspective. This entry is an attempt to reflect the underlying weaknesses that enable these attacks (or consequences) to take place. Other
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
CLASP | Resource exhaustion (file descriptor, disk space, sockets, ...) | ||
OWASP Top Ten 2004 | A9 | CWE More Specific | Denial of Service |
WASC | 10 | Denial of Service | |
WASC | 41 | XML Attribute Blowup | |
The CERT Oracle Secure Coding Standard for Java (2011) | SER12-J | Avoid memory and resource leaks during serialization | |
The CERT Oracle Secure Coding Standard for Java (2011) | MSC05-J | Do not exhaust heap space | |
Software Fault Patterns | SFP13 | Unrestricted Consumption |