From Zero Python to Building AI Agents That Hunt Bugs For You

Zakaria Eddafri
Zakaria Eddafri
Bug Bounty Hunter

At HackenProof, we believe that some of the most valuable security knowledge is created inside the hacker community itself. This belief is reflected in our ongoing series of guest articles, where security researchers from our community share practical insights, practical knowledge, and real-world lessons from their work in smart contract security, Web3 development, and bug bounty research. By publishing hacker-authored content, we aim to make expert-level security knowledge more accessible and to support continuous learning across the broader Web3 security ecosystem.

We regularly curate and publish the strongest technical articles based on their educational value, technical depth, and relevance to real security challenges. Authors whose work is published on the HackenProof blog receive the Star Author achievement, recognizing their contribution to knowledge sharing and community growth.

Read the article, explore the ideas, and share your thoughts with the community — and if you have expertise to share, this could be your first step toward becoming our next Star Author.

Introduction

This article was written by Zakaria Eddafri (@GallopingMrOwl) – an ethical hacker who began his journey with nothing more than an Android phone. His path on HackenProof started on October 1, 2019. Now he has 61 paid reports, and this is his third article on our blog. Check his latest article.

This article teaches complete beginners how to go from zero Python knowledge to building autonomous AI agents that automatically hunt for vulnerabilities in Web2 and Web3 targets. It walks through Python fundamentals, subprocess automation, HTTP testing, Web3 smart contract scanning, and LangChain ReAct agent construction. Instead of teaching security theory, it teaches how to build the tools that do the hunting for you.

The Elite Autonomous Agent Masterclass

“The best hackers don’t work harder. They build tools that work FOR them.”

Welcome, future elite. You clicked on this course because you saw an AI agent autonomously find a CRITICAL reentrancy vulnerability in a real smart contract. That wasn’t magic. That was Python + a ReAct loop + the right tools.

By the end of this course, you will:

  • Write Python fluently
  • Build scripts that automate Web2 & Web3 bug hunting
  • Create your own autonomous AI agent with custom tools
  • Understand MCP servers (the future of AI tool sharing)

No prior coding knowledge required. We start from absolute zero.

Let’s go.

MODULE 1: Python — Your New Superpower

“Every hacker tool you admire — Burp Suite extensions, Nuclei templates, Slither, Foundry scripts — they’re all built by people who learned exactly what you’re about to learn.”

Python is the #1 language for hacking, automation, and AI. Not because it’s the fastest, but because it’s the most readable and has the most libraries. Let’s master the basics.

1.1 — Variables: Storing Information

A variable is just a name for a piece of data. Think of it as a label on a box.

From Zero Python to Building AI Agents That Hunt Bugs For You

Exercise 1.1

From Zero Python to Building AI Agents That Hunt Bugs For You

Run it: python3 basics.py. You just wrote your first recon report!

Pro Tip: The `f"..."` syntax is called an f-string. It lets you inject variables directly into text. You will use this EVERYWHERE in hacking scripts.

1.2 — Lists: Collections of Things

A list holds multiple items in order. Think of it as your target list.

From Zero Python to Building AI Agents That Hunt Bugs For You

Exercise 1.2

From Zero Python to Building AI Agents That Hunt Bugs For You

1.3 — Dictionaries: Labeled Data

A dictionary stores data as key: value pairs. Think of it as a JSON object (because it literally IS one).

From Zero Python to Building AI Agents That Hunt Bugs For You

Exercise 1.3

From Zero Python to Building AI Agents That Hunt Bugs For You

1.4 — Loops: Doing Things Repeatedly

Loops let you automate repetitive actions. This is the core of scripting.

The for Loop (When you know how many times)

From Zero Python to Building AI Agents That Hunt Bugs For You

The while Loop (When you DON’T know how many times)

From Zero Python to Building AI Agents That Hunt Bugs For You

Exercise 1.4

From Zero Python to Building AI Agents That Hunt Bugs For You

1.5 — Functions: Reusable Blocks of Code

A function is a block of code you can call by name. This is the #1 most important concept for building AI agents, because every tool an agent uses IS a function.

From Zero Python to Building AI Agents That Hunt Bugs For You

Why Type Hints Matter (: str and > str)

From Zero Python to Building AI Agents That Hunt Bugs For You

