Dec 182010
 

chattrSiete root sul vostro sistema, date un rm di un file ed ottente un “rm: cannot remove `test’: Operation not permitted” possibile ?
Si se ci sono degli attributi estesi particolari.

La cosa “interessante” è che anche alcuni rootkit utilizzano questi attributi dopo aver cambiato alcuni binarii (ps, netstat) in modo che ripristinare gli originali sia un po’ più difficile.

Ma non preoccupatevi in questo articolo vi presenterò i comandi lsattr e chattr che vi aiuteranno nel mostrare e manipolare gli attributi estesi sulla vostra macchina Linux



I programmi chattr e lsattr su Linux e gli attributi che manipolano sono specifici per la famiglia Second Extended Filesystem (ext2, ext3), e sono disponibili come parte del pacchetto e2fsprogs. Non funzionano su file residenti su altri filesystem, come ad esempio ReiserFS o FAT.

Sintassi Chattr

chattr [-RV] [-+=AacDdijsSu] [-v version] files

L’operatore `+ ‘ fa sì che gli attributi selezionati siano aggiunti agli attributi dei file esistenti;`-‘ li induce ad essere rimossi, e `= ‘ li induce ad essere gli unici attributi che i file sono.

Le lettere `ASacDdijsu’ servono a selezionare l’attributo sul quale si sta operando.

Alcuni attributi includono:

* Non aggiornare l’atime (A)
* Aggiornamento sincrono (S)
* Aggiornamento sincrono delle directory (D)
* append only (a)
* compresso (c)
* no dump (d)
* immutabile (i)
* data journalling (j)
* cancellazione sicura (s)
* top of directory hierarchy (T)
* no tail-merging (t)
* Non cancellabile (u)

Esempio di uso nella mia tmp (FS ext4)

root@laptop:/tmp/test-extended# ls -l
total 0
-rw-r--r-- 1 root root 0 2010-12-17 22:59 test
-rw-r--r-- 1 root root 0 2010-12-17 22:59 test2
-rw-r--r-- 1 root root 0 2010-12-17 22:59 test3
 
root@laptop:/tmp/test-extended# lsattr
-----------------e- ./test
-----------------e- ./test3
-----------------e- ./test2
 
root@laptop:/tmp/test-extended# chattr +u test
root@laptop:/tmp/test-extended# lsattr
-u---------------e- ./test
-----------------e- ./test3
-----------------e- ./test2
 
root@laptop:/tmp/test-extended# rm test
root@laptop:/tmp/test-extended# ls
test2  test3

Sopresi ?
In realtà il flag -u era valido solo nell’originale FS ext, ma questa funzionalità (undelete) è stata persa a partire dal ext2, quindi ora è un flag totalmente inutile.

Ma vediamo adesso qualcosa che funziona correttamente.

root@laptop:/tmp/test-extended# touch test4
root@laptop:/tmp/test-extended# chattr +i test4
root@laptop:/tmp/test-extended# lsattr
-----------------e- ./test3
-----------------e- ./test2
----i------------e- ./test4
 
root@laptop:/tmp/test-extended# rm test4
rm: cannot remove `test4': Operation not permitted
root@laptop:/tmp/test-extended# ls -l
total 0
-rw-r--r-- 1 root root 0 2010-12-17 22:59 test2
-rw-r--r-- 1 root root 0 2010-12-17 22:59 test3
-rw-r--r-- 1 root root 0 2010-12-17 23:24 test4

Quindi il flag +i funziona, e serve per impostare il bit immutabile per evitare che anche root possa cancellare o modificare il contenuto di un file.

Potete utilizzare questo flag per impostare uno o più file come immutabili ed essere sicuri che non saranno cancellati (o modificati) per sbaglio.

Un altro esempio con il flag a (append):

root@laptop:/tmp/test-extended# touch test5
root@laptop:/tmp/test-extended# chattr +a test5
root@laptop:/tmp/test-extended# echo "this is a test" > test5
-bash: test5: Operation not permitted
root@laptop:/tmp/test-extended# lsattr
-----------------e- ./test3
-----------------e- ./test2
-----a-----------e- ./test5
----i------------e- ./test4
 
root@laptop:/tmp/test-extended# echo "this is a test" >> test5
root@laptop:/tmp/test-extended# cat test5
this is a test
root@capecchi:/tmp/test-extended# rm test5
rm: cannot remove `test5': Operation not permitted

Quindi un file che abbia impostato il flag a, può essere aprto solo in modalità append e non può essere cancellato. I log sono un buon candidato per questo per evitare che vengano manomessi.

Popular Posts:

Flattr this!

  One Response to “Introduzione agli attributi estesi”

  1. These are not extended attributes but file system attributes.
    File system attributes are predetermined flags that can be set on objects on certain file systems.
    Extended attributes are arbitrary strings.

Leave a Reply to ChrisK Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*