node-mitmproxy-pro 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 wuchangming
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# node-mitmproxy-pro
|
|
2
|
+
|
|
3
|
+
**注意**: 此项目由node-mitmproxy修改而来
|
|
4
|
+
原项目地址:https://github.com/wuchangming/node-mitmproxy
|
|
5
|
+
官网:https://www.npmjs.com/package/node-mitmproxy
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/node-mitmproxy-pro)
|
|
8
|
+
node-mitmproxy-pro是一个基于nodejs,支持http/https的中间人(MITM)代理,便于渗透测试和开发调试。
|
|
9
|
+
|
|
10
|
+
## 1、特性
|
|
11
|
+
1、支持https
|
|
12
|
+
2、支持配置的方式启动,也支持以模块的方式引入到代码中
|
|
13
|
+
|
|
14
|
+
## 2、安装
|
|
15
|
+
|
|
16
|
+
###### windows
|
|
17
|
+
```
|
|
18
|
+
npm install node-mitmproxy-pro -g
|
|
19
|
+
```
|
|
20
|
+
###### Mac
|
|
21
|
+
```
|
|
22
|
+
sudo npm install node-mitmproxy-pro -g
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 3、使用
|
|
26
|
+
|
|
27
|
+
#### 关于配置文件
|
|
28
|
+
|
|
29
|
+
###### 简单配置:
|
|
30
|
+
|
|
31
|
+
simpleConfig.js
|
|
32
|
+
```
|
|
33
|
+
module.exports = {
|
|
34
|
+
sslConnectInterceptor: (req, cltSocket, head) => true,
|
|
35
|
+
requestInterceptor: (requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {
|
|
36
|
+
console.log(`正在访问:${requestOptions.protocol}//${requestOptions.hostname}:${requestOptions.port}`);
|
|
37
|
+
console.log('cookie:', requestOptions.headers.cookie);
|
|
38
|
+
res.end('hello node-mitmproxy-pro!');
|
|
39
|
+
pipe();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
效果图:
|
|
45
|
+
<img width=500 src="./doc/img/hello_node-mitmproxy.jpg" />
|
|
46
|
+
|
|
47
|
+
[详细配置说明](https://github.com/CyrilGuoCODE/node-mitmproxy-pro#4配置详细说明)
|
|
48
|
+
[更多例子](./example/config/)
|
|
49
|
+
#### 启动方式
|
|
50
|
+
```
|
|
51
|
+
node-mitmproxy-pro -c simpleConfig.js
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 安装node-mitmproxy-pro CA根证书
|
|
55
|
+
生成CA根证书的默认路径:`%用户名%/node-mitmproxy-pro`
|
|
56
|
+
|
|
57
|
+
#### PC下安装根证书方式
|
|
58
|
+
###### Mac
|
|
59
|
+
```
|
|
60
|
+
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/node-mitmproxy-pro/node-mitmproxy-pro.ca.crt
|
|
61
|
+
```
|
|
62
|
+
###### windows
|
|
63
|
+
注: 证书需要安装到 ** 受信任的根证书目录 ** 下
|
|
64
|
+
参考 [issues#3](https://github.com/CyrilGuoCODE/node-mitmproxy-pro/issues/3)
|
|
65
|
+
```
|
|
66
|
+
start %HOMEPATH%/node-mitmproxy-pro/node-mitmproxy-pro.ca.crt
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 以nodejs模块的方式引用到代码中
|
|
70
|
+
```
|
|
71
|
+
var mitmproxy = require('node-mitmproxy-pro');
|
|
72
|
+
|
|
73
|
+
mitmproxy.createProxy({
|
|
74
|
+
sslConnectInterceptor: (req, cltSocket, head) => true,
|
|
75
|
+
requestInterceptor: (requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {
|
|
76
|
+
console.log(`正在访问:${requestOptions.protocol}//${requestOptions.hostname}:${requestOptions.port}`);
|
|
77
|
+
console.log('cookie:', requestOptions.headers.cookie);
|
|
78
|
+
res.end('Hello node-mitmproxy-pro!');
|
|
79
|
+
pipe();
|
|
80
|
+
},
|
|
81
|
+
responseInterceptor: (requestId, res, proxyRes, ssl, pipe) => {
|
|
82
|
+
pipe();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
## 4、配置详细说明
|
|
89
|
+
|
|
90
|
+
#### port
|
|
91
|
+
启动端口(默认:6789)
|
|
92
|
+
```
|
|
93
|
+
port: 6789
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### sslConnectInterceptor
|
|
97
|
+
判断该connnect请求是否需要代理,传入参数参考[http connnect](https://nodejs.org/api/http.html#http_event_connect) 。
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
(req, cltSocket, head) => {}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**参数说明:**
|
|
104
|
+
- `req`: 客户端请求对象
|
|
105
|
+
- `cltSocket`: 客户端socket连接
|
|
106
|
+
- `head`: 客户端请求头
|
|
107
|
+
|
|
108
|
+
该函数返回一个布尔值,用于判断该connect请求是否需要代理。
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
#### requestInterceptor
|
|
113
|
+
请求拦截器,用于拦截和处理HTTP/HTTPS请求。
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
(requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**参数说明:**
|
|
120
|
+
|
|
121
|
+
| 参数 | 类型 | 说明 |
|
|
122
|
+
|------|------|------|
|
|
123
|
+
| `requestId` | String | 请求唯一标识符,与对应响应的ID保持一致 |
|
|
124
|
+
| `requestOptions` | Object | 请求参数对象(可选,参数信息已包含在req.headers中) |
|
|
125
|
+
| `req` | Object | 原始请求对象 |
|
|
126
|
+
| `res` | Object | 响应对象,可用于提前结束流程并返回自定义响应体,无需经过实际网络请求 |
|
|
127
|
+
| `proxyReq` | Object | 代理请求对象,支持修改请求头和请求体 |
|
|
128
|
+
| `ssl` | Boolean | 标识是否为HTTPS请求 |
|
|
129
|
+
| `pipe` | Function | 管道函数,将请求对象写入代理请求对象。仅在无需修改请求时调用;如需自定义处理,可监听ondata事件自行实现 |
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
#### responseInterceptor
|
|
134
|
+
响应拦截器,用于拦截和处理HTTP/HTTPS响应。
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
(requestId, res, proxyRes, ssl, pipe) => {}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**参数说明:**
|
|
141
|
+
|
|
142
|
+
| 参数 | 类型 | 说明 |
|
|
143
|
+
|------|------|------|
|
|
144
|
+
| `requestId` | String | 请求唯一标识符,与对应请求的ID保持一致 |
|
|
145
|
+
| `res` | Object | 响应对象,支持修改响应头和响应体 |
|
|
146
|
+
| `proxyRes` | Object | 代理响应对象 |
|
|
147
|
+
| `ssl` | Boolean | 标识是否为HTTPS请求 |
|
|
148
|
+
| `pipe` | Function | 管道函数,将代理响应对象写入响应对象。仅在无需修改响应时调用;如需自定义处理,可监听ondata事件自行实现 |
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
#### caCertPath
|
|
153
|
+
CA根证书路径(ps: 无特殊情况无需配置)
|
|
154
|
+
默认:%HOMEPATH%/node-mitmproxy-pro/node-mitmproxy-pro.ca.crt
|
|
155
|
+
```
|
|
156
|
+
caCertPath: 'xxxx/xxxx.crt'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### caKeyPath
|
|
160
|
+
CA根证书密钥路径(ps: 无特殊情况无需配置)
|
|
161
|
+
默认:%HOMEPATH%/node-mitmproxy-pro/node-mitmproxy-pro.ca.key.pem
|
|
162
|
+
```
|
|
163
|
+
caKeyPath: 'xxxx/xxxx.pem'
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 5、更多
|
|
167
|
+
#### 关于伪造https证书的逻辑图
|
|
168
|
+
<img src="doc/img/node-MitmProxy https.png" width=650/>
|
|
169
|
+
|
|
170
|
+
## 6、API使用示例
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
const mitmproxy = require('node-mitmproxy-pro');
|
|
174
|
+
|
|
175
|
+
mitmproxy.createProxy({
|
|
176
|
+
sslConnectInterceptor: (req, cltSocket, head) => {
|
|
177
|
+
// 处理SSL连接
|
|
178
|
+
return true;
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
requestInterceptor: (requestId, requestOptions, req, res, proxyReq, ssl, pipe) => {
|
|
182
|
+
// 修改请求头
|
|
183
|
+
proxyReq.setHeader('X-Custom-Header', 'CustomValue');
|
|
184
|
+
|
|
185
|
+
// 不修改请求时,调用pipe
|
|
186
|
+
pipe();
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
responseInterceptor: (requestId, res, proxyRes, ssl, pipe) => {
|
|
190
|
+
// 修改响应头
|
|
191
|
+
res.setHeader('X-Response-Header', 'ResponseValue');
|
|
192
|
+
|
|
193
|
+
// 不修改响应时,调用pipe
|
|
194
|
+
pipe();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-mitmproxy-pro",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node.js MITM Proxy Pro",
|
|
5
|
+
"main": "lib",
|
|
6
|
+
"bin": "lib/bin/index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node ./test/ConfigTestCases.test.js",
|
|
9
|
+
"build": "babel -w src -d lib",
|
|
10
|
+
"prepublish": "babel src -d lib"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/CyrilGuoCODE/node-mitmproxy-pro.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"MITM",
|
|
18
|
+
"proxy",
|
|
19
|
+
"Node"
|
|
20
|
+
],
|
|
21
|
+
"author": "cyp,cyrilguo",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/CyrilGuoCODE/node-mitmproxy-pro/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/CyrilGuoCODE/node-mitmproxy-pro#readme",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"babel-cli": "^6.6.5"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"agentkeepalive": "^2.1.1",
|
|
32
|
+
"babel-core": "^6.8.0",
|
|
33
|
+
"babel-plugin-transform-async-to-generator": "^6.7.4",
|
|
34
|
+
"babel-polyfill": "^6.8.0",
|
|
35
|
+
"babel-preset-es2015": "^6.6.0",
|
|
36
|
+
"babel-register": "^6.8.0",
|
|
37
|
+
"charset": "^1.0.0",
|
|
38
|
+
"colors": "^1.1.2",
|
|
39
|
+
"commander": "^2.9.0",
|
|
40
|
+
"iconv-lite": "^0.4.13",
|
|
41
|
+
"jschardet": "^1.4.1",
|
|
42
|
+
"lodash": "^4.7.0",
|
|
43
|
+
"mkdirp": "^0.5.1",
|
|
44
|
+
"node-forge": "^0.6.39",
|
|
45
|
+
"through2": "^2.0.1",
|
|
46
|
+
"tunnel-agent": "^0.4.3"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"lib"
|
|
50
|
+
],
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">= 4"
|
|
53
|
+
}
|
|
54
|
+
}
|