linux系統中 SElinux安全子系統

小鯊魚2020發表於2020-11-22

1、SElinux 是什麼?

SElinux(Security-Enhanced Linux)是美國國家安全域性在linux開源社群的幫助下開發的一個強制訪問控制(Mandatory Access Control)的安全子系統。使用SElinux技術的目的是為了讓各個服務程式都受到約束,使其僅獲取到本應獲取的資源

 

SElinux能夠從多方面監控違法行為:對服務程式的功能進行限制SElinux域限制可以確保服務程式做不了出格的事情);對檔案資源的訪問限制SElinux安全上下文確保檔案資源只能被其所屬的服務程式進行訪問)。

 

2、SElinux服務有三種配置模式

  • enforcing:強制啟用安全策略模式,將攔截服務的不合法請求
  • permissinve:遇到服務越權訪問時,只發出警告而不強制攔截
  • disabled:對於越權的行為不警告也不攔截

 

3、 SElinux的配置檔案為/etc/selinux/config, 預設的模式為enforcing。

[root@PC1linuxprobe /]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

 

4、為了驗證SElinux效果,首先檢視 httpd服務的主配置檔案,關注此時的網站資料目錄,及httpd服務程式的預設首頁

[root@PC1linuxprobe /]# vim /etc/httpd/conf/httpd.conf

 

 

檢視網站資料目錄下檔案:

[root@PC1linuxprobe /]# ls /home/wwwroot/
index.html
[root@PC1linuxprobe /]# cat /home/wwwroot/index.html
xxxxyyyyyyzzzz

 

檢視此時httpd服務程式的首頁:

 

 

5、getenforce命令可以用來檢視SElinux當前的執行模式,setenforce命令可以修改SElinux當前的執行模式(0為禁用,1未啟用,臨時生效)

[root@PC1linuxprobe /]# getenforce   ## 檢視此時SElinux服務模式
Enforcing
[root@PC1linuxprobe /]# setenforce 0  ## 設為禁用
[root@PC1linuxprobe /]# getenforce
Permissive

 

看此時的httpd服務首頁:

 

 

6、解釋

 httpd服務程式的功能是允許使用者訪問網站內容,因此SElinux可定會預設放行使用者對網站的請求操作。但是,我們將網站資料的預設儲存目錄修改為了/home/wwwroot,這就產生問題了。 /home目錄是用來存放普通使用者的家目錄資料的,而現在,httpd提供的網站服務卻要去獲取普通使用者家目錄中的資料了,這顯然違反了SElinux的監管原則。

 

7、擁有不同的SElinux安全上下文值?????

[root@PC1linuxprobe /]# setenforce 1
[root@PC1linuxprobe /]# ls -lZ /var/www/html/
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[root@PC1linuxprobe /]# ls -lZ /home/wwwroot/
-rw-r--r--. root root unconfined_u:object_r:home_root_t:s0 index.html

 

相關文章