Tải bản đầy đủ (.pdf) (531 trang)

Hacking ebook penetrationtesting

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (14.7 MB, 531 trang )



Penetration testing



Penetration
testing
A Hands-On Introduction
to Hacking

by Georgia Weidman

San Francisco


Penetration testing. Copyright © 2014 by Georgia Weidman.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic
or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the
prior written permission of the copyright owner and the publisher.
Printed in USA
Fourth printing
18 17 16 15   4 5 6 7 8 9
ISBN-10: 1-59327-564-1
ISBN-13: 978-1-59327-564-8
Publisher: William Pollock
Production Editor: Alison Law
Cover Illustration: Mertsaloff/Shutterstock
Interior Design: Octopod Studios
Developmental Editor: William Pollock
Technical Reviewer: Jason Oliver


Copyeditor: Pamela Hunt
Compositor: Susan Glinert Stevens
Proofreader: James Fraleigh
Indexer: Nancy Guenther
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 415.863.9900; ; www.nostarch.com
Library of Congress Cataloging-in-Publication Data
Weidman, Georgia.
Penetration testing : a hands-on introduction to hacking / Georgia Weidman.
pages cm
Includes index.
ISBN 978-1-59327-564-8 (paperback) -- ISBN 1-59327-564-1 (paperback)
1. Penetration testing (Computer security) 2. Kali Linux. 3. Computer hackers.
QA76.9.A25W4258 2014
005.8'092--dc23
2014001066

I. Title.

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.



In memory of Jess Hilden


About the Author
Georgia Weidman is a penetration tester and
researcher, as well as the founder of Bulb
Security, a security consulting firm. She pre­
sents at conferences around the world includ­
ing Black Hat, ShmooCon, and DerbyCon, and
teaches classes on topics such as penetration
testing, mobile hacking, and exploit develop­
ment. Her work in mobile security has been
featured in print and on television internation­
ally. She was awarded a DARPA Cyber Fast
Track grant to continue her work in mobile
device security.

© Tommy Phillips Photography


Brief Contents

Foreword by Peter Van Eeckhoutte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Chapter 0: Penetration Testing Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Part I: The Basics
Chapter 1: Setting Up Your Virtual Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Chapter 2: Using Kali Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Chapter 3: Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Chapter 4: Using the Metasploit Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

Part II: Assessments
Chapter 5: Information Gathering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Chapter 6: Finding Vulnerabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Chapter 7: Capturing Traffic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

Part III: Attacks
Chapter 8: Exploitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Chapter 9: Password Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Chapter10: Client-Side Exploitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Chapter 11: Social Engineering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Chapter 12: Bypassing Antivirus Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Chapter 13: Post Exploitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Chapter 14: Web Application Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Chapter 15: Wireless Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339


Part IV: Exploit Development
Chapter 16: A Stack-Based Buffer Overflow in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Chapter 17: A Stack-Based Buffer Overflow in Windows . . . . . . . . . . . . . . . . . . . . . . . . 379
Chapter 18: Structured Exception Handler Overwrites . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Chapter 19: Fuzzing, Porting Exploits, and Metasploit Modules . . . . . . . . . . . . . . . . . . . . 421

Part V: Mobile Hacking
Chapter 20: Using the Smartphone Pentest Framework . . . . . . . . . . . . . . . . . . . . . . . . . . 445
Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477


viii   Brief Contents 


Conte nt s in De ta il
Foreword by Peter Van Eeckhoutte

xix

Acknowledgments

xxiii

Introduction

xxv

A Note of Thanks . . . . . . . . . . . . . . .
About This Book . . . . . . . . . . . . . . . .
Part I: The Basics . . . . . . . . .
Part II: Assessments . . . . . . .
Part III: Attacks . . . . . . . . . . .
Part IV: Exploit Development .
Part V: Mobile Hacking . . . . .

.
.
.
.
.
.

.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.

.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.

.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.


.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.

.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.

.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.

.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.


.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.

.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.

xxvi
xxvi
xxvii
xxvii
xxvii
xxviii

