GithubHelp home page GithubHelp logo

mproxy's Introduction

mproxy 使用说明

这是一个微型的http代理服务器实现,使用c语言实现,核心代码量不足500行,不依赖任何第三方的库(只能工作在unixlike系统下面). 其主要功能如下:

  • http代理
  • 支持https隧道
  • 支持简单加密隧道

注:本代码实现简陋,完成仓促,目前还停留在一个原型的阶段,经测试访问facebook,twitter,youtube ,google是OK的,但不保证所有的网站兼容性的问题,希望能够起到一个抛砖引玉的作用。欢迎提交pull request 继续完善. :)

通常情况下存在两种工作模式,普通代理模式和加密隧道模式.

普通代理

这种工作模式和普通的http代理一样,mproxy目前只做简单的http转发,不做任何页面的缓存。

加密隧道(翻墙专用)

这种工作模式需要以client,server的模式进行配合使用,即mproxy分别作为客户端和服务端,并在客户端及服务端形成一个简单的加密隧道,从而躲过GFW的侦测。具体的工作模式如下图所示:

   
   +----------+        +-----------+       +----------+      +----------+
   |          |        |           |       |          |      |          |
   |          |        |           |       |          |      |          |
   |  APP     +------->| mproxy    |+------> mproxy   +------> Web      |
   |          |        |           |       |          |      |          |
   |          |        | client    |       | server   |      |          |
   +----------+        +-----------+       +----------+      +----------+

编译

mproxy可以运行在unix-like 的操作系统下面,程序很小没有第三方的依赖,所以编译很简单,下面的一行命令搞定!

gcc -o mproxy mproxy.c

使用方法

作为普通的代理服务器。

./mproxy -l 8000 -d

这种工作方式对我们来讲意义不大,只做功能展示,重点在下面。

注: "-d" 参数表示程序作为deamon服务,避免终端退出程序结束

作为加密隧道的部署方式(翻墙专用)

有翻墙需求的同学需要使用mproxy分别作为本地代理和远程代理,并且指定两个代理之间传输数据的方式为加密方式。 注:翻墙的话远程代理服务器需要部署在不受GFW管制的国外(找个便宜的VPS即可).

step1 : 在远程服务器启动mproxy作为远程代理

你需要把mproxy源码在远程的服务器编译(直接拷贝二进制应该也可以)然后运行下面的命令。

./mproxy  -l 8081 -D -d

-D 指定接受数据进行解密,其对应参数'-E'应用在本地代理 -d 指定启动作为后台服务,避免终端退出程序结束

step2 : 本地启动 mproxy 作为本地代理,并指定传输方式加密。

在本地启动一个mporxy 并指定目上一步在远程部署的服务器地址和端口号。

./mproxy  -l 8080 -h xxx.xxx.xxx.xxx:8081 -E

-l 指定本地监听端口 -h 指定远端下一跳步的服务器地址及端口号,如果翻墙需要是一台国外的服务器 -E 发送数据的时候进行加密,其对应参数'-D' 应用在远程代理

step3 : 配置浏览器http代理使用mporxy本地代理

设置你的浏览器http代理指向你的本地代理,使用chrome浏览器的同学强烈推荐使用 switchSharp,安装完毕swichSharp以后只需要为switchSharp增加一个情景模式就好,如下图:

设置switchSharp

保存设置以后如果想翻墙的话就切换到你刚才配置的情景模式吧。

使用mproxy

注: mproxy暂不支持windows用户,但是可以和已经部署好的机器共享,只需要在switchSharp中把代理服务器的地址从“localhost"改成已经部署好mproxy的ip即可。

mproxy's People

Contributors

examplecode avatar ma-zz-xth-zz-on avatar readmecritic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mproxy's Issues

rfc要求代理从absolute uri中提取host,而不是从host 头部字段中提取

因为历史兼容性的原因,根据http1.0/1.1规范,代理必须从absolute uri中提取host,而不是从host head field中提取。

https://tools.ietf.org/html/rfc2616#section-5.1.2
The absoluteURI form is REQUIRED when the request is being made to a proxy.
...
Note that the proxy MAY forward the request on to another proxy or directly to the server specified by the absoluteURI.

section-5.2

1. If Request-URI is an absoluteURI, the host is part of the
Request-URI. Any Host header field value in the request MUST be
ignored.

最近GFW更新算法,mproxy是不是不能用了?

