TGCTF-2025-Web-Writeup
Web (ez)upload hint写有源码泄露 index.php.bak拿源码 1<?php 2define('UPLOAD_PATH', __DIR__ . '/uploads/'); 3$is_upload = false; 4$msg = null; 5$status_code = 200; // 默认状态码为 200 6if (isset($_POST['submit'])) { 7 if (file_exists(UPLOAD_PATH)) { 8 $deny_ext = array("php", "php5", "php4", "php3", "php2", "html", "htm", "phtml", "pht", "jsp", "jspa", "jspx", "jsw", "jsv", "jspf", "jtml", "asp", "aspx", "asa", "asax", "ascx", "ashx", "asmx", "cer", "swf", "htaccess"); 9 10 if (isset($_GET['name'])) { 11 $file_name = $_GET['name']; 12 } else { 13 $file_name = basename($_FILES['name']['name']); 14 } 15 $file_ext = pathinfo($file_name, PATHINFO_EXTENSION); 16 17 if (!in_array($file_ext, $deny_ext)) { 18 $temp_file = $_FILES['name']['tmp_name']; 19 $file_content = file_get_contents($temp_file); 20 21 if (preg_match('/.+?</s', $file_content)) { 22 $msg = '文件内容包含非法字符,禁止上传!'; 23 $status_code = 403; // 403 表示禁止访问 24 } else { 25 $img_path = UPLOAD_PATH . $file_name; 26 if (move_uploaded_file($temp_file, $img_path)) { 27 $is_upload = true; 28 $msg = '文件上传成功!'; 29 } else { 30 $msg = '上传出错!'; 31 $status_code = 500; // 500 表示服务器内部错误 32 } 33 } 34 } else { 35 $msg = '禁止保存为该类型文件!'; 36 $status_code = 403; // 403 表示禁止访问 37 } 38 } else { 39 $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!'; 40 $status_code = 404; // 404 表示资源未找到 41 } 42} 43 44// 设置 HTTP 状态码 45http_response_code($status_code); 46 47// 输出结果 48echo json_encode([ 49 'status_code' => $status_code, 50 'msg' => $msg, 51]); 审计一下代码,看到有个name,可以对文件名进行修改,想到目录穿越 ...