Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20081 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities ·

Ähnliche Präsentationen


Präsentation zum Thema: "Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20081 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities ·"—  Präsentation transkript:

1 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20081 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities · LinuxTag2008 Berlin Freitag, 30.05.2008, 16.00 – 17.00 · Chris Friedhoff chris@friedhoff.org

2 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20082 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond ● Einführung ● Nutzungsszenarien ● POSIX Capabilities - Theorie ● HowTo ● Pcaps & Dateisystemoperationen ● Beispiele ● FAQ & Fragen

3 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20083 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond ● Einführung ● Nutzungsszenarien – SUID-0-Bit ersetzen – Serversoftware als unprivilegierter User – Unterschiedliche Privilegienlevel für Userrollen ● POSIX Capabilities - Theorie ● HowTo ● Pcaps & Dateisystemoperationen ● Beispiele ● FAQ & Fragen

4 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20084 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Nutzungsszenarien -> SUID-0-Bit ersetzen ● SUID-0-Bit - warum ersetzen – Luser hat nicht genügend Rechte, damit Anwendung erfolgreich läuft – Anwendung muß im Kontext eines anderen Users laufen – auf Privilegien bezogen nur 2 User (Root Luser) – mit der Anwendung werden die Rechte eines anderen User verknüpft – Rechte des Fileowner -> SUID-Bit – mehr Rechte --> Root-owned – --> Anwendung läuft mit Rootrechten

5 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20085 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Nutzungsszenarien -> SUID-0-Bit ersetzen ● SUID-0-Bit - warum ersetzen – Privilegien reduzieren – seit 2.2 wird das Rootrecht als diskrete Privilegien dargestellt – mit Rootrecht dürfen z.B. ping oder traceroute: ● /etc/shadow ändern --> CAP_DAC_OVERRIDE ● Prozesse beenden --> CAP_KILL ● Firewall ändern --> CAP_NET_ADMIN ● chroot ausführen --> CAP_SYS_CHROOT ● Rebooten --> CAP_SYS_BOOT ● Systemzeit ändern --> CAP_SYS_TIME – siehe auch Slide POSIX Capabilities – 2.6.25 – !! BEIDE BRAUCHEN NUR: CAP_NET_RAW !!

