Discuz7.2的暴露网站所在路径的BUG

报错信息:
Warning: sprintf() [function.sprintf]: Too few arguments in ….\include\discuzcode.func.php on line 369

漏洞位置:
\include\discuzcode.func.php 369行附近

函数名称:
Discuz自定义的bbcodeurl函数,此函数中使用了PHP自带的函数sprintf

漏洞原因:
当用户在发帖的时候,选择使用远程图片地址,且指定了图片的宽,高,且URL中包含%百分号(比如汉字URL编码)的时候,被discuzcode.func.php程序中的discuzcode函数处理。在discuzcode函数处理图片的URL的正则替换部分,用parseimg函数进行处理,parseimg函数的三个参数全部是正则匹配的结果,三个参数依次是宽,高,URL地址。paeseimg函数又调用了bbcodeurl函数处理,并把匹配的URL当作bbcodeurl函数的第二个参数的一部分,交给bbcodeurl函数处理。的sprintf 函数的第一个参数来自用户输入的数据,程序在使用bbcodeurl函数的时候,没有检测用户输入的数据,直接把用户输入的数据作为自己参数的一部分,也就是$tags参数了。bbcodeurl函数用了sprintf函数进行字符串格式化。$tags又是第一个参数,其中,$tags字符串中的%号是格式化字符串的保留字符,以为着有几个单独的%号,就必须后接几个参数。由于程序没有判断$tags中包含几个单独的百分号,后面的参数也是固定的两个,如果URL中包含百分号的话,则导致参数的个数不对,报Warning错,就暴露了程序所在服务器的路径了(config.inc.php中的$errorreport变量限制了错误报告的对象,默认只允许报告给版主,管理人员)。

影响版本:
Discuz!7.2 (我只测试了这个版本)

现在时间:
2010-05-13 17:43

修复方法:
等待官方补丁或者转义【%】字符即可。。

临时解决办法:
discuzcode.func.php中bbcodeurl函数改成如下

function bbcodeurl($url, $tags) {
	if(!preg_match("/<.+?>/s", $url)) {
		if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://'))) {
			$url = 'http://'.$url;
		}
        $url = str_replace('%','%%',$url);
		return str_replace(array('submit', 'logging.php','%%'), array('', '','%'), sprintf($tags, $url, addslashes($url)));
	} else {
		return '&nbsp;'.$url;
	}
}

您可能喜欢下面几篇博文

发表评论

1 Comments.

  1. 试过了 爆出了路劲 但是没法得到webshell

Leave a Reply



[ Ctrl + Enter ]

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

CNXCT小组的博客 is Stephen Fry proof thanks to caching by WP Super Cache