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 varwww, which specifies that the httpd process can
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,HttpdThe _ 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 Red Hat and FEdOra, CentOS, and other similar Linux versions of default/tmp, 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, only threeCommandYou can configure it.
To setFile. Html 'target = '_ blank'>File TypeFirst, you must determine the file system type to use. To do this, you only need to enterLs? 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, useRestoreCon command to make sure 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:
Restorecon-R-v/web
At this point, 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.
Find all the Boolean values for the service you want to configureGrepTransfer all getsebool? 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, useSetSebool-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.