The point is, with an ever growing collection of Python libraries and easy to deploy code, Python is ideal for hackers. If you ever look at some of the source code for popular pentesting tools, you will see a large amount of Python.

Well, today I’m more of here to talk to about some applicable code you can use in pentesting situations, where you may not always have access to a Kali machine. And maybe with some ingenuity, you can even execute this code on a mobile device. So here are my favorite Pythonic recipes for the hacker!

1. Extract Phone Numbers

Let’s start off with something simple. Say we want to siphon some Phone Numbers from a document or some sort of webpage. We want to social engineer these numbers, but the page is just spewing a ton of bullshit we don’t care much for.

The core component that you need to understand is 5th line, where you would see a random string. What is it? That is known as a regular expression. This is basically a special string that signifies a specific pattern to look for. That specific regex specified looks for standard phone-numbers in these formats:

2. Hacking SMTP (email)

With the vast collection of modules for Python, there obviously is one for SMTP, also known as Simple Mail Transfer Protocol. This is the protocol utilized by email services. Let’s make a simple script that launches a dictionary attack on a sample Gmail account (can be utilized on other SMTP services, such as Yahoo).

Let’s look at a few lines. the for keyword takes each newline within the wordlist.txt and appends it as a possible password. When we look at line 8, a SMTP object is defined, connecting to the Gmail SMTP server on port 587. The SMTP object would attempt to login using with the username, and each password from within the wordlist.

3. TCP DoS attack

This quick script provides a way for the user to employ a quick stress.

As a language that includes elements of a procedural scripting language and object-oriented language, Python provides at-ease use for both hackers and engineers. I rely greatly on Python when it comes to writing scripts and projects, and hopefully, I’ll continue to utilize it. However, to add some variation, I’ll start with some projects in C, Rust and Ruby as well. Exploitation is looking nice, so that’s something I’m aiming at.

Thanks for reading, and more is coming! Here is a gr8 list of books by hackers for hackers with relevance to Python: