|
|
Subscribe / Log in / New account

Security

Exploiting symlinks and tmpfiles

By Jake Edge
September 19, 2007

"Insecure tmpfile creation" and "arbitrary file overwrite using symlinks" (and other similar names) are commonly seen vulnerabilities listed in the LWN daily security update. The problems are related in many ways and can be very serious, with damage ranging from corrupted files to full takeover of a vulnerable system. By and large, they are easy to avoid, so it is disheartening to see them crop up time and time again.

Typically, these kinds of attacks exploit race conditions, where correct functioning depends, inappropriately, on the order of operations between two or more processes in the system. The classic example is a program that checks for the existence of a file, in a directory writable by others, before opening it, to avoid overwriting an existing file. An attacker can arrange, usually through repeated attempts, to create the file just after the existence check and before the open. The vulnerable program's author made an incorrect assumption about what else could be going on in the system, which allows the attacker's program to race with it.

At first blush, it doesn't seem particularly harmful for a program to mistakenly overwrite the attacker's carefully inserted file. After all, the victimized program will probably just truncate the file before writing whatever data it had planned. This is where symbolic links (symlinks) come into play.

Symlinks are just an alias for an entry in the filesystem which can be created by anyone with write access to the directory where the symlink will reside. The target of the symlink can be most any string, normally they are the path to the target of the alias, but there is no requirement that the target exist. More importantly, there is no check that the process which creates the symlink has access rights to the target. When operations are performed on a symlink, the filesystem layer follows the pointer to the actual file, checking the permissions on the inode of that file.

What that means is that any random Linux user can create a symbolic link from /tmp/foo to /etc/passwd, though they will not be able to write to the former, because the permissions on the latter do not allow it. But, privileged programs, either setuid or those run as root, do have the proper permission. If they open and write to /tmp/foo, they have just corrupted the password file.

Vulnerable programs aren't usually quite that simple, but they do use predictable filenames or patterns. If an attacker knows that the administrator often runs a vulnerable program or script, which writes to /tmp/fooNNNNN where NNNNN is a random number, they can run a program which continuously makes links from those filenames to some file they wish to corrupt. If their program happens to generate the right link at the right time, the corruption succeeds. Normally, a program that creates a temporary file will delete it when it is done executing, but for symlinks that just removes the link, leaving the file that was pointed to with the whatever contents were written.

A setuid program provides even more opportunities for exploitation as the attacker can run it many times, under his control, while running other programs that create the symlinks. If the attacker can control, via input to the program, what gets written, the problem becomes worse still, quite possibly leading to complete compromise of the system. The scenarios for abusing this kind of hole are endless.

It doesn't necessarily have to be a temporary file that gets exploited, any file that gets opened in a directory that is writable by others can potentially be symlinked elsewhere. This can lead to unexpected results for reads, or corruption of unexpected files for writes. These types of vulnerabilities can be used when a regular user login (or system user like 'apache') is compromised, by an exploit or password disclosure, to further compromise the system. Some may be difficult to exploit reliably, but the consequences are such that it may be worth the effort.

As always, David Wheeler's Secure Programming for Linux and Unix HOWTO is an excellent resource for avoiding these kinds of problems. The basic idea is to avoid the race by using atomic filesystem operations or, for tmpfiles, mkstemp(). When creating files, ensure that the open() call uses O_CREAT | O_EXCL which will fail if the file already exists. Another important note is that a program should not close and reopen files that live in shared directories, instead they should be left open until the program is done with them.

These kind of problems have been around for twenty years or more, but still keep cropping up, which is a good indication that many programmers aren't following secure coding practices. Whenever one is writing code that is opening files, which is, after all, a very common operation, some consideration should be given to symlink/tmpfile vulnerabilities. With some perseverance, these kinds of vulnerabilities could become a thing of the past.

Comments (11 posted)

New vulnerabilities

cacti: denial of service

Package(s):cacti CVE #(s):CVE-2007-3112 CVE-2007-3113
Created:September 18, 2007 Updated:December 16, 2009
Description: A vulnerability in Cacti 0.8.6i and earlier versions allows remote authenticated users to cause a denial of service (CPU consumption) via large values of the graph_start, graph_end, graph_height, or graph_width parameters.
Alerts:
Debian DSA-1954-1 cacti 2009-12-16
Fedora FEDORA-2008-1737 cacti 2008-02-15
Fedora FEDORA-2007-3683 cacti 2007-11-22
Fedora FEDORA-2007-2199 cacti 2007-09-18
Mandriva MDKSA-2007:184 cacti 2007-09-17

Comments (none posted)

kvirc: remote arbitrary code execution

Package(s):kvirc CVE #(s):CVE-2007-2951
Created:September 14, 2007 Updated:February 27, 2008
Description: Stefan Cornelius from Secunia Research discovered that the "parseIrcUrl()" function in file src/kvirc/kernel/kvi_ircurl.cpp does not properly sanitize parts of the URI when building the command for KVIrc's internal script system.
Alerts:
SuSE SUSE-SR:2007:015 PHP, moodle, tomcat5, lighttpd, asterisk, libarchive, xpdf, evolution, kvirc, wireshark, gd, opera, clamav, gimp 2007-08-03
Gentoo 200709-02 kvirc 2007-09-13

