title: Simulate XSS attack
body: <p>I was trying to simulate the browser (and simulate XSS). Someone recommended me PhantomJS, however, I had some problems with executing simple JS commands.</p>
  
  <p>I've created simple php website: xss.php</p>
  
  <pre><code>&lt;form id = "myform"  action="xss.php" method="POST"&gt;
  &lt;input id="x" name='x'  type="text" /&gt;
  &lt;input type="submit" value="ok" /&gt;
  &lt;/form&gt;
  &lt;?php
    echo $_POST['x'];
    $fp = fopen("logs.txt", "a");
    fwrite($fp, $_POST['x']);
    fclose($fp);
  ?&gt;
  &lt;script&gt;document.getElementById('x').value='payload';
  document.getElementById('myform').submit();&lt;/script&gt;
  </code></pre>
  
  <p>When I run it from my browser, the form is sent (and its results its put into logs.txt. However, there is a problem, while trying to run that website via PhantomJS:</p>
  
  <p>run.js:</p>
  
  <pre><code>var page = require('webpage').create();
  var url = 'http://127.0.0.1/xss/xss.php';
  page.open(url, function (status) {
      if (status !== 'success') console.log('Network error');
      else
      {
           var p = page.evaluate(function () {
          });
          console.log('DONE');
  
      }
      phantom.exit();
  });
  </code></pre>
  
  <p>I run it via command line: <code>./phantomjs run.js</code>
  As far as I understand, this script should simulate the browser behavior and send the above form. However, there is nothing in logs.txt, which means, that phantomjs didn't run that script. Could you please tell me what I did wrong?</p>