You can use the following 5 functions to execute an external application or function in PHP:
string System (string command,int &Return_var) Note: command to execute commands, Return_var A status value that holds the execution of the execution of the command;string exec (string command,array &output,int $return _var) Note: Output obtains the execution name for each line of the string void PassThru (string command,int &Return_var) string shell_exec (string command) ": same function as Shell_exec
# # Vulnerability Example # #
<? PHP error_reporting (0); $dir=$_get[' dir ']; if (isset($dir)) { system("Ls-al"). $dir); } ? >
# eval Injection Attack #
# # Vulnerability Example # #
<? PHP $var= "var"; if (isset($_get[' arg '])) { $arg=$_get[' Arg ']; Eval ("\ $var =$arg;" ); Echo "\ $var =". $var ; } ? >
# dynamic Function #
# # Vulnerability Example # #
<? php func A () { dosomething (); } Func B () { dosomething (); } if (isset($_get["func"])) { $myfunc=$_get["func"] ; Echo $myfunc (); } ? >
# Defense Method #
1 , try not to execute external commands 2 , using custom functions or libraries to override the functionality of external commands 3 , using the Escapeshellarg function to handle command parameters 4 , using Safe_mode_exec_dir to specify the path to the executable Esacpeshellarg function will escape any character that causes the argument or command to end, single quote "'", replace with "\", double quote "" ", replace with" \ "", semicolon ";" Replace with "\;" Using Safe_mode_exec_dir to specify the path to the executable file, you can put the command that will be used into this path in advance = on safe_mode_exec_di r=/usr/local/ php/bin/
php_audit--Command Injection attack