Book Image

Python Penetration Testing Essentials - Second Edition

By : Mohit Raj
Book Image

Python Penetration Testing Essentials - Second Edition

By: Mohit Raj

Overview of this book

This 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.
Table of Contents (11 chapters)

Fake ping reply

In this section, you will learn how to send fake ping reply packets. In the fake ping reply code, I have not used any libraries.

Let's understand the code. The code name is icmp_reply.py. In order to run the code, you need to install the ping module from https://pypi.python.org/pypi/ping/0.2:

  • The following modules have been used in the code:
      import socket
import struct
import binascii
import ping
import Queue
import threading
import sys
import random
import my_logger
  • The following code defines a queue, Q, and two sockets. One socket will be used to receive packets and the other will be used to send packet:
      Q = Queue.Queue()
IP_address = 0
my_socket = socket.socket(socket.PF_PACKET, socket.SOCK_RAW,
socket.ntohs(0x0800))
my_socket_s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW...