Web_php_include(strstr与str_replace函数)

13 篇文章 0 订阅
10 篇文章 0 订阅

<?php
show_source(__FILE__);
echo $_GET['hello'];
$page=$_GET['page'];
while (strstr($page, "php://")) {
    $page=str_replace("php://", "", $page);#查找php://,null替换查找的值,并且规定搜索$page
}
include($page);
?>

strstr函数

strstr(str1,str2) 函数,判断字符串str2是否是str1的子串。如果是,则该函数返回str2在str1中首次出现的地址;否则,返回null。

str_replace函数

str_replace() 函数使用一个字符串替换字符串中的另一些字符。

语法:str_replace(find,replace,string,count)

 $page=str_replace("php://", "", $page);#查找php://,null替换查找的值,并且规定搜索$page 

参数描述
find必需。规定要查找的值。
replace必需。规定替换 find 中的值的值。
string必需。规定被搜索的字符串。
count可选。一个变量,对替换数进行计数。

 


这题过滤了php://,在这里我们得先了解一下什么是php://,以及php提供的各种杂项输入输出流

php://(访问各个输入/输出流),提供了IO流允许访问 PHP 的输入输出流、标准输入输出和错误描述符,内存中、磁盘备份的临时文件流以及可以操作其他读取写入文件资源的过滤器。如php://stdin、php://stdout 和 php://stderr 允许直接访问 PHP 进程相应的输入或者输出流。如php://input、php://output,php://input是一个可以访问请求的原始数据的只读流,构造payload

这里存在一个远程文件包含漏洞,虽然过滤了php,但使用大小写进行绕过

输入PHP://input,来写代码获取内容

cat fl4gisisish3r3.php

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
<?php // 连接数据库 $conn = mysqli_connect("localhost", "tms", "123456", "nut"); // 检查连接是否成功 if (!$conn) { die("数据库连接失败: " . mysqli_connect_error()); } // 处理表单提交 if ($_SERVER["REQUEST_METHOD"] == "POST") { // 获取表单数据 $aoiSteps = $_POST['aoi_step']; $defectTypes = $_POST['defect_type']; $layerCodes = $_POST['layer_code']; $types = $_POST['type']; $dpets = $_POST['dpet']; $subcodes = $_POST['subcode']; $codeDescriptions = $_POST['code_description']; $determinationRules = $_POST['determination_rule']; $imagePaths = []; // 存储图片路径的数组 // 处理上传的图片 for ($i = 0; $i < count($aoiSteps); $i++) { $imagePaths = []; // 存储图片路径的数组 // 处理每个字段对应的图片 for ($j = 1; $j <= 5; $j++) { $imageField = "image" . $j; $targetDir = "D:/phpstudy_pro/WWW/192.168.1.16/images"; // 设置上传目录的路径 $fileName = uniqid() . '_' . $_FILES[$imageField]["name"][$i]; // 生成唯一文件名 $targetFile = $targetDir . '/' . basename($fileName); // 将反斜杠替换为正斜杠 $targetFile = str_replace('\\', '/', $targetFile); if (isset($_FILES[$imageField]["tmp_name"][$i]) && $_FILES[$imageField]["error"][$i] == UPLOAD_ERR_OK && move_uploaded_file($_FILES[$imageField]["tmp_name"][$i], $targetFile)) { $imagePath = $targetFile; } else { $imagePath = ""; } $imagePaths[] = $imagePath; } // 绑定参数 $stmt->bind_param("sssssssssssss", $aoiSteps[$i], $defectTypes[$i], $layerCodes[$i], $types[$i], $dpets[$i], $subcodes[$i], $codeDescriptions[$i], $imagePaths[0], $imagePaths[1], $imagePaths[2], $imagePaths[3], $imagePaths[4], $determinationRules[$i]); if ($stmt->execute()) { echo "数据插入成功"; } else { echo "数据插入失败: " . $stmt->error; } } // 关闭数据库连接 mysqli_close($conn); } ?>无法正常上传
最新发布
07-25
在你提供的代码中,我注意到你没有创建预处理语句 `$stmt` 对象。请确保在执行绑定参数之前创建预处理语句对象。 以下是修改后的代码示例: ```php <?php // 连接数据库 $conn = mysqli_connect("localhost", "tms", "123456", "nut"); // 检查连接是否成功 if (!$conn) { die("数据库连接失败: " . mysqli_connect_error()); } // 处理表单提交 if ($_SERVER["REQUEST_METHOD"] == "POST") { // 获取表单数据 $aoiSteps = $_POST['aoi_step']; $defectTypes = $_POST['defect_type']; $layerCodes = $_POST['layer_code']; $types = $_POST['type']; $dpets = $_POST['dpet']; $subcodes = $_POST['subcode']; $codeDescriptions = $_POST['code_description']; $determinationRules = $_POST['determination_rule']; $imagePaths = []; // 存储图片路径的数组 // 处理上传的图片 for ($i = 0; $i < count($aoiSteps); $i++) { // 创建预处理语句对象 $stmt = $conn->prepare("INSERT INTO tms (aoi_step, defect_type, layer_code, type, dpet, subcode, code_description, image1_path, image2_path, image3_path, image4_path, image5_path, determination_rule) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); if (!$stmt) { die("预处理失败: " . $conn->error); } // 处理每个字段对应的图片 for ($j = 1; $j <= 5; $j++) { $imageField = "image" . $j; $targetDir = "D:/phpstudy_pro/WWW/192.168.1.16/images"; // 设置上传目录的路径 $fileName = uniqid() . '_' . $_FILES[$imageField]["name"][$i]; // 生成唯一文件名 $targetFile = $targetDir . '/' . basename($fileName); // 将反斜杠替换为正斜杠 $targetFile = str_replace('\\', '/', $targetFile); if (isset($_FILES[$imageField]["tmp_name"][$i]) && $_FILES[$imageField]["error"][$i] == UPLOAD_ERR_OK && move_uploaded_file($_FILES[$imageField]["tmp_name"][$i], $targetFile)) { $imagePath = $targetFile; } else { $imagePath = ""; } $imagePaths[] = $imagePath; } // 绑定参数 $stmt->bind_param("sssssssssssss", $aoiSteps[$i], $defectTypes[$i], $layerCodes[$i], $types[$i], $dpets[$i], $subcodes[$i], $codeDescriptions[$i], $imagePaths[0], $imagePaths[1], $imagePaths[2], $imagePaths[3], $imagePaths[4], $determinationRules[$i]); if ($stmt->execute()) { echo "数据插入成功"; } else { echo "数据插入失败: " . $stmt->error; } // 关闭预处理语句 $stmt->close(); } // 关闭数据库连接 mysqli_close($conn); } ?> ``` 在上述代码中,我们在循环内部创建了预处理语句对象 `$stmt`,并在循环结束后关闭了预处理语句。 请确保你的 HTML 表单中的图片字段在多行数据时也使用了数组形式,并且你的上传目录路径 `D:/phpstudy_pro/WWW/192.168.1.16/images` 是正确的。 如果问题仍然存在,请提供详细的错误信息,以便我可以更好地帮助你解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值