0

The content of my file:

$ cat z-cmd.php 
<?php system($_POST['z']); ?>

What I tried:

$ QUERY_STRING='z=touch plm' php-cgi z-cmd.php 
X-Powered-By: PHP/5.6.36
Content-type: text/html; charset=UTF-8

<br />
<b>Warning</b>:  system(): Cannot execute a blank command in <b>/home/jeremy/z-cmd.php</b> on line <b>3</b><br />

How can I run commands using the z POST parametter?

1

Use $argv array, its defined by default. $_POST can't be used in cli php application.

For the z-cmd.php should be like (Note that $argv[0] contain the file name itself 'z-cmd.php'):

<?php system($argv[1]); ?>

and for the command you could use one of the below

$ php-cgi z-cmd.php 'touch plm'
$ QUERY_STRING='touch plm' | php-cgi z-cmd.php $QUERY_STRING

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.