首页 > 解决方案 > 试图创建一个容易受到邮件头注入的表单

问题描述

被困在这几天了。我正在尝试重现我发现的邮件标头注入示例(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>

标签: phppostunicode

解决方案


推荐阅读