Execution Flow
1) Explore
[Verify that target host's platform supports symbolic links.] This attack pattern is only applicable on platforms that support symbolic links.
Technique
- Research target platform to determine whether it supports symbolic links.
- Create a symbolic link and ensure that it works as expected on the given platform.
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.
Technique
- Use kernel tracing utility such as ktrace to monitor application behavior.
- Use debugging utility such as File Monitor to monitor the application's filesystem I/O calls
- Watch temporary directories to see when temporary files are created, modified and deleted.
- Analyze source code for open-source systems like Linux, Apache, etc.
3) Experiment
[Verify ability to write to filesystem] The attacker verifies ability to write to the target host's file system.
Technique
- Create a file that does not exist in the target directory (e.g. "touch temp.txt" in UNIX-like systems)
- On platforms that differentiate between file creation and file modification, if the target file that the application writes to already exists, attempt to modify it.
- Verify permissions on target directory
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.
Technique
- Create an infinite loop containing commands such as "rm -f tempfile.dat; ln -s /etc/shadow tempfile.dat". Wait for an instance where the following steps occur in the given order: (1) Application ensures that tempfile.dat exists and that the user has access to it, (2) "rm -f tempfile.dat; ln -s /etc/shadow tempfile.dat", and (3) Application opens tempfile.dat for writing, and inadvertently opens /etc/shadow for writing instead.
- Use other techniques with debugging tools to replace the file between the time the application checks the file and the time the application opens it.
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.
Skills Required
This attack is sophisticated because the attacker has to overcome a few challenges such as creating symlinks on the target host during a precise timing, inserting malicious data in the temporary file and have knowledge about the temporary files created (file name and function which creates them).
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-ID |
Weakness Name |
CWE-367 |
Time-of-check Time-of-use (TOCTOU) Race Condition The product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. This can cause the product to perform invalid actions when the resource is in an unexpected state. |
CWE-61 |
UNIX Symbolic Link (Symlink) Following The product, when opening a file or directory, does not sufficiently account for when the file is a symbolic link that resolves to a target outside of the intended control sphere. This could allow an attacker to cause the product to operate on unauthorized files. |
CWE-662 |
Improper Synchronization The product utilizes multiple threads or processes to allow temporary access to a shared resource that can only be exclusive to one process at a time, but it does not properly synchronize these actions, which might cause simultaneous accesses of this resource by multiple threads or processes. |
CWE-689 |
Permission Race Condition During Resource Copy The product, while copying or cloning a resource, does not set the resource's permissions or access control until the copy is complete, leaving the resource exposed to other spheres while the copy is taking place. |
CWE-667 |
Improper Locking The product does not properly acquire or release a lock on a resource, leading to unexpected resource state changes and behaviors. |
References
REF-115
Wikipedia
http://en.wikipedia.org/wiki/Symlink_race REF-116
mkstemp
http://www.opengroup.org/onlinepubs/009695399/functions/mkstemp.html
Submission
Name |
Organization |
Date |
Date Release |
CAPEC Content Team |
The MITRE Corporation |
2014-06-23 +00:00 |
Modifications
Name |
Organization |
Date |
Comment |
CAPEC Content Team |
The MITRE Corporation |
2017-01-09 +00:00 |
Updated Related_Attack_Patterns |
CAPEC Content Team |
The MITRE Corporation |
2018-07-31 +00:00 |
Updated Attack_Phases, Examples-Instances |
CAPEC Content Team |
The MITRE Corporation |
2019-09-30 +00:00 |
Updated Related_Attack_Patterns |
CAPEC Content Team |
The MITRE Corporation |
2020-07-30 +00:00 |
Updated Description, Example_Instances |