Home Learn Practice Pricing Host a CTF Community Blogs
Sign Up
PROGRESS
0% Leave Room
← Python for Pentesters: Zero to Tool Builder

Module 1: What is Python? Setup and First Script

Task 1 What is Python and How Does it Work ▾
The most important tool for security professionals
Learn Python once and you can build tools, automate attacks, find vulnerabilities, and analyze data. Every serious security researcher uses Python.
What you will learn
  • Understand what Python is and why security professionals use it
  • Learn how a Python script runs step by step
  • Write your first Python script
What is Python?

Python is a programming language that looks very similar to plain English. You write a .py file, Python reads it line by line, and executes each instruction.

Real world analogy: Think of Python like a very smart calculator that understands English instructions. You tell it what to do in simple terms, and it executes networking, web requests, file operations and much more.

Python is an interpreted language - you do not need to compile it before running. Just type python3 script.py and it runs. The security community loves it because tools like Metasploit, Nmap and Burp Suite are all extensible with Python.

The journey from a Python script to output.
The journey from a Python script to output.

Why Python for Security?

  • Many CTF challenges are solved with Python scripts
  • Custom tools are easy to build - a port scanner in 20 lines
  • Automation: scan 1000 IPs, try password lists automatically
  • Web scraping, API calls, log analysis all easy in Python
  • Metasploit, Burp Suite, Volatility all extensible with Python
Key idea: After learning Python you will not just use tools - you will build your own tools.
Task 2 Setup: Python, VS Code and Your First Script ▾
VS Code - Recommended Editor
Free, lightweight, best Python support. Download: code.visualstudio.com/download

Install Python

# Windows:
# Download from python.org/downloads
# During install: check 'Add Python to PATH'

# Verify installation:
python --version
# or
python3 --version
# Output: Python 3.x.x

Install pip packages

# pip is Python's package manager
pip install requests        # for web requests
pip install paramiko        # for SSH
pip install colorama        # for colored output

# Check pip version:
pip --version

VS Code Setup

# Download VS Code: code.visualstudio.com/download
# Install these extensions:
# 1. Python (Microsoft) - required
# 2. Pylance - code suggestions
# 3. Python Indent - auto indentation
# 4. Error Lens - inline errors

First Script

# Save as hello_hacker.py
print('Hello, Hacker!')
print('Checking Python version...')
import sys
print(f'Python version: {sys.version}')
print('Security journey starts now!')
# Run it:
python3 hello_hacker.py

# Output:
# Hello, Hacker!
# Checking Python version...
# Python version: 3.11.0
# Security journey starts now!
requirements.txt - Save this file and run: pip install -r requirements.txt
requests>=2.28.0
paramiko>=3.0.0
colorama>=0.4.6
beautifulsoup4>=4.11.0
python-whois>=0.8.0
dnspython>=2.3.0
cryptography>=40.0.0
shodan>=1.28.0
Pro tip: Save requirements.txt in your project folder. Install all packages with one command: pip install -r requirements.txt
Task 3 Knowledge Check ⌨ ▾

Knowledge Check

Test what you just learned. Type your answer in the box.

Answer the questions below
Is Python a compiled or interpreted language? (one word)
What is the file extension for a Python script? (format .xx)
Which company makes the VS Code Python extension? (one word)