gpt4 book ai didi

xss - 确定 XSS 攻击漏洞

转载 作者:行者123 更新时间:2023-12-02 07:40:05 36 4
gpt4 key购买 nike

我正在经历一场无情的 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:&nbsp;'.htmlspecialchars($song_arr[$k]).'<br>Artist:&nbsp;'.htmlspecialchars($artist_arr[$k]).'<br>Submitted By:&nbsp;'.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 不断出现在我的索引页的绝对底部,其中我包含()上述所有三个文件,其内容位于不同的文件中。

有什么想法吗?

最佳答案

在电子邮件表单中,您回显所提交的无效电子邮件地址,而没有转义它们。更改此行:

 echo '"' . $address . '" is not a valid email address. Please try again.';

 echo '"' . htmlspecialchars($address) . '" is not a valid email address. Please try again.';

关于xss - 确定 XSS 攻击漏洞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2321509/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com