[40055] in bugtraq

home help back first fref pref prev next nref lref last post

unzip TOCTOU file-permissions vulnerability

daemon@ATHENA.MIT.EDU (Imran Ghory)
Tue Aug 2 12:37:12 2005

Message-ID: <7389fc4b05080116031536adf7@mail.gmail.com>
Date: Tue, 2 Aug 2005 00:03:05 +0100
From: Imran Ghory <imranghory@gmail.com>
Reply-To: Imran Ghory <imranghory@gmail.com>
To: bugtraq@securityfocus.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

[Another compression utility with the same race condition issue as bzip2
 (CAN-2005-0953), gzip (CAN-2005-0988) and cpio (CAN-2005-1111) - the
file is extracted and file descriptor closed before the file is
chmod'ed]

================================
unzip TOCTOU file-permissions vulnerability
================================

Software: unzip
Version: 5.52
Software URL: <http://www.info-zip.org/pub/infozip/UnZip.html>
Platform:  Unix, Linux.
Vulnerability type: Time-of-Check-Time-Of-Use
Severity: Low, local user, badly set permissions.

Vulnerable software
====================

unzip 5.52 and previous versions running on unix.

Vulnerability
==============

If a malicious local user has write access to a directory in which a
target user is using unzip to extract a file to then a
TOCTOU bug can be exploited to change the permission of any file
belonging to that user.

On decompressing unzip copies the permissions from the compressed
 file to the uncompressed file. However there is a gap between the
uncompressed file being written (and it's file handler being close)
and the permissions of the file being changed.

During this gap a malicious user can remove the decompressed file and
replace it with a hard-link to another file belonging to the user.
unzip will then change the permissions on the  hard-linked file to be
the same as that of the compressed file.

The vulnerable line of code can be found on line 1160 of the file
unix.c where chmod is used (rather than fchmod). unzip also use's
chmod in a number of other places which may also be vulnerable to
exploitation.

Workaround
========

Ensure that any directory which is being used by unzip to
decompress files is only writeable by the user or
alternatively set the sticky bit on the directory's permissions.

---
Imran Ghory

home help back first fref pref prev next nref lref last post