https://github.com/alufers/mitmproxy2swagger Skip to content Sign up * Product + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} alufers / mitmproxy2swagger Public * Notifications * Fork 31 * Star 938 Automagically reverse-engineer REST APIs via capturing traffic 938 stars 31 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 1 branch 0 tags Code Latest commit @alufers alufers Merge pull request #1 from jwilk-forks/spelling ... b5a0fb5 May 12, 2022 Merge pull request #1 from jwilk-forks/spelling Fix typos b5a0fb5 Git stats * 15 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .vscode first commit May 11, 2022 dist add a binary to pypi May 12, 2022 docs add video to readme May 12, 2022 example_outputs first commit May 11, 2022 mitmproxy2swagger add a binary to pypi May 12, 2022 .gitignore bump version May 12, 2022 README.md Fix typos May 12, 2022 dupsko.yml change required python version May 12, 2022 poetry.lock first commit May 11, 2022 pyproject.toml bump version May 12, 2022 View code mitmproxy2swagger Installation Usage Example output License README.md mitmproxy2swagger video.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. Installation First you will need python3 and pip3. $ pip install mitmproxy2swagger # ... or ... $ pip3 install mitmproxy2swagger Then clone the repo and run mitmproxy2swagger as per examples below. Usage 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": [mitmweb_sa] 3. Run the first pass of mitmproxy2swagger: $ mitmproxy2swagger -i -o -p 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. 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 -o -p [--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. 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 here. License MIT About Automagically reverse-engineer REST APIs via capturing traffic Topics reverse-engineering swagger openapi mitmproxy Resources Readme Stars 938 stars Watchers 5 watching Forks 31 forks Releases No releases published Packages 0 No packages published Contributors 2 * * Languages * HTML 98.9% * Python 1.1% * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.