將DocumentRoot設(shè)在/var/www/html下可以訪(fǎng)問(wèn)但是將DocumentRoot設(shè)在其他目錄(如:/webroot)下就出現(xiàn)Forbidden了。在./etc/httpd/conf/httpd.conf中的相關(guān)部分是這樣的:Alias /query "/home/query"
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
但是在瀏覽器中輸入:http://localhost/query/ 時(shí),出現(xiàn)Forbidden:ForbiddenYou don't have permission to access /query on this server.Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.Apache/2.0.52 (Red Hat) Server at localhost Port 80對(duì)于剛使用Redhat Enterprise Linux4 或Fedora Core 2以上/CentOS 4的用戶(hù),一定會(huì)為Apache經(jīng)常無(wú)法正常運(yùn)轉(zhuǎn),報(bào)以"Permission denied"等錯(cuò)誤而大為不解,甚至大為惱火。其實(shí)這是因?yàn)檫@些系統(tǒng)里激活了SELinux,而用戶(hù)的apache配置與SELinux的配置策略有抵觸產(chǎn)生的,只有通過(guò)適當(dāng)調(diào)整,使apache的配置和訪(fǎng)問(wèn)符合策略才能正常使用。現(xiàn)在下面來(lái)分析一下SELinux中有關(guān)httpd(apache)的context定義(略有刪節(jié))/home/[^/]+/((www)|(web)|(public_html))(/.+)? system_u:object_r:httpd_user_content_t/var/www(/.*)? system_u:object_r:httpd_sys_content_t/var/www/cgi-bin(/.*)? system_u:object_r:httpd_sys_script_exec_t/usr/lib/cgi-bin(/.*)? system_u:object_r:httpd_sys_script_exec_t/var/www/perl(/.*)? system_u:object_r:httpd_sys_script_exec_t/var/www/icons(/.*)? system_u:object_r:httpd_sys_content_t/var/cache/httpd(/.*)? system_u:object_r:httpd_cache_t/etc/vhosts -- system_u:object_r:httpd_config_t/usr/sbin/httpd -- system_u:object_r:httpd_exec_t/usr/sbin/apache(2)? -- system_u:object_r:httpd_exec_t/usr/sbin/suexec -- system_u:object_r:httpd_suexec_exec_t/var/log/httpd(/.*)? system_u:object_r:httpd_log_t/var/log/apache(2)?(/.*)? system_u:object_r:httpd_log_t/var/log/cgiwrap.log.* -- system_u:object_r:httpd_log_t/var/cache/ssl.*.sem -- system_u:object_r:httpd_cache_t/var/cache/mod_ssl(/.*)? system_u:object_r:httpd_cache_t/var/run/apache(2)?.pid.* -- system_u:object_r:httpd_var_run_t/var/lib/httpd(/.*)? system_u:object_r:httpd_var_lib_t/var/lib/php/session(/.*)? system_u:object_r:httpd_var_run_t/etc/apache-ssl(2)?(/.*)? system_u:object_r:httpd_config_t/usr/lib/apache-ssl(/.*)? -- system_u:object_r:httpd_exec_t/usr/sbin/apache-ssl(2)? -- system_u:object_r:httpd_exec_t/var/log/apache-ssl(2)?(/.*)? system_u:object_r:httpd_log_t/var/run/apache-ssl(2)?.pid.* -- system_u:object_r:httpd_var_run_t/var/run/gcache_port -s system_u:object_r:httpd_var_run_t/var/lib/squirrelmail/prefs(/.*)? system_u:object_r:httpd_squirrelmail_t/usr/bin/htsslpass -- system_u:object_r:httpd_helper_exec_t/usr/share/htdig(/.*)? system_u:object_r:httpd_sys_content_t/var/lib/htdig(/.*)? system_u:object_r:httpd_sys_content_t針對(duì)上述的內(nèi)容,可以對(duì)如下的幾個(gè)常見(jiàn)問(wèn)題進(jìn)行簡(jiǎn)單處理:1.phpmyadmin在非默認(rèn)/var/www/html目錄下無(wú)法運(yùn)轉(zhuǎn)通常類(lèi)似的情況都是在配置了虛擬主機(jī)時(shí),訪(fǎng)問(wèn)/phpmyadmin等提示403訪(fǎng)問(wèn)拒絕,日志里也提示Permission denied,這是因?yàn)閜hpmyadmin防止的目錄及文件本身屬性不符合context要求。假設(shè)phpmyadmin放在/web目錄下,那么執(zhí)行:chcon -R -t httpd_user_content_t /web則會(huì)令/web及其下所有子目錄/文件,包括phpmyadmin文件都獲得了httpd_user_content_t的屬性,如果其傳統(tǒng)的Unix屬性對(duì)httpd來(lái)說(shuō)是可讀的話(huà),再重新訪(fǎng)問(wèn)一下就應(yīng)該可以了。2./home目錄下的虛擬主機(jī)無(wú)法運(yùn)轉(zhuǎn)與問(wèn)題1也是類(lèi)似的,不過(guò)根據(jù)上文中context的定義,/home目錄下必須是用戶(hù)的$HOME/www或public_html或web目錄才是 httpd_user_content_t類(lèi)型,因此建議將要作為web頁(yè)面的內(nèi)容放置在用戶(hù)的$HOME/www或web或public_html里,并確保其屬性是httpd_user_content_t,使用如下命令查看:ls -Z /home/abc/drwxr-xr-x abc abc user_u:object_r:user_home_dir_t tmpdrwxrwxr-x abc abc user_u:object_r:httpd_user_content www如不是,則可通過(guò)chcon來(lái)逐級(jí)目錄及文件更改,直至最后能訪(fǎng)問(wèn):chcon -R -t httpd_user_content_t /home/abc/webchcon -t user_home_dir_t /home/abc3.CGI程序無(wú)法運(yùn)行如果cgi程序放在/var/www/cgi-bin/里也無(wú)法執(zhí)行,遇到403或500錯(cuò)誤的話(huà),可以檢查cgi 程序的屬性,按SELinux contexts文件里定義的,/var/www/cgi-bin/里必須是httpd_sys_script_exec_t 屬性。通過(guò)ls -Z查看,如果不是則通過(guò)如下命令更改:chcon -t httpd_sys_script_exec_t /var/www/cgi-bin/*.cgi如果是虛擬主機(jī)里的cgi,則參考問(wèn)題2使之能正常使用普通的功能后,再通過(guò)chcon設(shè)置cgi文件的context為httpd_sys_script_exec_t即可。4.Setuid/gid 程序無(wú)法運(yùn)行例如早期的SqWebMail及qmailadmin等,需要setuid/gid的支持,但在SELinux下這將受到嚴(yán)格限制。第一種方法是比較徹底的辦法,能保留系統(tǒng)的安全性,通過(guò):audit2allow -l -i /var/log/messages將SELinux拒絕的信息轉(zhuǎn)換為相應(yīng)的policy allow指令,將這些指令添加到SELinux policy 的src里相應(yīng)的配置文件,重新生成policy并加載。但這樣做相對(duì)比較麻煩。另一個(gè)方法最簡(jiǎn)單,但將使apache得不到保護(hù)。首先確定SELinux 類(lèi)型是targeted的:cat /etc/selinux/config|grep SELINUXTYPE然后,使apache脫離SELinux保護(hù):setsebool -P httpd_disable_trans 1然后重啟動(dòng)apache:/etc/init.d/httpd restart這樣所有apache強(qiáng)制的檢查都失效,需要setuid/gid的程序可以正常使用。但這樣帶來(lái)了增加漏洞的危險(xiǎn),對(duì)于迫切需要運(yùn)行而又很急的情況,本方法是一個(gè)最大限度減少系統(tǒng)安全缺失的最后辦法。對(duì)于取消SELinux 未必是一個(gè)好方法。大盤(pán)預(yù)測(cè)
國(guó)富論
posted on 2015-08-15 00:21
華夢(mèng)行 閱讀(377)
評(píng)論(0) 編輯 收藏