SELinux
Een SELinux-module voor CGI scripts Een SELinux-module voor CGI scripts
Marcel Nijenhof
marceln@pion.xs4all.nl 15 Mei 2008
Voorjaarsconferentie nluug
Wat is selinux
●
Ontwikkeld door de nsa
–
Eigen os flask
–
Geport na linux
●
Beveiligings model
–
Regels vast gelegd
–
Afdwingen regels
–
Relatie tussen
processen en objecten
–
Domeinen en typen
Voorbeeld: Aanpassen paswoord
Aanpassingen
●
Extended attributen
●
De “-Z” vlag (ls, ps, ..)
●
Logging
●
getenforce/setenforce
●
chcon/restorecon
●
Semange
●
Setsebool
●
Semodule
audit2allow
Cgips
Runcmd() {
echo "<h2>$@<h2>
echo "<pre>"
$@
echo "<pre>"
}
runcmd getenforce runcmd getsebool \
httpd_enable_cgi runcmd id Z
runcmd ps ef
●
Simpel cgi script
–
Draait enkele commando's
–
Laat resultaat zien
● Status selinux
● Selinux gebruiker
● Resultaat “ps -ef”
Resultaat zonder aanpassingen
●
SE Linux uit
ps ef
UID ... CMD
root ... init [3]
marceln ... bash
root ... /usr/sbin/httpd apache ... /usr/sbin/httpd ...
apache ... /var/www/cgibin/ps apache ... ps ef
●
SE Linux aan
ps ef
UID ... CMD
apache ... /var/www/cgibin/cgips apache ... ps ef
SE Linux en cgi scripten
●
Ps in een cgi script geeft geen informatie
●
Helaas zien we het
resultaat van ps niet
Oplossen
●
SELinux devel
–
Kopieer voorbeeld
–
Nieuw types
● cgips_t
● cgips_exec_t
–
Domein transitie
–
Toegangs regels via
“audit2allow”
Interface file
interface(`cgips_domtrans',`
gen_require(`
type cgips_t, cgips_exec_t;
')
domain_auto_trans($1,cgips_exec_t,cgips_t) domain_auto_trans($1,cgips_exec_t,cgips_t) allow $1 cgips_t:fd use;
allow cgips_t $1:fd use;
allow $1 cgips_t:fifo_file rw_file_perms;
allow $1 cgips_t:process sigchld;
')
Type enforcement
policy_module(cgips,1.0.1) require {
class chr_file getattr;
class dir { add_name getattr read remove_name
search write };
class fd use;
} ...
...
allow cgips_t bin_t:dir search;
allow cgips_t bin_t:file { execute execute_no_trans getattr read };
allow cgips_t crond_t:dir { getattr search };
Vmsplice exploit
./vmsplice.bin <<EOF echo
echo "> head \
1 /etc/shadow"
echo
head 1 /etc/shadow EOF
●
Kernel exploit
–
Onbekend bij call for paper
–
Wat doet SELinux voor nieuwe kernel exploit?
–
Nieuw cgi-script
● Voert exploit uit
● Toont /etc/shadow
Resultaat
●
Exploit werkt gewoon
–
Je wordt root
● Uid = 0
● Alles mag volgens posix
●
exploit werkt niet
–
Behoud Security context
● Role: httpd_sys_script_t
● Beperkingen SELinux
● Geen toegang tot
“/etc/shadow”
Conclusies
●
Het is lastig
–
Totaal ander model dan posix
●
Beveiligt niet de data van de applicatie zelf
–
De applicatie moet immers toegang hebben
●
Problemen met embedded apache modules
–
Geen exec
●
Het kan wel gevolgen van exploits inperken
–
Zie vmsplice voorbeeld
Vragen
Sheets: http://pion.xs4all.nl/lezingen/SELinux-nluug2008vj.odp Paper: http://pion.xs4all.nl/lezingen/SELinux-nluug2008vj.html Email: info@pion.xs4all.nl
Dit document is gelicenseerd onder “Attribution-ShareAlike 3.0Netherlands license”, beschikbaar op
http://creativecommons.org/licenses/by-sa/3.0/nl