πŸ” My Shodan + Black Hat Python Journey: Internet-Scale Reconnaissance & Offensive Security Automation

πŸ“– My Journey So Far

Today, I set out to bridge the gap between the local network hacking techniques in Black Hat Python and the vast internet-wide data available through Shodan. What I built is a complete, working environment that lets me discover targets globally and apply the book’s offensive security techniques in real-world scenarios.


🎯 What I Wanted to Accomplish

My goal: Transform theoretical Python security techniques into internet-scale reconnaissance and attack automation tools.

I wanted to stop practicing only on my local network and start using Shodan’s massive device database as my intelligence feed. Here’s why:

Before ShodanAfter Shodan
I could only test on my own networkI can discover millions of targets globally
I had to manually find targetsAutomated queries find targets for me
My reconnaissance was limitedFull internet visibility
I was just learning theoriesI can practice on real-world data
Small sample sizesDiverse, real-world data for practice

πŸ› οΈ What I Built and How I Did It

My Environment Setup

I created a dedicated Conda-based Python 3.13 environment (bhp) with everything isolated:

Key Components:

  • Python Environment: miniforge3 with Python 3.13
  • Core Libraries: scapy, requests, paramiko, pycryptodome, beautifulsoup4
  • Shodan Integration: Official shodan Python library
  • Path Management: Custom wrapper (~/bhp-python) to force the correct site-packages

My Workflow

Here’s how Shodan feeds into my Black Hat Python toolkit:

text

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Shodan Query   │───▢│  Target Discovery│───▢│  BHP Attack Module  β”‚
β”‚  (API Search)   β”‚    β”‚  (IP/Port List)  β”‚    β”‚  (Exploitation)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                         β”‚
         β–Ό                       β–Ό                         β–Ό
   "port:22"  ────────▢   SSH Servers List ──────▢  Paramiko SSH Client
   "port:53"  ────────▢   DNS Servers List ──────▢  Scapy DNS Attack
   "product:Apache" ──▢  Web Servers List ──────▢  Requests Web Hacking

πŸ“š How I Map Shodan to Each Black Hat Python Chapter

BHP ChapterTopicMy Shodan Integration
Chapter 2TCP/UDP ClientsI replace local port scanning with Shodan’s global port data
Chapter 3Raw SocketsI use Shodan to find targets for packet crafting
Chapter 4ScapyI find DNS servers with recursion enabled for amplification attacks
Chapter 5Web HackingI discover web servers with specific versions/vulnerabilities
Chapter 6Wireshark DissectionI analyze Shodan banner data with dpkt
Chapter 7Command & ControlI identify potential C2 infrastructure
Chapter 8TrojansI find targets with vulnerable services
Chapter 9ExfiltrationI discover hosts with open data ports
Chapter 10Privilege EscalationI identify misconfigured services
Chapter 11Windows FunI find Windows-based targets

πŸ’» My Tools I Created Today

1. ~/bhp-python – My Environment Wrapper

This forces Python to use the correct site-packages, bypassing all the anaconda3 conflicts I was fighting.

bash

~/bhp-python script.py

2. bhp-shodan – My Custom Shodan CLI

I built this to work without pkg_resources (which was causing issues in Python 3.13).

bash

bhp-shodan info                 # Check my credits
bhp-shodan host 1.1.1.1        # Host lookup
bhp-shodan search "port:53" 5  # Search for targets

3. shodan_working.py – My Full Recon Script

This combines host lookup, DNS search, and web server discovery in one tool.

4. shodan_tool.py – My Quick IP Scanner

A simple command-line tool to get info for any IP I want to investigate.

5. shodan_batch.py – My Batch Search Tool

Predefined searches for common services (SSH, DNS, Web, etc.) so I can quickly find targets.


πŸ” My Query Examples for Practice

For Chapter 2: TCP/UDP Clients

python

# Find SSH servers for connection testing
results = api.search('port:22')

For Chapter 4: Scapy – DNS Amplification

python

# Find DNS servers with recursion enabled
results = api.search('port:53 dns.recursion:enabled')

For Chapter 5: Web Hacking

python

# Find vulnerable Apache versions
results = api.search('product:Apache "2.4.49"')

For Chapter 7-8: Command & Control

python

# Find potential C2 infrastructure
results = api.search('port:443 org:Amazon')

🚨 My Security Practices

AspectMy Approach
API Key SecurityI never share my keys; they live in ~/.config/shodan/config.py with 600 permissions
Legal ComplianceI only scan/attack systems I own or have explicit permission to test
Rate LimitsFree tier gives me 100 queries/month; I track usage with api.info()
Ethical UseI use this for learning, defense, and authorized penetration testing only

πŸ“Š How I Track My Credits

python

api = shodan.Shodan(API_KEY)
info = api.info()
print(f"Query credits: {info.get('query_credits', 0)}")

What Each Operation Costs Me

OperationCredits Used
api.search()1 per query (up to 100 results)
api.host()1 per IP (sometimes free)
api.count()0 (free – I use this to check before searching)
api.stats()1 per query

πŸŽ“ My Learning Path

  1. Beginner: I run pre-built scripts to understand Shodan data
  2. Intermediate: I modify queries to find specific targets I’m interested in
  3. Advanced: I’m building custom BHP tools that use Shodan data dynamically
  4. Expert: I’m working toward creating automated reconnaissance-to-exploitation pipelines

βœ… Where I’m At Now

ComponentStatusNotes
Python Environmentβœ… Workingminiforge3, Python 3.13
All BHP Packagesβœ… Installedscapy, requests, paramiko, etc.
Shodan Libraryβœ… Workingv1.31.0
Shodan CLIβœ… WorkingMock pkg_resources fixed it
Custom Wrapperβœ… Working~/bhp-python
API Key⚠️ Needs Update0 credits – I need a fresh key

πŸš€ My Next Steps

  1. Get a fresh Shodan API key from https://account.shodan.io/
  2. Update my confignano ~/.config/shodan/config.py
  3. Test~/bhp-python -m shodan search port:80 --limit 1
  4. Start Chapter 2: Build TCP client with Shodan-discovered targets
  5. Work through each chapter: Apply Shodan intelligence to every BHP technique

πŸ“ My Project Structure

text

~/bhp-projects/
β”œβ”€β”€ shodan_final.py          # My complete reconnaissance script
β”œβ”€β”€ shodan_working.py        # Working version with API
β”œβ”€β”€ shodan_tool.py           # Quick IP scanner
β”œβ”€β”€ shodan_batch.py          # Batch search tool
β”œβ”€β”€ shodan_simple.py         # Simple search interface
β”œβ”€β”€ shodan_complete.py       # All-in-one tool
β”œβ”€β”€ recon_tool.py            # Reconnaissance tool
β”œβ”€β”€ simple_scanner.py        # Basic port scanner
└── test_shodan_import.py    # Environment verification

~/bin/
└── bhp-shodan               # My custom Shodan CLI wrapper

~/.config/shodan/
└── config.py                # My API key storage (chmod 600)

🎯 My Final Thoughts

“Shodan turns Black Hat Python from a local testing framework into a global offensive security platform. With Shodan’s data and Python’s flexibility, I can build tools that discover, analyze, and test millions of devices across the internet – all from my command line.”

This integration lets me:

  • Think globally about security threats
  • Practice on real-world data (legally and ethically)
  • Automate reconnaissance at scale
  • Build tools that bridge the gap between intelligence and action

My environment is ready. I just need to get my new API key and start exploring the internet’s attack surface with Black Hat Python! πŸπŸ”