Book Image

Hands-On Penetration Testing with Python

By : Furqan Khan
Book Image

Hands-On Penetration Testing with Python

By: Furqan Khan

Overview of this book

With the current technological and infrastructural shift, penetration testing is no longer a process-oriented activity. Modern-day penetration testing demands lots of automation and innovation; the only language that dominates all its peers is Python. Given the huge number of tools written in Python, and its popularity in the penetration testing space, this language has always been the first choice for penetration testers. Hands-On Penetration Testing with Python walks you through advanced Python programming constructs. Once you are familiar with the core concepts, you’ll explore the advanced uses of Python in the domain of penetration testing and optimization. You’ll then move on to understanding how Python, data science, and the cybersecurity ecosystem communicate with one another. In the concluding chapters, you’ll study exploit development, reverse engineering, and cybersecurity use cases that can be automated with Python. By the end of this book, you’ll have acquired adequate skills to leverage Python as a helpful tool to pentest and secure infrastructure, while also creating your own custom exploits.
Table of Contents (18 chapters)

Developing a Metasploit module to exploit a network service

In this section, we will see how to make a Metasploit exploit module to exploit a given vulnerability. In this case, we will focus on a buffer overflow vulnerability of a gaming application called Crossfire. For us to write custom Metasploit modules, we need to place them in a specific directory, because when we use the use exploit /.... command in Metasploit, by default, the framework looks for the available modules in the default Metasploit exploits directory. If it doesn't find the given exploit there, it then searches the extended modules directory, which is located at the following path: /root/msf4/modules/exploits. Let's create the path and a custom directory. We'll turn our Kali VM on and run the following commands:

mkdir -p ~/.msf4/modules/exploits/custom/cf
cd ~/.msf4/modules/exploits/custom/cf
touch...