官网地址:anyproxy.io(不知道为什么已经被和谐,需要翻墙)
主要步骤
- 安装nodejs
- 通过node的npm安装anyproxy
- 配置证书-手机端
- 配置证书-anyproxy启动的电脑端
- 客户端设置代理(anyproxy启动的ip和默认端口口8001)
- 启动anyproxy方式 (配置证书后,启动需要使用 -i 命令启动,才会抓取https的请求)
安装node
- node官网 https://nodejs.org/en/download/
- 下载对应类型的安装文件,执行安装完成
- 查看node是否安装成功,并查看版本号
node -v
<p> </p> </li>
安装anyproxy
- 必须使用 install -g命令来安装,-g 代表global全局安装 , 无-g的时候代码本地安装,无法直接使用anyproxy命令
npm install -g anyproxy
<p> </p> </li> <li>安装成功,校验安装是否成功,并查看版本号 <pre class="has" name="code"><code class="hljs sql">anyproxy <span class="hljs-comment">--version</span></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> <p> </p> </li>
手机安装证书凭证
- 启动anyproxy
-
$ anyproxy -i
-
-
[AnyProxy Log][ 2018 -10 -15 10: 47: 35]: Http proxy started on port 8001
-
[AnyProxy Log][ 2018 -10 -15 10: 47: 35]: web interface started on port 8002
-
- 打开浏览器http://localhost:8002/
- 点击RootCA, 手机扫描二维码,下载,并信任证书
如果手机扫描不成功,可以在手机浏览器上是 使用 如下链接获取
http://Anyproxy启动IP:8002/fetchCrtFile
- Android手机有多种信任方式。。自己研究下
最终如下图
电脑上安装证书凭证
- 直接打开浏览器http://localhost:8002/
- 点击RootCA, 下载,点击证书
启动anyproxy
- 普通启动
anyproxy
<p> </p> </li> <li>拦截https请求的启动方式 <pre class="has" name="code"><code class="hljs">anyproxy -i</code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> <p> </p> </li> <li>使用自定义拦截规则的启动方式<br> anyproxy -i --rule rule.js <pre class="has" name="code"><code class="hljs vbscript"><ol class="hljs-ln"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">$ anyproxy -i --rule modify_request_data.js</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">[AnyProxy <span class="hljs-built_in">Log</span>][<span class="hljs-number">2018</span><span class="hljs-number">-10</span><span class="hljs-number">-15</span> <span class="hljs-number">10</span>:<span class="hljs-number">47</span>:<span class="hljs-number">35</span>]: Http proxy started <span class="hljs-keyword">on</span> port <span class="hljs-number">8001</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">[AnyProxy <span class="hljs-built_in">Log</span>][<span class="hljs-number">2018</span><span class="hljs-number">-10</span><span class="hljs-number">-15</span> <span class="hljs-number">10</span>:<span class="hljs-number">47</span>:<span class="hljs-number">35</span>]: web interface started <span class="hljs-keyword">on</span> port <span class="hljs-number">8002</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">[AnyProxy <span class="hljs-built_in">Log</span>][<span class="hljs-number">2018</span><span class="hljs-number">-10</span><span class="hljs-number">-15</span> <span class="hljs-number">10</span>:<span class="hljs-number">47</span>:<span class="hljs-number">35</span>]: Active rule <span class="hljs-keyword">is</span>: Rule <span class="hljs-keyword">to</span> modify <span class="hljs-built_in">request</span> data</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> <p> </p> </li>
问题&解决方案
1.已安装过nodejs ,版本升级或者降级
- 查看当前nodejs版本号以及npm版本号
node -v
npm --version
- 安装n命令,通过nodejs 的包管理器npm安装n命令,n命令是nodejs的版本管理器
npm install -g n
linux和mac非root用户需要用sudo npm install -g n
- 使用n来安装最新版本的nodejs
n stable
linux和mac非root用户需要用sudo n stable
- 安装制定版本的nodejs
n 8.12.0
linux和mac非root用户需要用sudo n 8.12.0
2.AnyProxy已安装,版本升级
- 查看anyproxy版本号
anyproxy --version
npm ls anyproxy
- 通过nodejs的包管理器npm卸载原版本
npm uninstall anyproxy
mac或者linux上非root用户需要sudo npm uninstall anyproxy
- 通过npm再重新安装
npm install -g anyproxy
mac或者linux上非root用户需要sudo npm install -g anyproxy
3.启动一会就报错 ECONNRESET
-
[AnyProxy
ERROR][
2018
-10
-07
14:
40:
29]: got an uncaught exception,
is there anything goes wrong
in your rule file ?
-
Error: read ECONNRESET
-
at TCP.onStreamRead (internal/stream_base_commons.js:
111:
27)
原因:nodejs版本问题,最新版本引入的bug。【anyproxy 版本4.0.12 , node版本10.10.0】
解决方案:nodejs 版本降低,指定版本8.12.0【当前稳定版本】,问题解决
AnyProxy 是一个基于 Node.js 的代理服务器。代理服务器是个中间人,站在了客户端和服务端中间,双方通信的每个比特,都会滴水不漏地经过它。它控制了完整的请求头、请求体、响应头、响应体,可以在客 户端与服务端都无感知的情况下介入处理所有的流程。只要代理服务器可以实现灵活配置,前端工程师们的奇葩需求就有出头之日了。
特性:
支持 https 明文代理
支持低网速模拟
支持二次开发,可以用 javascript 控制代理的全部流程,搭建前端个性化调试环境
提供web版界面,观测请求情况
示例代码:
var proxy = require("anyproxy");
//create cert when you want to use https features
//please manually trust this rootCA when it is the first time you run it!
proxy.isRootCAFileExists() && proxy.generateRootCA();var options = {
type : "http",
port : 8001,
hostname : "localhost",
rule : require("path/to/my/ruleModule.js"),
dbFile : null, // optional, save request data to a specified file, will use in-memory db if not specified
webPort : 8002, // optional, port for web interface
socketPort : 8003, // optional, internal port for web socket, replace this when it is conflict with your own service
webConfigPort : 8088, // optional, internal port for web config(beta), replace this when it is conflict with your own service
throttle : 10, // optional, speed limit in kb/s
disableWebInterface : false, //optional, set it when you don't want to use the web interface
silent : false //optional, do not print anything into terminal. do not set it when you are still debugging.
};new proxy.proxyServer(options);