CAPEC-29: Leveraging Time-of-Check and Time-of-Use (TOCTOU) Race Conditions |
Description This attack targets a race condition occurring between the time of check (state) for a resource and the time of use of a resource. A typical example is file access. The adversary can leverage a file access race condition by "running the race", meaning that they would modify the resource between the first time the target program accesses the file and the time the target program uses the file. During that period of time, the adversary could replace or modify the file, causing the application to behave unexpectedly. Likelihood Of Attack Typical Severity Execution Flow Explore The adversary explores to gauge what level of access they have.
Experiment The adversary confirms access to a resource on the target host. The adversary confirms ability to modify the targeted resource.
Exploit The adversary decides to leverage the race condition by "running the race", meaning that they would modify the resource between the first time the target program accesses the file and the time the target program uses the file. During that period of time, the adversary can replace the resource and cause an escalation of privilege.
Prerequisites
| A resource is access/modified concurrently by multiple processes. |
| The adversary is able to modify resource. |
| A race condition exists while accessing a resource. |
Skills Required
[Level: Medium] This attack can get sophisticated since the attack has to occur within a short interval of time. |
Consequences This table specifies different individual consequences associated with the attack pattern. The Scope identifies the security property that is violated, while the Impact describes the negative technical impact that arises if an adversary succeeds in their attack. The Likelihood provides information about how likely the specific consequence is expected to be seen relative to the other consequences in the list. For example, there may be high likelihood that a pattern will be used to achieve a certain impact, but a low likelihood that it will be exploited to achieve a different impact.| Scope | Impact | Likelihood |
|---|
Integrity | Modify Data | | Confidentiality Access Control Authorization | Gain Privileges | | Confidentiality Integrity Availability | Alter Execution Logic | | Confidentiality | Read Data | | Availability | Resource Consumption | |
Mitigations
| Use safe libraries to access resources such as files. |
| Be aware that improper use of access function calls such as chown(), tempfile(), chmod(), etc. can cause a race condition. |
| Use synchronization to control the flow of execution. |
| Use static analysis tools to find race conditions. |
| Pay attention to concurrency problems related to the access of resources. |
Example Instances
| The Net Direct client for Linux before 6.0.5 in Nortel Application Switch 2424, VPN 3050 and 3070, and SSL VPN Module 1000 extracts and executes files with insecure permissions, which allows local users to exploit a race condition to replace a world-writable file in /tmp/NetClient and cause another user to execute arbitrary code when attempting to execute this client, as demonstrated by replacing /tmp/NetClient/client. See also: CVE-2007-1057 |
The following code illustrates a file that is accessed multiple times by name in a publicly accessible directory. A race condition exists between the accesses where an adversary can replace the file referenced by the name. include <sys/types.h> include <fcntl.h> include <unistd.h> define FILE "/tmp/myfile" define UID 100 void test(char *str) { int fd; fd = creat(FILE, 0644); if(fd == -1) return; chown(FILE, UID, -1); /* BAD */ close(fd); } int main(int argc, char **argv) { char *userstr; if(argc > 1) { userstr = argv[1]; test(userstr); } return 0; } [REF-107] |
References
[REF-131] J. Viega and
G. McGraw. "Building Secure Software". Addison-Wesley. 2002.
|
|
Content History | Submissions |
|---|
| Submission Date | Submitter | Organization |
|---|
| 2014-06-23 (Version 2.6) | CAPEC Content Team | The MITRE Corporation | | | Modifications |
|---|
| Modification Date | Modifier | Organization |
|---|
| 2017-01-09 (Version 2.9) | CAPEC Content Team | The MITRE Corporation | | Updated Related_Attack_Patterns | | 2017-08-04 (Version 2.11) | CAPEC Content Team | The MITRE Corporation | | Updated Attack_Phases, Attack_Prerequisites, Description Summary, Examples-Instances | | 2018-07-31 (Version 2.12) | CAPEC Content Team | The MITRE Corporation | | Updated References | | 2019-09-30 (Version 3.2) | CAPEC Content Team | The MITRE Corporation | | Updated @Abstraction | | 2020-07-30 (Version 3.3) | CAPEC Content Team | The MITRE Corporation | | Updated Example_Instances, Execution_Flow, Related_Attack_Patterns | | 2022-09-29 (Version 3.8) | CAPEC Content Team | The MITRE Corporation | | Updated Example_Instances |
More information is available — Please select a different filter.
|