CAPEC Details
Name Symlink Attack
Likelyhood of attack Typical severity
Low High
Summary An attacker positions a symbolic link in such a manner that the targeted user or application accesses the link's endpoint, assuming that it is accessing a file with the link's name. The endpoint file may be either output or input. If the file is output, the result is that the endpoint is modified, instead of a file at the intended location. Modifications to the endpoint file may include appending, overwriting, corrupting, changing permissions, or other modifications. In some variants of this attack the attacker may be able to control the change to a file while in other cases they cannot. The former is especially damaging since the attacker may be able to grant themselves increased privileges or insert false information, but the latter can also be damaging as it can expose sensitive information or corrupt or destroy vital system or application files. Alternatively, the endpoint file may serve as input to the targeted application. This can be used to feed malformed input into the target or to cause the target to process different information, possibly allowing the attacker to control the actions of the target or to cause the target to expose information to the attacker. Moreover, the actions taken on the endpoint file are undertaken with the permissions of the targeted user or application, which may exceed the permissions that the attacker would normally have.
Prerequisites The targeted application must perform the desired activities on a file without checking whether the file is a symbolic link or not. The attacker must be able to predict the name of the file the target application is modifying and be able to create a new symbolic link where that file would appear.
Execution Flow
Step Phase Description Techniques
1 Explore [Identify Target] Attacker identifies the target application by determining whether there is sufficient check before writing data to a file and creating symlinks to files in different directories.
  • The attacker writes to files in different directories to check whether the application has sufficient checking before file operations.
  • The attacker creates symlinks to files in different directories.
2 Experiment [Try to create symlinks to different files] The attacker then uses a variety of techniques, such as monitoring or guessing to create symlinks to the files accessed by the target application in the directories which are identified in the explore phase.
  • The attacker monitors the file operations performed by the target application using a tool like dtrace or FileMon. And the attacker can delay the operations by using "sleep(2)" and "usleep()" to prepare the appropriate conditions for the attack, or make the application perform expansive tasks (large files parsing, etc.) depending on the purpose of the application.
  • The attacker may need a little guesswork on the filenames on which the target application would operate.
  • The attacker tries to create symlinks to the various filenames.
3 Exploit [Target application operates on created symlinks to sensitive files] The attacker is able to create symlinks to sensitive files while the target application is operating on the file.
  • Create the symlink to the sensitive file such as configuration files, etc.
Solutions Design: Check for the existence of files to be created, if in existence verify they are neither symlinks nor hard links before opening them. Implementation: Use randomly generated file names for temporary files. Give the files restrictive permissions.
Related Weaknesses
CWE ID Description
CWE-59 Improper Link Resolution Before File Access ('Link Following')
Related CAPECS
CAPEC ID Description
CAPEC-159 An adversary exploits a weakness in the way an application searches for external libraries to manipulate the execution flow to point to an adversary supplied library or code base. This pattern of attack allows the adversary to compromise the application or server via the execution of unauthorized code. An application typically makes calls to functions that are a part of libraries external to the application. These libraries may be part of the operating system or they may be third party libraries. If an adversary can redirect an application's attempts to access these libraries to other libraries that the adversary supplies, the adversary will be able to force the targeted application to execute arbitrary code. This is especially dangerous if the targeted application has enhanced privileges. Access can be redirected through a number of techniques, including the use of symbolic links, search path modification, and relative path manipulation.
Taxonomy: ATTACK
Entry ID Entry Name
1547.009 Boot or Logon Autostart Execution:Shortcut Modification