Giter Club home page Giter Club logo

pproxy's Introduction

pproxy 0.5.2

intro

http抓包代理程序,http协议调试工具。
采用golang编写,采用bs模式(s-代理程序,b-会话查看、配置管理等功能)

0.4.2版本已经支持websocket代理,以及重定向(和普通http请求一样使用)

0.5 版本是对底层存储进行了替换,并且尝试支持https抓包

install

下载编译好的可执行文件: http://pan.baidu.com/s/1i3pAe7V

已经安装golang的用户直接安装:

go get -u github.com/hidu/pproxy

功能特性

1.url重定向
   如把 http://www.baidu.com/s?wd=pproxy 修改为 http://m.baidu.com/s?wd=pproxy
   或者把 ws://www.test.com/a 重定向到 ws://www.example.com/b
   
2.form表单动态修改  
   get、post可以动态修改(增删改)  
   
3.hosts文件支持
  相当于 修改host或者dns 如  
  将www.baidu.com 请求全部发往127.0.0.1  
  将www.baidu.com:81 请求全部发往192.168.1.2:8080  
  
4.可查看request 和response详情
   form表单参数,header等都可以很方便的看到
   
5.登录认证支持
   支持httpBasic认证
   
6.replay功能
   可以修改request的参数(get、post、header)

7.父级代理
  

配置

rewrite req

使用javascript来配置重定向功能,如

if(req.host=="www.baidu.com"){
   req.host="www.163.com"
   req.host_addr="127.0.0.0:81" // send req to 127.0.0.1:81
}

当然也可以这样:

if(req.host.indexOf("baidu.com")>-1){
  req.host_addr="127.0.0.0:81"
}

req变量示例

#url : http://www.example.com/album/list?cid=126
#req对象有如下一下属性:
schema : http
host : www.example.com
port : 80
path : /album/list
get: {cid:[123]}
post: {}
username : 
password : 
method: GET
form_get  : {add:function(k,v){},set:function(k,v){},get:function(k){},len:function(){}} 
form_post : {add:function(k,v){},set:function(k,v){},get:function(k){},len:function(){}}

host_addr: #修改该请求的host是使用,如 127.0.0.1:3218

#注意 get 和post的值是数组,如上cid参数
#form_get 用于更方便的操作  get参数对象
#form_post 用于更方便的操作 post参数对象

hosts

增强的hosts文件使用:

www.baidu.com 127.0.0.1
www.baidu.com:81 10.0.2.2:8080

other

忽略禁用req_rewrite.js
在js文件的第一行内容写入 //ignore

req_rewrite.js支持不同用户设置不同的规则。默认使用当前验证使用用户名的规则,若无则使用默认的。

配置文件结构:

conf/
├── pproxy.conf          #server的配置
├── hosts_8080           #8080端口server的hosts规则
├── req_rewrite_8080.js  #8080端口server的url重写规则
├── hosts_8081
├── req_rewrite_8081.js
└── users                #全局帐号配置文件

users配置:

#帐号 admin,密码 是 psw,是管理员帐号
name:admin psw:psw is_admin:admin

#密码也可以存储为md5值,使用  psw_md5:32位md密码
name:admin_sec psw_md5:7bb483729b5a8e26f73e1831cde5b842 is_admin:admin

可以在线修改配置时必须使用管理员帐号登录

配置文件示例(pproxy.conf):

#提供代理服务的端口
port : 8080

#管理界面的端口,为0表示和代理服务使用相同的端口,eg:8081
adminPort : 0

title : demo
notice :notice notice

#数据存放目录,相对于当前配置的路径
dataDir : ../data/

#数据存放天数,0为永久存储(目前只在重启的时候会进行数据清理)
dataStoreDay : 15

#代理服务认证方式
#options:{none : 无认证,basic:http basic ,basic_try:尝试httpBasic认证 ,basic_any:任意帐号}
authType : none

