SELinux基礎/激活或關閉SELinux/改變object的域/啟用或關閉程式功能
擷取更多幫助 《SELinux權威指南》
或許應該叫:如何了解Windows
Linux比Windows更安全,這樣說不合理.
安全等級: A>B>C>D
Linux(c2) Windows(c2)
GUI界面:MAC>Windows
圖形工作站:mac
Windows 專業普及計算機系統。圖形不如mac,又不夠安全。
SELinux基礎
1)通路模型
Linux原有通路模型:自主通路控制 DAC
安全隐患: 程序所能通路資源的範圍 為使用者所能通路的資源範圍
1
2
3
4
5
<code>後門: rootkit程式</code>
<code>程序被脅持:</code>
<code> </code><code>基于程序作為跳闆,就有了程序屬主的權限 </code>
<code> </code><code>root</code>
<code> </code><code>普通使用者--> 檢視其他檔案 --> 找到漏洞,提權操作</code>
SELinux通路模型: 強制通路機制 MAC
類似sandbox機制:程序啟動在一個沙箱内部,
為程序運作,啟用一個專用的沙箱
<code>sandbox 沙箱: 最小資源集合</code>
<code>程序脫離控制時,不能通路使用者所有能通路的檔案</code>
2)SELinux工作級别
<a href="https://s2.51cto.com/wyfs02/M00/A4/E7/wKioL1mz6YWBNZtlAAARy9FjKRo167.png" target="_blank"></a>
strict 嚴格級别 每個程序都受到SELinux的控制
targetted 有限個程序受SELinux控制,監控容易被入侵的程序
3)SELinux工作方式
subject(主語) operation(謂) object(賓)
subject: 程序
operation: 取決于被操作對象支援的模式 及 操作者是否在有效區域内
object: 程序、檔案、使用者
檔案: operation: open, read, write, close, chown, chmod
活動範圍(域):
subject: domain
object: type
4)SELinux安全标簽顯示
SELinux為每個檔案、程序提供安全标簽
檢視:
程序:ps axuZ
- 沒有激活SELinux
<code>例如:- root </code><code>26238</code> <code>3.0</code> <code>0.4</code> <code>4936</code> <code>1076</code> <code>pts/</code><code>0</code> <code>R+ </code><code>21</code><code>:</code><code>24</code> <code>0</code><code>:</code><code>00</code> <code>ps axuZ</code>
檔案: ls -Z 顯示SELinux的安全上下文
<code>例如:-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg</code>
user:role:type
user: SELinux的user
role: 角色,類似linux的組
type: 類型, 沙箱的範圍
subject: domain
object: type
object能被subject操作隻有:type是domain的子集:domain == type 或 domain包含type
激活SELinux
1)配置檔案位置:
<a href="https://s4.51cto.com/wyfs02/M01/A4/E8/wKioL1mz7FvQCZUuAAAcFRya6Cg261.png" target="_blank"></a>
2)SELinux狀态
擷取SELinux目前狀态
<code>getenforce</code>
設定狀态:目前有效,重新開機失效
<code>setenforce </code><code>#</code>
<code> </code><code>0 設定為permissive</code>
<code> </code><code>1 設定為enforce</code>
<a href="https://s2.51cto.com/wyfs02/M01/06/36/wKiom1mz7VDR3iMBAAATLYWfOQs953.png" target="_blank"></a>
enforcing 強制:受限的程序必然受限,不受限的程序不受限。
permissive 允許:受限的程序違規操作不會禁止,但會被記錄于審計日志中。 日志位置:/var/log/audit.log
disabled 關閉
3)激活或關閉SELinux
開啟selinux: disabled --> enforcing/permissive
<code>sed</code> <code>-i </code><code>'s,SELINUX=disabled,SELINUX=enforcing,'</code> <code>/etc/selinux/config</code>
開啟SELinux必須重新開機,在/重新挂載後,重新對所有檔案打标才可以對selinux操作
<a href="https://s1.51cto.com/wyfs02/M01/06/37/wKiom1mz7_jRvdMRAAAWGGVlWv0453.png" target="_blank"></a>
關閉selinux:enforcing/permissive --> disabled
<code>sed</code> <code>-i -r </code><code>'s@(SELINUX=)(enforcing|permissive)@\1disabled@'</code> <code>/etc/sysconfig/selinux</code>
激活SELinux後
1)程序通路檔案的安全上下文
1)、程序的屬主對檔案的權限,通過
2)、檔案的type是否是程序domain的子集
程序檢視規則庫,檢視程序所屬的domain是否被授權了能夠通路檔案所屬type
是:能通路
否:被SELinux規則所拒絕,并記錄至日志檔案中 /var/log/audit.log,審計:在合理的使用範圍内,程序對檔案可執行的合理的操作
<code>SELinux的規則庫:</code>
<code> </code><code>規則:哪種域能通路哪種或哪些和類型内檔案</code>
<code> </code><code>法無授權即禁止 --> 在SELinux規則庫中沒有定義的規則,均被禁止</code>
<code>程序如何通路非本域domain的檔案?</code>
<code> </code><code>修改檔案的type 屬于程序domain即可</code>
2)改變檔案所屬的域
<a href="https://s2.51cto.com/wyfs02/M00/A4/E8/wKioL1mz8j7DcRerAAAMximtTWI905.png" target="_blank"></a>
使用示例
<a href="https://s3.51cto.com/wyfs02/M01/06/37/wKiom1mz_DTwQUgKAAAeYlq1EjQ343.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M02/A4/E8/wKioL1mz_DSis3ydAABBWOIy1ss324.png" target="_blank"></a>
3)還原标簽
<a href="https://s5.51cto.com/wyfs02/M00/06/37/wKiom1mz_JTj5robAAAWQqJTMmI406.png" target="_blank"></a>
<a href="https://s2.51cto.com/wyfs02/M01/A4/E8/wKioL1mz_KbRnxK7AAB1UB72zBI888.png" target="_blank"></a>
4)設定程式功能開啟或關閉
預設對于某些程式的功能,相對安全級别較低的功能,将被SELinux自動被禁止,例如ftp的匿名使用者:任何使用者可以上傳檔案
擷取程式功能sebool
getsebool -a 所有程式功能
getsebool ftp_home_dir
設定程式功能
setsebool [-P] sebool=value
-P 永久有效,将修改的結果儲存至政策庫中 (需要一定時間:找到規則庫,設定,轉換為binary格式 )
例如:
setsebool ftp_home_dir 1
setsebool ftp_home_dir 0
setsebool ftp_home_dir on
setsebool ftp_home_dir off
本文轉自 lccnx 51CTO部落格,原文連結:http://blog.51cto.com/sonlich/1964022,如需轉載請自行聯系原作者