Python Penetration Testing Essentials
Techniques for ethical hacking with Python, 2nd Edition
Mohit
- 230 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Python Penetration Testing Essentials
Techniques for ethical hacking with Python, 2nd Edition
Mohit
About This Book
This book gives you the skills you need to use Python for penetration testing, with the help of detailed code examples. This book has been updated for Python 3.6.3 and Kali Linux 2018.1.About This Book• Detect and avoid various attack types that put the privacy of a system at risk• Leverage Python to build efficient code and eventually build a robust environment• Learn about securing wireless applications and information gathering on a web serverWho This Book Is ForIf you are a Python programmer, a security researcher, or an ethical hacker and are interested in penetration testing with the help of Python, then this book is for you. Even if you are new to the field of ethical hacking, this book can help you find the vulnerabilities in your system so that you are ready to tackle any kind of attack or intrusion.What You Will Learn• The basics of network pentesting including network scanning and sniffing• Wireless, wired attacks, and building traps for attack and torrent detection• Web server footprinting and web application attacks, including the XSS and SQL injection attack• Wireless frames and how to obtain information such as SSID, BSSID, and the channel number from a wireless frame using a Python script• The importance of web server signatures, email gathering, and why knowing the server signature is the first step in hackingIn DetailThis book gives you the skills you need to use Python for penetration testing (pentesting), with the help of detailed code examples.We start by exploring the basics of networking with Python and then proceed to network hacking. Then, you will delve into exploring Python libraries to perform various types of pentesting and ethical hacking techniques. Next, we delve into hacking the application layer, where we start by gathering information from a website. We then move on to concepts related to website hacking—such as parameter tampering, DDoS, XSS, and SQL injection.By reading this book, you will learn different techniques and methodologies that will familiarize you with Python pentesting techniques, how to protect yourself, and how to create automated programs to find the admin console, SQL injection, and XSS attacks.Style and approachThe book starts at a basic level and moves to a higher level of network and web security. The execution and performance of code are both taken into account.
Frequently asked questions
Information
Sniffing and Penetration Testing
- The concept of a sniffer
- The types of network sniffing
- Network sniffing using Python
- Packet crafting using Python
- The ARP spoofing concept and implementation by Python
- Testing security by custom-packet crafting
Introducing a network sniffer
- Passive sniffing
- Active sniffing
Passive sniffing
Active sniffing
Implementing a network sniffer using Python
- struct.pack(fmt, v1, v2, ...): This method returns a string that contains the values v1, v2, and so on, packed according to the given format
- struct.unpack(fmt, string): This method unpacks the string according to the given format
import struct ms= struct.pack('hhl', 1, 2, 3) print (ms) k= struct.unpack('hhl',ms) print k
G:PythonNetworkingnetwork>python str1.py ☻ ♥ (1, 2, 3)
import socket import struct host = "192.168.0.1" port = 12347 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) conn, addr = s.accept() print "connected by", addr msz= struct.pack('hhl', 1, 2, 3) conn.send(msz) conn.close()
import socket import struct s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = "192.168.0.1" port =12347 s.connect((host,port)) msg= s.recv(1024) print msg print struct.unpack('hhl',msg) s.close()
C:network>python unstruc.py ☻ ♥ (1, 2, 3)
G:PythonNetworkingprogram>python struct1.py connected by ('192.168.0.11', 1417)
Format characters
Format | C type | Python type | Standard size |
x | pad byte | no value | |
c | char | string of length 1 | 1 |
b | signed char | integer | 1 |
B | unsigned char | integer | 1 |
? | _Bool | bool | 1 |
h | short | integer | 2 |
H | unsigned short | integer | 2 |
i | int | integer | 4 |
I | unsigned int | integer | 4 |
l | long | integer | 4 |
L | unsigned long | integer | 4 |
q | long long | integer | 8 |
Q | unsigned long long | integer | 8 |
f | float | float | 4 |
d | double | float | 8 |
s | char[] | string | |
p | char[] | string | |
P | void * | integer |
Let's check what will happen when one value is packed in different formats:
>>> import struct
>>> struct.pack('b',2) 'x02' >>> struct.pack('B',2) 'x02' >>> struct.pack('h',2) 'x02x00'
>>> struct.pack('q',2) 'x02x00x00x00x00x00x00x00'
>>> struct.pack('!q',2) 'x00x00x00x00x00x00x00x02' >>>
- PF_PACKET: It operates at the device-driver layer. The pcap library for Linux uses PF_PACKET sockets. To run this, you must be logged in as a root. If you want to send and receive messages at the most basic level, below the internet protocol layer, then you need to use PF_PACKET.
- Raw socket: It does not care about the network layer stack and p...