Újonckör. Dr. Bencsáth Boldizsár. Access control Some slides: William Stallings and Lawrie Brown Computer Security: Principles and Practice

Hasonló dokumentumok
Adatbiztonság GI. Dr. Bencsáth Boldizsár. Access control Some slides: William Stallings and Lawrie Brown Computer Security: Principles and Practice

Adatbiztonság a gazdaságinformatikában

Csatlakozás a BME eduroam hálózatához Setting up the BUTE eduroam network

Using the CW-Net in a user defined IP network

Széchenyi István Egyetem

Linux Essentials. Torma Hajnalka

Operációs rendszerek 1.

4. Gyakorlat: Csoportházirend beállítások

Cloud computing. Cloud computing. Dr. Bakonyi Péter.

SOPHOS simple + secure. A dobozba rejtett biztonság UTM 9. Kókai Gábor - Sophos Advanced Engineer Balogh Viktor - Sophos Architect SOPHOS

Verziókezelt konfigurációmanagement++ Pásztor György, SZTE Klebelsberg Könyvtár

(NGB_TA024_1) MÉRÉSI JEGYZŐKÖNYV

11. Gyakorlat: Certificate Authority (CA), FTP site-ok

Proxer 7 Manager szoftver felhasználói leírás

Cloud computing Dr. Bakonyi Péter.

Angol Középfokú Nyelvvizsgázók Bibliája: Nyelvtani összefoglalás, 30 kidolgozott szóbeli tétel, esszé és minta levelek + rendhagyó igék jelentéssel

EN United in diversity EN A8-0206/419. Amendment

(Asking for permission) (-hatok/-hetek?; Szabad ni? Lehet ni?) Az engedélykérés kifejezésére a következő segédigéket használhatjuk: vagy vagy vagy

discosnp demo - Peterlongo Pierre 1 DISCOSNP++: Live demo

USER MANUAL Guest user

Correlation & Linear Regression in SPSS

Operációs rendszerek. UNIX fájlrendszer

Lopocsi Istvánné MINTA DOLGOZATOK FELTÉTELES MONDATOK. (1 st, 2 nd, 3 rd CONDITIONAL) + ANSWER KEY PRESENT PERFECT + ANSWER KEY

ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA I. VIZSGÁZTATÓI PÉLDÁNY

Lexington Public Schools 146 Maple Street Lexington, Massachusetts 02420

T Á J É K O Z T A T Ó. A 1108INT számú nyomtatvány a webcímen a Letöltések Nyomtatványkitöltő programok fülön érhető el.

Construction of a cube given with its centre and a sideline

Operációs Rendszerek II. labor alkalom

Utasítások. Üzembe helyezés

STUDENT LOGBOOK. 1 week general practice course for the 6 th year medical students SEMMELWEIS EGYETEM. Name of the student:

Cashback 2015 Deposit Promotion teljes szabályzat

Operációs rendszerek gyak.

ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA I. VIZSGÁZTATÓI PÉLDÁNY

Felhasználók és csoportok

2. lépés: openssh szerver telepítés sudo apt-get install openssh-server

On The Number Of Slim Semimodular Lattices

Can/be able to. Using Can in Present, Past, and Future. A Can jelen, múlt és jövő idejű használata

EMTP, EGY ÚJ LEVELEZÕ PROTOKOLL ÉS IMPLEMENTÁCIÓJA

Intézményi IKI Gazdasági Nyelvi Vizsga

10. Gyakorlat: Alkalmazások publikálása Remote Desktop Szervízen keresztül

Unix/Linux alapok 2. Operációs rendszerek I. készítette: Kozlovszky Miklós, Bringye Zsolt Póserné Oláh Valéria, Windisch Gergely

ANGOL NYELVI SZINTFELMÉRŐ 2012 A CSOPORT. to into after of about on for in at from

Programozás alapjai óra. Morvai Flórián, 2010 Dr. Dévényi Károly előadásvázlata alapján

ENROLLMENT FORM / BEIRATKOZÁSI ADATLAP

Computer Architecture

Laborgyakorlat: A Windows XP haladó telepítése

1. MINTAFELADATSOR KÖZÉPSZINT. Az írásbeli vizsga időtartama: 30 perc. III. Hallott szöveg értése

Operációs Rendszerek II. labor. 2. alkalom

1. Gyakorlat: Telepítés: Windows Server 2008 R2 Enterprise, Core, Windows 7

Utolsó módosítás:

LINUX LDAP címtár. Mi a címtár?

chmod umask chown, chgrp

Tudományos Ismeretterjesztő Társulat

Tavaszi Sporttábor / Spring Sports Camp május (péntek vasárnap) May 2016 (Friday Sunday)

Az Open Data jogi háttere. Dr. Telek Eszter

Számítógépes Hálózatok GY 8.hét

DANS és Narcis. Burmeister Erzsébet. HUNOR találkozó, Budapest március 13.

Dependency preservation

Budapest By Vince Kiado, Klösz György

ANGOL NYELVI SZINTFELMÉRŐ 2013 A CSOPORT. on of for from in by with up to at

DOAS változások, összefoglaló

SAMBA. Forrás: Lajber Zoltán: SAMBA alapok dia, SZIE

Miskolci Egyetem Gazdaságtudományi Kar Üzleti Információgazdálkodási és Módszertani Intézet. Correlation & Linear. Petra Petrovics.

Szakmai továbbképzési nap akadémiai oktatóknak december 14. HISZK, Hódmezővásárhely / Webex

Néhány folyóiratkereső rendszer felsorolása és példa segítségével vázlatos bemutatása Sasvári Péter

Laborgyakorlat: Virtuális memória beállítások testreszabása

FOSS4G-CEE Prágra, 2012 május. Márta Gergely Sándor Csaba

Operációs rendszerek I. IIII. gyakorlat

JEROMOS A BARATOM PDF

Tudományos Ismeretterjesztő Társulat

Az időhöz kötődő parancsok

Az Intel gyorsindító készlete a Linux*-hoz v1.2 Gyorstájékoztató. Megrendelési szám: C

Genome 373: Hidden Markov Models I. Doug Fowler

XV1100K(C)/XV1100SK(C)

Create & validate a signature

EXKLUZÍV AJÁNDÉKANYAGOD A Phrasal Verb hadsereg! 2. rész

Youtube videó letöltés és konvertálás Linuxon

Sebastián Sáez Senior Trade Economist INTERNATIONAL TRADE DEPARTMENT WORLD BANK

2. Local communities involved in landscape architecture in Óbuda

Correlation & Linear Regression in SPSS

Hálózati adminisztráció Linux (Ubuntu 8.04) 12. gyakorlat

Eladni könnyedén? Oracle Sales Cloud. Horváth Tünde Principal Sales Consultant március 23.

A modern e-learning lehetőségei a tűzoltók oktatásának fejlesztésében. Dicse Jenő üzletfejlesztési igazgató

Minta ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA II. Minta VIZSGÁZTATÓI PÉLDÁNY

Készítette: Szabóné Nacsa Rozália

KN-CP50. MANUAL (p. 2) Digital compass. ANLEITUNG (s. 4) Digitaler Kompass. GEBRUIKSAANWIJZING (p. 10) Digitaal kompas

Fájl rendszer. Fájl koncepció Elérési módok Könyvtár szerkezet Védelem Konzisztencia szemantika

Az állományok kezelésére használt fontosabb parancsok

Előszó.2. Starter exercises. 3. Exercises for kids.. 9. Our comic...17

Mobil webszerverek. Márton Gábor Nokia Research Center. W3C Mobilweb Műhelykonferencia, Budapest október 18.

Utazás Szállás. Szállás - Keresés. Szállás - Foglalás. Útbaigazítás kérése. ... kiadó szoba?... a room to rent? szállásfajta.

TestLine - Angol teszt Minta feladatsor

Smaller Pleasures. Apróbb örömök. Keleti lakk tárgyak Répás János Sándor mûhelyébõl Lacquerware from the workshop of Répás János Sándor

3. MINTAFELADATSOR KÖZÉPSZINT. Az írásbeli vizsga időtartama: 30 perc. III. Hallott szöveg értése

1. sz. melléklet: Az önálló PDC-ként működő Samba szerver konfigurációs állománya

Please stay here. Peter asked me to stay there. He asked me if I could do it then. Can you do it now?

