使用PHP从图像中删除EXIF数据是否足以防止恶意代码在服务器中执行?
我想保护服务器免受这些做法: http://php.webtutor.pl/en/2011/05/13/php-code-injection-a-simple-virus-written-in-php-and-carried-in-a-jpeg-image/
<?php
$img = imagecreatefromjpeg('malicious_codes.jpg');
$w = imagesx($img);
$h = imagesy($img);
$trans = imagecolortransparent($img);
if($trans >= 0) {
$rgb = imagecolorsforindex($img, $trans);
$oldimg = $img;
$img = imagecreatetruecolor($w,$h);
$color = imagecolorallocate($img,$rgb['red'],$rgb['green'],$rgb['blue']);
imagefilledrectangle($img,0,0,$w,$h,$color);
imagecopy($img,$oldimg,0,0,0,0,$w,$h);
}
imagejpeg($img,'safe_image.jpg');
?>
答案 0 :(得分:0)
答案 1 :(得分:0)
这将向您显示PHP中JPEG文件中的EXIF信息。
$uploadfile = "uploaded/pic.jpg";
$exif = exif_read_data($uploadfile, 0, true);
echo "<b>Your file</b><br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
这段代码应该删除所有EXIF信息
$img = new Imagick($uploadfile);
$img->stripImage();
$img->writeImage($uploadfile);
您可以在这里尝试: https://iconnaut.com/exif.php