Home > CAPEC List > CAPEC-132: Symlink Attack (Version 2.6)  

CAPEC-132: Symlink Attack

 
Symlink Attack
Definition in a New Window Definition in a New Window
Attack Pattern ID: 132
Abstraction: Detailed
Status: Draft
Completeness: Complete
Presentation Filter:
+ 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.

+ Attack Execution Flow
Explore
  1. 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.

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    The attacker writes to files in different directories to check whether the application has sufficient checking before file operations.

    env-Local
    2

    The attacker creates symlinks to files in different directories.

    env-Local

    Indicators

    IDTypeIndicator DescriptionEnvironments
    1Positive

    The application does not check whether the file is a symlink or not before writing data to it.

    env-Local
    2Positive

    The system allows creating symlinks.

    env-Local
    3Inconclusive

    Some directories do not allow creating symlink.

    env-Local
    4Negative

    The application checks whether the file is a symlink or not before writing data to it.

    env-Local

    Outcomes

    IDTypeOutcome Description
    1Success
    The application does not check whether the file is a symlink or not before writing data to it and the attacker can create symlinks to the files.

    Security Controls

    IDTypeSecurity Control Description
    1Preventative
    Perform checks on files to be handled: a) check for existence of file; b) check for symlinks; c) check for hard links.
Experiment
  1. 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.

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    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.

    env-Local
    2

    The attacker may need a little guesswork on the filenames on which the target application would operate.

    env-Local
    3

    The attacker tries to create symlinks to the various filenames.

    env-Local

    Indicators

    IDTypeIndicator DescriptionEnvironments
    1Positive

    The attacker can create symlinks to the files in the target directories.

    env-Local

    Outcomes

    IDTypeOutcome Description
    1Success
    The attacker creates symlink to the files while the target application is operating on the file.

    Security Controls

    IDTypeSecurity Control Description
    1Preventative
    Perform checks on files to be handled for existence, symlinks or hard links.
    2Preventative
    Give the sensitive files restricted permissions.
Exploit
  1. 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.

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    Create the symlink to the sensitive file such as configuration files, etc.

    env-Local

    Outcomes

    IDTypeOutcome Description
    1Success
    The attacker creates symlinks to sensitive files and the target application operates on them leading to a breach in the security assumptions of the target application.

    Security Controls

    IDTypeSecurity Control Description
    1Preventative
    Perform checks on files to be handled for existence, symlinks or hard links.
    2Preventative
    Give sensitive files restricted permissions.
    3Preventative
    Generate semi-random filenames and add the "O_CREAT|O_EXCL" flags to any "open()" calls made.
+ Attack 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.

+ Typical Severity

High

+ Typical Likelihood of Exploit

Likelihood: Low

+ Methods of Attack
  • Spoofing
  • Analysis
  • Time and State
+ Examples-Instances

Description

The attacker creates a symlink with the "same" name as the file which the application is intending to write to. The application will write to the file- "causing the data to be written where the symlink is pointing". An attack like this can be demonstrated as follows:

root# vulprog myFile
{...program does some processing...]
attacker# ln –s /etc/nologin myFile
[...program writes to 'myFile', which points to /etc/nologin...]

In the above example, the root user ran a program with poorly written file handling routines, providing the filename "myFile" to vulnprog for the relevant data to be written to. However, the attacker happened to be looking over the shoulder of "root" at the time, and created a link from myFile to /etc/nologin. The attack would make no user be able to login.

+ Attacker Skills or Knowledge Required

Skill or Knowledge Level: Low

To create symlinks

Skill or Knowledge Level: High

To identify the files and create the symlinks during the file operation time window

+ Resources Required

No special resources are required beyond the ability to create the necessary symbolic link.

+ Solutions and Mitigations

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.

+ Attack Motivation-Consequences
ScopeTechnical ImpactNote
Confidentiality
"Varies by context"
Information Leakage
Integrity
Modify files or directories
Confidentiality
Read files or directories
Integrity
Modify application data
Confidentiality
Read memory
Integrity
Modify memory
Confidentiality
Read application data
Authorization
Execute unauthorized code or commands
Run Arbitrary Code
Accountability
Authentication
Authorization
Non-Repudiation
Gain privileges / assume identity
Access_Control
Authorization
Bypass protection mechanism
Availability
DoS: crash / exit / restart
DoS: instability
+ Purposes
  • Exploitation
  • Penetration
+ CIA Impact
Confidentiality Impact: HighIntegrity Impact: HighAvailability Impact: High
+ Technical Context
Architectural Paradigms
Client-Server
Frameworks
All
Platforms
All
+ References
[R.132.1] Shaun Colley. "Crafting Symlinks for Fun and Profit". <http://www.infosecwriters.com/texts.php?op=display&id=159>.
+ Content History
Submissions
SubmitterOrganizationDateSource
CAPEC Content TeamThe MITRE Corporation2014-06-23Internal_CAPEC_Team

More information is available — Please select a different filter.
Page Last Updated: December 04, 2014