Jump to content

Symlink race: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
Yobot (talk | contribs)
m Example: WP:CHECKWIKI error fixes + general fixes using AWB (7896)
Line 9: Line 9:
In this naive example, the [[Unix]] program <tt>foo</tt> is <tt>[[setuid]]</tt>. Its function is to retrieve information for the [[account (computing)|account]]s specified by the user. For "efficiency", it sorts the requested accounts into a temporary file (<tt>/tmp/foo</tt> naturally) before making the queries.
In this naive example, the [[Unix]] program <tt>foo</tt> is <tt>[[setuid]]</tt>. Its function is to retrieve information for the [[account (computing)|account]]s specified by the user. For "efficiency", it sorts the requested accounts into a temporary file (<tt>/tmp/foo</tt> naturally) before making the queries.


The directory <tt>/tmp</tt> is world-writable. Malicious user Mallory creates a symbolic link to the file <tt>/root/.rhosts</tt> named <tt>/tmp/foo</tt>. Then, he invokes <tt>foo</tt> with <tt><i>user</i></tt> as the requested account. The program creates the (temporary) file <tt>/tmp/foo</tt> (really creating <tt>/root/.rhosts</tt>) and puts information about the requested account (e.g. <tt><i>user password</i></tt>) in it. It removes the temporary file (merely removing the symbolic link).
The directory <tt>/tmp</tt> is world-writable. Malicious user Mallory creates a symbolic link to the file <tt>/root/.rhosts</tt> named <tt>/tmp/foo</tt>. Then, he invokes <tt>foo</tt> with <tt>''user''</tt> as the requested account. The program creates the (temporary) file <tt>/tmp/foo</tt> (really creating <tt>/root/.rhosts</tt>) and puts information about the requested account (e.g. <tt>''user password''</tt>) in it. It removes the temporary file (merely removing the symbolic link).


Now the <tt>/root/.rhosts</tt> contains password information, which (if it even happens to be in the proper format) is the incantation necessary to allow anyone to use <tt>[[rlogin]]</tt> to log into the computer as the [[superuser]].
Now the <tt>/root/.rhosts</tt> contains password information, which (if it even happens to be in the proper format) is the incantation necessary to allow anyone to use <tt>[[rlogin]]</tt> to log into the computer as the [[superuser]].

Revision as of 19:02, 4 January 2012

A symlink race is a kind of software security vulnerability that results from a program creating files in an insecure manner. A malicious user can create a symbolic link to a file not otherwise accessible to him or her. When the privileged program creates a file of the same name as the symbolic link, it actually creates the linked-to file instead, possibly inserting content desired by the malicious user (see example below), or even provided by the malicious user (as input to the program).

It is called a "race" because in its typical manifestation, the program checks to see if a file by that name already exists, then creates the file. An attacker must create the link in the interval between the check and when the file is created.

Example

In this naive example, the Unix program foo is setuid. Its function is to retrieve information for the accounts specified by the user. For "efficiency", it sorts the requested accounts into a temporary file (/tmp/foo naturally) before making the queries.

The directory /tmp is world-writable. Malicious user Mallory creates a symbolic link to the file /root/.rhosts named /tmp/foo. Then, he invokes foo with user as the requested account. The program creates the (temporary) file /tmp/foo (really creating /root/.rhosts) and puts information about the requested account (e.g. user password) in it. It removes the temporary file (merely removing the symbolic link).

Now the /root/.rhosts contains password information, which (if it even happens to be in the proper format) is the incantation necessary to allow anyone to use rlogin to log into the computer as the superuser.

Workaround

The C standard library function mkstemp can be used to safely create temporary files. For shell scripts, the system utility mktemp does the same thing.