Effective defense against PHP Trojan attacks

Source: Internet
Author: User
1. Avoid jumping out of the web directory and first modify httpd. conf. If you only allow Your php script program to operate in the web directory, you can also modify the httpd. conf file to limit the php operation path. For example, if your web directory is usrlocalapachehtdocs, add the following lines to httpd. conf: php_admin_valueopen_basedirusrlo.

1. Avoid jumping out of the web directory and first modify httpd. conf. If you only allow Your php script program to operate in the web directory, you can also modify the httpd. conf file to limit the php operation path. For example, if your web directory is/usr/local/apache/htdocs, add the following lines to httpd. conf: php_admin_value open_basedir/usr/lo

1. Prevent jumping out of the web directory

First, modify httpd. conf. If you only allow Your php script program to operate in the web directory, you can also modify the httpd. conf file to limit the php operation path. For example, if your web directory is/usr/local/apache/htdocs, add the following lines in httpd. conf:

Php_admin_value open_basedir/usr/local/apache

/Htdocs

In this way, files other than/usr/local/apache/htdocs to be read by the script will not be allowed. If the error is displayed, the following error will be prompted:

Warning: open_basedir restriction in effect. File is in wrong directory in

/Usr/local/apache/htdocs/open. php on line 4

And so on.

2. Prevent php trojans from executing webshell

Enable safe_mode,

Set in, php. ini

Disable_functions = passthru, exec, shell_exec, system

Select either of them.

3. Prevent php trojans from reading and writing file directories

In php. ini

Disable_functions = passthru, exec, shell_exec, system

Add the php file processing function.

Mainly include

Fopen, mkdir, rmdir, chmod, unlink, dir

Fopen, fread, fclose, fwrite, file_exists

Closedir, is_dir, readdir. opendir

Fileperms. copy, unlink, delfile

Become

Disable_functions = passthru, exec, shell_exec, system, fopen, mkdir, rmdir, chmod, unlink, dir

, Fopen, fread, fclose, fwrite, file_exists

, Closedir, is_dir, readdir. opendir

, Fileperms. copy, unlink, delfile

Okay, it's done. We have no choice but to use the php Trojan. Unfortunately, those things that use the text database won't work anymore.

If apache is built on the windos platform, we still need to note that apache runs the system permission by default, which is terrible, which makes people feel uncomfortable. let's drop apache permissions.

Net user apache fuckmicrosoft/add

Net localgroup users apache/del

OK. We have created a user apche that does not belong to any group.

Open the computer manager, select a service, click the apache service attribute, Select log on, select this account, fill in the account and password created above, restart the apache service, OK, apache runs under low permissions.

In fact, we can also set the permissions for each folder so that apache users can only execute what we want it to do, and create a separate user for each directory to read and write. This is also a popular configuration method for many VM providers. However, this method is used to prevent minor usage.

Differences between php_admin_value and php_value

The php_admin_value (php_admin_flag) command can only be used in the httpd. conf file of Apache, while php_value (php_flag) is used in the. htaccess file.

If php_admin_value is added to the file to be uploaded, you can write it like this.

Php_admin_value open_basedir "/usr/local/apache/htdocs/www:/tmp" l

Note: The two directories are separated by colons (in Linux ).

In Windows, replace the colon with a semicolon:

Php_admin_value open_basedir "d:/www/mysite; c:/windows/temp"

/Temp is the default cache directory of your system. It is usually unclear. You can check phpinfo.

CentOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.