I have this code :
$cmd = escapeshellcmd($_GET['command']);
$cmd2 = escapeshellcmd($_GET['command2']);
exec("program" . $cmd . $cmd2);
And I want know if is secure to allow any person to use it with an html form ?
I have this code :
$cmd = escapeshellcmd($_GET['command']);
$cmd2 = escapeshellcmd($_GET['command2']);
exec("program" . $cmd . $cmd2);
And I want know if is secure to allow any person to use it with an html form ?
No, don't let using escapeshellcmd
or escapeshellarg
give you a false sense of security. Passing values directly to the commandline even escaped without any form of validation is asking for trouble.
If you are adamant I'd advise reading the following discussion:
What's the difference between escapeshellarg and escapeshellcmd?
You need to whitelist allowed commands.
$cmd = escapeshellcmd($_GET['command']);
$cmd2 = escapeshellcmd($_GET['command2']);
$allowed_cmds = array('ls', 'foo', ...);
if(in_array($cmd, $allowed_cmds)) {
if(in_array($cmd2, $allowed_cmds)) {
exec("program" . $cmd . $cmd2);
}
}
Personally though, you are doing something wrong. I've written socket systems, websites, database abstractions, language processing libraries, email servers, regex parsers, and a whole slue of other things.
I've never needed the nasty, slow exec
.