Leanpub Header

Skip to main content

Practical mitmproxy

Mastering mitmproxy 12 for Security Researchers, Mobile App Testers, and API Developers

Practical mitmproxy

A hands-on guide to mitmproxy 12: trust the CA, filter, modify and replay traffic, write Python addons, choose the right proxy mode, intercept mobile apps past certificate pinning, and automate API security tests. Every output shown is a real run against a lab API.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

mitmproxy sits between a client and a server and shows you every request and response, including HTTPS. Starting it is easy. Getting a phone, a container or a pinned app to send its traffic through it, and then doing something useful with that traffic, is where most people get stuck.

This book teaches mitmproxy 12 from first capture to automated API testing. Every example runs against the same small lab shop, an HTTPS API with a deliberate price-tampering bug and an IDOR, so the techniques build on each other:

  • Install mitmproxy, get clients to trust its CA, and read what the three frontends (mitmproxy, mitmweb, mitmdump) show you.
  • Find flows with filter expressions, then modify and replay them: modify_headers, modify_body, map_local, map_remote, client and server replay.
  • Write addons in Python: event hooks, options, commands and custom content views.
  • Pick the right mode for the client: regular, transparent, reverse, upstream, SOCKS, WireGuard and local capture.
  • Intercept Android and iOS apps, and get past certificate pinning with Frida and objection.
  • Handle HTTP/2, HTTP/3 and WebSockets, export flows as HAR, curl or OpenAPI, and turn captures into repeatable security tests.

No output in the book is invented or retyped. Each output block comes from a real mitmproxy 12.2.3 run in the lab, and every claim cites its source: the mitmproxy documentation, the v12.2.3 source code, or the captured run.

Researched and drafted with AI assistance by Ground Truth Books. The text was checked against the mitmproxy 12.2.3 documentation and source, and the code examples were run under mitmproxy 12.2.3. "mitmproxy" is used descriptively; this book is not affiliated with or endorsed by the mitmproxy project.

Bundle

Bundles that include this book

Author

About the Author

Ground Truth Books

Ground Truth Books publishes practical technical books on computer science, IT tools, data science, machine learning, software engineering and AI.

The name comes from machine learning, where "ground truth" means the real, verified answers you check a model against. That's how these books are made. They're researched and drafted with AI assistance, and then checked against reality. Examples are run against real captures and data in a lab, and those runs are cited like any other source, so you can see which output came straight from the tool. Every claim is cited to its source, with official documentation, specifications and source code preferred over blog posts.

Each book is built around doing the work. Chapters end with exercises, and an appendix gives worked answers you can reproduce on your own machine, using the same freely available data and captures.

Books are updated when the tools change. If you find an error, please report it: a corrected edition is free for every reader, which is one of the best things about Leanpub.

Contents

Table of Contents

Chapter 1: Introduction

  1. What this book covers
  2. Who this book is for
  3. How to use this book
  4. A note on versions and commands
  5. Getting Started

Chapter 2: Installing mitmproxy 12.2.3

  1. Installation on Linux, macOS, and Windows
  2. Verifying the installation
  3. First run: what lands in ~/.mitmproxy
  4. Upgrading and uninstalling

Chapter 3: The Three Frontends

  1. mitmproxy: the interactive TUI
  2. mitmweb: the web interface
  3. mitmdump: the scriptable CLI
  4. Shared command-line options
  5. Interception and Inspection

Chapter 4: How mitmproxy Intercepts HTTPS

  1. The proxy core and sans-I/O design
  2. TLS termination and certificate generation
  3. The mitmproxy CA and trust stores
  4. What interception cannot see

Chapter 5: Trusting the mitmproxy CA

  1. Installing the CA on Linux
  2. Installing the CA on macOS and Windows
  3. Browsers and runtimes with their own trust store
  4. Troubleshooting CA trust