6 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20086 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Liste der POSIX Capabilities - 2.6.25 0 - CAP_CHOWN - Eigentümer von Files beliebig setzen 1 - CAP_DAC_OVERRIDE - Sich über Dateizugriffsrechte hinwegsetzen (DAC, Discretionary Access Control), nur das Immutable-Flag ist davon nicht betroffen 2 - CAP_DAC_READ_SEARCH - In allen Files und Dirs lesen 3 - CAP_FOWNER - Auf alle Files die Funktionen ausüben, die üblicherweise nur deren Eigentümern gestattet sind (etwa chmod()und utime()) 4 - CAP_FSETID - Set-UID-Flag auch für fremde Files setzen 5 - CAP_KILL - Beliebigen Prozessen Signale senden 6 - CAP_SETGID - Beliebige Gruppen-ID annehmen 7 - CAP_SETUID - Beliebige User-ID annehmen 8 - CAP_SETPCAP - Eigene Capabilities an fremde Prozesse übertragen oder dort entfernen 9 - CAP_LINUX_IMMUTABLE - Immutable- und Append-Only- Attribute ändern 10 - CAP_NET_BIND_SERVICE - Privilegierte Ports verwenden 11 - CAP_NET_BROADCAST - Broadcast-Nachrichten senden und empfangen 12 - CAP_NET_ADMIN - Sammlung vieler Netzwerk-Konfigurationen (Interface, Firewall, Routing, Sockets, Promicious Mode setzen uvm.) 13 - CAP_NET_RAW - Sockets vom Typ Raw (IPv4-Pakete) und Packet (Ethernet-Frames) verwenden 14 - CAP_IPC_LOCK - Shared-Memory-Segmente sperren 15 - CAP_IPC_OWNER - Nachrichten per IPC (Interprozesskommunikation) an beliebige Prozesse senden 16 - CAP_SYS_MODULE - Kernel-Module laden und entladen, den Kernel beliebig ändern sowie Capabilities-Bounding-Sets ändern 17 - CAP_SYS_RAWIO - Verwenden von ioperm() und iopl() sowie beliebige USB-Kommunikation 18 - CAP_SYS_CHROOT - chroot()-Kommando absetzen 19 - CAP_SYS_PTRACE - Beliebige Prozesse mit ptrace() überwachen und kontrollieren 20 - CAP_SYS_PACCT - Prozess-Accounting konfigurieren 21 - CAP_SYS_ADMIN - Viele administrative Aufgaben, etwa Domain- und Hostnamen ändern, Dateisysteme mounten und unmounten, Swapping ein/ausschalten, Semaphore löschen uvm. 22 - CAP_SYS_BOOT - Das System per reboot() neu starten 23 - CAP_SYS_NICE - Die Priorität per nice() hochsetzen, Realtime- Scheduling verwenden und die CPU-Affinität fremder Prozesse ändern 24 - CAP_SYS_RESOURCE - Ressourcenlimits überschreiten, etwa Quota, reservierter Filesystemraum, Größenbeschränkungen bei IPC-Nachrichten uvm. 25 - CAP_SYS_TIME - Die Systemzeit stellen 26 - CAP_SYS_TTY_CONFIG - TTY-Geräte konfigurieren 27 - CAP_MKNOD - Alle Funktionen von mknod() beim Anlegen von Gerätedateien nutzen 28 - CAP_LEASE - Dateien leasen (siehe fcntl()-Leases) 29 - CAP_AUDIT_WRITE - Meldungen an das Audit-Subsystem senden 30 - CAP_AUDIT_CONTROL - Audit-Subsystem per auditctl() konfigurieren 31 - CAP_SETFCAP - Filesystem-Capabilities setzen 32 - CAP_MAC_OVERRIDE – MAC Checks übergehen 33 - CAP_MAC_ADMIN - MAC Konfiguration & Änderung

7 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20087 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Nutzungsszenarien -> Serversoftware als unprivilegierter User ● Serversoftware als unprivilegierter User – warum & Idee – braucht nicht volles Rootrecht --> also nicht alle Pcaps – um z.B. privilegierte Ports zu öffnen --> CAP_NET_ADMIN – unprivilegierte User mit privater Gruppe – Ownership zugehöriger Konfigurations-, Log- & anderer Files anpassen ● somit weiterhin kein Zugriff auf diese Files durch andere Luser – notwendige Pcaps werden dem Executable zugewiesen – notfalls x-Bits anpassen – im Krisenfall keine Privilegieneskalation

8 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20088 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Nutzungsszenarien -> Unterschiedliche Privilegienlevel für Userrollen ● Unterschiedliche Privilegienlevel für Userrollen – Intro – Pcap wird Executable „nicht direkt nutzbar“ zugewiesen (Permitted Flag „p“) – Pcap wird als nur erbbar zugewiesen (Inheritable Flag „i“) – Aufrufender muß das notwendige Pcap für dieses Executable auch als vererbbar haben ( Inheritable Flag „i“) – --> aufrufender Prozess und aufgerufenes Executable müssen in Bezug auf ihr Inheritance Set übereinstimmen – --> damit wird das notwendige Pcap auch für den neu entstandenen Prozess nutzbar – User werden mit bestimmten Programmen über Pcaps Inheritance gekoppelt und nur diese User können erfolgreich diese Programme ausführen – CAP_DAC_OVERRIDE --> Backup Rolle – CAP_NET_ADMIN --> Firewall Admin Rolle

9 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20089 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond ● Einführung ● Nutzungsszenarien ● POSIX Capabilities - Theorie – Capability Flag, Set & State – Permitted Flag & Set – Effective Flag & Set – Inheritable Flag & Set – Capability Rules ● HowTo ● Pcaps & Dateisystemoperationen ● Beispiele ● FAQ & Fragen

