常见的php命令执行函数有哪些,可以通过什么函数过滤

请先 登录 后评论

5 个回答

阿蓝

php中命令执行函数有system、exec、popen、passthru、sell_exec等

请先 登录 后评论
donky16

system(), exec(), popen(), passthru(), shell_exec()函数

可以设置disable_functions来进行过滤

请先 登录 后评论
SNCKER

system()
passthru()   # passthru — 执行外部程序并且显示原始输出。
exec()       # exec — 执行一个外部程序。
shell_exec() # shell_exec — 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。
反引号 # shell_exec缩写。
popen()
proc_open()
pcntl_exec()

如果系统不需要执行命令建议配置disable_functions禁用

disable_functions = exec,passthru,popen,proc_open,shell_exec,system,assert,chroot,getcwd,scandir,unlink,delete,rmdir,rename,chgrp,chmod,chown,fopen,copy,mkdir,file,file_get_contents,fputs,fwrite,dir,putenv

需要用到且参数由用户输入则可以使用转义函数如:addcslashes,防止用户注入命令

请先 登录 后评论
空城 - 安全小菜鸡

PHP执行系统命令的有几个常用的函数:

如有:system函数、exec函数、popen函数,passthru函数,shell_exec函数他们都可以执行系统命令

以及反引号运算符:反引号``。PHP将尝试将反引号中的内容作为外壳命令执行,并将其输出信息作为返回值返回,效果与函数shell_exec()相同


防御:

1、减少命令执行函数的使用,并在disable_functions中禁用

2、在进入命令执行的函数或方法之前,对参数进行过滤。

3、参数的值尽量使用引号包裹,并在拼接前调用addslashes进行转义

这个文章还不错

https://blog.csdn.net/qq_43168364/article/details/105595532



请先 登录 后评论
萬種
系统命令的函数有
  1. system()
  2. passthru()
  3. exec()
  4. shell_exec()
  5. popen()
  6. proc_open()
  7. pcntl_exec()
请先 登录 后评论
  • 4 关注
  • 0 收藏,5861 浏览
  • Mondaycry 提出于 2021-10-22 14:46

相似问题