redhat linux 6中setroubleshoot 與 audit 關係

來源:互聯網
上載者:User

最近在看Linux selinux 對於setroubleshoot與audit不是十分理解。找到如下官方解釋

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html-single/Security-Enhanced_Linux/index.html#sect-Security-Enhanced_Linux-Working_with_SELinux-Which_Log_File_is_Used

根據說明,在redhat 6中,retroubleshoot不再作為一個單獨的服務,而是分為兩個進程,同時,只要在開機載入過程中,如果使用了selinux,安裝了retroubleshoot,那麼就會自動啟動兩個進程:seapplet與sedispatch。作用如下:

sedispatch runs as part of the audit subsystem, and via dbus, sends a message when an AVC denial occurs, which will go straight to setroubleshootd if it is already running, or it will start setroubleshootd if it is not running. seapplet is a tool which runs in the system's toolbar, waiting for dbus messages in setroubleshootd, and will launch the notification bubble, allowing the user to review the denial.

根據上面所說,做如下測試。

首先啟動selinux,安裝setroubleshoot

然後查看狀態

[root@localhost ~]# getenforce

Enforcing

[root@localhost ~]# service auditd status

auditd (pid 1222) is running...

可以看到現在selinux與auditd都是啟動狀態,開啟兩個終端,然後分別查看messages與audit.log

現在要做的實驗是使用ftp伺服器,說下實驗流程。當安裝ftp之後,建立新使用者,然後在一個用戶端登入該使用者。正常情況下,當使用正確使用者名稱與密碼登入之後,ftp預設登入位置為目前使用者的家目錄。可是在selinux中有設定,是不允許客戶進入家目錄,這時登入成功之後,審計就會在日誌中寫入,而setroubleshoot則會抓去日誌,進行分析,然後給使用者一個解決方案。下面來驗證這個過程

由於開始時我安裝的作業系統是迷你安裝。所以需要進行如下操作

[root@localhost ~]# yum -y install vsftpd

[root@localhost ~]# yum -y install setroubleshoot*

[root@localhost ~]# yum -y groupinstall "X Window System"

[root@localhost ~]# yum -y groupinstall "KDE Desktop"

注意:在上面安裝過程中,在安裝setroubleshoot之後,使用ps aux | grep seapplet,發現沒有此進程不需要擔心。seapplest與sedispatch在安裝X11與案頭管理器KDE之後重新啟動就會出現。個人感覺應該是setroubleshoot必須有案頭支援。OK,繼續看。

[root@localhost ~]# ps aux | grep sedispatch | grep -v grep

root 1236 0.0 0.0 21200 1140 ? S< 11:28 0:00 /usr/sbin/sedispatch

[root@localhost ~]# ps aux | grep seapplet | grep -v grep

root 2494 0.0 0.3 217800 7208 ? S 12:43 0:00 /usr/bin/seapplet

步驟一:安裝vsftpd 安裝步驟略過,安裝結束之後直接啟動vsftpd,不需要做任何更改

步驟二:建立新使用者 步驟略過

步驟三:開始監控setroubleshoot日誌----messages 與auditd日誌-----audit.log,建議使用tailf

步驟四:在用戶端使用ftp登入,輸入剛剛建立的使用者名稱與密碼,是正確的。

步驟五:查看是否日誌有變動。看如下

650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://www.bkjia.com/uploads/allimg/131227/1A314D24-0.jpg" width="557" height="273" />

操作之前

650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://www.bkjia.com/uploads/allimg/131227/1A314H05-1.jpg" width="557" height="282" />

操作之後,大家可以根據日誌資訊來進行分析,我用的是KDE案頭

650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://www.bkjia.com/uploads/allimg/131227/1A314IT-2.jpg" width="558" height="321" />

大家可以看到,根據資訊,明確能夠瞭解出現問題的原因,正常情況下,會案頭上出現一個五角星標誌

650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://www.bkjia.com/uploads/allimg/131227/1A314DV-3.jpg" width="558" height="213" />

下面大家來看看上面兩個日誌是否有區別:

audit.log

