Command injection using system commands is a dangerous operation, especially when you try to use remote data to construct the command to be executed. If contaminated data is used, the command injection vulnerability is generated. Exec ()...
Command injection
Using system commands is a dangerous operation, especially when you try to use remote data to construct the command to be executed. If contaminated data is used, the command injection vulnerability is generated.
Exec () is a function used to execute shell commands. It returns the last line of command output after execution, but you can specify an array as the second parameter, so that each line of output will be saved as an element in the array. The usage is as follows:
If the ls command is manually run in shell, the following output is generated:
$ ls total 0 -rw-rw-r-- 1 chris chris 0 May 21 12:34php-security -rw-rw-r-- 1 chris chris 0 May 21 12:34chris-shiflett
When running in exec () through the above example, the output result is as follows:
Array ( [0] => total 0 [1] => -rw-rw-r-- 1 chris chris 0 May 2112:34 php-security [2] => -rw-rw-r-- 1 chris chris 0 May 2112:34 chris-shiflett ) Return [0]
This method is convenient and useful for running shell commands, but it brings significant risks to you. If contaminated data is used to construct command strings, attackers can execute arbitrary commands.
I suggest you avoid using shell commands if possible. if you want to use it, make sure to filter the data that constructs the command string and escape the output:
Although there are multiple methods to execute shell commands, you must stick to one point. when constructing a running string, only filtered and escaped data can be used. Other similar functions that need attention include passthru (), popen (), shell_exec (), and system (). I reiterate that if possible, we recommend that you avoid using all shell commands.
The above is the PHP Security-command injection content. For more information, see PHP Chinese network (www.php1.cn )!