Phenotype. Genotype. It is like any other experiment! What is a bioinformatics experiment? Remember the Goal. Infectious Disease Paradigm

Új funkciók az RBP-ben október 1-től New functions in RBP from 1 October Tatár Balázs

SQL/PSM kurzorok rész

Ellenőrző lista. 2. Hálózati útvonal beállítások, kapcsolatok, névfeloldások ellenőrzése: WebEC és BKPR URL-k kliensről történő ellenőrzése.

Átírás:

Újonckör Access control Some slides: William Stallings and Lawrie Brown Computer Security: Principles and Practice Lecture slides by Lawrie Brown 2016. október 7. Budapest Dr. Bencsáth Boldizsár adjunktus BME Hálózati Rendszerek és Szolgáltatások Tanszék bencsath@crysys.hit.bme.hu

2 Linux Security Model Linux s traditional security model is: people or processes with root privileges can do anything other accounts can do much less hence attacker s want to get root privileges can run robust, secure Linux systems crux of problem is use of Discretionary Access Controls (DAC)

Linux Security Transactions Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. 3

4 File System Security in Linux everything as a file e.g. memory, device-drivers, named pipes, and other system resources hence why filesystem security is so important I/O to devices is via a special file e.g. /dev/cdrom, /dev/console, /dev/sda have other special files like named pipes a conduit between processes / programs

5 Users and Groups a user-account (user) represents someone capable of using files associated both with humans and processes a group-account (group) is a list of user-accounts users have a main group may also belong to other groups users & groups are not files

6 Users and Groups user's details are kept in /etc/passwd maestro:x:200:100:maestro Edward Hizzersands:/home/maestro:/bin/bash additional group details in /etc/group conductors:x:100: pianists:x:102:maestro,volodya use useradd, usermod, userdel to alter

Usage of the passwd,group files root@shamir:/# strace -v -f ls -la z 2>&1 grep "\(nssw\)\ \(pass\)" open("/etc/nsswitch.conf", O_RDONLY) = 3 read(3, "# /etc/nsswitch.conf\n#\n# Example"..., 4096) = 503 open("/etc/passwd", O_RDONLY O_CLOEXEC) = 3 7 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz.

more /etc/nsswitch.conf # /etc/nsswitch.conf # # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: group: shadow: compat compat compat hosts: networks: files mdns4_minimal [NOTFOUND=return] dns mdns4 files protocols: services: ethers: rpc: db files db files db files db files netgroup: nis 8 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz.

9 File Permissions files have two owners: a user & a group each with its own set of permissions with a third set of permissions for other permissions are to read/write/execute in order user/group/other, cf. -rw-rw-r-- 1 maestro user 35414 Mar 25 01:38 baton.txt set using chmod command

10 Directory Permissions read = list contents write = create or delete files in directory execute = use anything in or change working directory to this directory e.g. $ chmod g+rx extreme_casseroles $ ls -l extreme_casseroles drwxr-x--- 8 biff drummers 288 Mar 25 01:38 extreme_casseroles

Directory x rights and subdirs root@shamir:/data/home/boldi# ls -la /z total 12 drwxr-xr-- 3 root root 4096 Feb 24 00:36. drwxr-xr-x 39 root root 4096 Feb 24 00:36.. drwxr-xr-x 2 root root 4096 Feb 24 00:36 a root@shamir:/data/home/boldi# ls -la /z/a total 12 drwxr-xr-x 2 root root 4096 Feb 24 00:36. drwxr-xr-- 3 root root 4096 Feb 24 00:36.. -rw-r--r-- 1 root root 8 Feb 24 00:36 aa root@shamir:/data/home/boldi# exit boldi@shamir:~ $ ls -la /z ls: cannot access /z/..: Permission denied ls: cannot access /z/.: Permission denied ls: cannot access /z/a: Permission denied total 0 d??????????????./ d??????????????../ d?????????????? a/ boldi@shamir:~ $ cd /z -bash: cd: /z: Permission denied boldi@shamir:~ $ ls -la /z/a ls: cannot access /z/a: Permission denied boldi@shamir:~ $ cat /z/a/aa cat: /z/a/aa: Permission denied Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. 11

File read vs. x on dir boldi@shamir:~ $ ls -la /z ls: cannot access /z/..: Permission denied ls: cannot access /z/file: Permission denied ls: cannot access /z/.: Permission denied ls: cannot access /z/a: Permission denied total 0 d??????????????./ d??????????????../ d?????????????? a/ -?????????????? file boldi@shamir:~ $ cat /z/file cat: /z/file: Permission denied boldi@shamir:~ $ sudo -s root@shamir:/data/home/boldi# ls -la /z/file -rw-r--r-- 1 root root 4 Feb 24 00:39 /z/file 12 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz.

13 Sticky Bit originally used to lock file in memory now used on directories to limit delete if set must own file or dir to delete other users cannot delete even if have write permission When the sticky bit is set, only the item's owner, the directory's owner, or the superuser(root) can rename or delete files. set using chmod command with +t flag, e.g. chmod +t extreme_casseroles directory listing includes t or T flag (T=t, but not x) drwxrwx--t 8 biff drummers 288 Mar 25 01:38 extreme_casseroles only apply to specific directory not child dirs

14 SetUID and SetGID setuid bit means program "runs as" owner no matter who executes it setgid bit means run as a member of the group which owns it again regardless of who executes it "run as" = "run with same privileges as are very dangerous if set on file owned by root or other privileged account or group only used on executable files, not shell scripts

15 SetGID and Directories setuid has no effect on directories setgid does and causes any file created in a directory to inherit the directory's group useful if users belong to other groups and routinely create files to be shared with other members of those groups instead of manually changing its group

Kernel vs User Space Kernel space refers to memory used by the Linux kernel and its loadable modules (e.g., device drivers) User space refers to memory used by all other processes kernel enforces Linux DAC it is critical to isolate kernel from user space kernel space never swapped to disk only root may load and unload kernel modules The situations is very similar on windows, modules -> drivers Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. 16

17 setuid root Vulnerabilities a setuid root program runs as root no matter who executes it used to provide unprivileged users with access to privileged resources must be very carefully programmed if can be exploited due to a software bug may allow otherwise-unprivileged users to use it to wield unauthorized root privileges distributions now minimise setuid-root programs system attackers still scan for them!

18 Rootkits allow attacker to cover their tracks if successfully installed before detection, all is very nearly lost originally collections of hacked commands hiding attacker s files, directories, processes now use loadable kernel modules intercepting system calls in kernel-space hiding attacker from standard commands may be able to detect with some tools, e.g. chkrootkit General solution: wipe and rebuild system (including BIOS and other firmware!)

19 Basic Unix tools cat: Concatenate and print files cd: Change the working directory ls: List directory contents chgrp <group> <file>: Change the file group ownership chmod <right> <file>: Change the file modes/attributes/permissions cp <source> <target>: Copy files mkdir: Make directories touch: Change file access and modification times id: Return user identity

sudo. vendeg: nbnb1234 user: nbnb1234 (név/jelszó) 20 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz.

21 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. Témák /opt directory dolgok Web backdoorok Crontab gond Web keresztüljárás és szeparáció Webes hibák logger, fájl láthatóság,.htaccess Web Rendszer backdoor

Teszt fájlok /opt User: user /opt/test/myfile[1,2,3 ] Myfile1: nem törölhető, root sem tudja törölni. Miért? Mitől függ, hogy egy fájl törölhető-e? Ki törölhet egy fájlt? Válasz: lsattr ext3 immutable flag van rajta. Csak a root szedheti le. Myfile2: setgid bit van a directoryn. Hozzunk létre egy fájlt, és az a directory csoportjával jön létre nem a mienkkel, még akkor is, ha mi benne se vagyunk a csoportban. Nézzük meg az umaskot. Módosítsuk az umaskot, hogy csoport írási joggal jöjjön létre az új fájl. Readme, writeme: Ezeket a fájlokat a csoport és mindenki más is olvashatja illetve írhatja. A tulajdonosa viszont nem, próbáljuk ki! Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. 22

23 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. /opt/test myfile3 readthis. Nem tudjuk olvasni a fájlt a user userrel, pedig úgy tűnik a jogok jók. Van egy furcsa + jel a jogok helyén. ACL-t használtunk getfacl-lel nézzük meg. Setfacl-lel módosítható. Myfile4: nincs olvasasi jog a directory-n, de van x jog. Ha tudjuk milyen fájl van a directoryban, ettől még ki lehet olvasni a tartalmát esetleg. Nézzük meg rootként és a user userrel Myfile5: nincs x jog a directoryn. Ezért ugyan megnézhetjük, hogy kb mi van benne, de bele nem tudunk menni. A fájlokat sem tudjuk kiolvasni kintről sem.

