-3

I want use the PHP script for execution commands from address bar.

For example :

the-site.com/shell.php?exec=ls%20/

In browser I see this result :

bin
lib
etc
home
usr

1 Answers1

1

You can do this, but I'd advise against it - you're opening yourself up to all kinds of trouble.

Consider accidentally sending rm -rf /.

If you must do this, use a (white)list of tried and tested commands and only allow your script to execute these, then restrict access to the script's entry-point to your internal network only.

I'd post some code for you but, to be honest, I'd worry that you would just use it without testing it - or more importantly understanding it.

Essentially, you're looking at something like:-

$whitelist = array(/* list of allowed commands */);

if (/* command in whitelist */) {
    execute();
}

You'll do doubt be needing to pass parameters to your scripts at some point, so make you sure you validate and escape them too. Here's an interesting post with some pointers and links for you to read:-

Best way to sanitize exec command with user inserted variables

Community
  • 1
  • 1
Anthony Sterling
  • 2,451
  • 16
  • 10