27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

echo "File \"$file\" blotted out and deleted."; echo<br />

# This is a fairly secure, if inefficient and slow method<br />

#+ of thoroughly "shredding" a file. The "shred" command,<br />

#+ part of the GNU "fileutils" package, does the same thing,<br />

#+ but more efficiently.<br />

# The file cannot not be "undeleted" or retrieved by normal methods.<br />

# However...<br />

#+ this simple method will likely *not* withstand forensic analysis.<br />

# Tom Vier's "wipe" file−deletion package does a much more thorough job<br />

#+ of file shredding than this simple script.<br />

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

# For an in−depth analysis on the topic of file deletion and security,<br />

#+ see Peter Gutmann's paper,<br />

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

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

exit 0<br />

od<br />

The od, or octal dump filter converts input (or files) to octal (base−8) or other bases. This is useful for<br />

viewing or processing binary data files or otherwise unreadable system device files, such as<br />

/dev/urandom, and as a filter for binary data. See Example 9−26 and Example 12−10.<br />

hexdump<br />

Performs a hexadecimal, octal, decimal, or ASCII dump of a binary file. This command is the rough<br />

equivalent of od, above, but not nearly as useful.<br />

objdump<br />

Displays an object file or binary executable in either hexadecimal form or as a disassembled listing<br />

(with the −d option).<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 />

mcookie<br />

This command generates a "magic cookie", a 128−bit (32−character) pseudorandom hexadecimal<br />

number, normally used as an authorization "signature" by the X server. This also available for use in a<br />

script as a "quick 'n dirty" random number.<br />

random000=`mcookie | sed −e '2p'`<br />

# Uses 'sed' to strip off extraneous characters.<br />

Of course, a script could use md5 for the same purpose.<br />

# Generate md5 checksum on the script itself.<br />

random001=`md5sum $0 | awk '{print $1}'`<br />

Chapter 12. External Filters, Programs and Commands 211

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

Saved successfully!

Ooh no, something went wrong!