File from future (clock set back) -rw-r--r-- 1 root root 18092 Aug 4 2016 LICENSE.txt root@debian1webserver:/var/www/html# stat LICENSE.txt File: LICENSE.txt Size: 18092 Blocks: 40 IO Block: 4096 regular file Device: 801h/2049d Inode: 84 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2016-08-04 23:44:14.000000000-0400 Modify: 2016-08-04 23:44:14.000000000-0400 Change: 2014-11-13 12:41:40.932000000-0500 Birth: - root@debian1webserver:/var/www/html# date Thu Nov 13 12:41:48 EST 2014 24 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz.

25 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. Web Backdoors http://10.55.1.199/modules/mod_login/glad.php http://10.55.1.199/modules/mod_menu/gallery.php Van még minimum kettő! /var/www 1. módszer: grep-eljünk eval-ra, base64-re, stb. 2. módszer: friss fájlok keresése, pl. find. ctime -10 3. módszer: yara szabályokkal keressünk, pl. yara r /root/backdoor.yara /var/www/

26 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. Elrontott crontab. A /home/user/bin/every_minute script lefut minden percben A root futtatja Nincs jogunk a fájlt írni user userrel Viszont törölhetjük, felülírhatjuk egy újjal ami a root nevében indít parancsokat! Próbáljuk ki.

27 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. Rendszer backdoor /sbin/mount.fuse3g egy backdoor Nézzük meg a dátumokat (fuse, fuse3g) stat paranccsal Touch r paranccsal lett átírva a fuse3g dátuma hogy azonos legyen Strings paranccsal nézzük meg milyen stringek vannak benne A parancs titok parameterrel root shellt ad A forráskódja is a gépen van. Rákereshetünk pl. a grep-pel hol van a titok szó Ls la /var/tmp. Feltűnik valami? directory

Webes 28 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz.

Webes izoláció 29 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz.

30 Making new directories and files: the umask boldi@rivest:~/access_control $ ls -la total 24 drwxr-xr-x 2 boldi users 4096 2010-10-26 12:58./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ boldi@rivest:~/access_control $ mkdir test boldi@rivest:~/access_control $ ls -la total 28 drwxr-xr-x 3 boldi users 4096 2010-10-26 12:58./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ drwxr-xr-x 2 boldi users 4096 2010-10-26 12:58 test/ boldi@rivest:~/access_control $ umask 0022 boldi@rivest:~/access_control $ touch test.txt boldi@rivest:~/access_control $ ls -la total 28 drwxr-xr-x 3 boldi users 4096 2010-10-26 12:58./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ drwxr-xr-x 2 boldi users 4096 2010-10-26 12:58 test/ -rw-r--r-- 1 boldi users 0 2010-10-26 12:58 test.txt

31 Playing with umask Umask determines what rights are set on the newly created files. boldi@rivest:~/access_control $ umask -S u=rwx,g=rx,o=rx boldi@rivest:~/access_control $ umask 0022 boldi@rivest:~/access_control $ umask u=rwx,g=rwx,o=rx boldi@rivest:~/access_control $ umask 0002 boldi@rivest:~/access_control $ umask u=rx,g=rx,o=rx boldi@rivest:~/access_control $ umask 0222 (read:4 write:2 execute:1) Octal umasks are calculated via the bitwise AND of the unary complement of the argument (using bitwise NOT) and the permissions specified by the program: typically 666 in the case of files, and 777 in the case of directories. A umask set to u=rwx,g=rwx,o= (0007 in octal form) will result in new files having the modes -rw-rw----, and new directories having the modes drwxrwx---

