Use SELinux to protect your Apache

Source: Internet
Author: User
Use SELinux to protect your Apache-general Linux technology-Linux technology and application information. The following is a detailed description. SELinux can be used to ensure that your website does not have to withstand real harm. You can use the SELinux type to create an exact definition: What a service can do and where it can do it. By default, the httpd_sys_content type is set to/var/www, which specifies that the httpd process can work in this directory. You can configure it with three commands.

AD:


Your Web server may indeed be attacked, but SELinux can be used to ensure that your website does not have to withstand real harm.

You can use the SELinux type to create an exact definition: What a service can do and where it can do it. By default, the httpd_sys_content type is set to/var/www, which specifies that the httpd process can work in this directory. If attackers break the Apache Web server and try to write data elsewhere, like the default/tmp of similar Linux versions such as RedHat, Fedora, and CentOS, you need to know what you are working on. If you configure Apache to serve the content in the/data directory, SELinux will also prevent this by default.

Many Linux administrators disable SELinux because these default settings may cause complexity. Although disabling SELinux makes it easier for your server to provide services, it still increases security risks.

Set SELinux management for Apache

Setting SELinux management for services such as Apache is not difficult. The problem is that there is no simple graphic tool for you to install quickly. However, you only need to use three commands to configure it.

To set the file type in the directory you want the service to access, you must first determine the file system type to use. To do this, simply enter ls in the default directory used by the service? LdZ.

For Apache, do you use ls? LdZ/var/www. You will notice that in this case ,? The Z option provides additional file attributes, while? T option is the most critical one. This process specifies the existing file system type, which is set by Apache (httpd_sys_content_t ). This is also the file type you need to set according to the new file root.

You can use two commands to set your content format: You can use chcon to make a temporary change, and it disappears after restart; Use the semanage followed by followed, you can make permanent changes.

The semanage command seems complicated, but it is actually very simple, because you only need to change the type and target directory you want to use. In the following example, you only need to change two parameters.

Semanage fcontext-a-t httpd_sys_content_t/web (/.*)/? After using semanage to set the default file type, use the restorecon command to ensure that it is applied. In the preceding example, if the directory/web file type is changed to allow Apache to access the server file in that directory, run the following command to apply the change:

In this regard, Apache will be able to serve files in the new non-default file root directory.

Manage boolean values for SELinux

Another aspect of SELinux you need to manage is the Boolean value of SELinux. These are binary values that enable or disable some features. Boolean values can be obtained from multiple services. Use getsebool? A command to get an overview of the entire existing boolean value. This command will usually list the settings you can apply into a long list.

Do you want the service you want to configure to find all boolean values and transmit all getsebool through grep? A output. For example, use getsebool? A | grep http to find all boolean values that match the row http. Even if you do not have a clear understanding of all boolean values, you can still understand them by observing their names and what they may do.

Use getsebool-a to find out which SELinux can be used to modify Service Behavior:

[Root @ bia Desktop] # getsebool-a | grep http
Allow_httpd_anon_write --> off
Allow_httpd_mod_auth_ntlm_winbind --> off
Allow_httpd_mod_auth_pam --> off
Allow_httpd_sys_script_anon_write --> off
Httpd_builtin_scripting --> on
Httpd_can_check_spam --> off
Httpd_can_network_connect --> off
Httpd_can_network_connect_cobbler --> off
Httpd_can_network_connect_db --> off
Httpd_can_network_relay --> off
Httpd_can_sendmail --> off
Httpd_dbus_avahi --> on
Httpd_enable_cgi --> on
Httpd_enable_ftp_server --> off
Httpd_enable_homedirs --> off
Httpd_execmem --> off
Httpd_read_user_content --> off
Httpd_setrlimit --> off
Httpd_ssi_exec --> off
Httpd_tmp_exec --> off
Httpd_tty_comm --> on
Httpd_unified --> on
Httpd_use_cifs --> off
Httpd_use_gpg --> off
Httpd_use_nfs --> off
After learning which Boolean value you want to use, use setsebool-P to apply them. If you want Apache to use nfs, use setsebool-P http_use_nfs. To obtain a complete list of all available boolean values, consult the httpd_selinux page, which explains the Apache-specific file labels and boolean values.

Original article:
CODE: http://www.searchsv.com.cn/showcontent_53067.htm

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.