Leveraging Time-of-Check and Time-of-Use (TOCTOU) Race Conditions |
Attack Pattern ID: 29 (Standard Attack Pattern Completeness: Complete) | Typical Severity: High | Status: Draft |
Summary
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.
Attack Execution Flow
The attacker explores to gauge what level of access he has.
The attacker confirms access to a resource on the target host. The attacker confirms ability to modify the targeted resource.
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.
A resource is access/modified concurrently by multiple processes.
The attacker is able to modify resource.
A race condition exists while accessing a resource.
Description
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.
Related Vulnerabilities
CVE-2007-1057
Description
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 attacker can replace the file referenced by the name.
Skill or Knowledge Level: Medium
This attack can get sophisticated since the attack has to occur within a short interval of time.
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.
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.
- Data Modification
- Privilege Escalation
- Run Arbitrary Code
- Information Leakage
- Denial of Service
CWE-ID | Weakness Name | Weakness Relationship Type |
---|---|---|
367 | Time-of-check Time-of-use (TOCTOU) Race Condition | Targeted |
368 | Context Switching Race Condition | Secondary |
366 | Race Condition within a Thread | Secondary |
370 | Missing Check for Certificate Revocation after Initial Check | Secondary |
362 | Race Condition | Secondary |
662 | Insufficient Synchronization | Targeted |
691 | Insufficient Control Flow Management | Targeted |
663 | Use of a Non-reentrant Function in an Unsynchronized Context | Targeted |
665 | Improper Initialization | Secondary |
Nature | Type | ID | Name | Description | View(s) this relationship pertains to |
---|---|---|---|---|---|
ChildOf | Attack Pattern | 26 | Leveraging Race Conditions | Mechanism of Attack1000 | |
ChildOf | Category | 172 | Time and State Attacks | Mechanism of Attack (primary)1000 | |
ParentOf | Attack Pattern | 27 | Leveraging Race Conditions via Symbolic Links | Mechanism of Attack1000 |
J. Viega and G. McGraw. Building Secure Software. Addison-Wesley, 2002.
CWE - Input Validation
Submissions | ||||
---|---|---|---|---|
Submitter | Organization | Date | Comments | |
Eric Dalci | Cigital, Inc | 2007-01-25 |
Modifications | |||||
---|---|---|---|---|---|
Modifier | Organization | Date | Comments | ||
Sean Barnum | Cigital, Inc | 2007-03-07 | Review and revise | ||
Richard Struse | VOXEM, Inc | 2007-03-26 | Review and feedback leading to changes in Name, Attack Flow, Attack Prerequisites and Related Attack Patterns | ||
Sean Barnum | Cigital, Inc | 2007-04-13 | Modified pattern content according to review and feedback |