安全研究

安全漏洞
Perdition IMAP代理str_vwrite函数远程格式串处理漏洞

发布日期:2007-10-31
更新日期:2007-11-01

受影响系统:
Simon Horman Perdition <=1.17
不受影响系统:
Simon Horman Perdition v 1.17.1
描述:
BUGTRAQ  ID: 26270

Perdition是一款POP3和IMAP4代理服务器。

Perdition IMAPD的一个IMAP输出字符串格式化函数中存在格式串漏洞,远程攻击者可能利用此漏洞控制服务器。

在某些情况下,未经验证便将IMAP标签(IMAP命令的最初部分)拷贝到了字符缓冲区,然后做为格式串将这个缓冲区传送给了vsnprintf()。在调用vsnprintf之前,执行了以下格式串验证以防范注入:

str.c:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168: static const char *__str_vwrite(io_t * io, const flag_t flag,
169:         const size_t nargs, const char *fmt, va_list ap,
170:         int *bytes)
171: {
(...)
186:     fmt_args = 0;
187:     for (place = 0; fmt[place] != '\0'; place++) {
188:         if (fmt[place] == '%')
189:             fmt[place + 1] == '%' ? place++ : fmt_args++;
190:     }
191:     if (fmt_args != nargs) {
(...)
195:         VANESSA_LOGGER_DEBUG_UNSAFE("nargs and fmt mismatch: "
196:                 "%d args requested, %d args in format",
197:                      nargs, fmt_args);
198:         return (NULL);
199:     }
200:
201:     *bytes = vsnprintf(__str_write_buf, STR_WRITE_BUF_LEN - 2, fmt,
ap);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

在187-191行,将格式标识符的实际数目与nargs参数中所给出的预期数目做了比较,但可以在IMAP标签的末尾注入空字节来绕过这个检查,空字节会截断字符串的剩余部分,因此可以在IMAP标签中注入nargs任意格式标识符。实际上攻击者仅可以控制单个格式标识符,但仍可以通过写入全局函数指针上的多个连续单字节控制指令指针,导致执行任意代码。

<*来源:Bernhard Mueller (research@sec-consult.com
  
  链接:http://secunia.com/advisories/27458/
        http://marc.info/?l=bugtraq&m=119384506416589&w=2
*>

测试方法:

警 告

以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

perl -e 'print "abc%n\x00\n"' | nc perdition.example.com 143

建议:
厂商补丁:

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

http://www.vergenet.net/linux/perdition/download/1.17.1/
http://www.vergenet.net/linux/perdition/download/latest/

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