32 An example with multiple groups A UNIX user can be in multiple groups: boldi@rivest:~$ id uid=1000(boldi) gid=1000(boldi) groups=4(adm), 1000(boldi) boldi@rivest:~$ newgrp adm boldi@rivest:~$ id uid=1000(boldi) gid=4(adm) groups=4(adm),1000(boldi) Only one group is effective at a time. At starting this is the default group setting from the /etc/passwd file, but the user can change it with the newgrp command. boldi@rivest:/tmp/test$ mkdir a boldi@rivest:/tmp/test$ ls -la total 340 drwxrwxr-x 3 boldi boldi 4096 Oct 26 13:20. drwxrwxrwt 3 root root 4096 Oct 26 13:20.. drwxrwxr-x 2 boldi adm 4096 Oct 26 13:20 a

33 Setgid directories boldi@rivest:/tmp/test$ chmod g+s. boldi@rivest:/tmp/test$ ls -la total 340 drwxrwsr-x 3 boldi boldi 4096 Oct 26 13:20. drwxrwxrwt 3 root root 4096 Oct 26 13:23.. drwxrwxr-x 2 boldi adm 4096 Oct 26 13:20 a boldi@rivest:/tmp/test$ id uid=1000(boldi) gid=4(adm) groups=4(adm),1000(boldi) boldi@rivest:/tmp/test$ mkdir b boldi@rivest:/tmp/test$ ls -la total 344 drwxrwsr-x 4 boldi boldi 4096 Oct 26 13:23. drwxrwxrwt 3 root root 4096 Oct 26 13:23.. drwxrwxr-x 2 boldi adm 4096 Oct 26 13:20 a drwxrwsr-x 2 boldi boldi 4096 Oct 26 13:23 b In directories with group s (x+s) any new file will have the same group owner as the directory itself (and the s right is inhibited)

34 Example: Extra rights of the root user root@shamir:/data/home/boldi/access_control# ls -la total 28 drwxr-xr-x 3 boldi users 4096 2010-10-26 12:58./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ drwxr-xr-x 2 boldi users 4096 2010-10-26 12:58 test/ -rw-r--r-- 1 boldi users 0 2010-10-26 12:58 test.txt root@shamir:/data/home/boldi/access_control# id uid=0(root) gid=0(root) groups=0(root),124(smbusers),195(printusers) root@shamir:/data/home/boldi/access_control# mkdir a root@shamir:/data/home/boldi/access_control# ls -la total 32 drwxr-xr-x 4 boldi users 4096 2010-10-26 13:30./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ drwxr-xr-x 2 root root 4096 2010-10-26 13:30 a/ drwxr-xr-x 2 boldi users 4096 2010-10-26 12:58 test/ -rw-r--r-- 1 boldi users 0 2010-10-26 12:58 test.txt Root used can write files in all directories, no matter of security settings

35 Root&g+s boldi@shamir:~/access_control/f $ ls -la total 20 drwxrwsr-x 2 boldi adm 4096 Apr 5 00:17./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 d boldi@shamir:~/access_control/f $ sudo touch e boldi@shamir:~/access_control/f $ ls -la total 20 drwxrwsr-x 2 boldi adm 4096 Apr 5 00:17./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 d -rw-r--r-- 1 root adm 0 Apr 5 00:17 e Expl: Root was able to make a new file in the directory, but that also inherited group ownership due to g+s.

36 Directory rights vs. file rights boldi@shamir:~/access_control $ ls -la total 24 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:36./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ -rw-r--r-- 1 root root 0 2010-10-26 13:36 b boldi@shamir:~/access_control $ id uid=1005(boldi) gid=100(users) groups=30(dip),100(users) boldi@shamir:~/access_control $ rm b rm: remove write-protected regular empty file `b'? y boldi@shamir:~/access_control $ ls -la total 24 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:36./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ boldi@shamir:~/access_control $ The file was owned by root, but the directory is writable by user boldi. Therefore he can delete the file. (he cannot write the file, but the deletion is basically modifying the directory in UNIX)

37 cp boldi@shamir:~/access_control/f $ ls -la total 8 drwxr-xr-x 2 boldi users 4096 Apr 5 00:04./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 root users 0 Apr 5 00:04 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c boldi@shamir:~/access_control/f $ cp c b cp: cannot create regular file `b': Permission denied boldi@shamir:~/access_control/f $ rm b rm: remove write-protected regular empty file `b'? y boldi@shamir:~/access_control/f $ cp c b boldi@shamir:~/access_control/f $ ls -la total 16 drwxr-xr-x 2 boldi users 4096 Apr 5 00:05./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi users 6 Apr 5 00:05 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c The first copy command tries to overwrite the file rather than delete and re-make But manual remove and then copy works. Of course, in this case the file has new owner

38 cp From the last slide we know that a simple copy on already existing file does not delete and re-make the file, so the rights might remain: boldi@shamir:~/access_control/f $ ls -la total 16 drwxr-xr-x 2 boldi users 4096 Apr 5 00:05./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-rw-rw- 1 root users 2 Apr 5 00:08 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c boldi@shamir:~/access_control/f $ cp c b boldi@shamir:~/access_control/f $ ls -la total 16 drwxr-xr-x 2 boldi users 4096 Apr 5 00:05./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-rw-rw- 1 root users 6 Apr 5 00:08 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c As You can see b is owerwritten (see size), but the owner, rights remained.

39 What s up with group setgid+cp? boldi@shamir:~/access_control/f $ ls -la total 16 drwxrwsr-x 2 boldi adm 4096 Apr 5 00:05./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-rw-rw- 1 root users 2 Apr 5 00:11 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c boldi@shamir:~/access_control/f $ cp c b boldi@shamir:~/access_control/f $ ls -la total 16 drwxrwsr-x 2 boldi adm 4096 Apr 5 00:05./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-rw-rw- 1 root users 6 Apr 5 00:11 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c boldi@shamir:~/access_control/f $ rm b boldi@shamir:~/access_control/f $ cp c b boldi@shamir:~/access_control/f $ ls -la total 16 drwxrwsr-x 2 boldi adm 4096 Apr 5 00:11./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi adm 6 Apr 5 00:11 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c Explanation: Although there was groups setgid, cp did not make a new inode thus all rights remained as-is, but if we delete and remake file, that s different.

40 Hard links boldi@shamir:~/access_control/f $ ls -la total 20 drwxrwsr-x 2 boldi users 4096 Apr 5 00:13./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 2 boldi users 4 Apr 5 00:12 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c -rw-r--r-- 2 boldi users 4 Apr 5 00:12 d boldi@shamir:~/access_control/f $ chgrp eid b boldi@shamir:~/access_control/f $ ls -la total 20 drwxrwsr-x 2 boldi users 4096 Apr 5 00:13./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 d Explanation: chgrp on b also affected rights of d, as d was a hard link to b. (check 2 after the rights string).

41 Different behaviour of rm boldi@shamir:~/access_control/f $ ls -la total 20 drwxrwsr-x 2 boldi adm 4096 Apr 5 00:17./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 b -rw-r--r-- 1 boldi users 6 Apr 5 00:04 c -rw-r--r-- 2 boldi eid 4 Apr 5 00:12 d -rw-r--r-- 1 root adm 0 Apr 5 00:17 e boldi@shamir:~/access_control/f $ rm e d c rm: remove write-protected regular empty file `e'? y boldi@shamir:~/access_control/f $ OS only asked about e, not the other files.

42 Rights on my own files boldi@shamir:~/access_control $ touch c boldi@shamir:~/access_control $ ls -la total 24 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:39./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ -rw-r--r-- 1 boldi users 0 2010-10-26 13:39 c boldi@shamir:~/access_control $ chmod a-r c boldi@shamir:~/access_control $ ls -la total 24 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:39./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ --w------- 1 boldi users 0 2010-10-26 13:39 c boldi@shamir:~/access_control $ cat c cat: c: Permission denied boldi@shamir:~/access_control $ chmod a+r c boldi@shamir:~/access_control $ cat c boldi@shamir:~/access_control $ The read rights from file c are removed. Even if the owner is boldi, he is not permitted to read the file. But boldi is the owner of the file and thus give the access rights back. Now he can read the file. (access right setting is allowed to root and the owner of the file)

Own files #2 The above mentioned example does not relate to directory rights: boldi@shamir:~/access_control/f $ ls -la total 16 dr-xr-xr-x 2 boldi adm 4096 Apr 5 00:21./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi eid --w------- 1 boldi adm 4 Apr 5 00:12 b 4 Apr 5 00:21 c boldi@shamir:~/access_control/f $ chmod a+r c boldi@shamir:~/access_control/f $ ls -la total 16 dr-xr-xr-x 2 boldi adm 4096 Apr 5 00:21./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi eid -rw-r--r-- 1 boldi adm 4 Apr 5 00:12 b 4 Apr 5 00:21 c As You can see, the rights of e was recovered although there was no write permission on the directory, nor on the file. Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. 43

Modifying access rights boldi@shamir:~/access_control $ ls -la total 24 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:39./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ -rw-rw-r-- 1 pek users 0 2010-10-26 13:39 c boldi@shamir:~/access_control $ chmod a-r c chmod: changing permissions of `c': Operation not permitted Even if the file is writable and the directory is writable, the access rights cannot be modified by other users than the owner Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. 44

