通过我的联系表检查,我发现了跨站点脚本漏洞,但没有足够的知识来解决这个问题。
受影响的参数:name 使用的向量:">alert(document.cookie) 发现模式:\">alert(document.cookie) 完整攻击:/http://############## ###/contact.php [name=\">alert(document.cookie) &email= &message=]
受影响的参数:电子邮件 使用的向量:">alert(document.cookie) 发现模式:\">alert(document.cookie) 完整攻击:/http://############## ###/contact.php [name= &email=\">alert(document.cookie) &message=]
受影响的参数:消息 使用的向量:">alert(document.cookie) 发现模式:\">alert(document.cookie) 完整攻击:/http://############## ###/contact.php [name= &email= &message=\">alert(document.cookie)]
我当前的表单代码如下所示
<?php
if (isset($_POST['submit'])) {
$error = "";
if (!empty($_POST['name'])) {
$name = $_POST['name'];
if (!preg_match('/^[a-zA-Z0-9]+$/i', $name)){
$error .= "The name you entered is not valid. <br/>";
}
} else {
$error .= "You didn't type in your name. <br />";
}
if (!empty($_POST['email'])) {
$email = $_POST['email'];
if (!preg_match("/^[_a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){
$error .= "The e-mail address you entered is not valid. <br/>";
}
} else {
$error .= "You didn't type in an e-mail address. <br />";
}
if (!empty($_POST['messagesubject'])) {
$messagesubject = $_POST['messagesubject'];
} else {
$error .= "You didn't type in a subject. <br />";
}
if (!empty($_POST['message'])) {
$message = $_POST['message'];
} else {
$error .= "You didn't type in a message. <br />";
}
if(($_POST['code']) == $_SESSION['code']) {
$code = $_POST['code'];
} else {
$error .= "The captcha code you entered does not match. Please try again. <br />";
}
if (empty($error)) {
$from = 'From: ' . $name . ' <' . $email . '>';
$to = "aaron@fosternetwork.co.uk";
$subject = strip_tags("CWS - Contact Us - \n" . $messagesubject);
$content = strip_tags("Name: " . $name . "\nSubject: " . $messagesubject . "\nMessage: \n" . $message);
$success = "<h2>Thank you! <span>Your message has been sent!</span></h2>";
mail($to,$subject,$content,$from);
$emailSent = true;
}
}
?>
形式
<form action="contact.php" method="post">
<label>Name:</label>
<input type="text" name="name" value="<?php if ($_POST['name']) { echo $_POST['name']; } ?>" />
<label>Email:</label>
<input type="text" name="email" value="<?php if ($_POST['email']) { echo $_POST['email']; } ?>" />
<label>Subject:</label>
<input type="text" name="messagesubject" value="<?php if ($_POST['messagesubject']) { echo $_POST['messagesubject']; } ?>" />
<label>Message:</label><br />
<textarea name="message" rows="20" cols="20"><?php if ($_POST['message']) { echo $_POST['message']; } ?></textarea>
<label>Please input the following code: <img src="captcha.php"></label>
<input type="text" name="code"> <br />
<button type="submit" class="colorButton" name="submit" value="Send message">Send Message</button>
</form>
非常感谢任何帮助。