CAPEC-29 - 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. The typical example is the file access. The attacker can leverage a file access race condition by "running the race", meaning that he 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 attacker could do something such as replace the file and cause an escalation of privilege.

Severity

Likelihood

Confidentiality

Integrity

Availability

  • Attack Methods 2
  • Time and State
  • Modification of Resources
  • Purposes 1
  • Exploitation
  • Sec Principles 1
  • Least Privilege
  • Scopes 5
  • Modify memory
  • Integrity
  • Gain privileges / assume identity
  • Authorization
  • Access_Control
  • Confidentiality
  • Alter execution logic
  • Availability
  • Integrity
  • Confidentiality
  • Read application data
  • Confidentiality
  • DoS: resource consumption (CPU)
  • Availability

Medium level: This attack can get sophisticated since the attack has to occur within a short interval of time.

A resource is access/modified concurrently by multiple processes.

The attacker is able to modify resource.

A race condition exists while accessing a resource.

Vulnerability testing tool can be used to probe for race condition.

The attacker may also look for temporary file creation. The attacker may try to replace them and take advantage of a race condition.

Step 1 -

The attacker explores to gauge what level of access he has..


Step 1 -

The attacker confirms access to a resource on the target host. The attacker confirms ability to modify the targeted resource..


Step 1 -

The attacker decides to leverage the race condition by "running the race", meaning that he 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 attacker 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.