45 write r.&rename? Write->read r.? boldi@shamir:~/access_control $ ls -la total 28 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:51./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ -rw-rw-r-- 1 pek users 3 2010-10-26 13:51 c boldi@shamir:~/access_control $ chmod a-r c chmod: changing permissions of `c': Operation not permitted boldi@shamir:~/access_control $ mv c d boldi@shamir:~/access_control $ ls -la total 28 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:51./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ -rw-rw-r-- 1 pek users 3 2010-10-26 13:51 d Boldi has no right to modify the access permissions of file c, but can rename it to d. (as it is a directory write) boldi@shamir:~/access_control $ ls -la total 28 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:53./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ --w--w---- 1 boldi users 3 2010-10-26 13:51 e boldi@shamir:~/access_control $ cat e cat: e: Permission denied Write permission does not mean that You can also read it.

46 Priorities among rights boldi@shamir:~/access_control $ ls -la total 28 drwxr-xr-x 2 boldi users 4096 2010-10-26 13:53./ drwxr-xr-x 189 boldi users 20480 2010-10-26 12:58../ ----rw-r-- 1 boldi users 3 2010-10-26 13:51 e boldi@shamir:~/access_control $ cat e cat: e: Permission denied Even if others and group has read permission, the owner cannot read the file if he does not have it. (The system only checks the owner s permissions if You are the owner, only check group permissions if You are not. The same stands for group and others.) pek@shamir:/data/home/boldi/access_control$ cat e Aa But other users (such as pek) can read the file

Beyond standard unix rights Some file systems, e.g. ext2, ext3 have extra possibilities, like file attributes (chattr,lsattr), a means append only boldi@shamir:~/access_control/f $ ls -la total 12 drwxrwxr-x 2 boldi adm 4096 Apr 5 00:32./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi eid -rw-r--r-- 1 boldi users 4 Apr 5 00:12 b 0 Apr 5 00:32 c boldi@shamir:~/access_control/f $ sudo chattr +a c boldi@shamir:~/access_control/f $ ls -la total 12 drwxrwxr-x 2 boldi adm 4096 Apr 5 00:32./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi eid -rw-r--r-- 1 boldi users 4 Apr 5 00:12 b 0 Apr 5 00:32 c boldi@shamir:~/access_control/f $ rm c rm: cannot remove `c': Operation not permitted Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. 47

48 Ext2 attr. boldi@shamir:~/access_control/f $ echo "aaaa" >c -bash: c: Operation not permitted boldi@shamir:~/access_control/f $ echo "aaaa" >>c boldi@shamir:~/access_control/f $ ls -la total 16 drwxrwxr-x 2 boldi adm 4096 Apr 5 00:32./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi eid 4 Apr 5 00:12 b -rw-r--r-- 1 boldi users 5 Apr 5 00:34 c boldi@shamir:~/access_control/f $ echo "aaaa" >>c boldi@shamir:~/access_control/f $ ls -la total 16 drwxrwxr-x 2 boldi adm 4096 Apr 5 00:32./ drwxr-xr-x 3 boldi users 4096 Apr 5 00:04../ -rw-r--r-- 1 boldi eid 4 Apr 5 00:12 b -rw-r--r-- 1 boldi users 10 Apr 5 00:34 c boldi@shamir:~/access_control/f $ lsattr -----a-------------./c -------------------./b The append right is useful e.g. In case of.bash_history: The shell can append new info to it, but the user won t be able to delete his history.

49 Dr. Bencsáth Boldizsár, Hálózati Rendszerek és Sz. Tsz. Other ways of separation Chroot Jail Container-based virtualization Virtualization