前言

5 月份交的一个简单洞,水个博客 : )

漏洞分析

在后台多处包含缓存文件,导致可以在多处执行任意 php 代码。

在 /adminxxx/index.php (xxx 为随机生成的三位数)中。

最后一行:

1
include parse_admin_tlp($module);

跟进到 /inc/zzz_main.php 中。

第 1979 行:

1
2
3
4
5
6
7
8
9
function parse_admin_tlp( $module ) {
$tpltype = G( 'ID' ) ? 'edit' : 'add';
$tplfile = SITE_DIR . conf( 'adminpath' ) . 'template/' . $module . '.tpl';
$cachefile = RUN_DIR . 'cache/' . conf( 'adminpath' ) . md5( $module . $tpltype ) . '.tpl';
if ( !is_file( $cachefile ) || time_file( $tplfile ) > time_file( $cachefile ) || size_file( $tplfile ) == 0 ) {
create_file( $cachefile, template_parse( load_file( $tplfile ) ) );
}
return $cachefile;
}

如果 cachefile 文件不存在,则根据 tplfile 创建 cachefile 文件,如果 cachefile 文件存在,则将文件名直接返回,即在调用处 /adminxxx/index.php 的最后一行包含 cachefile 文件。

而 cachefile 文件内容可以在后台修改,如果其内容修改为任意 php 代码,则会造成任意 php 代码执行。

利用方法

先生成一个 cachefile 文件。

后台 —> 用户管理 —> 会员组管理。

01

该请求提交到 /adminxxx/index.php 处理,此时 module 变量的值为 usergrouplist,如果没有相应的缓存文件,在最后一行会生成该文件。

1
2
php -r "var_dump(md5('usergrouplistadd'));"
string(32) "f6f373570fe983d7f5ea813871d99f6d"

文件名:f6f373570fe983d7f5ea813871d99f6d.tpl

修改缓存文件内容。

后台 —> 静态缓存 —> 缓存列表 —> 后台缓存 —> 修改 f6f373570fe983d7f5ea813871d99f6d.tpl 文件内容为

1
<?php phpinfo();?>

访问http://servername/adminxxx/?usergrouplist

02

后台的很多页面的展示都由 /adminxxx/index.php 处理,只要将相应的 cachefile 文件的内容改为 php 代码,在最后一行包含时就会被执行。

比如:

03

04

总结

实际上,这个洞在下一个版本中并没有修好。