我刚刚发现我的 Debian 服务器上的数千个原始图像文件已被缩略图文件替换。而且我敢肯定,这个手术不是我自己做的。所以肯定有一些黑客进入了我的服务器并造成了破坏。但是当我在文件被替换期间检查上次登录历史时,没有可疑的登录。所以我认为我的 PHP 代码可能存在一些安全问题。下面是我的PHP图片上传代码:
function upload() {
$sql = "SELECT photocount FROM user WHERE id={$_SESSION['id']}";
try {
$db = getConnection();
$stmt = $db->query($sql);
$user = $stmt->fetch(PDO::FETCH_OBJ);
if($user->photocount<9){
$filename = explode(".",$_FILES['upload_file']['name']);
$ext = end($filename);
$ctime = time();
$filename = $ctime.$_SESSION['id'].".".$ext;
header('content-type:text/html charset:utf-8');
if(!file_exists($_FILES['upload_file']['name'])) move_uploaded_file($_FILES['upload_file']['tmp_name'],"uploads/" .$filename);
$resizeimage = new resizeimage("uploads/".$filename, "160", "160", "1","uploads/small/".$filename);
$sql = "INSERT INTO photo (uid,thumbnail,original) VALUES('{$_SESSION['id']}','http://chongai.co/m/uploads/small/{$filename}', 'http://chongai.co/m/uploads/{$filename}')";
$sqll = "UPDATE user SET photocount=photocount+1 WHERE id={$_SESSION['id']}";
try {
$stmt = $db->query($sql);
$stmt = $db->query($sqll);
$sql = "SELECT id FROM photo WHERE thumbnail='http://chongai.co/m/uploads/small/{$filename}'";
$stmt = $db->query($sql);
$img = $stmt->fetch(PDO::FETCH_OBJ);
$db = null;
echo '{"status": ' . json_encode("Upload Success") . ',"file": ' . json_encode("http://chongai.co/m/uploads/small/{$filename}") . ',"id": ' . json_encode($img->id) . '}';
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}else{
echo '{"status": ' . json_encode("You can only upload 8 photos") . '}';
}
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
顺便说一句:我的网络服务器是 nginx。
任何帮助都会很棒!这!