当前位置:首页 > CMS教程 > 其它CMS > 列表

Ecmall最新SQL注射漏洞分析

发布:smiling 来源: PHP粉丝网  添加日期:2014-12-05 10:14:29 浏览: 评论:0 

最近看一个站长博客更新了EcmallSQL注射漏洞的技术文章,下面我把定整理一下与各位朋友一起分享,希望例子对大家会有所帮助.

你的域名/index.php 土淘网

用的Ecmall的建站模板,用过这个模板的应该都通杀了吧,存在搜索框注入,注入点为:

你的域名/index.php?app=store&act=search&id=45&keyword=aaa&min_price=100&max_price=10000

首先将获取get传来的参数,然后组合到一个sql查询语句condition中.

1.search.app.php中的这段代码就是构建查询min和max价格的sql代码,没有过滤,代码如下:

  1. /** 
  2.  
  3.  * 取得查询条件语句 
  4.  
  5.  * 
  6.  
  7.  * @param   array   $param  查询参数(参加函数_get_query_param的返回值说明) 
  8.  
  9.  * @return  string  where语句 
  10.  
  11.  */ 
  12.  
  13. function _get_goods_conditions($param) 
  14.  
  15. { 
  16.  
  17. /* 组成查询条件 */ 
  18.  
  19. $conditions = " g.if_show = 1 AND g.closed = 0 AND s.state = 1"; // 上架且没有被禁售,店铺是开启状态, 
  20.  
  21. if (isset($param['keyword'])) 
  22.  
  23. { 
  24.  
  25. $conditions .= $this->_get_conditions_by_keyword($param['keyword'], ENABLE_SEARCH_CACHE); 
  26.  
  27. } 
  28.  
  29. if (isset($param['cate_id'])) 
  30.  
  31. { 
  32.  
  33. $conditions .= " AND g.cate_id_{$param['layer']} = '" . $param['cate_id'] . "'"; 
  34.  
  35. } 
  36.  
  37. if (isset($param['brand'])) 
  38.  
  39. { 
  40.  
  41. $conditions .= " AND g.brand = '" . $param['brand'] . "'"; 
  42.  
  43. } 
  44.  
  45. if (isset($param['region_id'])) 
  46.  
  47. { 
  48.  
  49. $conditions .= " AND s.region_id = '" . $param['region_id'] . "'"; 
  50.  
  51. } 
  52.  
  53. if (isset($param['price'])) 
  54.  
  55. { 
  56.  
  57. $min = $param['price']['min']; 
  58.  
  59. $max = $param['price']['max']; 
  60.  
  61. $min > 0 && $conditions .= " AND g.price >= '$min'"; 
  62.  
  63. $max > 0 && $conditions .= " AND g.price <= '$max'"; 
  64.  
  65. } 
  66.  
  67. return $conditions; 
  68.  
  69. } 

2.下面这部分代码是query执行部分,直接将上面的参数带入查询了:

  1. /* 按价格统计 */ 
  2.  
  3. if ($total_count > NUM_PER_PAGE) 
  4.  
  5. { 
  6.  
  7. $sql = "SELECT MIN(g.price) AS min, MAX(g.price) AS max FROM {$table} WHERE" . $conditions; 
  8.  
  9. $row = $goods_mod->getRow($sql); 
  10.  
  11. $min = $row['min']; 
  12.  
  13. $max = min($row['max'], MAX_STAT_PRICE); 
  14.  
  15. $step = max(ceil(($max - $min) / PRICE_INTERVAL_NUM), MIN_STAT_STEP); 
  16.  
  17. $sql = "SELECT FLOOR((g.price - '$min') / '$step') AS i, count(*) AS count FROM {$table} WHERE " . $conditions . " GROUP BY i ORDER BY i"; 
  18.  
  19. $res = $goods_mod->db->query($sql); 
  20.  
  21. while ($row = $goods_mod->db->fetchRow($res)) 
  22.  
  23. { 
  24.  
  25. $data['by_price'][] = array( 
  26.  
  27. 'count' => $row['count'], 
  28. //开源软件:phpfensi.com 
  29. 'min'   => $min + $row['i'] * $step, 
  30.  
  31. 'max'   => $min + ($row['i'] + 1) * $step, 
  32.  
  33. ); 
  34.  
  35. } 
  36.  
  37. } 
  38.  
  39. } 

