| 名称 |
Leveraging Time-of-Check and Time-of-Use (TOCTOU) Race Conditions |
|
|
| 摘要 |
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. |
| 前置条件 |
A resource is access/modified concurrently by multiple processes. The adversary is able to modify resource. A race condition exists while accessing a resource. |
| 执行流程 |
| 步骤 |
阶段 |
描述 |
技术手法 |
| 1 |
Explore |
The adversary explores to gauge what level of access they have. |
|
| 2 |
Experiment |
The adversary confirms access to a resource on the target host. The adversary confirms ability to modify the targeted resource. |
|
| 3 |
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. |
|
|
| 解决方案 | 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. |
| 关联弱点 |
|
CWE 编号
|
描述
|
| CWE-362 |
Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') |
| CWE-366 |
Race Condition within a Thread |
| CWE-367 |
Time-of-check Time-of-use (TOCTOU) Race Condition |
| CWE-368 |
Context Switching Race Condition |
| CWE-370 |
Missing Check for Certificate Revocation after Initial Check |
| CWE-662 |
Improper Synchronization |
| CWE-663 |
Use of a Non-reentrant Function in a Concurrent Context |
| CWE-665 |
Improper Initialization |
| CWE-691 |
Insufficient Control Flow Management |
|
| 关联 CAPEC |
|
CAPEC 编号
|
描述
|
| CAPEC-26 |
The adversary targets a race condition occurring when multiple processes access and manipulate the same resource concurrently, and the outcome of the execution depends on the particular order in which the access takes place. The adversary can leverage a race condition by "running the race", modifying the resource and modifying the normal execution flow. For instance, a race condition can occur while accessing a file: the adversary can trick the system by replacing the original file with their version and cause the system to read the malicious file. |
|