KEY INSIGHT: When you later use @tool to give a function to an AI agent, LangChain reads the type hints (: str, -> str) AND the docstring ("""...""") to tell the LLM exactly what the function does. If you skip these, the AI will be blind.

Exercise 1.5

From Zero Python to Building AI Agents That Hunt Bugs For You

1.6 — Conditionals: Making Decisions

From Zero Python to Building AI Agents That Hunt Bugs For You

MODULE 1 FINAL CHALLENGE

“If you can build this, you’re ready for Module 2.”

Build a script called recon_report.py that:

  1. Creates a list of 3 target contracts
  2. Loops through each one
  3. Assigns a random severity score (1–10)
  4. Prints a formatted report
From Zero Python to Building AI Agents That Hunt Bugs For You

Run it: python3 recon_report.py

If that runs and you understand every line, congratulations — you have the Python foundation to build AI agents. Let’s level up.

MODULE 2: Python for Hackers — Talking to the Real World

“A Python script that can’t touch the terminal, read files, or make HTTP requests is useless. In this module, you give Python its HANDS.”

2.1 — Subprocess: Running Terminal Commands from Python

This is the MOST IMPORTANT skill for building AI agents. subprocess is how you make Python run grep, gfunc, nmap, curl, or ANY terminal command.

From Zero Python to Building AI Agents That Hunt Bugs For You

Making it Safe (CRITICAL for Agents!)

From Zero Python to Building AI Agents That Hunt Bugs For You

KEY INSIGHT: The safe_run() function above is essentially the EXACT skeleton of every tool in our agent.py. The three things that make it production-ready are: try/except, timeout, and output truncation.

Exercise 2.1

From Zero Python to Building AI Agents That Hunt Bugs For You

2.2 — HTTP Requests: Talking to APIs and Websites

Bug bounty hunters live on HTTP. The requests library lets you send GET, POST, PUT, DELETE requests from Python.

From Zero Python to Building AI Agents That Hunt Bugs For You

Sending POST requests (like submitting a form)

From Zero Python to Building AI Agents That Hunt Bugs For You

Exercise 2.2: Build a Header Scanner

From Zero Python to Building AI Agents That Hunt Bugs For You

2.3 — File I/O: Reading and Writing Files

Agents need to read smart contract files and write reports. File handling is essential.

From Zero Python to Building AI Agents That Hunt Bugs For You

Exercise 2.3: Build a Contract Scanner

From Zero Python to Building AI Agents That Hunt Bugs For You

MODULE 2 FINAL CHALLENGE

“Combine everything. Build a mini recon tool.”

Build web_recon.py:

From Zero Python to Building AI Agents That Hunt Bugs For You

You now have Python skills that directly translate to bug bounty hunting. Time to apply them.

MODULE 3: Web2 Bug Hunting with Python

“Every time you manually test something twice, you should have automated it the first time.”

3.1 — Directory Bruteforcing

From Zero Python to Building AI Agents That Hunt Bugs For You

3.2 — API Endpoint Testing

From Zero Python to Building AI Agents That Hunt Bugs For You

3.3 — Parameter Fuzzing

From Zero Python to Building AI Agents That Hunt Bugs For You

MODULE 4: Building Web3 Security Tools

“Smart contracts are just programs. And programs have bugs. Let’s find them.”

4.0 — Introduction to gfunc: Your Static Analysis Companion

Before diving into Python automation, let’s introduce gfunc — a powerful static analysis tool that you’ll use throughout this module and the next.

What is gfunc?

gfunc is a universal function call graph tool that analyzes multiple programming languages, including Solidity, Rust, Move, and Go. It can:

  • Extract complete function bodies with dependencies
  • Generate call graphs showing which functions call which
  • Slice code to show data flows
  • Find function definitions across multiple files

For this course, we’ll focus on its Solidity analysis capabilities, but know that the same tool works across different blockchain languages!

Installation

From Zero Python to Building AI Agents That Hunt Bugs For You

Alternatively, download pre-built binaries from the releases page.

Basic Usage

From Zero Python to Building AI Agents That Hunt Bugs For You

Example Output

From Zero Python to Building AI Agents That Hunt Bugs For You

KEY INSIGHT: gfunc gives you deterministic code extraction. Unlike an LLM which might hallucinate code, gfunc reads the actual source files and returns exactly what’s there. This is why it’s perfect for AI agents — the AI can trust the output completely.

