Copyright
Acquiring Editor: Steve Elliot
Editorial Project Manager: Matthew Cater
Production Project Manager: A. B. McGee
Designer: Alisa Andreola
Syngress is an imprint of Elsevier
225 Wyman Street, Waltham, MA 02451, USA
2012 Elsevier, Inc. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from the publisher. Details on how to seek permission, further information about the Publishers permissions policies and our arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our website: www.elsevier.com/permissions.
This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may be noted herein).
Notices
Knowledge and best practice in this field are constantly changing. As new research and experience broaden our understanding, changes in research methods or professional practices, may become necessary. Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any information or methods described herein. In using such information or methods they should be mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions, or ideas contained in the material herein.
Library of Congress Cataloging-in-Publication Data
Andress, Jason.
Coding for penetration testers : building better tools / Jason Andress, Ryan Linn.
p. cm.
ISBN 978-1-59749-729-9 (pbk.)
1. Penetration testing (Computer security). 2. Computer networksSecurity measuresTesting.
I. Linn, Ryan. II. Title.
QA76.9.A25A5454 2011
005.8dc23
2011029098
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library.
Printed in the United States of America
11 12 13 14 15 10 9 8 7 6 5 4 3 2 1
For information on all Syngress publications visit our website at www.syngress.com
Foreword
My Dear Reader,
This wretched war, the gravest threat humankind has ever faced, is not going well at all. We have suffered major setbacks, as our ruthless adversary has conquered vast territories, leaving little ground controlled by our ragtag band of rebels. Our few surviving generals blame the lack of skills in our fighting forces, allowing the enemy to rout us in every hard-fought battle. Our situation is dire.
Historians have traced this impossibly sad state of affairs to some crucial mistakes we made collectively in the 20122015 time frame. We had spent the prior 30 years building ever more powerful networked machines, including PCs, smartphones, and industrial control systems, all interconnected on that blasted Internet. At first, before 2012, the machines were our servants, mindless systems processing transactions, scurrying about vacuuming our floors, and otherwise making life more pleasant for humans. Then, in 2012, Moores relentless law kicked things into maximum overdrive. Within a decade, the machines had become sentient, matching the smartest humans on the planet. They quickly became our most trusted advisors and friends. We should have seen the warning signs and used that precious time to develop our skills. Instead, we stupidly let ourselves atrophy. As they surpassed humans, the machines began to view us as pets, but we rejected their control. Soon, they came to the conclusion that humans were a disease, a cancer of this planet, and they viewed themselves as the cure, tirelessly working for our eradication. The war began.
We could have stopped them, I tell you, if only we had enough people with scripting and coding skills.
Through an astonishing scientific breakthrough, our physicists have managed to figure out a way to transmit this message back in time to you. I have been tasked by the Human Ruling Council to ask no, beg you to read this book and master its skills so that you can turn the tide of history itself. In these pages, you will learn how to wield control of computer systems through writing scripts and code in a variety of the most important languages today: Python, Ruby, PowerShell, and more. Youll also learn how to apply various coding concepts to extend the capabilities of some of the most powerful free security scanners and tools. The book covers these topics from a penetration testers perspective, showing you how to find and exploit security flaws in the exciting and rapidly growing field of information security. Whats more, using the automation available in these powerful scripting languages and tools, youll be able to improve defenses throughout enterprises of any scale, from small mom-and-pop shops to large multinationals. These skills will help both security professionals and general IT practitioners do their jobs more effectively. The book is eminently practical, showing you how to get real stuff done in these scripting languages. Thats your immediate payoff.
But its usefulness in improving your skills and career isnt the only reason to read the book. I wont mince words our very survival as a species is inherently linked to your mastering the knowledge of this book. We need you to learn script writing to keep the machines in check over your coming decade so that you can avoid our sad fate. I implore you to learn it and live it, for your sake and for that of future generations. What are you waiting for? Help us, Dear Reader. Youre our only hope!
Ed Skoudis
SANS Instructor and
Co-Founder of Counter Hack Challenges
June 10, 2011
About the Authors
Jason Andress (ISSAP, CISSP, GPEN, CEH) is a seasoned security professional with a depth of experience in both the academic and business worlds. Presently he carries out information security oversight duties, performing penetration testing, risk assessment, and compliance functions to ensure that critical assets are protected.
Jason has taught undergraduate and graduate security courses since 2005 and holds a doctorate in computer science, researching in the area of data protection. He has authored several publications and books, writing on topics including data security, network security, penetration testing, and digital forensics.
Ryan Linn is a penetration tester, an author, a developer, and an educator. He comes from a systems administration and Web application development background, with many years of information technology (IT) security experience.