#那些request和response数据进行存储
#options:{ all : 所有   only_broadcast : 发送到session list的才存储}
responseSave : only_broadcast

#session列表查看数据
# options :{ all:所有人可见 ip_or_user : 输入正确的ip或者user后可见}
sessionView : all

#父级代理
#eg http://10.10.2.2:3128 or http://name:[email protected]:3128
# http://pass:[email protected]:3128 the user and psw will pass through to the parent proxy
parentProxy:


#是否使用中间人方式对https进行抓包,若启用的话 需要客户端按照证书-/res/private/client_cert.pem
#pproxy内置默认证书存放在/res/private目录中
#options:{on:启用  off:禁用}
ssl : on

#ssl 服务端秘钥文件地址,为空则使用默认内置的 /res/private/server_key.pem
ssl_server_key: 
#ssl 公钥地址 ,为空则使用默认内置的 /res/private/client_cert.pem
ssl_client_cert :

(管理)web查看界面

方式1: 直接访问 http://serverHost:port
方式2: 直接访问 http://serverHost:adminPort
方式3: 浏览器设置http代理 serverHost:port,访问 http://pproxy.man 或者 http://pproxy.com

其他

如何自己修改源码中的静态资源?

该项目的静态资源(res目录中的所有内容)都编译到go文件中去了,可以处理即可:

  1. 安装goassest工具:
go get -u github.com/hidu/goassest

2.到pproxy代码根目录下运行命令:

goassest

调试过程中可以添加参数 -assest_direct 可以让静态资源实时生效而不需要重新编译静态资源:

go run proxy_main.go -assest_direct

pproxy's People

Contributors

bryant1410 avatar hidu 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

pproxy's Issues

内网机器无法对外使用

典型的如腾讯云、UCloud等
他们的网络结构通常是 一个内网IP + 一个类似路由器NAT的弹性IP

代理服务可以正常使用
但web界面打不开,报

dial tcp: lookup XXXX: too many open files

使用有公网IP的服务就正常了,例如linode、vr等

运行比较长时间后出现 too many open files 错误

出错信息如下:
2014/11/04 03:18:35 server.go:1745: http: Accept error: accept tcp [::]:8080: too many open files; retrying in 1s
2014/11/04 03:18:36 server.go:1745: http: Accept error: accept tcp [::]:8080: too many open files; retrying in 1s
2014/11/04 03:18:37 server.go:1745: http: Accept error: accept tcp [::]:8080: too many open files; retrying in 1s
2014/11/04 03:18:38 server.go:1745: http: Accept error: accept tcp [::]:8080: too many open files; retrying in 1s
2014/11/04 03:18:39 server.go:1745: http: Accept error: accept tcp [::]:8080: too many open files; retrying in 1s
运行环境:CentOS Linux 2.6.32-431.23.3.el6.x86_64 #
版本号:pproxy_0.4.4,使用编译好的二进制版本

这个要怎么破?

Ubuntu 20.04 no tcp4 ?

sysctl -p
kernel.sysrq = 1
kernel.printk = 5
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Ubuntu 20.04 LTS \n \l

lsof -i :5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
pproxy 7796 root 3u IPv6 65209 0t0 TCP *:5000 (LISTEN)

想加一些自定义的抓取。

想加一些自定义的抓取。重新定义了一些http 模式的请求规则 , 有一些简单的头信息,个特殊的body结构。 发现这个工具捕获不到。 不知道追加自己的http解析功能从哪里下手

请详细说明req_rewrite的使用方法

我在req_rewrite_8080.js加入了以下内容

if(req.host.indexOf(".mp3")>-1){
req.host_addr="127.0.0.0"
}

想就此方法屏蔽所有带.mp3的连接,但不起作用。
请详细说明req_rewrite的使用方法,谢谢!
盼复!

源码运行出错

试着把代码git clone下来,运行一下,报如下错误:

D:\Gworks\src\github.com\hidu\pproxy>go run proxy_main.go
panic: Error parsing builtin CA x509: RSA key missing NULL parameters