Chapter 6: Filter Expressions and Flow Inspection

  1. Filter expression syntax
  2. Common filter patterns
  3. Inspecting flows in the TUI
  4. Inspecting flows in mitmweb
  5. Modification and Replay

Chapter 7: Modifying Requests and Responses

  1. Interactive modification in the TUI
  2. modify_headers, modify_body, map_local and map_remote
  3. Modification with addons
  4. Common modification recipes

Chapter 8: Replaying Requests

  1. Client-side replay
  2. Server-side replay
  3. Replay in mitmweb
  4. Replay caveats and pitfalls
  5. Addon Development

Chapter 9: Addon Architecture and Events

  1. Anatomy of an addon
  2. Event hooks and their order
  3. Loading and running addons
  4. The abbreviated scripting syntax

Chapter 10: Options, Commands, and Hooks

  1. Declaring addon options
  2. Defining custom commands
  3. Custom contentviews
  4. Exposing addons in the UI

Chapter 11: Working with Flows and Messages

  1. The flow object model
  2. HTTP request and response objects
  3. Headers, cookies and bodies
  4. Reading flow files from Python
  5. Deployment Modes

Chapter 12: Choosing a Mode: Regular, Transparent and Reverse

  1. The mode specification syntax
  2. Choosing a mode for your task
  3. Regular proxy mode
  4. Transparent mode on Linux
  5. Transparent mode on macOS
  6. Reverse proxy mode

Chapter 13: Upstream, SOCKS, and WireGuard Modes

  1. Upstream proxy mode
  2. SOCKS proxy mode
  3. WireGuard mode
  4. Combining modes

Chapter 14: Local Capture Mode

  1. Local redirect on Linux
  2. Local redirect on macOS
  3. Local redirect on Windows
  4. Capturing Docker containers
  5. Mobile and Advanced Protocols

Chapter 15: Intercepting Android and iOS Apps

  1. Android emulator setup
  2. Installing the CA as a system certificate
  3. Android 14 and newer CA installation
  4. Physical Android devices
  5. WireGuard for Android apps
  6. Emulator networking and localhost
  7. iOS proxy and CA setup
  8. Full trust for TLS on iOS

Chapter 16: Bypassing Certificate Pinning

  1. What certificate pinning is
  2. Frida and objection basics
  3. Universal unpinning scripts
  4. Pinning on iOS
  5. Pinning bypass caveats

Chapter 17: HTTP/2, HTTP/3, and WebSockets

  1. HTTP/2 interception
  2. HTTP/3 and QUIC
  3. WebSocket message handling
  4. Protocol-specific addon events
  5. Automation and Reference

Chapter 18: Exporting Flows: HAR, curl and OpenAPI

  1. Saving and loading flow files
  2. Streaming large transfers
  3. Exporting HAR
  4. Copying requests as curl and raw
  5. From flows to an OpenAPI spec

Chapter 19: Automating API Security Testing

  1. A harness you drive with addons
  2. Building a fuzzing addon
  3. Automated replay and regression
  4. Auth token rotation
  5. Reporting what the tests found

Chapter 20: Conclusion

  1. What you can now do
  2. Where to go next
  3. Keeping current with mitmproxy

Appendix A: Command-line options reference

  1. How options reach the tools
  2. Invocation and file I/O
  3. Proxy modes and listeners
  4. TLS and certificates
  5. Modification and replay
  6. Protocol and bodies
  7. Frontend-specific flags
  8. Environment variables

Appendix B: Filter expression reference

  1. Operators
  2. Combining expressions
  3. Regex arguments
  4. Flow selectors
  5. Where filters apply

Appendix C: Addon event reference

  1. Addon event reference

Appendix D: Flow export formats

  1. At a glance
  2. The .mitm flow file
  3. HAR (HTTP Archive)
  4. Export commands: curl, HTTPie, raw
  5. OpenAPI 3.0 through mitmproxy2swagger

Glossary

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub