CAPEC-27 Metadata
Likelihood of Attack
Medium
Typical Severity
High
Overview
Summary
This attack leverages the use of symbolic links (Symlinks) in order to write to sensitive files. An attacker can create a Symlink link to a target file not otherwise accessible to them. When the privileged program tries to create a temporary file with the same name as the Symlink link, it will actually write to the target file pointed to by the attackers' Symlink link. If the attacker can insert malicious content in the temporary file they will be writing to the sensitive file by using the Symlink. The race occurs because the system checks if the temporary file exists, then creates the file. The attacker would typically create the Symlink during the interval between the check and the creation of the temporary file.
Prerequisites
The attacker is able to create Symlink links on the target host. Tainted data from the attacker is used and copied to temporary files. The target host does insecure temporary file creation.
Execution Flow
Step | Phase | Description | Techniques |
---|---|---|---|
1 | Explore | [Verify that target host's platform supports symbolic links.] This attack pattern is only applicable on platforms that support symbolic links. |
|
2 | Explore | [Examine application's file I/O behavior] Analyze the application's file I/O behavior to determine where it stores files, as well as the operations it performs to read/write files. |
|
3 | Experiment | [Verify ability to write to filesystem] The attacker verifies ability to write to the target host's file system. |
|
4 | Exploit | [Replace file with a symlink to a sensitive system file.] Between the time that the application checks to see if a file exists (or if the user has access to it) and the time the application actually opens the file, the attacker replaces the file with a symlink to a sensitive system file. |
|
Potential Solutions / Mitigations
Use safe libraries when creating temporary files. For instance the standard library function mkstemp can be used to safely create temporary files. For shell scripts, the system utility mktemp does the same thing. Access to the directories should be restricted as to prevent attackers from manipulating the files. Denying access to a file can prevent an attacker from replacing that file with a link to a sensitive file. Follow the principle of least privilege when assigning access rights to files. Ensure good compartmentalization in the system to provide protected areas that can be trusted.
Related Weaknesses (CWE)
Related CAPECs
CAPEC ID | Description |
---|---|
CAPEC-29 | 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. |
Stay Ahead of Attack Patterns
Understanding CAPEC patterns helps security professionals anticipate and thwart potential attacks. Leverage these insights to enhance threat modeling, strengthen your software development lifecycle, and train your security teams effectively.