最近GFW更新算法,mproxy是不是不能用了?? 今天早上到公司,突然就不能用了,
下面 agent端的错误,server端没有日志输出。。。:
Sep 13 2017 15:12:55 Cannot connect to host [clients1.google.com:443]
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:www.google.com port: 443 io_flag:2
Sep 13 2017 15:12:55 ======= forward request to remote host:www.google.com port:443 =======
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:s2.googleusercontent.com port: 443 io_flag:2
Sep 13 2017 15:12:55 ======= forward request to remote host:s2.googleusercontent.com port:443 =======
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:s2.googleusercontent.com port: 443 io_flag:2
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:s2.googleusercontent.com port: 443 io_flag:2
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:s2.googleusercontent.com port: 443 io_flag:2
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:s2.googleusercontent.com port: 443 io_flag:2
Sep 13 2017 15:12:55 ======= forward request to remote host:s2.googleusercontent.com port:443 =======
Sep 13 2017 15:12:55 ======= forward request to remote host:s2.googleusercontent.com port:443 =======
Sep 13 2017 15:12:55 ======= forward request to remote host:s2.googleusercontent.com port:443 =======
Sep 13 2017 15:12:55 ======= forward request to remote host:s2.googleusercontent.com port:443 =======
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:www.google.com port: 443 io_flag:2
Sep 13 2017 15:12:55 ======= forward request to remote host:www.google.com port:443 =======
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:clients1.google.com port: 443 io_flag:2
Sep 13 2017 15:12:55 ======= forward request to remote host:clients1.google.com port:443 =======
Sep 13 2017 15:12:55 receive CONNECT request
Sep 13 2017 15:12:55 Host:clients1.google.com port: 443 io_flag:2
Sep 13 2017 15:12:55 ======= forward request to remote host:clients1.google.com port:443 =======
Sep 13 2017 15:12:55 Cannot connect to host [clients1.google.com:443]
Sep 13 2017 15:12:55 Cannot connect to host [clients1.google.com:443]
Sep 13 2017 15:12:55 Read Http header failed

padavan路由器运行mproxy

路由器 ./mproxy -l 8000 -d 模式运行
手机端直接填入代理IP和端口,路由器可以收到信息,但是一直报错
`Jun 21 2016 16:18:38 ============ handle new client ============
Jun 21 2016 16:18:38 >>>Header:CONNECT acs.m.taobao.com:443 HTTP/1.1
Host: acs.m.taobao.com:443
Proxy-Connection: Keep-Alive
User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; MI 8 MIUI/V12.0.3.0.QEACNXM)

Jun 21 2016 16:18:38 receive CONNECT request
Jun 21 2016 16:18:38 Host:acs.m.taobao.com port: 443 io_flag:0
Jun 21 2016 16:18:38 ====== Bad remote request,close it! ====
`
不知道是哪里出问题了

接收和发送字节不匹配的问题

最近研究了一下代码,发现如果把send 和recv 得到的buffer 长度和字母打印出来,得到的长度是一样的,但实际buffer里的数据长度却不一样。实际收到的字节比发出的字节要多一些。很奇怪啊,为什么会这样?加密不是每个字节一一对应的吗?这样解密是才能得到正确的数据。但是又能正常工作。好奇怪的现象。

recv len = 502
buffer recv = GET http://www.google.com/ HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0 (Android 7.1.1; Mobile; rv:53.0) Gecko/53.0 Firefox/53.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Cookie: NID=104=m5-no8IetRfnkhU2ccoy3wv-3pnG1ZdBMETkAchadvIN0NLskY4lsZzGdVMTDK7LpSdXzXA1Z3I_5LBEcL-rsrbcr3E8opwieGQp19hdRFg0qR13CwocB1dP5aIc8W_3
Connection: keep-alive
Upgrade-Insecure-Requests: 1

send len = 502
buffer send = ���r:&&"h}}%%%|5==5>7|1=?}r����}c|c_X�=!&hr%%%|5==5>7|1=?_X!7 �57<&hr�=(;>>3}g|brz�<6 =;6re|c|cir�=0;>7ir $hga|b{r�719=}ga|br�; 74=}ga|b_X�117"&hr&7&}:&?>3"">;13&;=<}:&?>y?>3"">;13&;=<}*?>i#ob|kx}xi#ob|j_X�117"&�3<5'357hr(:��(:i#ob|j7<�i#ob|g7<i#ob|a_X�117"&�<1=6;<5hr5(;"~r674>3&7_X�==9;7hr���ocbfo?g<=j&

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.