10 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200810 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities – Theorie ● POSIX Capabilities – Definition laut IEEE Draft P1003.1e – Capability: "An attribute of a process that is included in the determination of whether or not a process has the appropriate privilege to perform a specific POSIX.1 action where appropriate privilege is required" (S.4). – This section defines... that... one or more capabilities to be associated with a process or a file, for the capabilities associated with a process to be enabled or disabled, and for a set of these capabilities to be passed on to the next program associated with a process. (S.164) – Posix.1 specifies that certain actions require a process to possess appropriate privilege in order to complete those actions. Specific capabilities of a process that exec's a particular file may be revoked, inherited from the previous process image, or granted to the process, depending on the value(s) if the... capability state of the file and the process capability state of the previous process image. (S.164)

11 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200811 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities – Theorie – Flag, Set, State, P, E, I ● POSIX Capabilities - Theorie – Capability Flag, Set & State ● per Capability Attribute --> Flag ● alle Capabilities mit demselben Flag --> Set ● alle Sets zusammen --> Capability State – Permitted Flag (p) & Set (P) ● generell verfügbar aber nicht direkt einsetzbar – Effective Flag (e) & Set (E) ● direkt einsetzbar & wirksam – Inheritable Flag (i) & Set (I) ● erbbar für Files oder vererbbar für Prozesse

12 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200812 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities Rules I (1) pI' = pI (2) pP' = (X & fP) | (pI & fI) (3) pE' = fE & pP' ● p{P,E,I}' = post-exec() PCaps Sets, State des neuen Prozesses ● X = System Upper Limit, seit 2.6.25 Parent Process Upper Limit ● f{P,E,I} = File State of the called executable ● pP = Process Permitted Set (here of the calling process) ● pE = Process Effective Set (here of the calling process) ● pI = Process Inheritable Set (here of the calling process) ● & --> Intersection (Schnittmenge) ● | --> Union (Vereinigungsmenge)

13 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200813 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities Rules II (1) pI' = pI ● pI' = post-exec() Process Inheritance Set des neuen Prozesses ● pI = Process Inheritable Set des aufrufenden Prozesses ● Das Process Inheritance Set geht unverändert über ● Ein Prozess kann, wenn die Inheritance Sets übereinstimmen, eine Kette von Prozessen starten

14 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200814 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities Rules III (2) pP' = (X & fP) | (pI & fI) ● pP' = post-exec() Process Permitted Set ● X = System Upper Limit (cap-bound), seit 2.6.25 Parent Process Upper Limit ● fP = File Permitted Set of the called executable, (Minimal Forced Set) ● fI = File Inheritance Set of the called executables ● pI = Process Inheritable Set (here of the calling process) ● Der Effekt des Minimal Forced Set wird durch das Upper Limit begrenzt ● Inheritance allein kann das pP' bestimmen – Selektion, welche Prozesse erfolgreich Prozesse starten können

15 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200815 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities Rules IV (3) pE' = fE & pP' ● pE' = post-exec() Process Effective Set des neuen Prozesses ● fE = File Effective Set of the called executable ● pP' = post-exec() Process Permitted Set des neuen Processes ● Es kommen nur die Pcaps aus dem fE ins pE', wenn sie auch im pP' sind ● pE' wird von Pcaps fähigen Apps selber verwaltet ● legacy Apps brauchen ein fE – deswegen ist fP=fE

16 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200816 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond ● Einführung ● Nutzungsszenarien ● POSIX Capabilities - Theorie ● HowTo – Kernel – Check & Konfiguration – Userspace – libcap2 – Setzen & Lesen der PCaps – Benötigte Pcaps ermitteln – ping – Benötigte Pcaps ermitteln – strace – Benötigte Pcaps ermitteln – capable_probe ● Pcaps & Dateisystemoperationen ● Beispiele ● FAQ & Fragen

