search
Homephp教程php手册php中禁止危险php函数的例子

在php中我们如果想让系统函数不被执行可以在php.ini中加上Disable_functions后面跟函数名就可以了.

禁用方法如下:打开/etc/php.ini文件,搜索定位到这行:

1.disable_functions = 

添加需禁用的函数名,比如如下代码:

phpinfo,eval,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen

相反的如果要运行php运行某个函数删除相应的函数即可,但文章有个“eval”函数,这个不是系统函数所以无法禁止不信大家可试下.

以上只是列了部分不叫常用的文件处理函数,你也可以把上面执行命令函数和这个函数结合,就能够抵制大部分的phpshell了.

但是我后来看一文章告诉我们这样做不是万能的在linux中可以直接突破Disable_functions执行Linux命令,代码如下:

<?php  
	//PHP4调用方法  
	dl(&#39;../../../../../home/apache/htdocs/php4.so&#39;);  
	biguanspider(&#39;uname -a&#39;);//调用函数  
	 www.phprm.com 
	//开源代码phprm.com 
	<?php  
	//PHP5调用方法  
	dl(&#39;../../../../../home/apache/htdocs/php5.so&#39;);  
	spiderbiguan(&#39;uname -a&#39;);//调用函数  
	 

很多管理员在封杀PHP危险函数的时候一般都是这样的:disable_functions = proc_open,exec,passthru,shell_exec,system,popen

但是如果编译PHP时带–enable-pcntl参数就危险了,可以用pcntl_exec函数执行指定程序,也可以反弹一个SHELL,在PHPINFO里查看编译参数.

描述:pcntl_exec — 在当前进程空间执行指定程序,具体的做法我就不写了,所以linux安全还是得从本身设置不要想到php这样配置就KO了.

教程链接:

随意转载~但请保留教程地址★

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),