11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

od<br />

hexdump<br />

objdump<br />

mcookie<br />

Capitolo 12. Filtri, programmi e coman<strong>di</strong> esterni<br />

#+ un lavoro molto più completo <strong>di</strong> quanto non faccia questo semplice script.<br />

# http://www.ibiblio.org/pub/Linux/utils/file/wipe-2.0.0.tar.bz2<br />

# Per un’analisi approfon<strong>di</strong>ta sull’argomento della cancellazione sicura dei<br />

#+ file, ve<strong>di</strong> lo stu<strong>di</strong>o <strong>di</strong> Peter Gutmann,<br />

#+ "Secure Deletion of Data From Magnetic and Solid-State Memory".<br />

# http://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html<br />

Il filtro od, ovvero octal dump, converte l’input (o i file) in formato ottale (base-8) o in altre basi. È<br />

utile per visualizzare o elaborare file dati binari o file <strong>di</strong> <strong>di</strong>spositivi <strong>di</strong> sistema altrimenti illeggibili,<br />

come /dev/urandom, e come filtro per i dati binari. Ve<strong>di</strong> Esempio 9-28 e Esempio 12-13.<br />

Esegue la conversione in esadecimale, ottale, decimale o ASCII <strong>di</strong> un file binario. Questo comando<br />

è grosso modo equivalente ad od, visto prima, ma non altrettanto utile.<br />

Visualizza informazioni su un file oggetto, o un binario eseguibile, sia in formato esadecimale che<br />

come listato assembly (con l’opzione -d).<br />

bash$ objdump -d /bin/ls<br />

/bin/ls: file format elf32-i386<br />

Disassembly of section .init:<br />

080490bc :<br />

80490bc: 55 push %ebp<br />

80490bd: 89 e5 mov %esp,%ebp<br />

. . .<br />

Questo comando genera un “magic cookie”, un numero esadecimale pseudocasuale <strong>di</strong> 128-bit<br />

(32-caratteri), normalmente usato come “firma” <strong>di</strong> autenticazione dal server X. È <strong>di</strong>sponibile anche<br />

per gli script come mezzo “sbrigativo” per ottenere un numero casuale.<br />

random000=$(mcookie)<br />

Naturalmente, uno script potrebbe utilizzare per lo stesso scopo md5.<br />

# Genera una checksum md5 dello script stesso.<br />

random001=‘md5sum $0 | awk ’{print $1}’‘<br />

# Usa ’awk’ per eliminare il nome del file.<br />

337

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!