Table Of ContentTable of Contents
FOREWORD
ACKNOWLEDGMENTS
INTRODUCTION
Wicked Cool Ruby Scripts
You Need Ruby Basics
Documentation
Organization and Approach
The Website
1. GENERAL PURPOSE UTILITIES
Check for Changed Files
Check for Changed Files
The Code
Running the Code
The Results
How It Works
Hacking the Script
Encrypt a File
Encrypt a File
The Code
Running the Code
The Results
How It Works
Hacking the Script
Decrypt a File
Decrypt a File
The Code
Running the Code
The Results
How It Works
File Splitting
File Splitting
The Code
Running the Code
The Results
How It Works
Hacking the Script
File Joining
File Joining
The Code
Running the Code
The Results
How It Works
Hacking the Script
Windows Process Viewer
Windows Process Viewer
The Code
Running the Code
The Results
How It Works
Hacking the Script
File Compressor
File Compressor
The Code
Running the Code
The Results
How It Works
File Decompression
File Decompression
The Code
Running the Code
The Results
How It Works
Mortgage Calculator
Mortgage Calculator
The Code
Running the Code
The Results
How It Works
Hacking the Script
2. WEBSITE SCRIPTING
Web Page Link Validator
Web Page Link Validator
The Code
Running the Code
The Results
How It Works
Hacking the Script
Orphan File Checker
Orphan File Checker
The Code
Running the Script
The Results
How It Works
Form Generator
Form Generator
The Code
Running the Code
The Results
How It Works
Hacking the Script
RSS Parsing
RSS Parsing
The Code
Running the Code
The Results
How It Works
Hacking the Script
Stock Exchange Grep
Stock Exchange Grep
The Code
Running the Code
The Results
How It Works
Hacking the Script
IP Address Generation
IP Address Generation
The Code
Running the Code
The Results
How It Works
Subnet Calculator
Subnet Calculator
The Code
Running the Code
The Results
How It Works
Hacking the Script
3. LI(U)NIX SYSTEM ADMINISTRATION
Fixing Bad Filenames
Fixing Bad Filenames
The Code
Running the Code
The Results
How It Works
Hacking the Script
Adding a User
Adding a User
The Code
Running the Code
The Results
How It Works
Hacking the Script
Modifying a User
Modifying a User
The Code
Running the Code
The Results
How It Works
Hacking the Script
Killing a Stuck Process
Killing a Stuck Process
The Code
Running the Code
The Results
How It Works
Validating Symlinks
Validating Symlinks
The Code
Running the Code
The Results
How It Works
Hacking the Script
4. PICTURE UTILITIES
Mass Editing
Mass Editing
The Code
Running the Code
The Results
How It Works
Image Information Extraction
Image Information Extraction
The Code
Running the Code
The Results
How It Works
Hacking the Script
Creating a Thumbnail
Creating a Thumbnail
The Code
Running the Code
The Results
How It Works
Hacking the Script
Resize a Picture
Resize a Picture
The Code
Running the Code
The Results
How It Works
Hacking the Script
Adding a Watermark to Pictures
Adding a Watermark to Pictures
The Code
Running the Code
The Results
How It Works
Convert to Black and White
Convert to Black and White
The Code
Running the Code
The Results
How It Works
Creating a Photo Gallery
Creating a Photo Gallery
The Code
Running the Code
Results
How It Works
Hacking the Script
5. GAMES AND LEARNING TOOLS
Sudoku Solver
Sudoku Solver
The Code
Running the Code
The Results
How It Works
Flash Cards
Flash Cards
The Code
Running the Code
The Results
How It Works
Hacking the Script
Number-Guessing Game
Number-Guessing Game
The Code
Running the Code
The Results
How It Works
Rock, Paper, Scissors
Rock, Paper, Scissors
The Code
Running the Code
The Results
How It Works
Hacking the Script
Word Scramble
Word Scramble
The Code
Running the Code
The Results
How It Works
Hangman
Hangman
The Code
Running the Code
The Results
How It Works
Pig
Pig
The Code
Running the Code
The Results
How It Works
Hacking the Script
6. STRING UTILITIES
PDF Generator
PDF Generator
The Code
Running the Code
The Results
How It Works
Word Frequency
Word Frequency
The Code
Running the Code
The Results
How It Works
Hacking the Script
Comma-Separated Value Parser
Comma-Separated Value Parser
The Code
Running the Code
The Results
How It Works
Hacking the Script
CSV to XML
CSV to XML
The Code
Running the Code
The Results
How It Works
Hacking the Script
Ruby Grep
Ruby Grep
The Code
Running the Code
The Results
How It Works
Hacking the Script
Password Check
Password Check
The Code
Running the Code
The Results
How It Works
Hacking the Script
7. SERVERS AND SCRAPERS
Define
Define
The Code
Running the Code
The Results
How It Works
Hacking the Script
Automated SMS
Automated SMS
The Code
Running the Code
The Results
How It Works
Link Scrape
Link Scrape
The Code
Running the Code
The Results
How It Works
Hacking the Script
Image Scrape
Image Scrape
The Code
Running the Code
The Results
How It Works
Hacking the Script
Scraper
Scraper
The Code
Running the Code
The Results
How It Works
Encrypted Client
Encrypted Client
The Code
Running the Code
The Results
How It Works
Encrypted Server
Encrypted Server
The Code
Running the Code
The Results
How It Works
8. ARGUMENTS AND DOCUMENTATION
File Security
File Security
The Code
Running the Code
The Results
How It Works
Web Scraper
Web Scraper
The Code
Running the Code
The Results
How It Works
Photo Utilities
Photo Utilities
The Code
Running the Code
The Results
How It Works
Conclusion
9. SORTING ALGORITHMS
Bubble Sort
Bubble Sort
The Code
Running the Code
The Results
How It Works
Selection Sort
Selection Sort
The Code
Running the Code
The Results
How It Works
Shell Sort
Shell Sort
The Code
Running the Code
The Results
How It Works
Merge Sort
Merge Sort
The Code
Running the Code
The Results
How It Works
Heap Sort
Heap Sort
The Code
Running the Code
The Results
How It Works
Quick Sort
Quick Sort
The Code
Running the Code
The Results
How It Works
Shear Sort
Shear Sort
The Code
Running the Code
The Results
How It Works
A Note About Efficiencies
10. WRITING A METASPLOIT 3.1 MODULE WITH RUBY
Introduction to Metasploit
Installation
Writing a Module
Building the Exploit
Watching in Real Time
Explanation of Metasploit Module Shell
Finding the Payload Space
A. AFTERWORD
Wicked Cool Ruby Scripts
Useful Scripts that Solve Difficult Problems
Steve Pugh
Editor
William Pollock
Copyright © 2009
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
555 De Haro Street, Suite 250, San Francisco, CA 94107
phone: 415.863.9900; fax: 415.863.9950; info@nostarch.com; www.nostarch.com
Library of Congress Cataloging-in-Publication Data:
Pugh, Steve.
Wicked cool Ruby scripts : useful scripts that solve difficult problems / Steve Pugh.
p. cm. -- (Wicked cool ...)
Includes index.
ISBN-13: 978-1-59327-182-4
ISBN-10: 1-59327-182-4
1. Macro instructions (Electronic computers) 2. Computers--Access control--Passwords. I. Title.
QA76.7.P84 2008
005.13'3--dc22
2008042965
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and
company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with
every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the
trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an "As Is" basis, without warranty. While every precaution has been taken in
the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with
respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
No Starch Press
Dedication
To my loving wife. You're a true gem!