我正在经历一场似乎无法阻止的无情的XSS攻击。我的网站上总共有三个输入表单-一个用于上传图片,一个用于向页面添加评论,第三个用于通过php发送电子邮件。我正在以这样或那样的方式保护他们所有人,但不知何故,漏洞仍然存在。
我的评论代码:
for($j = 0; $j < 3 ; $j++)
{
$s = $styles[array_rand($styles)];
if($song_arr[$k] != '' && $artist_arr[$k] != '' && $name_arr[$k] != '')
{
echo '<td>';
echo '<div class="'.$s.'" style="clear:left" >';
echo '<p class="rendom">';
echo 'Song: '.htmlspecialchars($song_arr[$k]).'<br>Artist: '.htmlspecialchars($artist_arr[$k]).'<br>Submitted By: '.htmlspecialchars($name_arr[$k]);
echo '</p>';
echo '</div>';
echo '</td>';
}
$k++;
}上传表单:
if ((($_FILES["userfile"]["type"] == "image/jpg")
|| ($_FILES["userfile"]["type"] == "image/jpeg")
|| ($_FILES["userfile"]["type"] == "image/pjpeg"))
&& ($_FILES["userfile"]["size"] < 20000)) {
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
if (move_uploaded_file ($_FILES['userfile']['tmp_name'],'userfile.jpg')) {
$image = new SimpleImage();
$image->load('userfile.jpg');
$image->resize(29,136);
$image->save('userfile.jpg');
?>
<img src="img/text/uploadSuccess.jpg" alt="Image uploaded successfully." /><br />
<br />
<img src="userfile.jpg?rand=<? echo rand(1,10000); ?>" />
<?
} else {
echo 'Moving uploaded file failed';
}
} else {
echo 'File upload failed';
}
} else {
echo 'Invalid Filetype';
}电子邮件表单:
<?php
// Process input variables (trim, stripslash, reformat, generally prepare for email)
$recipients = trim($_POST['recipients']);
$sender_email = trim($_POST['sender_email']);
$sender_name = stripslashes(trim($_POST['sender_name']));
$subject = stripslashes(str_replace(array("\r\n", "\n", "\r"), " ", trim($_POST['subject'])));
$message = stripslashes(str_replace(array("\r\n", "\n", "\r"), "<br />", trim($_POST['message'])));
// Check email addresses for validity
// Explode the comma-separated list of recipients + the sender email address into an array. Even if there is only one recipient, this will check for validity.
$addresses = explode("," , $recipients.",".$sender_email);
// For each email address specified...
foreach ($addresses as $address) {
// If the email address doesn't match the RFC8622 spec regex, assume invalid
if (!(preg_match("~^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+(?:[A-Z]{2}|com|org|net|uk|edu|jp|de|br|ca|gov|au|info|nl|fr|us|ru|it|cn|ch|tw|es|se|be|dk|pl|at|il|tv|nz|biz)$~i", trim($address)))) {
// Output error message for invalid email address and end script.
echo '"' . $address . '" is not a valid email address. Please try again.';
return;
}
}
// Check other vars are not empty
if ((empty($sender_name)) OR (empty($subject)) OR (empty($message))) {
// Output error message and end script.
echo 'Please complete all form fields and try again.';
return;
}
// Send HTML email
$headers = "MIME-Version: 1.0\r\nContent-type:text/html;charset=iso-8859-1\r\nFrom: ". $sender_name ." <". $sender_email ."> \n\n";
if (mail($recipients,$subject,$message,$headers)) {
// Mail successfully sent, output success message and end script
echo 'Message sent. We will be in touch with you shortly.';
return;
} else {
// Something unknown went wrong. =(
echo 'Something went wrong which the little worker monkeys could not fix. Please try again.';
return;
}
?>XSS一直显示在我的索引页的绝对底部,我在其中包含了上面所有三个文件,它们的内容都在不同的文件中。
有什么想法吗?
发布于 2010-02-24 04:54:15
在电子邮件表单中,您可以回显提交的无效电子邮件地址,而不对其进行转义。更改此行:
echo '"' . $address . '" is not a valid email address. Please try again.';至
echo '"' . htmlspecialchars($address) . '" is not a valid email address. Please try again.';发布于 2010-02-24 04:48:48
快速浏览一下,似乎显示不受信任数据的唯一位置是在注释中。您还使用了htmlspecialchars,它可以防止任何html代码被解释。
您说恶意代码位于页面的底部。也许攻击者找到了在你的服务器上上传并包含他的脚本目录的方法?所包含的代码是什么样子的?是JavaScript还是HTML?
发布于 2010-03-02 08:54:20
这不是一个答案,也不是一个好消息,但我确实看到了一些与您在Youtube上令人不安的视频广告“宙斯:克里米亚工具包之王”中描述的非常相似的东西:http://www.youtube.com/watch?v=hfjPO8_pGIk
无论如何,这段视频都值得一看。
我和赛门铁克没有任何关系。
https://stackoverflow.com/questions/2321509
复制相似问题