{"id":21740999,"url":"https://github.com/produck/mitm","last_synced_at":"2025-04-13T03:41:51.004Z","repository":{"id":40505548,"uuid":"165081388","full_name":"produck/mitm","owner":"produck","description":"HTTP/HTTPS man in the middle proxy server","archived":false,"fork":false,"pushed_at":"2024-01-09T04:05:56.000Z","size":652,"stargazers_count":5,"open_issues_count":11,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T20:51:28.871Z","etag":null,"topics":["http","mitm","server","ssl","websocket"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/produck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-01-10T15:14:03.000Z","updated_at":"2024-04-18T04:40:53.000Z","dependencies_parsed_at":"2022-08-09T22:21:56.794Z","dependency_job_id":"b6938297-24ce-4351-a0ec-2a461cb43b68","html_url":"https://github.com/produck/mitm","commit_stats":null,"previous_names":["lemonce3/mitm"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fmitm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fmitm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fmitm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/produck%2Fmitm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/produck","download_url":"https://codeload.github.com/produck/mitm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248660945,"owners_count":21141372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","mitm","server","ssl","websocket"],"created_at":"2024-11-26T06:16:13.267Z","updated_at":"2025-04-13T03:41:50.983Z","avatar_url":"https://github.com/produck.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mitm\n\nMitm is a fully configurable proxy base on Node.js, which can handle HTTP, HTTPS, WS or WSS request correctly.\n\n## Feature\n\n* work as HTTP, HTTPS, WS or WSS proxy\n* when working as https or wss proxy, Mitm could intercept https requests for any domain without complaint by browser (If you trusted its root CA)\n\n## Installing\nmitm is available via [npm](https://www.npmjs.com/):\n\n```bash\n$ npm install @lemonce/mitm\n```\n\n## Get Started\n\nCreate a mitm instance by functions. Basic usage with default options. For Example. \n\n```js\nconst mitm = require('@lemonce/mitm');\nconst mitmServer = mitm.createServer();\n```\n\n\n## API Referrence\n\n### Options\n\nInstantiates Mitm Server using the supplied options. This section will discuss each of the options.\n\n| Name | Type | Description |\n| -- | -- | -- |  \n| strategy | Object | Strategy options. |\n| socket | Object | Socket options. |\n| certificate | Object | Root cerificate and its storage method. |\n| onError | Function | Handle the Mitm error.  |\n\n#### parameters for strategy\n\nAccording to your needs, you can set up interception strategy. Using the following parameters.\n\n| Name | Type | Description |\n| -- | -- | -- |\n| sslConnect | Function | SSL supported. The default value is false. |\n| websocket | Function | WebSocket supported. The default value is supported. |\n| request | Function | Request options. The default method is forward. |\n| response | Function | Response options. The default method is respond. |\n\n\n#### parameters for socket\n\n| Name | Type | Description |\n| -- | -- | -- |\n| path | String | Socket path. |\n| getName | Function | Return a socket store path. |\n\n#### parameters for certificate\n\nWhen you need to intercept the HTTPS request, the root certifiacate information and the self-made certificate storage method should be provided. Using the following parameters.\n\n| Name | Type | Description |\n| -- | -- | -- |\n| cert | String | Root certificate's cert. |\n| key | String | Root certificate's RAS private key.  |\n| store | Function | Certificate storage methods.  |\n\n## Using\n\n### Intercepting HTTP requests\n\nWith the following options, the mitm server will intercept HTTP requests, the response page will display 'hello, world' and status message will show 'test'. \n\n```js\nconst mitm = require('@lemonce/mitm');\n\nconst options = {\n\tstrategy: {\n\t\trequest(context, respond, forward) {\n\t\t\tcontext.response.body = 'hello, world';\n\t\t\tcontext.response.headers = {};\n\t\t\tcontext.response.statusCode = 200;\n\t\t\tcontext.response.statusMessage = 'test';\n\t\t\trespond();\n\t\t},\n\t\tresponse(context, respond) {\n\t\t\trespond();\n\t\t}\n\t},\n\tsocket: {\n\t\tpath: path.resolve(__dirname, './socketStore'),\n\t\tgetName(protocol, hostname, port) {\n\t\t\treturn `${protocol}-${hostname}-${port}`;\n\t\t}\n\t},\n\tonError(type, message) {\n\t\tconsole.log('error type', type);\n\t\tconsole.log('error message', message);\n\t}\n}\n\nconst mitmServer = mitm.createServer(options);\nmitmServer.listen(9000);\n\n```\n\n### Intercept HTTPS requests\n\nWith the following options, the mitm server will intercept HTTPS requests.\n\n```js\nconst mitm = require('@lemonce/mitm');\nconst rootCA = {\n\tkey: '',\n\tcert: ''\n}\nconst options = {\n\tsslConnect() {\n\t\treturn true;\n\t},\n\tstrategy: {\n\t\trequest(context, respond, forward) {\n\t\t\tcontext.response.body = 'hello, world';\n\t\t\tcontext.response.headers = {};\n\t\t\tcontext.response.statusCode = 200;\n\t\t\tcontext.response.statusMessage = 'test';\n\t\t\trespond();\n\t\t},\n\t\tresponse(context, respond) {\n\t\t\trespond();\n\t\t}\n\t},\n\tsocket: {\n\t\tpath: path.resolve(__dirname, './socketStore'),\n\t\tgetName(protocol, hostname, port) {\n\t\t\treturn `${protocol}-${hostname}-${port}`;\n\t\t}\n\t},\n\tcerticate: {\n\t\tcert: rootCA.cert,\n\t\tkey: rootCA.key,\n\t\tstore: {\n\t\t\tget(hostname) {\n\t\t\t\treturn certificateStore[hostname];\n\t\t\t},\n\t\t\tset(hostname, certKeyPair) {\n\t\t\t\treturn certicateStore[hostname] = certKeyPair;\n\t\t\t}\n\t\t}\n\t},\n\tonError(type, message) {\n\t\tconsole.log('error type', type);\n\t\tconsole.log('error message', message);\n\t}\n}\n\nconst mitmServer = mitm.createServer(options);\nmitmServer.listen(9000);\n```\n\n\n### Intercept WS/WSS requests\n\n```js\nconst mitm = require('@lemonce/mitm');\nconst certicateStore = {};\nconst rootCA = {\n\tkey: '',\n\tcert: ''\n}\n\nconst options = {\n\tstrategy: {\n\t\tsslConnect() {\n\t\t\treturn true;\n\t\t},\n\t\twebsocket(clientSocket, proxySocket) {\n\t\t\tclientSocket.pipe(proxySocket);\n\t\t\tproxySocket.pipe(clientSocket);\n\t\t},\n\t\trequest(context, respond, forward) {\n\t\t\tcontext.response.body = 'hello, world';\n\t\t\tcontext.response.headers = {};\n\t\t\tcontext.response.statusCode = 200;\n\t\t\tcontext.response.statusMessage = 'test';\n\t\t\trespond();\n\t\t},\n\t\tresponse(context, respond) {\n\t\t\trespond();\n\t\t}\n\t},\n\tsocket: {\n\t\tpath: path.resolve(__dirname, './socketStore'),\n\t\tgetName(protocol, hostname, port) {\n\t\t\treturn `${protocol}-${hostname}-${port}`;\n\t\t}\n\t},\n\tcerticate: {\n\t\tcert: rootCA.cert,\n\t\tkey: rootCA.key,\n\t\tstore: {\n\t\t\tget(hostname) {\n\t\t\t\treturn certificateStore[hostname];\n\t\t\t},\n\t\t\tset(hostname, certKeyPair) {\n\t\t\t\treturn certicateStore[hostname] = certKeyPair;\n\t\t\t}\n\t\t}\n\t},\n\tonError(type, message) {\n\t\tconsole.log('error type', type);\n\t\tconsole.log('error message', message);\n\t}\n}\nconst mitmServer = mitm.createServer(options);\nmitmServer.listen(9000);\n\n```\n\n## About\n\nThanks to [node-mitmproxy](https://www.npmjs.com/package/node-mitmproxy) for the inspiration for this project. Due to the node-mitmproxy was stopped, we developed the Mitm base on it for our requirement.\n\n## License\nMIT License\n\nCopyright (c) 2019 lc3\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproduck%2Fmitm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproduck%2Fmitm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproduck%2Fmitm/lists"}