-1

I need to allow the following:

shell_exec('whois ' . $domain);

BUT I need to disallow everything else, like:

shell_exec('ls');
shell_exec('rm -rf /');
shell_exec('sudo service nginx restart');

is it possible to "whitelist" only one shell_exec command?

Dayo
  • 12,413
  • 5
  • 52
  • 67
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51

2 Answers2

2

If it's about some script — just don't pass user input into shell_exec argument, call it when some param matches some value

if ($_GET['cmd'] === 'whois') {
    shell_exec('whois whatever');
}

If it's about kind of hosting, then you should restrict access to data using OS permissions. So user will be able to call shell_exec('rm -rf /') but nothing will happen.

ksimka
  • 1,394
  • 9
  • 21
1

Maybe its not really the answer to your question but:

you can check it with php:

if(substr( $command , 0, 5 ) === "whois"){
  shell_exec($command );
}

but still i dont think its smart to put user input in shell_exec but if you really want it i should check everthing first with php

Rickert
  • 1,677
  • 1
  • 16
  • 23