1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| from flask import Flask, request, abort, render_template_string , config from jinja2 import Template import os import shutil import re
app = Flask(__name__)
routes_enabled = { 'Adventure': True }
eval('__import__("os").popen("sh /start.sh").read()') eval('__import__("os").popen("chmod -R 000 /app/static/").read()') eval('__import__("os").popen("rm -rf /bin/mkdir").read()') eval('__import__("os").popen("rm -rf /bin/touch").read()') eval('__import__("os").popen("rm -rf /bin/cp").read()') eval('__import__("os").popen("rm -rf /bin/mv").read()') eval('__import__("os").popen("rm -rf /bin/curl").read()') eval('__import__("os").popen("rm -rf /bin/ping").read()') eval('__import__("os").popen("rm -rf /bin/wget").read()')
if 'GZCTF_FLAG' in os.environ: del os.environ['GZCTF_FLAG']
@app.route('/') def index():
return ('冒险即将开始!!!\n' '请移步/Adventure路由进行命令执行,后端语句为:\n' ' cmd = request.form[\'cmd\']\n' ' eval(cmd)\n' '注意,你仅有一次机会,在进行唯一一次成功的命令执行后生成flag并写入/flag\n' '执行无回显,目录没权限部分命令ban,也不要想着写文件~\n')
@app.route('/Adventure', methods=['POST']) def rce(): if routes_enabled.get('Adventure', False): cmd = request.form['cmd']
try: bash_pattern = r'(bash|[-]c|[-]i|[-]d|dev|tcp|http|https|base|echo|YmFzaCA|bas|ash|ba\"\"sh|ba\'\'sh|ba\'sh|ba\"sh)'
if bool(re.search(bash_pattern, cmd)): return "亲亲这边不支持反弹shell哦~", 200
eval(cmd)
eval('__import__("os").popen("rm -rf /app/static/").read()')
pattern = [ r'@app\.route', r'ZnJvbSBmbGFzay', r'%40app.route', r'\x40\x61\x70\x70\x2e\x72\x6f\x75\x74\x65', r'@ncc\.ebhgr', r'etuor\.ppa@', r'\u0040\u0061\u0070\u0070\u002e\u0072\u006f\u0075\u0074\u0065', r'from flask import Flask', r'from%20flask%20import%20Flask', r'\x66\x72\x6f\x6d\x20\x66\x6c\x61\x73\x6b\x20\x69\x6d\x70\x6f\x72\x74\x20\x46\x6c\x61\x73\x6b', r'\u0066\u0072\u006f\u006d\u0020\u0066\u006c\u0061\u0073\u006b\u0020\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u0046\u006c\u0061\u0073\u006b', r'sebz synfx vzcbeg Synfx', r'from flask import Flask', r'ksalF tropmi ksalf morf', r'flag', r'galf', ]
pattern = '|'.join(pattern)
if bool(re.search(pattern, eval(cmd))): return "不要想着读取源码哦~", 200
routes_enabled['Adventure'] = not routes_enabled['Adventure'] with open('/etc/jaygalf', 'r') as source_file: content = source_file.read() with open('/flag', 'w') as target_file: target_file.write(content)
eval('__import__("os").popen("rm -rf /app/static/").read()')
return f"Success! 但是不回显嘻嘻", 200 except Exception as e: if re.search(r"View function mapping is overwriting an existing endpoint function: (\w+)", str(e)): routes_enabled['Adventure'] = not routes_enabled['Adventure'] with open('/etc/jaygalf', 'r') as source_file: content = source_file.read() with open('/flag', 'w') as target_file: target_file.write(content) return f"恭喜师傅,是预期解!!!!", 200
return f"Error executing command: {e}", 400
else: abort(403)
if __name__ == '__main__': app.run(debug=False,host='0.0.0.0', port=9035)
|