17 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200817 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Kernel - Check ● Kernelversion => 2.6.24 – aktivierte File POSIX Capabilities – Extended Attributes fähiges Dateisystem $ uname -r 2.6.25.4-a $ $ grep '\(XATTR\|CAPA\)' /boot/config-`uname -r` $ zgrep '\(XATTR\|CAPA\)' /proc/config.gz CONFIG_EXT3_FS_XATTR=y CONFIG_SECURITY_CAPABILITIES=y CONFIG_SECURITY_FILE_CAPABILITIES=y

18 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200818 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Kernel - Konfiguration $ kernel make menuconfig Security options ---> File POSIX Capabilities (EXPERIMENTAL) File systems ---> Ext3 journalling file system support Ext3 extended attributes Wer mit der "different security model" Option arbeitet, muss noch "Default Linux Capabilities" angeben. Security options ---> Enable different security models Default Linux Capabilities

19 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200819 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Userspace - libcap2 Download von http://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/ $ tar xjf libcap-2.09.tar.bz2 $ cd libcap-2.09 $ make $ sudo make install Das Programm quicktest.sh im Verzeichnis progs testet das PCaps Setup. $ cd progs $ sudo./quicktest.sh

20 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200820 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Setzen und Lesen der Pcaps I ● nachdem der Kernel und die Userspacetools installiert und rebooted wurde... ● Überblick über die vorhandenen Pcaps less /usr/include/linux/capability.h man capabilities ● Grünes Licht für Pcaps, (http://www.linux- magazin.de/heft_abo/ausgaben/2008/06/gruenes_licht_fuer_pcaps) Linux Magazin 06/2008, Seite 80, eine deutschsprachige Aufstellung der verschiedenen POSIX Capabilities

21 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200821 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Setzen und Lesen der Pcaps II ● Eine POSIX Capability zuzuweisen ist so einfach wie $ sudo setcap cap_net_admin=ep /bin/ping ● Das Auslesen der gesetzeten POSIX Capabilities ist genauso einfach $ getcap /bin/ping /bin/ping: = cap_net_raw+ep ● Man kann auch nach dem Extended Attribute selber fragen $ attr -l /bin/ping Attribute "capability" has a 12 byte value for /bin/ping ● Gelöscht werden POSIX File Capabilities mit $ sudo setcap -r /bin/ping

22 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200822 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Benötigte Pcaps ermitteln - ping ● ping als Beispiel - Entfernen des SUID-Bit $ ls -l /bin/ping -rws--x--x 1 root root 29364 2006-08-14 00:20 /bin/ping $ ping -c 1 localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.111 ms --- localhost ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.111/0.111/0.111/0.000 ms ● Durch das Entfernen des SUID-Bits kann ping - wie erwartet - nicht mehr erfolgreich ausgeführt werden. $ sudo chmod u-s /bin/ping $ ping -c 1 localhost ping: icmp open socket: Operation not permitted

23 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200823 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Benötigte Pcaps ermitteln – ping - strace ● da die Fehlermeldung nicht sehr erklärend ist, kommt strace zum Einsatz $ strace ping localhost 2>&1 | grep EPERM socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = -1 EPERM (Operation not permitted) ● Unserem Programm ping fehlt offensichtlich das Recht einen Socket vom Typ SOCK_RAW anzufragen. ● Die Headerdatei /usr/include/linux/capability.h zeigt /* Allow use of RAW sockets */ /* Allow use of PACKET sockets */ #define CAP_NET_RAW 13 ●... dies war jedoch ein einfaches Beispiel...

24 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200824 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Benötigte Pcaps ermitteln – capable_probe - I ● Kernelmodul von Serge E. Hallyn, Autor des Pcaps Patches – POSIX file capabilities: Parceling the power of root" http://www.ibm.com/developerworks/linux/library/l-posixcap.html – Kprobe: cap_capable() -> cr_capable() -> cap_capable() – gibt anfragendes Programm & angefragte Pcaps in /var/log/messages aus – !! nicht vergessen zu entladen → sonst wird das Logfile geflutet !! $ kernel make menuconfig General Setup ---> Kprobes ● capable_probe $ tar capable_probe.tar.bz2 $ cd capable_probe $ make $ sudo make install

25 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200825 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond HowTo – Benötigte Pcaps ermitteln – capable_probe - II ● console1 $ tail -f /var/log/messages/ | grep ping ● console2 $ sudo modprobe capable_probe $ ping localhost ping: icmp open socket: Operation not permitted $ sudo modprobe -r capable_probe ● console1 Dec 26 14:57:21 apollo kernel: cr_capable: asking for capability 21 for ping Dec 26 14:57:21 apollo kernel: cr_capable: asking for capability 13 for ping Dec 26 14:57:21 apollo kernel: cr_capable: asking for capability 7 for ping Dec 26 14:57:21 apollo kernel: cr_capable: asking for capability 21 for ping ● PCap "7: CAP_SETUID" - Wir brauchen keine setuid Manipulation. ● PCap "21: CAP_SYS_ADMIN" – Catchall, vermeidet man besser! ● PCap "13: CAP_NET_RAW" - wir sind wieder bei Pcap 13 angekommen

26 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200826 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond ● Einführung ● Nutzungsszenarien ● POSIX Capabilities - Theorie ● HowTo ● Pcaps & Dateisystemoperationen – Distro Updates – mv & cp aus coreutils Paket – tar – rsync ● Beispiele ● FAQ & Fragen

27 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200827 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Dateisystemoperationen – Distro Updates & mv & cp ● Frage: Bleibt die Pcaps Konfiguration durch Dateisystemoperationen erhalten? ● Wie alle Extended Attributes, so auch die Pcaps... ● Distro & Paket Updates → Pcaps verschwinden – Updates sind Löschen und neu Anlegen von Files -> neue Inodes – Postinstallationsskripts müssten Pcaps zuweisen ● mv & cp aus coreutils Paket – nicht out-of-the-box – coreutils-xattr.patch ● Update von attr Paket mit xattr_conf.diff Patch – /etc/xattr.conf definiert welche Xattr berücksichtigt werden

28 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200828 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Dateisystemoperationen – mv & cp & tar ● mv & cp aus coreutils Paket – mv innerhalb des Dateisystem ist nur Umbennenen in Dateisystemtabelle ● keine Inodeänderung → Pcaps bleiben erhalten auch ohne Unterstüzung – mv von einem zu einem anderen Dateisystem ist Löschen und neu Anlagen ● mit Patch bleiben Pcaps erhalten – cp ist immer neu Anlegen ● mit Patch bleiben Pcaps erhalten ● tar – unterstützt bis 1.20 nicht Xattr – externe Unterstüzung mit xattrs.patch – mein Patch erweitert um security.capability Namespace

29 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200829 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Dateisystemoperationen – rsync ● rsync – unterstützt ab 3.x Xattr – mit {-X|--xattrs} Schalter und als Root ausgeführt ● alle Namespaces außer system.* – mit {-X|--xattrs} Schalter und als Luser ausgeführt ● nur user.* Namespace

30 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200830 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond ● Einführung ● Nutzungsszenarien ● POSIX Capabilities - Theorie ● HowTo ● Pcaps & Dateisystemoperationen ● Beispiele – SUID-0-Bit ersetzen - ping – Serversoftware als unprivilegierter User – Apache – Inheritance ● FAQ & Fragen

31 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200831 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – SUID-0-Bit ersetzen ● SUID-0-Bit Files suchen mit $ find {,/usr}/{,s}bin -user root -perm -4000 -exec ls -l {} \; ● SUID-Bit entfernen & strace & capable_probe ● setcap & testen ● pcaps4suid0 – ping=13 – traceroute=13 – chsh=0,2,4,7 – chfn=0,2,4,7 – passwd=0,1,3 – unix_chkpwd=1 – mount/umount=1,21

32 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200832 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – SUID-0-Bit ersetzen - ping $ ls -l /bin/ping -rws--x--x 1 root root 29364 2006-08-14 00:20 /bin/ping $ $ ping -c 1 localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.111 ms --- localhost ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.111/0.111/0.111/0.000 ms $ sudo chmod u-s /bin/ping $ ping -c 1 localhost ping: icmp open socket: Operation not permitted $ $ strace ping localhost 2>&1 | grep EPERM socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = -1 EPERM (Operation not permitted) $ $ sudo setcap cap_net_admin=ep /bin/ping $ getcap /bin/ping /bin/ping: = cap_net_raw+ep $ attr -l /bin/ping Attribute "capability" has a 12 byte value for /bin/ping

33 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200833 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Serversoftware als unprivilegierter User – Apache - I ● pcaps4server: apache, bind, cupsd, dhcps, samba ● hier Apache; privilegierte Ports 80 & 443; schützenswerte Files ● User & Gruppe apache hinzufügen $ sudo groupadd apache $ sudo useradd -g apache -d / apache ● Apache soll User behalten $ sudo sed -i -e "{s|^\(User\).*|\1 apache|; s|^\(Group\).*|\1 apache|}" /etc/httpd/httpd.conf ● Pid File, wenn gewünscht mit privatem PidFileDir $ sudo mkdir /var/run/httpd $ sudo sed -i "s|\(^PidFile\).*|\1 /var/run/httpd|" /etc/apache/httpd.conf

34 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200834 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Serversoftware als unprivilegierter User – Apache - II ● Ownership von Dirs & Files anpassen $ sudo chown -R apache:apache /var/run/httpd/ $ sudo chown -R apache:apache /etc/httpd/ $ sudo chown -R apache:apache /var/log/httpd/ $ sudo chown -R apache:apache /PATH/TO/YOUR/HTTPD-DOCDIR ● nur root & apache sollen httpd starten $ ls -l /usr/sbin/httpd -rwxr-xr-x 1 root root 332996 Feb 14 22:39 /usr/sbin/httpd $ sudo chown apache:apache /usr/sbin/httpd $ sudo chmod g-x,o-x /usr/sbin/httpd $ ls -l /usr/sbin/httpd -rwxr--r-- 1 apache apache 332996 Feb 14 22:39 /usr/sbin/httpd

35 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200835 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Serversoftware als unprivilegierter User – Apache - III ● httpd braucht nur zum Oeffnen & Binden an privilegierte Ports Pcaps – legacy support → e $ sudo setcap cap_net_bind_service=ep /usr/sbin/httpd ● root startet als $ su -c /usr/sbin/httpd apache ● wir sehen, wie der Daemon läuft $ pidof httpd 15259 15258 15257 15256 $ $ ps -o cmd,pid,ppid,stime,time,euser,ruser -H f -U apache -u apache CMD PID PPID STIME TIME EUSER RUSER /usr/sbin/httpd 15256 1 09:55 00:00:00 apache apache \_ /usr/sbin/httpd 15257 15256 09:55 00:00:00 apache apache \_ /usr/sbin/httpd 15258 15256 09:55 00:00:00 apache apache \_ /usr/sbin/httpd 15259 15256 09:55 00:00:00 apache apache

36 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200836 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Inheritance ● Inheritance erlaubt nur dann einem Prozess einen neuen Prozess per exec() erfolgreich auszuführen, wenn sowohl das Process Inheritance Set (pI) wie auch das File Inheritance Set (fI) die zum erfolgreichen Ausführen notwendigen Pcaps enthalten ● man kann also selektiv vorgeben, welche Prozesse neue privilegienfordernde Prozesse starten können ● eingeloggte User sind systemintern auch nur Prozesse ● wir ändern ping, damit nur noch ausgewählte User es starten können $ ls -l /bin/ping -rwx--x--x 1 root root 28992 2007-05-09 19:59 /bin/ping $ getcap /bin/ping /bin/ping = cap_net_raw+ep $ sudo setcap cap_net_raw=ei /bin/ping $ getcap /bin/ping /bin/ping = cap_net_raw+ei

37 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200837 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Inheritance ● damit ein eingeloggter User ein Process Inheritance Set hat, wird das pam_cap PAM Modul in den Login-Prozess integriert und über /etc/security/capability.conf konfiguriert $ cat /etc/pam.d/login #%PAM-1.0 auth required pam_securetty.so auth include system-auth auth required pam_cap.so account required pam_nologin.so account include system-auth password include system-auth session include system-auth session required pam_loginuid.so $ $ grep chris /etc/security/capability.conf 13 chris

38 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200838 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Inheritance ● die Aenderung der /etc/pam.d/login und der /etc/security/capability.conf erfolgte nach dem Starten unserer Session, wir haben also noch kein Process Inheritance Set $ /sbin/getpcaps $$ Capabilities for `2545': = $ $ ping -c 1 localhost ping: icmp open socket: Operation not permitted $ $ su - chris Password: $ $ getpcaps $$ Capabilities for `3610': = cap_net_raw+i $ $ ping -c 1 localhost PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.123 ms...

39 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200839 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Exploring Inheritance Welcome to Linux 2.6.25-a (tty2) apollo login: chris Password:... $ getpcaps $$ Capabilities for `32168': = cap_net_raw+i $ $ su - chris Password:... $ getpcaps $$ Capabilities for `32183': = cap_net_raw+i $ $ ssh apollo Last login: Mon May 5 14:36:55 2008 from apollo.friedhoff.loc Have a nice Day.... $ $ getpcaps $$ Capabilities for `32230': = $ $ su - chris Password:... $ getpcaps $$ Capabilities for `32245': =

40 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200840 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond Beispiel – Exploring Inheritance $ pstree -up init(1)-+-acpid(2422)... |-klogd(2160) |-login(2437)---bash(2461,chris)---vim(32197) |-login(31451)---bash(32168,chris)---su(32182)---bash(32183)---ssh(32222)... |-sshd(2394)---sshd(32223)---sshd(32228,chris)---bash(32230)---su(32244)---bash(32245)--- pstree(32261)... $ $ getpcaps 31451 32168 32182 32183 32222 2394 32223 32228 32230 32244 32245 Capabilities for `31451': =ep cap_net_raw+i Capabilities for `32168': = cap_net_raw+i Capabilities for `32182': = cap_net_raw+i Capabilities for `32183': = cap_net_raw+i Capabilities for `32222': = cap_net_raw+i Capabilities for `2394': =ep Capabilities for `32223': =ep Capabilities for `32228': = Capabilities for `32230': = Capabilities for `32244': = Capabilities for `32245': = Capabilities for `32230': = Capabilities for `32244': = Capabilities for `32245': =

41 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200841 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond ● Einführung ● Nutzungsszenarien ● POSIX Capabilities - Theorie ● HowTo ● Pcaps & Dateisystemoperationen ● Beispiele ● FAQ & Fragen

42 Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag200842 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond FAQ ● Warum sollen PCaps mich interessieren? – Als Distro Maintainer ist es zur Erhöhung der Systemsicherheit interessant die SUID-0 Executables durch PCaps Executables zu ersetzen. – Als Serveradmin reduziert man die denkbaren Folgen eines Angriffs auf den Server, wenn die Software als unprivilegierter User läuft. ● Wird meine Distro PCaps unterstützen oder anwenden? – Da PCaps sind im Gegensatz zu SUID-0 sicherheitstechnisch überlegen sind, werden Distros mittelfristig PCaps supporten und anwenden. ● Was ist legacy support? – Legacy support ist die Unterstützung von Apps, die selber nicht mit PCaps umgehen können und damit ihre Sets nicht selber verwalten können. Sie bekommen neben dem Permitted auch gleich das Effective Set bestückt. ● Benutzen andere OS auch PCaps? – Ja, unter Solaris heißen sie zum Beispiel Privilegien. ● Wo finde ich mehr Infos & die erwähnten Patches? – http://www.friedhoff.org/posixfilecaps.html


Herunterladen ppt "Version 1.2 - 28.05.2008C. Friedhoff - PCaps - Linuxtag20081 POSIX {,File} Capabilities - killall setuid-0 binaries and far beyond POSIX Capabilities ·"

Ähnliche Präsentationen


Google-Anzeigen