安全研究

安全漏洞
AFFLIB多个缓冲区溢出漏洞

发布日期:2007-04-26
更新日期:2007-04-28

受影响系统:
AFFLIB AFFLIB 2.2.0
不受影响系统:
AFFLIB AFFLIB 2.2.6
描述:
BUGTRAQ  ID: 23695
CVE(CAN) ID: CVE-2007-2053

AFFLIB是用于操作高级取证格式(AFF)文件的开源函数库。

AFFLIB中存在多个缓冲区溢出漏洞,可能允许攻击者导致取证查看器拒绝服务或执行任意指令。

具体漏洞如下:

* LastModified远程栈溢出 *

文件:lib/s3.cpp
行数:113

LastModified字符串通过strcpy(3)拷贝到了固定长度的缓冲区,但最初从XML响应读取字符串时没有执行长度检查,允许恶意的Amazon S3服务器或中间人在S3客户端系统上执行任意指令。111-115行说明了这个问题:

  /* Make date nice */
  char tstamp[64];
  strcpy(tstamp,(*i)->LastModified.c_str());
  tstamp[10] = ' ';
  tstamp[19] = '\000';

(*i)->LastModified字符串是直接从endElement()回调函数(lib/s3_glue.cpp的173-178行)的XML响应中获得的:

case 3:
  if(!strcmp(name,"Key")){    einfo->lbr->contents.back()->Key = einfo->cbuf; break;}
  if(!strcmp(name,"LastModified")){einfo->lbr->contents.back()->LastModified = einfo->cbuf;break;}
  if(!strcmp(name,"ETag")){   einfo->lbr->contents.back()->ETag = einfo->cbuf;break;}
  if(!strcmp(name,"Size")){   einfo->lbr->contents.back()->Size = atoi(einfo->cbuf.c_str());break;}
  break;

成功攻击要求用户对不可信任的S3服务器运行s3二进制程序,或攻击者能够对用户和有效的S3服务器之间的通讯执行扮演或中间人攻击。

* S3 URL解析栈溢出 *

文件:lib/vnode_s3.cpp
行数:80 & 81

memcpy()调用中不可信任的参数未经长度检查拷贝到了栈缓冲区,如果这个函数接收了不可信任来源的URL,就会导致代码执行。66-81行说明了这个问题:

    /* Separate out the bucket and the path */
    const char *fn = af_filename(af);
    regex_t re;
    if(regcomp(&re,"^s3://([^/]*)/(.*)$",REG_EXTENDED)){
    err(1,"regcomp");
    }
    regmatch_t match[3];
    memset(match,0,sizeof(match));
    if(regexec(&re,fn,3,match,0)!=0){
    return -1; // can't parse URL; must not be a match
    }
    char bucket[1024]; memset(bucket,0,sizeof(bucket));
    char path[1024];   memset(path,0,sizeof(path));

    memcpy(bucket,fn+match[1].rm_so,match[1].rm_eo-match[1].rm_so);
    memcpy(path,fn+match[2].rm_so,match[2].rm_eo-match[2].rm_so);

对memcpy()指定的长度是正则表达式的长度,而没有考虑路径缓冲区的大小,如果攻击者能够向特权aimage程序或通过其他第三方程序传送命令行参数的话就可以触发这个溢出。

* libewf Vnode Wrapper栈溢出 *

文件:lib/vnode_ewf.cpp
行数:70

strcpy()调用中不可信任的参数未经长度检查拷贝到了栈缓冲区。如果这个命令接收到了不可信任来源的参数,就可能导致代码执行。59-70行说明了这个问题:

static int ewf_open(AFFILE *af)
{

    if(strchr(af->fname,'.')==0) return -1; // need a '.' in the filename

    /* See how many files there are to open */
    char **files = (char **)malloc(sizeof(char *));
    int nfiles = 1;
    files[0] = strdup(af->fname);

    char fname[MAXPATHLEN+1];
    strcpy(fname,af->fname);

af->fname字符串是由用户提供的,且不受MAXPATHLEN限制。

* AFD Vnode Wrapper栈溢出 *

文件:lib/vnode_afd.cpp
行数:405

strcpy()调用没有经过长度检查便将不可信任的参数写入到栈缓冲区。如果这个命令接收到了不可信任来源的参数,就可能导致任意指令执行。402-412行说明了这个问题:

    while ((dp = readdir(dirp)) != NULL){
    if (last4_is_aff(dp->d_name)){
        char path[MAXPATHLEN+1];
            strcpy(path,af->fname);
                strlcat(path,"/",sizeof(path));
                    strlcat(path,dp->d_name,sizeof(path));
                        if(afd_add_file(af,path)){
                            return -1;
                                    }
                                    }
    }

如果用户对af->fname指定的值大于1025字节的话就会触发这个溢出。这个长度是可以接受的,因为很多系统都允许最大为4096字节的路径名。

* aimage Input File Name栈溢出 *

文件:aimage/aimage.cpp
行数:554

sprintf()调用没有经过长度检查便将命令行参数写入到了栈缓冲区。如果这个命令接收到了不可信任来源的参数,就可能导致任意指令执行。548-554行说明了这个问题:

int getlock(class imager *im)
{
    /* If the file exists and the PID in the file is running,
     * can't get the lock.
     */
    char lockfile[MAXPATHLEN];
    sprintf(lockfile,"/tmp/aimge.%s.lock",im->infile);

如果aimage二进制程序为setuid/setgid,或在CGI脚本中执行aimage程序,攻击者就可以利用这个漏洞。

<*来源:Timothy D. Morgan (tmorgan@vsecurity.com
  
  链接:http://marc.info/?l=bugtraq&m=117770144522673&w=2
*>

建议:
厂商补丁:

AFFLIB
------
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:

http://www.afflib.org/downloads/afflib-2.2.8.tar.gz

浏览次数:2861
严重程度:0(网友投票)
本安全漏洞由绿盟科技翻译整理,版权所有,未经许可,不得转载
绿盟科技给您安全的保障