(PHP 4, PHP 5)
escapeshellcmd — shell 元字符轉義
說明
string escapeshellcmd ( string$command
)
escapeshellcmd() 對字符串中可能會欺騙 shell 命令執行任意命令的字符進行轉義。 此函數保證用戶輸入的數據在傳送到 exec() 或 system() 函數,或者 執行操作符 之前進行轉義。
反斜線()會在以下字符之前插入: #&;`|*?~<>^()[]{}$, x0A 和 xFF。 ' 和 " 僅在不配對兒的時候被轉義。 在 Windows 平臺上,所有這些字符以及 % 都會被空格代替。(譯注:實際測試發現在 Windows 平臺是前綴 ^ 來轉義的。)
參數
command
要轉義的命令。
返回值
轉義后的字符串。
范例
Example #1 escapeshellcmd() example
<?phpWarning
// 我們故意允許任意數量的參數
$command = './configure '.$_POST['configure_options'];
$escaped_command = escapeshellcmd($command);
system($escaped_command);
?>
escapeshellcmd() 應被用在完整的命令字符串上。 即使如此,攻擊者還是可以傳入任意數量的參數。 請使用 escapeshellarg() 函數 對單個參數進行轉義。
參見
escapeshellarg() - 把字符串轉碼為可以在 shell 命令里使用的參數 exec() - 執行一個外部程序 popen() - 打開進程文件指針 system() - 執行外部程序,并且顯示輸出 執行運算符