type=AVC msg=audit(1377664273.274:36): avc: denied { search } for pid=2117 comm="vsftpd" name="/" dev=dm-2 ino=2 scontext=unconfined_u:system_r:ftpd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:home_root_t:s0 tclass=dir

type=SYSCALL msg=audit(1377664273.274:36): arch=c000003e syscall=80 success=no exit=-13 a0=7fe0a273afe0 a1=1f4 a2=0 a3=7fffa8c137e0 items=0 ppid=2112 pid=2117 auid=0 uid=0 gid=0 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=(none) ses=1 comm="vsftpd" exe="/usr/sbin/vsftpd" subj=unconfined_u:system_r:ftpd_t:s0-s0:c0.c1023 key=(null)

可以看到 type=AVC標誌。而再來看setroubleshoot

Aug 28 12:39:26 localhost setroubleshoot: SELinux is preventing /usr/sbin/vsftpd from search access on the directory /home. For complete SELinux messages. run sealert -l 30972dbc-350e-4f82-9044-a8ffafd9e31c

在setroubleshoot中,能夠看到前面localhost主機名稱之後的setroubleshoot,證明是由setroubleshoot來整理寫入。根據上面紅色字型部分,我們執行一下看看結果

SELinux is preventing /usr/sbin/vsftpd from search access on the directory /home.

***** Plugin catchall_boolean (47.5 confidence) suggests *******************

If you want to allow ftp servers to login to local users and read/write all files on the system, governed by DAC.

Then you must tell SELinux about this by enabling the 'allow_ftpd_full_access'boolean.

Do

setsebool -P allow_ftpd_full_access 1

***** Plugin catchall_boolean (47.5 confidence) suggests *******************

If you want to allow ftp to read and write files in the user home directories

Then you must tell SELinux about this by enabling the 'ftp_home_dir'boolean.

Do

setsebool -P ftp_home_dir 1

***** Plugin catchall (6.38 confidence) suggests ***************************

If you believe that vsftpd should be allowed search access on the home directory by default.

Then you should report this as a bug.

You can generate a local policy module to allow this access.

Do

allow this access for now by executing:

# grep vsftpd /var/log/audit/audit.log | audit2allow -M mypol

# semodule -i mypol.pp

相信根據上面的英文說明就應該能夠知道該如何做,也會知道出現錯誤的原因。

下面繼續進行下一個實驗,關閉auditd服務

[root@localhost ~]# service auditd stop

Stopping auditd: [ OK ]

650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://www.bkjia.com/uploads/allimg/131227/1A3146051-4.jpg" width="557" height="242" />

接下來我們看看開始提到的setroubleshoot兩個進程情況

[root@localhost ~]# ps aux |grep sedispatch | grep -v grep

[root@localhost ~]# ps aux |grep seapplet | grep -v grep

root 2494 0.0 0.3 217800 7208 ? S 12:43 0:00 /usr/bin/seapplet

從上面可以看出,隨著auditd的停止,sedispatch也停掉。現在有seapplet繼續監管。此時在用戶端登入ftp查看情況

650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://www.bkjia.com/uploads/allimg/131227/1A3145023-5.jpg" width="558" height="310" />

上方日誌輸出中,可以看出,當auditd停掉,那麼審計任務結束,而此時selinux已經開始接管。因為日誌後面能夠看到另外一個資訊標誌avc,只是現在無法定論此時日誌究竟由何種工具進行監控

上述實驗得到如下資訊:

setroubleshoot在redhat 6之後,確實已經不再作為一種服務來進行安裝,而是預設直接嵌入至kernel,兩進程如下:seapplet與sedispatch。而seapplet是與selinux進行通訊,sedispatch則是因為auditd服務而啟動。

日誌得到過程中,首先由kernel運行應用程式,當有錯誤時,報出,此時由audit拿到,然後寫入audit.log,這時setroubleshoot在audit中得到日誌,進行分析,然後給出解決方案。

但是在最後,當把auditd服務停掉之後,依舊能夠得到錯誤資訊。根據官方解釋,此時應該是由selinux得到報出。可是此時setroubleshoot卻無任何提示。此處希望有人能夠指點。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.