goroutine 1 [running]:
github.com/hidu/pproxy/vendor/github.com/hidu/goproxy.init.1()
        D:/Gworks/src/github.com/hidu/pproxy/vendor/github.com/hidu/goproxy/certs.go:10 +0x1ea
github.com/hidu/pproxy/vendor/github.com/hidu/goproxy.init()
        D:/Gworks/src/github.com/hidu/pproxy/vendor/github.com/hidu/goproxy/signer.go:88 +0x2f2
github.com/hidu/pproxy/serve.init()
        D:/Gworks/src/github.com/hidu/pproxy/serve/wsServer.go:179 +0xd7
main.init()
        D:/Gworks/src/github.com/hidu/pproxy/proxy_main.go:52 +0x66
exit status 2

按照说明,pproxy.conf里密钥留空会自动使用默认内置的 /res/private/server_key.pem、client_cert.pem,怎么还是报RSA Key missing呢,盼解答

panic: Here be dragons: cmpl.parseStatement(*ast.FunctionStatement)

Env:
centos 6.5 x86_64 bit

golang 1.6.3

run with default configure files

[root@localhost pproxy]# ./pproxy
panic: Here be dragons: cmpl.parseStatement(*ast.FunctionStatement)

goroutine 1 [running]:
panic(0x9df2a0, 0xc820487e90)
/home/lee/go/src/runtime/panic.go:481 +0x3e6
github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto.(__compiler).parseStatement(0xc820487e70, 0x7f4806b1ef80, 0xc8200241b0, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto/cmpl_parse.go:356 +0x983
github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto.(__compiler)._parse(0xc820487e70, 0xc8204809c0, 0xc820487e70)
/home/lee/gowork/src/github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto/cmpl_parse.go:372 +0x1b3
github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto.(__compiler).parse(0xc820487e70, 0xc820487e70)
/home/lee/gowork/src/github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto/cmpl.go:23 +0x49
github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto.cmpl_parse(0xc8204809c0, 0x91a5c0)
/home/lee/gowork/src/github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto/cmpl_parse.go:363 +0x70
github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto.(__runtime).cmpl_runOrEval(0xc820071340, 0x91a5c0, 0xc82044ef70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto/runtime.go:478 +0xfa
github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto.(__runtime).cmpl_run(0xc820071340, 0x91a5c0, 0xc82044ef70, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto/runtime.go:493 +0x61
github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto.Otto.Run(0x0, 0xc820071340, 0x91a5c0, 0xc82044ef70, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/vendor/github.com/robertkrimen/otto/otto.go:292 +0x5c
github.com/hidu/pproxy/serve.(_requestModifier).parseJs(0xc820135d40, 0xc8201338c0, 0x201, 0xabc020, 0x0, 0x0, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/serve/req_modifer.go:96 +0x31d
github.com/hidu/pproxy/serve.(_requestModifier).tryLoadJs(0xc820135d40, 0xabc020, 0x0, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/serve/req_modifer.go:47 +0xda
github.com/hidu/pproxy/serve.(_requestModifier).loadAllJs(0xc820135d40, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/serve/req_modifer.go:63 +0x21f
github.com/hidu/pproxy/serve.NewProxyServe(0xb1f4b0, 0x12, 0x0, 0x7f4806b1b9d0, 0x0, 0x0)
/home/lee/gowork/src/github.com/hidu/pproxy/serve/serve.go:168 +0x6a8
main.main()
/home/lee/gowork/src/github.com/hidu/pproxy/proxy_main.go:42 +0x30a

流量统计功能

好东西来赞一个,拿来看手机应用的后端请求了。
建议加入按会话的请求和响应大小统计功能,甚至可以压缩以节省手机流量。

能讲讲原理吗?

我简单看了一下,好像只有代理服务,请问如何实现抓包的呢?也可能我没看到,望指出!

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.