xxviii

0
Penetration Testing Primer
The Stages of the Penetration Test .
Pre-engagement . . . . . . .
Information Gathering . .
Threat Modeling . . . . . .
Vulnerability Analysis . . .
Exploitation . . . . . . . . . .
Post Exploitation . . . . . . .
Reporting . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.

1
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

2
2
4
4
4
4
4
5
6

Part I
The Basics
1
Setting Up Your Virtual Lab
Installing VMware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Setting Up Kali Linux . . . . . . . . . . . . . . . . . . . . . . . . . . .
Configuring the Network for Your Virtual Machine .
Installing Nessus . . . . . . . . . . . . . . . . . . . . . . . .
Installing Additional Software . . . . . . . . . . . . . . .
Setting Up Android Emulators . . . . . . . . . . . . . . .
Smartphone Pentest Framework . . . . . . . . . . . . . .
Target Virtual Machines . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating the Windows XP Target . . . . . . . . . . . . . . . . . . .
VMware Player on Microsoft Windows . . . . . . . . .
VMware Fusion on Mac OS . . . . . . . . . . . . . . . .
Installing and Activating Windows . . . . . . . . . . . .

9
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.

. 9
10
13
17
20
22
27
28
29
29
31
32


Installing VMware Tools . . . . . . . . . . . . . . . . . . . . . . . .
Turning Off Windows Firewall . . . . . . . . . . . . . . . . . . . .
Setting User Passwords . . . . . . . . . . . . . . . . . . . . . . . . .
Setting a Static IP Address . . . . . . . . . . . . . . . . . . . . . . .
Making XP Act Like It’s a Member of a Windows Domain .
Installing Vulnerable Software . . . . . . . . . . . . . . . . . . . .
Installing Immunity Debugger and Mona . . . . . . . . . . . . .
Setting Up the Ubuntu 8.10 Target . . . . . . . . . . . . . . . . . . . . . . .
Creating the Windows 7 Target . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a User Account . . . . . . . . . . . . . . . . . . . . . . . .
Opting Out of Automatic Updates . . . . . . . . . . . . . . . . .
Setting a Static IP Address . . . . . . . . . . . . . . . . . . . . . . .
Adding a Second Network Interface . . . . . . . . . . . . . . . .

Installing Additional Software . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.

2
Using Kali Linux
Linux Command Line . . . . . . . . . . . . . . . . . . . . . . . .
The Linux Filesystem . . . . . . . . . . . . . . . . . . . . . . . . .
Changing Directories . . . . . . . . . . . . . . . . .
Learning About Commands: The Man Pages . . . . . . .
User Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a User . . . . . . . . . . . . . . . . . . . . . .
Adding a User to the sudoers File . . . . . . . . .
Switching Users and Using sudo . . . . . . . . .
Creating a New File or Directory . . . . . . . . .
Copying, Moving, and Removing Files . . . . .
Adding Text to a File . . . . . . . . . . . . . . . . .
Appending Text to a File . . . . . . . . . . . . . . .
File Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Editing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Searching for Text . . . . . . . . . . . . . . . . . . .
Editing a File with vi . . . . . . . . . . . . . . . . . .
Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . .
Using grep . . . . . . . . . . . . . . . . . . . . . . . .
Using sed . . . . . . . . . . . . . . . . . . . . . . . . .
Pattern Matching with awk . . . . . . . . . . . . .
Managing Installed Packages . . . . . . . . . . . . . . . . . .
Processes and Services . . . . . . . . . . . . . . . . . . . . . .
Managing Networking . . . . . . . . . . . . . . . . . . . . . .
Setting a Static IP Address . . . . . . . . . . . . . .
Viewing Network Connections . . . . . . . . . . .

Netcat: The Swiss Army Knife of TCP/IP Connections .
Check to See If a Port Is Listening . . . . . . . . .
Opening a Command Shell Listener . . . . . . .
Pushing a Command Shell Back to a Listener .
Automating Tasks with cron Jobs . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

x 

Contents in Detail

35
37
37
38
39
40
46
48
48
48
50
51
52
52
54

55
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

56
56
56
57
58
58
59
59
60
60
61
61
61
62

63
63
64
65
65
66
66
67
67
68
69
69
70
70
71
72
73


3
Programming75
Bash Scripting . . . . . . . . . . . . . . . . . . . . . . . .
Ping . . . . . . . . . . . . . . . . . . . . . . . . .
A Simple Bash Script . . . . . . . . . . . . .
Running Our Script . . . . . . . . . . . . . . .
Adding Functionality with if Statements .
A for Loop . . . . . . . . . . . . . . . . . . . . .
Streamlining the Results . . . . . . . . . . . .
Python Scripting . . . . . . . . . . . . . . . . . . . . . . .
Connecting to a Port . . . . . . . . . . . . . .

if Statements in Python . . . . . . . . . . . .
Writing and Compiling C Programs . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
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.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

. 88
. 90
. 90
. 91
. 94
. 94
. 95
. 95
. 95
. 96
. 96
. 97
. 98
. 98
. 98
. 99

101
101
101
102
103
104
104
104
105
105
107
109

4
Using the Metasploit Framework
Starting Metasploit . . . . . . . . . . . . . . . . . . . .
Finding Metasploit Modules . . . . . . . . . . . . . .
The Module Database . . . . . . . . . . .
Built-In Search . . . . . . . . . . . . . . . . .
Setting Module Options . . . . . . . . . . . . . . . .
RHOST . . . . . . . . . . . . . . . . . . . . . .
RPORT . . . . . . . . . . . . . . . . . . . . . .
SMBPIPE . . . . . . . . . . . . . . . . . . . . .
Exploit Target . . . . . . . . . . . . . . . . .
Payloads (or Shellcode) . . . . . . . . . . . . . . . . .
Finding Compatible Payloads . . . . . .
A Test Run . . . . . . . . . . . . . . . . . . . .
Types of Shells . . . . . . . . . . . . . . . . . . . . . . .
Bind Shells . . . . . . . . . . . . . . . . . . .
Reverse Shells . . . . . . . . . . . . . . . . .

Setting a Payload Manually . . . . . . . . . . . . . .
Msfcli . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting Help . . . . . . . . . . . . . . . . . .
Showing Options . . . . . . . . . . . . . . .
Payloads . . . . . . . . . . . . . . . . . . . . .
Creating Standalone Payloads with Msfvenom .
Choosing a Payload . . . . . . . . . . . . .
Setting Options . . . . . . . . . . . . . . . .
Choosing an Output Format . . . . . . .
Serving Payloads . . . . . . . . . . . . . . .
Using the Multi/Handler Module . . . .
Using an Auxiliary Module . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

75
76
76
77
77
78
79
81
83
83
84
85

87

Contents in Detail 

xi



Part II
Assessments
5
Information Gathering

113

Open Source Intelligence Gathering . . .
Netcraft . . . . . . . . . . . . . . . .
Whois Lookups . . . . . . . . . . .
DNS Reconnaissance . . . . . . .
Searching for Email Addresses
Maltego . . . . . . . . . . . . . . . .
Port Scanning . . . . . . . . . . . . . . . . . . .
Manual Port Scanning . . . . . .
Port Scanning with Nmap . . . .
Summary . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

6
Finding Vulnerabilities

133

From Nmap Version Scan to Potential Vulnerability .
Nessus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Nessus Policies . . . . . . . . . . . . . . . . . . .
Scanning with Nessus . . . . . . . . . . . . . . .

A Note About Nessus Rankings . . . . . . . .
Why Use Vulnerability Scanners? . . . . . . .
Exporting Nessus Results . . . . . . . . . . . . .
Researching Vulnerabilities . . . . . . . . . . .
The Nmap Scripting Engine . . . . . . . . . . . . . . . . .
Running a Single NSE Script . . . . . . . . . . . . . . . .
Metasploit Scanner Modules . . . . . . . . . . . . . . . .
Metasploit Exploit Check Functions . . . . . . . . . . . .
Web Application Scanning . . . . . . . . . . . . . . . . .
Nikto . . . . . . . . . . . . . . . . . . . . . . . . . .
Attacking XAMPP . . . . . . . . . . . . . . . . . .
Default Credentials . . . . . . . . . . . . . . . . .
Manual Analysis . . . . . . . . . . . . . . . . . . . . . . . . .
Exploring a Strange Port . . . . . . . . . . . . .
Finding Valid Usernames . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

7
Capturing Traffic
Networking for Capturing Traffic .
Using Wireshark . . . . . . . . . . . . .
Capturing Traffic . . . . . .
Filtering Traffic . . . . . . .
Following a TCP Stream .
Dissecting Packets . . . . .

xii 

Contents in Detail

114
114
115
116
118
119
123
124
125
132

133
134
134
138

140
141
141
142
142
144
146
147
148
149
149
150
151
151
153
153

155
.
.
.
.
.
.

.
.
.
.
.

.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.

.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.

.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.

.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

156
156
156
158
159
160


ARP Cache Poisoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ARP Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
IP Forwarding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ARP Cache Poisoning with Arpspoof . . . . . . . . . . . . . . . . . . . .
Using ARP Cache Poisoning to Impersonate the Default Gateway
DNS Cache Poisoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Dnsspoof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SSL Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SSL Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Ettercap for SSL Man-in-the-Middle Attacks . . . . . . . . . . . .
SSL Stripping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using SSLstrip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.

160
161
163
164
165
167
168
169
170
170
171
173
174
175


Part III
Attacks
8
Exploitation179
Revisiting MS08-067 . . . . . . . . . . . . . . . . . . . . . . .
Metasploit Payloads . . . . . . . . . . . . . . . . .
Meterpreter . . . . . . . . . . . . . . . . . . . . . . .
Exploiting WebDAV Default Credentials . . . . . . . . .
Running a Script on the Target Web Server .
Uploading a Msfvenom Payload . . . . . . . .
Exploiting Open phpMyAdmin . . . . . . . . . . . . . . . .
Downloading a File with TFTP . . . . . . . . . .
Downloading Sensitive Files . . . . . . . . . . . . . . . . . .
Downloading a Configuration File . . . . . . .
Downloading the Windows SAM . . . . . . . .
Exploiting a Buffer Overflow in Third-Party Software .
Exploiting Third-Party Web Applications . . . . . . . . .
Exploiting a Compromised Service . . . . . . . . . . . . .
Exploiting Open NFS Shares . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

9
Password Attacks
Password Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Online Password Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wordlists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Guessing Usernames and Passwords with Hydra . . . . . . .
Offline Password Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Recovering Password Hashes from a Windows SAM File .
Dumping Password Hashes with Physical Access . . . . . . .
LM vs. NTLM Hashing Algorithms . . . . . . . . . . . . . . . . . .
The Trouble with LM Password Hashes . . . . . . . . . . . . . .

180
180
181
182
183
183
186
187
188

188
189
190
191
193
194
196

197
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

197

198
199
202
203
204
206
208
209
Contents in Detail 

xiii


John the Ripper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Cracking Linux Passwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Cracking Configuration File Passwords . . . . . . . . . . . . . . . . . . . . .
Rainbow Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Online Password-Cracking Services . . . . . . . . . . . . . . . . . . . . . . .
Dumping Plaintext Passwords from Memory with Windows Credential Editor .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.

.

.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.


.
.
.
.
.
.
.

.
.
.
.
.
.
.

10
Client-Side Exploitation

215

Bypassing Filters with Metasploit Payloads .
All Ports . . . . . . . . . . . . . . . . . .
HTTP and HTTPS Payloads . . . . . .
Client-Side Attacks . . . . . . . . . . . . . . . . .
Browser Exploitation . . . . . . . . . .
PDF Exploits . . . . . . . . . . . . . . .
Java Exploits . . . . . . . . . . . . . . .
browser_autopwn . . . . . . . . . . .

Winamp . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . .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.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

11
Social Engineering

The Social-Engineer Toolkit . . . .
Spear-Phishing Attacks . . . . . . .
Choosing a Payload . .
Setting Options . . . . .
Naming Your File . . . .
Single or Mass Email .
Creating the Template
Setting the Target . . . .
Setting Up a Listener . .
Web Attacks . . . . . . . . . . . . .
Mass Email Attacks . . . . . . . . .
Multipronged Attacks . . . . . . . .
Summary . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

Trojans . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Msfvenom . . . . . . . . . . . . . . . . . . . . .
How Antivirus Applications Work . . . . . . . . . . .
Microsoft Security Essentials . . . . . . . . . . . . . . .
VirusTotal . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting Past an Antivirus Program . . . . . . . . . . .
Encoding . . . . . . . . . . . . . . . . . . . . .
Custom Cross Compiling . . . . . . . . . . .

Encrypting Executables with Hyperion .
Evading Antivirus with Veil-Evasion . . .
Contents in Detail

216
216
217
218
219
225
230
235
237
240

243
.
.
.
.
.
.
.
.
.
.
.
.
.


12
Bypassing Antivirus Applications

xiv 

210
212
212
213
213
213
214

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.

244
245
246
247
247
247
248
248
249
250
253
255
255


257
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

258
258
260
261
262

263
263
266
269
270


Hiding in Plain Sight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

13
Post Exploitation
Meterpreter . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the upload Command . . . . . . . .
getuid . . . . . . . . . . . . . . . . . . . . . . . .
Other Meterpreter Commands . . . . . . .
Meterpreter Scripts . . . . . . . . . . . . . . . . . . . . .
Metasploit Post-Exploitation Modules . . . . . . . . .
Railgun . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Local Privilege Escalation . . . . . . . . . . . . . . . . .
getsystem on Windows . . . . . . . . . . . .
Local Escalation Module for Windows .
Bypassing UAC on Windows . . . . . . .
Udev Privilege Escalation on Linux . . . .
Local Information Gathering . . . . . . . . . . . . . . .
Searching for Files . . . . . . . . . . . . . . .
Keylogging . . . . . . . . . . . . . . . . . . . .
Gathering Credentials . . . . . . . . . . . .
net Commands . . . . . . . . . . . . . . . . .
Another Way In . . . . . . . . . . . . . . . . .

Checking Bash History . . . . . . . . . . . .
Lateral Movement . . . . . . . . . . . . . . . . . . . . . .
PSExec . . . . . . . . . . . . . . . . . . . . . . .
Pass the Hash . . . . . . . . . . . . . . . . . .
SSHExec . . . . . . . . . . . . . . . . . . . . . .
Token Impersonation . . . . . . . . . . . . .
Incognito . . . . . . . . . . . . . . . . . . . . . .
SMB Capture . . . . . . . . . . . . . . . . . . .
Pivoting . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a Route in Metasploit . . . . . . .
Metasploit Port Scanners . . . . . . . . . . .
Running an Exploit through a Pivot . . . .
Socks4a and ProxyChains . . . . . . . . . .
Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a User . . . . . . . . . . . . . . . . . .
Metasploit Persistence . . . . . . . . . . . .
Creating a Linux cron Job . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . .

277
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
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.
.
.

.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

14

Web Application Testing
Using Burp Proxy . . . . . . . . . . . . . . . . . . . . . .
SQL Injection . . . . . . . . . . . . . . . . . . . . . . . . .
Testing for SQL Injection Vulnerabilities .
Exploiting SQL Injection Vulnerabilities .
Using SQLMap . . . . . . . . . . . . . . . . .
XPath Injection . . . . . . . . . . . . . . . . . . . . . . . .

278
279
279
280
280
281
283
283
283
284
285
287
291
291
292
292
294
295
295
296
296
298

299
300
301
302
304
305
306
306
307
309
309
310
311
311

313
.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.

.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.

.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

314
319
320
321
321

323
Contents in Detail 

xv


Local File Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Remote File Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Command Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Cross-Site Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Checking for a Reflected XSS Vulnerability . . . . . . . . . . .
Leveraging XSS with the Browser Exploitation Framework .
Cross-Site Request Forgery . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Web Application Scanning with w3af . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

15
Wireless Attacks

324
327
327
329
330
331
335
335
337

339


Setting Up . . . . . . . . . . . . . . . . . . . . . . . . . . .
Viewing Available Wireless Interfaces .
Scan for Access Points . . . . . . . . . . . .
Monitor Mode . . . . . . . . . . . . . . . . . . . . . . . .
Capturing Packets . . . . . . . . . . . . . . . . . . . . . .
Open Wireless . . . . . . . . . . . . . . . . . . . . . . . .
Wired Equivalent Privacy . . . . . . . . . . . . . . . . .
WEP Weaknesses . . . . . . . . . . . . . . .
Cracking WEP Keys with Aircrack-ng .
Wi-Fi Protected Access . . . . . . . . . . . . . . . . . . .
WPA2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Enterprise Connection Process . . . .
The Personal Connection Process . . . . .
The Four-Way Handshake . . . . . . . . . .
Cracking WPA/WPA2 Keys . . . . . . . .
Wi-Fi Protected Setup . . . . . . . . . . . . . . . . . . .
Problems with WPS . . . . . . . . . . . . . .
Cracking WPS with Bully . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

339
340
341
341
342
343
343
346
347
350
351
351
351
352
353
356
356
357
357


Part IV
Exploit Development
16
A Stack-Based Buffer Overflow in Linux
Memory Theory . . . . . . . . . . . . . . . . .
Linux Buffer Overflow . . . . . . . . . . . . .
A Vulnerable Program . . . . . .
Causing a Crash . . . . . . . . . .
Running GDB . . . . . . . . . . . . .
Crashing the Program in GDB .

xvi 

Contents in Detail

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

361
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.


.
.
.
.
.
.

362
364
365
366
367
372


Controlling EIP . . . . .
Hijacking Execution .
Endianness . . . . . . .
Summary . . . . . . . . . . . . . . .

.
.
.
.

.
.
.
.


.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.


.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.


.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.


.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.


.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.


.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.


.
.
.
.

.
.
.
.

17
A Stack-Based Buffer Overflow in Windows
Searching for a Known Vulnerability in War-FTP . . . . . . . . .
Causing a Crash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Locating EIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Generating a Cyclical Pattern to Determine Offset .
Verifying Offsets . . . . . . . . . . . . . . . . . . . . . . . .
Hijacking Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting a Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.

.
.
.
.
.
.

379

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.

.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.

18
Structured Exception Handler Overwrites
SEH Overwrite Exploits . . . . . . . . . .
Passing Control to SEH . . . . . . . . . .
Finding the Attack String in Memory .
POP POP RET . . . . . . . . . . . . . . . . .
SafeSEH . . . . . . . . . . . . . . . . . . . .
Using a Short Jump . . . . . . . . . . . . .
Choosing a Payload . . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

380
382
384
385
388
390
395
400

401

19
Fuzzing, Porting Exploits, and Metasploit Modules

Fuzzing Programs . . . . . . . . . . . . . . . . . . . . . .
Finding Bugs with Code Review . . . . . .
Fuzzing a Trivial FTP Server . . . . . . . . .
Attempting a Crash . . . . . . . . . . . . . .
Porting Public Exploits to Meet Your Needs . . . .
Finding a Return Address . . . . . . . . . .
Replacing Shellcode . . . . . . . . . . . . . .
Editing the Exploit . . . . . . . . . . . . . . .
Writing Metasploit Modules . . . . . . . . . . . . . . .
A Similar Exploit String Module . . . . .
Porting Our Exploit Code . . . . . . . . . .
Exploitation Mitigation Techniques . . . . . . . . . .
Stack Cookies . . . . . . . . . . . . . . . . . .
Address Space Layout Randomization .
Data Execution Prevention . . . . . . . . . .
Mandatory Code Signing . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . .

373
375
376
378

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

403
407
408
411
412
416
418

419

421
421
422
422
424
427
429
430
430
432
435
435
439
440
440
441
441
442

Contents in Detail 

xvii


Part V
Mobile Hacking
20
Using the Smartphone Pentest Framework

Mobile Attack Vectors . . . . . . . . . . . . . . . .
Text Messages . . . . . . . . . . . . . .
Near Field Communication . . . . . .
QR Codes . . . . . . . . . . . . . . . . . .
The Smartphone Pentest Framework . . . . . .
Setting Up SPF . . . . . . . . . . . . . . .
Android Emulators . . . . . . . . . . . .
Attaching a Mobile Modem . . . . . .
Building the Android App . . . . . . .
Deploying the App . . . . . . . . . . . .
Attaching the SPF Server and App .
Remote Attacks . . . . . . . . . . . . . . . . . . . . .
Default iPhone SSH Login . . . . . . .
Client-Side Attacks . . . . . . . . . . . . . . . . . .
Client-Side Shell . . . . . . . . . . . . . .
USSD Remote Control . . . . . . . . . .
Malicious Apps . . . . . . . . . . . . . . . . . . . . .
Creating Malicious SPF Agents . . .
Mobile Post Exploitation . . . . . . . . . . . . . . .
Information Gathering . . . . . . . . .
Remote Control . . . . . . . . . . . . . .
Pivoting Through Mobile Devices .
Privilege Escalation . . . . . . . . . . .
Summary . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


445
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

446
446
446
447

447
447
449
449
449
450
452
453
453
454
454
456
458
459
464
464
465
466
471
472

REsources473
Index477

xviii 

Contents in Detail


Fore word


I met Georgia Weidman at a conference almost two
years ago. Intrigued by what she was doing in the
mobile device security field, I started following her
work. At nearly every conference I’ve attended since
then, I’ve run into Georgia and found her passionately sharing knowledge and ideas about mobile
device security and her Smartphone Pentesting
Framework.
In fact, mobile device security is only one of the things Georgia does.
Georgia performs penetration tests for a living; travels the world to deliver
training on pentesting, the Metasploit Framework, and mobile device security; and presents novel and innovative ideas on how to assess the security of
mobile devices at conferences.
Georgia spares no effort in diving deeper into more advanced topics and working hard to learn new things. She is a former student of my
(rather challenging) Exploit Development Bootcamp, and I can attest to
the fact that she did very well throughout the entire class. Georgia is a true


hacker—always willing to share her findings and knowledge with our great
infosec community—and when she asked me to write the foreword to this
book, I felt very privileged and honored.
As a chief information security officer, a significant part of my job
revolves around designing, implementing, and managing an information
security program. Risk management is a very important aspect of the program because it allows a company to measure and better understand its
current position in terms of risk. It also allows a company to define priorities and implement measures to decrease risk to an acceptable level, based
on the company’s core business activities, its mission and vision, and legal
requirements.
Identifying all critical business processes, data, and data flows inside
a company is one of the first steps in risk management. This step includes
compiling a detailed inventory of all IT systems (equipment, networks,
applications, interfaces, and so on) that support the company’s critical business processes and data from an IT perspective. The task is time consuming

and it’s very easy to forget about certain systems that at first don’t seem to
be directly related to supporting critical business processes and data, but
that are nonetheless critical because other systems depend on them. This
inventory is fundamentally important and is the perfect starting point for a
risk-assessment exercise.
One of the goals of an information-security program is to define what
is necessary to preserve the desired level of confidentiality, integrity, and
availability of a company’s IT systems and data. Business process owners
should be able to define their goals, and our job as information-security
professionals is to implement measures to make sure we meet these goals
and to test how effective these measures are.
There are a few ways to determine the actual risk to the confidentiality,
integrity, and availability of a company’s systems. One way is to perform a
technical assessment to see how easy it would be for an adversary to undermine the desired level of confidentiality, break the integrity of systems, and
interfere with the availability of systems, either by attacking them directly
or by attacking the users with access to these systems.
That’s where a penetration tester (pentester, ethical hacker, or whatever you want to call it) comes into play. By combining knowledge of how
systems are designed, built, and maintained with a skillset that includes
finding creative ways around defenses, a good pentester is instrumental in
identifying and demonstrating the strength of a company’s informationsecurity posture.
If you would like to become a penetration tester or if you are a systems/
network administrator who wants to know more about how to test the
security of your systems, this book is perfect for you. You’ll learn some of
the more technical phases of a penetration test, beginning with the initial
information-gathering process. You’ll continue with explanations of how to
exploit vulnerable networks and applications as you delve deeper into the
network in order to determine how much damage could be done.
This book is unique because it’s not just a compilation of tools with
a discussion of the available options. It takes a very practical approach,
xx   Foreword



designed around a lab—a set of virtual machines with vulnerable applications—so you can safely try various pentesting techniques using publicly
available free tools.
Each chapter starts with an introduction and contains one or more
hands-on exercises that will allow you to better understand how vulnerabilities can be discovered and exploited. You’ll find helpful tips and tricks
from an experienced professional pentester, real-life scenarios, proven techniques, and anecdotes from actual penetration tests.
Entire books can be written (and have been) on the topics covered in
each chapter in this book, and this book doesn’t claim to be the Wikipedia
of pentesting. That said, it will certainly provide you with more than a first
peek into the large variety of attacks that can be performed to assess a target’s security posture. Thanks to its guided, hands-on approach, you’ll learn
how to use the Metasploit Framework to exploit vulnerable applications and
use a single hole in a system’s defenses to bypass all perimeter protections,
dive deeper into the network, and exfiltrate data from the target systems.
You’ll learn how to bypass antivirus programs and perform efficient socialengineering attacks using tools like the Social-Engineer Toolkit. You’ll see
how easy it would be to break into a corporate Wi-Fi network, and how to use
Georgia’s Smartphone Pentest Framework to assess how damaging a company’s bring your own device policy (or lack thereof) could be. Each chapter is designed to trigger your interest in pentesting and to provide you with
first-hand insight into what goes on inside a pentester’s mind.
I hope this book will spark your creativity and desire to dive deeper into
certain areas; to work hard and learn more; and to do your own research
and share your knowledge with the community. As technology develops,
environments change, and companies increasingly rely on technology
to support their core business activities, the need for smart pentesters
will increase. You are the future of this community and the informationsecurity industry.
Good luck taking your first steps into the exciting world of pentesting.
I’m sure you will enjoy this book!
Peter “corelanc0d3r” Van Eeckhoutte
Founder of Corelan Team

Foreword   xxi




Ac k n o w l e d g m e n t s

Many thanks go to the following people and organizations (in no particular
order).
My parents, who have always supported my career endeavors—including
paying for me to go to my first conference and get my first certifications when
I was still a broke college student.
Collegiate Cyber Defense Competition, particularly the Mid-Atlantic
region Red Team, for helping me find what I wanted to do with my life.
ShmooCon for accepting my first talk ever and also being the first conference I ever attended.
Peiter “Mudge” Zatko and everyone who involved in the DARPA Cyber
Fast Track program for giving me the opportunity to start my own company
and build the Smartphone Pentest Framework.
James Siegel for being my lucky charm and making sure I get on stage
on time at events.
Rob Fuller for taking the time to come to James Madison University
and visit the CCDC team after the competition. That day I decided to make
a career of infosec.
John Fulmer for helping me with the crypto details in the wireless chapter.
Rachel Russell and Micheal Cottingham for being my first infosec buddies.
Jason and Rachel Oliver for technical and content review, and also for
making the perfect smoky eye look at ShmooCon and Black Hat.


×