CAPECattack pattern

CAPEC-29 Leveraging Time-of-Check and Time-of-Use (TOCTOU) Race Conditions

High Official page ↗
Abstraction
Standard
Status
Draft
Likelihood of attack
High
Typical severity
High
CAPEC version
3.9

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.

Execution flow

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.

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

• [Medium] This attack can get sophisticated since the attack has to occur within a short interval of time.

Consequences

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

Related

Child of · CAPEC (1)

  • CAPEC-26 Leveraging Race Conditions attack pattern

Weakness · CWE (9)

  • CWE-362 Concurrent Execution using Shared Resource with Improper Synchronization weakness
  • CWE-366 Race Condition within a Thread weakness
  • CWE-367 Time-of-check Time-of-use (TOCTOU) Race Condition weakness
  • CWE-368 Context Switching Race Condition weakness
  • CWE-370 Missing Check for Certificate Revocation after Initial Check weakness
  • CWE-662 Improper Synchronization weakness
  • CWE-663 Use of a Non-reentrant Function in a Concurrent Context weakness
  • CWE-665 Improper Initialization weakness
  • CWE-691 Insufficient Control Flow Management weakness

Referenced by CAPEC · child of (1)

  • CAPEC-27 Leveraging Race Conditions via Symbolic Links attack pattern

Referenced by CWE · attack pattern (9)

  • CWE-362 Concurrent Execution using Shared Resource with Improper Synchronization weakness
  • CWE-366 Race Condition within a Thread weakness
  • CWE-367 Time-of-check Time-of-use (TOCTOU) Race Condition weakness
  • CWE-368 Context Switching Race Condition weakness
  • CWE-370 Missing Check for Certificate Revocation after Initial Check weakness
  • CWE-662 Improper Synchronization weakness
  • CWE-663 Use of a Non-reentrant Function in a Concurrent Context weakness
  • CWE-665 Improper Initialization weakness
  • CWE-691 Insufficient Control Flow Management weakness