LilCTF-2025-Web-Writeup
这次我们第二名,大家太强了,彦门万岁! 这里是我个人的wp,这次Web我做了5题,所以这里就只写我自己做的题目。 ez_bottle 关键代码 1@post('/upload') 2def upload(): 3 zip_file = request.files.get('file') 4 if not zip_file or not zip_file.filename.endswith('.zip'): 5 return 'Invalid file. Please upload a ZIP file.' 6 7 if len(zip_file.file.read()) > MAX_FILE_SIZE: 8 return 'File size exceeds 1MB. Please upload a smaller ZIP file.' 9 10 zip_file.file.seek(0) 11 12 current_time = str(time.time()) 13 unique_string = zip_file.filename + current_time 14 md5_hash = hashlib.md5(unique_string.encode()).hexdigest() 15 extract_dir = os.path.join(UPLOAD_DIR, md5_hash) 16 os.makedirs(extract_dir) 17 18 zip_path = os.path.join(extract_dir, 'upload.zip') 19 zip_file.save(zip_path) 20 21 try: 22 with zipfile.ZipFile(zip_path, 'r') as z: 23 for file_info in z.infolist(): 24 if is_symlink(file_info): 25 return 'Symbolic links are not allowed.' 26 27 real_dest_path = os.path.realpath(os.path.join(extract_dir, file_info.filename)) 28 if not is_safe_path(extract_dir, real_dest_path): 29 return 'Path traversal detected.' 30 31 z.extractall(extract_dir) 32 except zipfile.BadZipFile: 33 return 'Invalid ZIP file.' 34 35 files = os.listdir(extract_dir) 36 files.remove('upload.zip') 37 38 return template("文件列表: {{files}}\n访问: /view/{{md5}}/{{first_file}}", 39 files=", ".join(files), md5=md5_hash, first_file=files[0] if files else "nofile") 40 41@route('/view/<md5>/<filename>') 42def view_file(md5, filename): 43 file_path = os.path.join(UPLOAD_DIR, md5, filename) 44 if not os.path.exists(file_path): 45 return "File not found." 46 47 with open(file_path, 'r', encoding='utf-8') as f: 48 content = f.read() 49 50 if contains_blacklist(content): 51 return "you are hacker!!!nonono!!!" 52 53 try: 54 return template(content) 55 except Exception as e: 56 return f"Error rendering template: {str(e)}" 上传一个zip,他会解压并显示文件列表,并且可以查看文件内容 ...