Zurück zum Ranking

alufers/mitmproxy2swagger

HTML

Automagically reverse-engineer REST APIs via capturing traffic

mitmproxyopenapireverse-engineeringswagger
Sterne-Wachstum
Sterne
9.6k
Forks
368
Wochenwachstum
Issues
9
5k
Jan. 2023März 2024Mai 2025Juli 2026
README

mitmproxy2swagger

PyPI version Arch Linux repository

https://user-images.githubusercontent.com/5400940/168086818-c48f60ab-3f95-42eb-b435-c8b1a6326b81.mp4

A tool for automatically converting mitmproxy captures to OpenAPI 3.0 specifications. This means that you can automatically reverse-engineer REST APIs by just running the apps and capturing the traffic.


🆕 NEW!

Added support for processing HAR exported from the browser DevTools. See Usage - HAR for more details.


Installation

First you will need python3 and pip3.

$ pip install mitmproxy2swagger
# ... or ...
$ pip3 install mitmproxy2swagger
# ... or ...
$ git clone git@github.com:alufers/mitmproxy2swagger.git
$ cd mitmproxy2swagger
$ docker build -t mitmproxy2swagger .

Then clone the repo and run mitmproxy2swagger as per examples below.

Usage

Mitmproxy

To create a specification by inspecting HTTP traffic you will need to:

  1. Capture the traffic by using the mitmproxy tool. I personally recommend using mitmweb, which is a web interface built-in to mitmproxy.

    $ mitmweb
    Web server listening at http://127.0.0.1:8081/
    Proxy server listening at http://*:9999
    ...
    

    IMPORTANT

    To configure your client to use the proxy exposed by mitm proxy, please consult the mitmproxy documentation for more information.

  2. Save the traffic to a flow file.

    In mitmweb you can do this by using the "File" menu and selecting "Save":

    A screenshot showing the location of the "Save" option in the "File" menu

  3. Run the first pass of mitmproxy2swagger:

    $ mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix>
    # ... or ...
    $ docker run -it -v $PWD:/app mitmproxy2swagger mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix>
    

    Please note that you can use an existing schema, in which case the existing schema will be extended with the new data. You can also run it a few times with different flow captures, the captured data will be safely merged.

    <api_prefix> is the base url of the API you wish to reverse-engineer. You will need to obtain it by observing the requests being made in mitmproxy.

    For example if an app has made requests like these:

    https://api.example.com/v1/login
    https://api.example.com/v1/users/2
    https://api.example.com/v1/users/2/profile
    

    The likely prefix is https://api.example.com/v1.

  4. Running the first pass should have created a section in the schema file like this:

    x-path-templates:
      # Remove the ignore: prefix to generate an endpoint with its URL
      # Lines that are closer to the top take precedence, the matching is greedy
      - ignore:/addresses
      - ignore:/basket
      - ignore:/basket/add
      - ignore:/basket/checkouts
      - ignore:/basket/coupons/attach/{id}
      - ignore:/basket/coupons/attach/104754
    

    You should edit the schema file with a text editor and remove the ignore: prefix from the paths you wish to be generated. You can also adjust the parameters appearing in the paths.

  5. Run the second pass of mitmproxy2swagger:

    $ mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix> [--examples]
    # ... or ...
    $ docker run -it -v $PWD:/app mitmproxy2swagger mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix> [--examples]
    

    Run the command a second time (with the same schema file). It will pick up the edited lines and generate endpoint descriptions.

    Please note that mitmproxy2swagger will not overwrite existing endpoint descriptions, if you want to overwrite them, you can delete them before running the second pass.

    Passing --examples will add example data to requests and responses. Take caution when using this option, as it may add sensitive data (tokens, passwords, personal information etc.) to the schema. Passing --headers will add headers data to requests and responses. Take caution when using this option, as it may add sensitive data (tokens, passwords, personal information etc.) to the schema.

HAR

  1. Capture and export the traffic from the browser DevTools.

    In the browser DevTools, go to the Network tab and click the "Export HAR" button.

    A screenshot showing where the export har button is located

  2. Continue the same way you would do with the mitmproxy dump. mitmproxy2swagger will automatically detect the HAR file and process it.

Example output

See the examples. You will find a generated schema there and an html file with the generated documentation (via redoc-cli).

See the generated html file.

Development and contributing

This project uses:

  • uv for dependency management
  • prek for code formatting and linting
  • pytest for unit testing

To install the dependencies:

uv sync

Run linters:

uv run prek run --all-files

Install prek hooks:

uv run prek install

Run tests:

uv run pytest

Run tests with coverage:

uv run pytest --cov=mitmproxy2swagger

License

MIT

Ähnliche Repositories
mitmproxy/mitmproxy

An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.

PythonPyPIMIT Licensepythonsecurity
mitmproxy.org
44.4k4.6k
docmirror/dev-sidecar

开发者边车,github打不开,github加速,git clone加速,git release下载加速,stackoverflow加速

JavaScriptnpmMozilla Public License 2.0dev-sidecarfastgit
23.3k2.9k
coyove/goflyway

An encrypted HTTP server

GoGo ModulesMIT Licensegolangsocks
4.3k639
abhinavsingh/proxy.py

💫 Ngrok FRP Alternative • ⚡ Fast • 🪶 Lightweight • 0️⃣ Dependency • 🔌 Pluggable • 😈 TLS interception • 🔒 DNS-over-HTTPS • 🔥 Poor Man's VPN • ⏪ Reverse & ⏩ Forward • 👮🏿 "Proxy Server" framework • 🌐 "Web Server" framework • ➵ ➶ ➷ ➠ "PubSub" framework • 👷 "Work" acceptor & executor framework

PythonPyPIBSD 3-Clause "New" or "Revised" Licensehttp-proxypython3
abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/
3.5k631
projectdiscovery/proxify

A versatile and portable proxy for capturing, manipulating, and replaying HTTP/HTTPS traffic on the go.

GoGo ModulesMIT Licensemitmproxymitm
projectdiscovery.io
3.1k266
DanOps-1/Gpt-Agreement-Payment

ChatGPT Plus/Team/Pro 订阅协议端到端重放工具集 · hCaptcha 视觉求解器 · 反欺诈机制实证研究 / End-to-end protocol replay toolkit for ChatGPT Plus/Team/Pro subscription with from-scratch hCaptcha solver and empirical anti-fraud research

PythonPyPIMIT Licenseadversarial-mlanti-fraud
2.2k13
summitt/Nope-Proxy

TCP/UDP Non-HTTP Proxy Extension (NoPE) for Burp Suite.

JavaMavenappsecappsecurity
1.7k240
monkeyWie/proxyee

HTTP proxy server,support HTTPS&websocket.MITM impl,intercept and tamper HTTPS traffic.

JavaMavenMIT Licensehttphttps
1.6k577
lqqyt2423/go-mitmproxy

mitmproxy implemented with golang. 用 Golang 实现的中间人攻击(Man-in-the-middle),解析、监测、篡改 HTTP/HTTPS 流量。

GoGo ModulesMIT Licensemitmproxymitm
1.5k303
ssh-mitm/ssh-mitm

SSH-MITM - ssh audits made simple

PythonPyPIGNU General Public License v3.0sshssh-server
docs.ssh-mitm.at
1.5k155
secretsquirrel/BDFProxy

Patch Binaries via MITM: BackdoorFactory + mitmProxy.

PythonPyPIbdfpython
1k199
mitmproxy/android-unpinner

Remove Certificate Pinning from APKs

PythonPyPIandroidreverse-engineering
1k81