前言
PHP命令执行漏洞
应用程序的某些功能功能需要调用可以执行系统命令的函数,如果这些函数或者函数的参数被用户控制,就有可能通过命令连接符将恶意命令拼接到正常的函数中,从而随意执行系统命令,这就是命令执行漏洞。
基本函数
1.system()用于执行外部程序,并且显示输出
<?php system('whoami'); ?>
2.exec()函数用于执行一个外部程序
<?php exec('whoami');?>
3.shell_exec()函数通过shell环境执行命令,并且将完整的输出以字符串的方式返回
<?php shell_exec('whoami'); ?>
4.passthru函数用于执行外部程序并且显示原始输出
<?php passthru('whoami'); ?>
5.popen()函数用于打开进程文件指针
- r: 只读。
- w: 只写 (打开并清空已有文件或创建一个新文件)
<?php touch popen("3.txt","r"); ?> 在当前目录创建名为3.txt的文件
6.Proc_popen函数用于执行一个命令,并且打开来输入输出的文件指针(有问题)
proc_open (字符串 $cmd ,数组 $descriptorspec ,数组 &$pipes [,字符串 $cwd=NULL [,数组 $env=NULL[,数组 $other_options=NULL ]]])
<?php $proc=proc_open("whoami", array( array("pipe","r"), array("pipe","r"), array("pipe","r")),$pipes); print stream_get_contents($pipes[i]); ?>