php - 试图创建一个容易受到邮件头注入的表单
问题描述
被困在这几天了。我正在尝试重现我发现的邮件标头注入示例(http://www.phpsecure.info/v2/article/MailHeadersInject.en.php)。关于此事的帖子已经存在(电子邮件标头注入 - 示例不起作用),但它没有任何解决方案。我使用 POST 方法获得了一个基本的联系表单,其中包含三个字段(发件人、主题和消息),然后用于发送邮件。我需要用户能够在字段中输入 Unicode/Hexa 字符。
例如,如果用户输入address%40gmail%2ecom
我希望 SMTP 有效负载中的输出为From: address@gmail.com
如果我硬编码$from = "address%40gmail%2ecom"
输出是想要的。
但是,如果我在表单的“来自”字段中使用用户输入,即$from = $_POST['from']
检查 SMTP 客户端的调试日志时得到的输出是From: address%40gmail%2ecom
. 我是在编码方面做错了什么,还是我必须摆脱一些保护措施?
如果这是相关的,我正在使用 WAMPserver 和 PHP 7.1。
我的代码:
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<title>Vulnerable contact page</title>
<link rel="stylesheet" href="email.css"/>
</head>
<body>
<form method="POST" action="">
<fieldset>
<legend>Send us a mail</legend>
<label for="sender">From : </label>
<input type="text" name="from" id="sender">
</br>
<label for="subject">Subject : </label>
<input type="text" name="subject" id="subject">
</br>
<label for="message">Your message : </label>
<input type="text" name="message" id="message">
</fieldset>
<p>
<input type="submit" value="Send"/>
<input type="reset" value="Cancel"/>
</p>
</form>
<?php
if(isset($_POST['from'])) {
$to = "*********@gmail.com";
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $from\n";
mail($to, $subject, $message, $headers);
}
?>
</body>
</html>
解决方案
推荐阅读
- list - 如何知道二维列表包含颤动中的另一个列表
- sql - 如何检查给定日期范围内的帐户余额是否有变化
- xamarin - Xamarin Forms Android Paddings 未在 CollectionView 中显示
- python - 清单中的库存编号
- asp.net - 表格中未显示 VBnet 编辑/删除按钮
- powershell - 从全名获取目录,重命名目录
- angular - Angular Element - 将 Shadow DOM 设置为关闭
- r - 未渲染绘图时,Shiny 会保留空白的空白空间
- php - 自定义验证联系表格7
- c# - 使用错误编码保存赎回文件(可能)