利用另一个文件来注入,缺陷文件:/app/coupon.app.php,代码如下:

  1. function extend() 
  2.  
  3. { 
  4.  
  5.     $coupon_id = isset($_GET['id']) ? trim($_GET['id']) : ''; 
  6.  
  7.     if (emptyempty($coupon_id)) 
  8.  
  9.     { 
  10.  
  11.         echo Lang::get('no_coupon'); 
  12.  
  13.         exit; 
  14.  
  15.     } 
  16.  
  17.     if (!IS_POST) 
  18.  
  19.     { 
  20.  
  21.         header("Content-Type:text/html;charset=" . CHARSET); 
  22.  
  23.         $this->assign('id', $coupon_id); 
  24.  
  25.         $this->assign('send_model', Lang::get('send_model')); 
  26.  
  27.         $this->display("coupon_extend.html"); 
  28.  
  29.     } 
  30.  
  31.     else 
  32.  
  33.     { 
  34.  
  35.         if (emptyempty($_POST['user_name'])) 
  36.  
  37.         { 
  38.  
  39.             $this->pop_warning("involid_data"); 
  40.  
  41.             exit; 
  42.  
  43.         } 
  44.  
  45.         $user_name = str_replace(array("r","rn"), "n", trim($_POST['user_name'])); 
  46.  
  47.         $user_name = explode("n", $user_name); 
  48.  
  49.         $user_mod =&m ('member'); 
  50.  
  51.         $users = $user_mod->find(db_create_in($user_name, 'user_name')); 
  52.  
  53.         if (emptyempty($users)) 
  54.  
  55.         { 
  56.  
  57.             $this->pop_warning('involid_data'); 
  58.  
  59.             exit; 
  60.  
  61.         } 
  62.  
  63.         if (count($users) > 30) 
  64.  
  65.         { 
  66.  
  67.             $this->pop_warning("amount_gt"); 
  68.  
  69.             exit; 
  70.  
  71.         } 
  72.  
  73.         else 
  74.  
  75.         { 
  76.  
  77.             $users = $this->assign_user($coupon_id, $users); 
  78.  
  79.             $store = $this->_store_mod->get_info($this->_store_id); 
  80.  
  81.             $coupon = $this->_coupon_mod->get_info($coupon_id); 
  82.  
  83.             $coupon['store_name'] = $store['store_name']; 
  84.  
  85.             $coupon['store_id'] = $this->_store_id; 
  86.  
  87.             $this->_message_to_user($users, $coupon); 
  88.  
  89.             $this->_mail_to_user($users, $coupon); 
  90.  
  91.             $this->pop_warning("ok","coupon_extend"); 
  92.  
  93.         } 
  94.  
  95.     } 
  96.  
  97. } 

首先是coupon_id只过滤了空格,随后在else语句里进入了get_info函数:

  1. function get_info($id) 
  2.  
  3. { 
  4.  
  5.     $goods = $this->get(array( 
  6.  
  7.         'conditions' => "goods_id = '$id'", 
  8.  
  9.         'join'       => 'belongs_to_store', 
  10.  
  11.         'fields'     => 'this.*, store.state' 
  12.  
  13.     )); 
  14. ..省略 

读过代码的就知道了,其实上面的conditions之类的都是拼接成SQL语句最终要进入数据库的,所以注射产生:

POST index.php?app=coupon&act=extend&id=1[exp]

data:user_name=test(当前已经登录的用户名)

注意:文章只告诉各位有什么bug,让各位站长及时补上哦,并且本文章只供学习使用,一切后果与本站无关.

Tags: Ecmall漏洞分析 SQL注射漏洞

分享到: