Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


admin_grundlagen:selinux_-_webserver_inhalte_freigeben

Dies ist eine alte Version des Dokuments!


Voraussetzungen

HTML Datei im Zielverzeichnis anlegen

cd /var/www/html/
id -Z
ls -dZ .
matchpathcon .

→ Type: httpd_sys_content_t

test.html
<html>
  <head>
    <title>Hello SELinux!</title>
  </head>
  <body>
    Hello SELinux
  </body>
</html>
ls -Z test.html

→ Type: httpd_sys_content_t, Webserver kann darauf zugreifen

HTML Datei im Heimatverzeichnis anlegen

als root:

cd
id -Z
ls -dZ .
matchpathcon .

→ Type: admin_home_t

test.html
<html>
  <head>
    <title>Hello SELinux!</title>
  </head>
  <body>
    Hello SELinux
  </body>
</html>
ls -Z test.html

→ Type: admin_home_t

mv test.html /var/www/html

→ Webserver kann nicht darauf zugreifen

SELinux file type korrigieren

setroubleshootd

Wenn zum Zeitpunkt des Zugriffs setroubleshootd aktiviert ist, gibt es hier Hilfe:

journalctl -f _COMM=setroubleshootd

SELinux is preventing /usr/sbin/httpd from getattr access on the file /var/www/html/test.html

auditd

Wenn zum Zeitpunkt des Zugriffs der auditd läuft:

ausearch -m avc -c httpd

denied { getattr } … comm=„httpd“ path=„/var/www/html/test.html“ … tcontext=…admin_home_t

chcon

chcon -t httpd_sys_content_t /var/www/html/test.html

oder

chcon --reference /var/www/html /var/www/html/test.html

restorecon

restorecon /var/www/html/test.html

PHP Anwendung: Rechte testen

yum install php
service httpd restart
cd /var/www/html/
id -Z
ls -dZ .
matchpathcon .

→ Type: httpd_sys_content_t

PHP-Shell1) installieren: (niemals auf produktiven Systemen)

wget https://github.com/flozz/p0wny-shell/raw/master/shell.php
ls -Z shell.html

→ Type: httpd_sys_content_t, Webserver kann darauf zugreifen

http://localhost/shell.php

HTML Datei außerhalb des DocumentRoot anlegen

/etc/httpd/conf.d/srv.conf
Alias /srv /srv/test
 
<Directory /srv/test>
  Require all granted
</Directory>
apachectl graceful
mkdir -p /srv/test
ls -dZ /srv/test/

→ Type: var_t

chcon --reference /var/www/html /srv/test
ls -dZ /srv/test/

→ Type: httpd_sys_content_t

matchpathcon /srv/test/

→ Type: var_t (Achtung!)

test.html
<html>
  <head>
    <title>Hello SELinux!</title>
  </head>
  <body>
    Hello SELinux
  </body>
</html>
ls -Z /srv/www/html/test.html

→ Type: var_t, Webserver kann nicht darauf zugreifen

chcon --reference /var/www/html /srv/test/test.html
ls -Z /srv/www/html/test.html

→ Type: httpd_sys_content_t, Webserver kann darauf zugreifen

restorecon -RF /srv/test/
ls -Z /srv/www/html/test.html

→ Type: var_t, Webserver kann nicht darauf zugreifen

semanage fcontext --add -t httpd_sys_content_t '/srv/test(/.*)?'
restorecon -RF /srv/test/

→ Type: httpd_sys_content_t, Webserver kann darauf zugreifen

admin_grundlagen/selinux_-_webserver_inhalte_freigeben.1542068013.txt.gz · Zuletzt geändert: 2018/11/13 00:13 von ingo_wichmann