Comments (none posted)

mediawiki: cross-site scripting

Package(s):mediawiki CVE #(s):CVE-2007-4828
Created:September 19, 2007 Updated:September 19, 2007
Description: The API pretty-printing mode in mediawiki suffers from a cross-site scripting vulnerability. Only sites which have enabled the API interface are vulnerable. See this advisory for more information.
Alerts:
Fedora FEDORA-2007-2189 mediawiki 2007-09-18

Comments (1 posted)

openoffice.org: arbitrary code execution via TIFF images

Package(s):openoffice.org CVE #(s):CVE-2007-2834
Created:September 17, 2007 Updated:June 12, 2008
Description: A heap overflow vulnerability has been discovered in the TIFF parsing code of the OpenOffice.org suite. The parser uses untrusted values from the TIFF file to calculate the number of bytes of memory to allocate. A specially crafted TIFF image could trigger an integer overflow and subsequently a buffer overflow that could cause the execution of arbitrary code.
Alerts:
Fedora FEDORA-2008-5239 openoffice.org 2008-06-11
Fedora FEDORA-2008-4104 openoffice.org 2008-05-17
Gentoo 200710-24 openoffice 2007-10-23
Ubuntu USN-524-1 openoffice.org/-amd64 2007-10-04
Fedora FEDORA-2007-2372 openoffice.org 2007-10-03
SuSE SUSE-SA:2007:052 OpenOffice_org 2007-09-21
Mandriva MDKSA-2007:186 openoffice.org 2007-09-17
rPath rPSA-2007-0189-1 openoffice.org 2007-09-18
Foresight FLEA-2007-0056-1 openoffice.org 2007-09-18
Fedora FEDORA-2007-700 openoffice.org 2007-09-18
Red Hat RHSA-2007:0848-01 openoffice.org 2007-09-18
Debian DSA-1375-1 openoffice.org 2007-09-17

Comments (none posted)

phpwiki: authentication bypass

Package(s):phpwiki CVE #(s):CVE-2007-3193
Created:September 19, 2007 Updated:September 19, 2007
Description: Versions of phpwiki prior to 1.3.14 suffer from an authentication bypass vulnerability when using an LDAP server containing an account with an empty password.
Alerts:
Gentoo 200709-10 phpwiki 2007-09-18

Comments (1 posted)

qt: buffer overflow

Package(s):qt CVE #(s):CVE-2007-4137
Created:September 14, 2007 Updated:December 10, 2007
Description: A buffer overflow was found in how Qt expanded malformed Unicode strings. If an application linked against Qt parsed a malicious Unicode string, it could lead to a denial of service or potentially allow for the execution of arbitrary code.
Alerts:
Debian DSA-1426-1 qt-x11-free 2007-12-08
Gentoo 200710-28 qt 2007-10-25
rPath rPSA-2007-0204-1 qt 2007-10-03
Foresight FLEA-2007-0059-1 dist 2007-10-04
SuSE SUSE-SR:2007:019 star, cpio, emacs, krb5, pptpd, mysql, qt3, balsa, id3lib 2007-09-28
Ubuntu USN-513-1 qt-x11-free 2007-09-18
Fedora FEDORA-2007-703 qt 2007-09-18
Fedora FEDORA-2007-2216 qt 2007-09-18
Mandriva MDKSA-2007:183 qt 2007-09-13

Comments (none posted)

quagga: denial of service

Package(s):quagga CVE #(s):CVE-2007-4826
Created:September 14, 2007 Updated:October 25, 2010
Description: The bgpd daemon in Quagga prior to 0.99.9 allowed remote BGP peers to cause a denial of service crash via a malformed OPEN message or COMMUNITY attribute.
Alerts:
Oracle ELSA-2012-1258 quagga 2012-09-13
CentOS CESA-2010:0785 quagga 2010-10-25
CentOS CESA-2010:0785 quagga 2010-10-20
Red Hat RHSA-2010:0785-01 quagga 2010-10-20
Debian DSA-1379-1 quagga 2007-10-01
Trustix TSLSA-2007-0028 fetchmail, quagga 2007-09-21
Fedora FEDORA-2007-2196 quagga 2007-09-18
Ubuntu USN-512-1 quagga 2007-09-15
Mandriva MDKSA-2007:182 quagga 2007-09-13

Comments (none posted)

streamripper: buffer overflow

Package(s):streamripper CVE #(s):CVE-2007-4337
Created:September 14, 2007 Updated:December 9, 2008
Description: Chris Rohlf discovered several boundary errors in the httplib_parse_sc_header() function when processing HTTP headers.
Alerts:
Debian DSA-1683-1 streamripper 2008-12-08
Gentoo 200709-03 streamripper 2007-09-13

Comments (none posted)

Page editor: Jake Edge
Next page: Kernel development>>


Copyright © 2007, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds