Download Complete Python Penetration Testing Essentials Techniques for ethical hacking with Python 2nd Edition Mohit PDF for All Chapters
Download Complete Python Penetration Testing Essentials Techniques for ethical hacking with Python 2nd Edition Mohit PDF for All Chapters
com
https://ebookmeta.com/product/python-penetration-testing-
essentials-techniques-for-ethical-hacking-with-python-2nd-
edition-mohit/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmeta.com/product/beginning-ethical-hacking-with-
python-1st-edition-sanjib-sinha/
ebookmeta.com
https://ebookmeta.com/product/learning-kali-linux-security-testing-
penetration-testing-and-ethical-hacking-1st-edition-ric-messier/
ebookmeta.com
https://ebookmeta.com/product/mayor-of-elf-town-4-1st-edition-dante-
king-2/
ebookmeta.com
Theatre Translation: A Practice as Research Model 1st
Edition Angela Tiziana Tarantini
https://ebookmeta.com/product/theatre-translation-a-practice-as-
research-model-1st-edition-angela-tiziana-tarantini/
ebookmeta.com
https://ebookmeta.com/product/essential-revision-notes-for-frcs-urol-
book-1-1st-edition-jack-donati-bourne/
ebookmeta.com
https://ebookmeta.com/product/eyewitness-to-chaos-personal-accounts-
of-the-intervention-in-haiti-1994-1st-edition-walter-e-kretchik/
ebookmeta.com
https://ebookmeta.com/product/the-blobfish-book-jessica-olien/
ebookmeta.com
Spoon Feeding Basic must Know Physics for Boys and Men for
IIT JEE Olympiad kind of exams by Professor Subhashish
Chattopadhyay 1st Edition Professor Subhashish
Chattopadhyay
https://ebookmeta.com/product/spoon-feeding-basic-must-know-physics-
for-boys-and-men-for-iit-jee-olympiad-kind-of-exams-by-professor-
subhashish-chattopadhyay-1st-edition-professor-subhashish-
chattopadhyay/
ebookmeta.com
College Reunions and Clues Tiffany Black Travel Cozy
Mystery 4 A.R. Winters Et El
https://ebookmeta.com/product/college-reunions-and-clues-tiffany-
black-travel-cozy-mystery-4-a-r-winters-et-el/
ebookmeta.com
||||||||||||||||||||
||||||||||||||||||||
||||||||||||||||||||
5FDIOJRVFTGPSFUIJDBMIBDLJOHXJUI1ZUIPO
Mohit
BIRMINGHAM - MUMBAI
||||||||||||||||||||
||||||||||||||||||||
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, without the prior written permission of the publisher, except in the case of brief quotations
embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented.
However, the information contained in this book is sold without warranty, either express or implied. Neither the
author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to
have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy
of this information.
ISBN 978-1-78913-896-2
XXXQBDLUQVCDPN
||||||||||||||||||||
||||||||||||||||||||
NBQUJP
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as
well as industry leading tools to help you plan your personal development and advance
your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at XXX1BDLU1VCDPN and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at TFSWJDF!QBDLUQVCDPN for more details.
At XXX1BDLU1VCDPN, you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on Packt books and
eBooks.
||||||||||||||||||||
||||||||||||||||||||
Contributors
||||||||||||||||||||
||||||||||||||||||||
My special thanks to my wife, Shalini Jaiswal, for her unconditional support, and my
friends Ranjan, Ritesh, Mickey, Vivek, Hari, Sujay, Shankar, and Santosh for their care
and support all the time.
Rejah Rehim is currently the Director and Chief Information Security Officer (CISO) of
Appfabs. Previously holding the title of Security Architect at FAYA India, he is a long-time
preacher of open source and steady contributor to the Mozilla Foundation. He has
successfully created the world's first security testing browser bundle, PenQ, an open
source Linux-based penetration testing browser bundle preconfigured with tools
for security testing. He is also an active member of OWASP and the chapter
leader of OWASP Kerala. Additionally, Rejah also holds the title of commander at
Cyberdome, an initiative of the Kerala Police Department.
||||||||||||||||||||
||||||||||||||||||||
Table of Contents
Preface 1
Chapter 1: Python with Penetration Testing and Networking 6
Introducing the scope of pentesting 7
The need for pentesting 7
Components to be tested 8
Qualities of a good pentester 8
Defining the scope of pentesting 9
Approaches to pentesting 9
Introducing Python scripting 10
Understanding the tests and tools you'll need 11
Learning the common testing platforms with Python 11
Network sockets 11
Server socket methods 12
Client socket methods 13
General socket methods 13
Moving on to the practical 14
Socket exceptions 22
Useful socket methods 23
Summary 29
Chapter 2: Scanning Pentesting 30
How to check live systems in a network and the concept of a live
system 31
Ping sweep 31
The TCP scan concept and its implementation using a Python script 35
How to create an efficient IP scanner in Windows 37
How to create an efficient IP scanner in Linux 44
The concept of the Linux-based IP scanner 44
nmap with Python 47
What are the services running on the target machine? 51
The concept of a port scanner 51
How to create an efficient port scanner 54
Summary 59
Chapter 3: Sniffing and Penetration Testing 60
Introducing a network sniffer 61
Passive sniffing 61
Active sniffing 61
Implementing a network sniffer using Python 61
||||||||||||||||||||
||||||||||||||||||||
Table of Contents
Format characters 63
Learning about packet crafting 73
Introducing ARP spoofing and implementing it using Python 74
The ARP request 74
The ARP reply 75
The ARP cache 75
Testing the security system using custom packet crafting 78
A half-open scan 79
The FIN scan 82
ACK flag scanning 83
Summary 85
Chapter 4: Network Attacks and Prevention 86
Technical requirements 86
DHCP starvation attack 87
The MAC flooding attack 93
How the switch uses the CAM tables 93
The MAC flood logic 94
Gateway disassociation by RAW socket 95
Torrent detection 96
Running the program in hidden mode 104
Summary 106
Chapter 5: Wireless Pentesting 107
Introduction to 802.11 frames 108
Wireless SSID finding and wireless traffic analysis with Python 110
Detecting clients of an AP 120
Wireless hidden SSID scanner 122
Wireless attacks 125
The deauthentication (deauth) attack 125
Detecting the deauth attack 128
Summary 131
Chapter 6: Honeypot – Building Traps for Attackers 132
Technical requirements 132
Fake ARP reply 133
Fake ping reply 135
Fake port-scanning reply 142
Fake OS-signature reply to nmap 145
Fake web server reply 146
Summary 149
Chapter 7: Foot Printing a Web Server and a Web Application 150
The concept of foot printing a web server 150
Introducing information gathering 151
[ ii ]
||||||||||||||||||||
||||||||||||||||||||
Table of Contents
[ iii ]
||||||||||||||||||||
||||||||||||||||||||
Preface
This book is a practical guide that shows you the advantages of using Python for
pentesting, with the help of detailed code examples. This book starts by exploring the
basics of networking with Python and then proceeds to network and wireless pentesting,
including information gathering and attacking. You will learn how to build honeypot traps.
Later on, we delve into hacking the application layer, where we start by gathering
information from a website, and then eventually move on to concepts related to website
hacking, such as parameter tampering, DDOS, XSS, and SQL injection.
$IBQUFS, Sniffing and Penetration Testing, teaches how to perform active sniffing and how
to create a Transport layer sniffer. You will learn special kinds of scanning.
$IBQUFS, Network Attacks and Prevention, outlines different types of network attacks, such
as DHCP starvation and switch mac flooding. You will learn how to detect a torrent on the
client side.
||||||||||||||||||||
||||||||||||||||||||
Preface
$IBQUFS, Wireless Pentesting, goes through wireless frames and explains how to obtain
information such as SSID, BSSID, and the channel number from a wireless frame using a
Python script. In this type of attack, you will learn how to perform pentesting attacks on the
AP.
$IBQUFS, Honeypot ` Building Traps for Attackers, focuses on how to build a trap for
attackers. You will learn how to bulid code from TCP layer 2 to TCP layer 4.
$IBQUFS, Foot Printing a Web Server and a Web Application, dives into the importance of a
web server signature, email gathering, and why knowing the server signature is the first
step in hacking.
$IBQUFS, Client-Side and DDoS Attacks, explores client-side validation and how to bypass
client-side validation. This chapter covers the implantation of four types of DDoS attacks.
$IBQUFS, Pentesting SQL and XSS, discusses two major web attacks: SQL injection and
XSS. In SQL injection, you will learn how to find the admin login page using a Python
script.
In order to perform experiments or run the codes reader can use the virtual machine
(Vmware, virtual box). For Wireless pen-testing readers can use a wireless card TP-Link TL-
WN722N. Becuase TL-WN722N wireless card supports the Kali Linux in VMware.
[2]
||||||||||||||||||||
||||||||||||||||||||
Preface
Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:
The code bundle for the book is also hosted on GitHub at IUUQTHJUIVCDPN
1BDLU1VCMJTIJOH1ZUIPO1FOFUSBUJPO5FTUJOH&TTFOUJBMT4FDPOE&EJUJPO. In case
there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available
at IUUQTHJUIVCDPN1BDLU1VCMJTIJOH. Check them out!
Code in Action
Visit the following link to check out videos of the code being run:
IUUQTHPPHMT#)7/%
[3]
||||||||||||||||||||
||||||||||||||||||||
Preface
Conventions used
There are a number of text conventions used throughout this book.
$PEF*O5FYU: Indicates code words in text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an
example: "Mount the downloaded 8FC4UPSN ENH disk image file as another disk in
your system."
When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW,TPDLFUOUPIT Y
J
Bold: Indicates a new term, an important word, or words that you see onscreen. For
example, words in menus or dialog boxes appear in the text like this. Here is an example:
"Select System info from the Administration panel."
[4]
||||||||||||||||||||
||||||||||||||||||||
Preface
Get in touch
Feedback from our readers is always welcome.
General feedback: Email GFFECBDL!QBDLUQVCDPN and mention the book title in the
subject of your message. If you have questions about any aspect of this book, please email
us at RVFTUJPOT!QBDLUQVCDPN.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit XXXQBDLUQVCDPNTVCNJUFSSBUB, selecting your book,
clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we
would be grateful if you would provide us with the location address or website name.
Please contact us at DPQZSJHIU!QBDLUQVCDPN with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit
BVUIPSTQBDLUQVCDPN.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about our
products, and our authors can see your feedback on their book. Thank you!
[5]
||||||||||||||||||||
||||||||||||||||||||
1
Python with Penetration Testing
and Networking
Penetration (pen) tester and hacker are similar terms. The difference is that penetration
testers work for an organization to prevent hacking attempts, while hackers hack for any
purpose such as fame, selling vulnerability for money, or to exploit the vulnerability of
personal enmity.
Lots of well-trained hackers have got jobs in the information security field by hacking into a
system and then informing the victim of their security bug(s) so that they might be fixed.
A hacker is called a penetration tester when they work for an organization or company to
secure its system. A pentester performs hacking attempts to break into the network after
getting legal approval from the client and then presents a report of their findings. To
become an expert in pentesting, a person should have a deep knowledge of the concepts of
their technology. In this chapter, we will cover the following topics:
||||||||||||||||||||
Other documents randomly have
different content
Yo no sé por qué razón,
de mi tragedia, bufón,
te ríes... Mas tu eres vivo
por tu danzar sin motivo.
ELOGIOS
CXXXIX
A DON FRANCISCO GINER DE LOS RÍOS
CXL
AL JOVEN MEDITADOR
JOSÉ ORTEGA GASSET
A ti laurel y yedra
corónente, dilecto
de Sofía, arquitecto.
Cincel, martillo y piedra
y masones te sirvan; las montañas
de Guadarrama frío
te brinden el azul de sus entrañas,
meditador de otro Escorial sombrío;
y que Felipe austero,
al borde de su regia sepultura,
asome a ver la nueva arquitectura,
y bendiga la prole de Lutero.
CXLI
A XAVIER VALCARCE
CXLII
MARIPOSA DE LA SIERRA
A Juan Ramón Jiménez,
por su libro Platero y yo.
CXLIII
DESDE MI RINCÓN
ELOGIOS
ENVÍO
CXLIV
A UNA ESPAÑA JOVEN
CXLV
ESPAÑA, EN PAZ
CXLVII
AL MAESTRO RUBÉN DARÍO
CXLVIII
A LA MUERTE DE RUBÉN DARÍO
CXLIX
A NARCISO ALONSO CORTÉS,
POETA DE CASTILLA
Jam senior, sed cruda deo viridisque senecta.
Virgilio (Eneida).
CXL
MIS POETAS
CLI
A DON MIGUEL DE UNAMUNO
Por su libro Vida de Don Quijote y Sancho.
Este donquijotesco
Don Miguel de Unamuno, fuerte vasco,
lleva el arnés grotesco
y el irrisorio casco
del buen manchego. Don Miguel
camina,
jinete de quimérica montura,
metiendo espuela de oro a su locura,
sin miedo de la lengua que malsina.
A un pueblo de arrieros,
lechuzos y tahures y logreros
dicta lecciones de Caballería.
CLII
A JUAN RAMÓN JIMÉNEZ
Por su libro Arias tristes.
iluminando la fuente
en donde el agua surtía,
sollozando intermitente.
Sólo la fuente se oía.
Después, se escuchó el
acento
de un oculto ruiseñor.
Quebró una racha de viento
la curva del surtidor.