Now let’s automate gfunc with Python!

4.1 — Grep-Based Vulnerability Scanner

The fastest way to find bugs? Search for dangerous patterns.

From Zero Python to Building AI Agents That Hunt Bugs For You

CRITICAL INSIGHT: Everything grep finds is a starting point, not proof of a vulnerability. A function using .call() might be perfectly safe if it follows Checks-Effects-Interactions. Always verify manually before reporting.

Exercise 4.1

Add 3 more patterns to SECURITY_PATTERNS:

  • "Uninitialized Storage": r"storage.*;\\n.*function"
  • "Magic Numbers": r"[0-9]{4,}"
  • "TODO Comments": r"TODO"
  • "FIXME Comments": r"FIXME"

4.2 — Wrapping gfunc as a Python Tool

This is how we turn your custom gfunc binary into a Python function that an AI can use:

From Zero Python to Building AI Agents That Hunt Bugs For You

KEY INSIGHT: This exact function, with @tool added on top, is what gives the AI agent the power to read code deterministically. The AI calls this function, reads the output, and reasons about it. No hallucination possible.

MODULE 5: Building Autonomous AI Agents

“This is where everything comes together. You’ve been training. Now you build the machine.”

5.1 — What IS an Agent?

An agent is an LLM (like GPT-4, Claude, or Qwen) that has been given tools (Python functions) and a reasoning loop (ReAct).

ComponentWhat It DoesOur Example

Brain

The LLM that thinks

ChatOllama("qwen2.5:32b")

Tools

Python functions the LLM can call

run_grep(), gfunc_slice()

Loop

Forces Thought → Action → Observation

LangGraph’s create_react_agent

Prompt

Instructions that guide behavior

“You are a security auditor…”

5.2 — Building It Step by Step

Step 1: Install

From Zero Python to Building AI Agents That Hunt Bugs For You

Step 2: Define Your Tools

From Zero Python to Building AI Agents That Hunt Bugs For You

Step 3: Connect the Brain

From Zero Python to Building AI Agents That Hunt Bugs For You

Step 4: Write the System Prompt

From Zero Python to Building AI Agents That Hunt Bugs For You

Step 5: Create the Agent Loop

From Zero Python to Building AI Agents That Hunt Bugs For You

That’s it. You just built an autonomous AI security agent. 🎉

MODULE 5 FINAL CHALLENGE

“Customize the agent. Make it YOURS.”
  1. Add a NEW tool: list_contracts() — Lists all .sol files in contracts/
  2. Add a NEW tool: count_lines(filepath) — Returns the line count of a file
  3. Modify the system prompt to also check for “flash loan attacks”
  4. Run the agent against a real project

MODULE 6: The MCP Server (The Final Boss)

“Your AI tools are incredible. But they only work inside your Python script. What if Claude Desktop, Cursor, or ANY AI could use them? That’s MCP.”

What is MCP?

MCP (Model Context Protocol) is a universal standard that lets AI apps connect to your tools over a local socket.

Feature@tool (What we built)MCP Server

Works in

Only your agent.py script

Claude Desktop, Cursor, any MCP client

Setup

1 line (@tool)

Requires a server process

Sharing

Copy the Python file

Connect via URL/stdio

Best for

Quick prototyping

Production tool sharing

Building a Basic MCP Server (Python FastMCP)

From Zero Python to Building AI Agents That Hunt Bugs For You
From Zero Python to Building AI Agents That Hunt Bugs For You

Now, Claude Desktop or Cursor can connect to this server and use your gfunc tool natively!

GRADUATION

“You started this course not knowing what a variable was. Now you can build autonomous AI agents that hunt bugs in smart contracts. That’s not learning. That’s evolution.”

What you built:

  1. Python scripts that automate Web2 recon (headers, directories, parameters)
  2. Python scripts that automate Web3 auditing (grep patterns, gfunc integration)
  3. A full ReAct AI agent that autonomously finds vulnerabilities
  4. Understanding of MCP servers for universal tool sharing

What’s next:

  • Drop REAL bug bounty targets into your contracts/ cage
  • Add more tools (Slither, Mythril, Foundry test runners)
  • Build MCP servers so you can use your tools everywhere
  • Hunt bugs. Earn bounties. Build your reputation.
“The best time to start was yesterday. The second best time is right now.”

Go get it.

Share article:

Read more on HackenProof Blog