CI_Knight

且行善举,莫问前程。

0%

我是从实习的时候开始使用Mitmproxy的,当时是为了Debug APP的bug才使用的。编写一个python小脚本将流量都转发到自己的Server上,对接口进行Debug。

mitmproxy叫做man in the middle proxy,就是中间人代理的意思,一般的中间人攻击就可以利用这个软件,相似的软件还有Burp Suite,是一个收费的软件,进官网下载免费版的就可以使用,有图形用户界面,功能也是相当强大,因为使用Java编写开发,有很好的跨平台能力。Windows平台上有Fiddler,功能也是很强大,不多说直接进入今天的正题。

环境介绍

一般开发有三种服务器,dev,beta,online。Android,iOS发Build包一般都会指向测试服务器,但是你要做开发,或者Debug就要指向自己服务器,或者是线上服务器,不能总是麻烦他们,所以这时就需要一个代理来转发请求。

online一般都是Https,所以对于https还要做一些其他处理。

安装一个Mitmproxy

不管是是什么平台只要安装好python-pip,就可以直接安装Mitmproxy

1
pip install mitmproxy

mitmproxy会在~/.mitmproxy目录下生成一个mitmproxy-ca-cert.pem证书。如果是对端开发,支持https就要安装自签证书。

1
python -m SimpleHTTPServer 8888

手机访问http://ip:8888 安装证书

1
mitmproxy -p 3128

手机设置代理到ip:3128,此时就能抓到https的数据包了。

自签证书

1
2
3
openssl genrsa -out cert.key 2048
openssl req -new -x509 -key cert.key -out cert.crt
cat cert.key cert.crt > cert.pem

运行

1
mitmproxy -p 3128 --cert=cert.pem

Script支持

转发一定少不了脚本支持

Example

1
2
3
4
5
6
def request(context, flow):
if 'www.baidu.com' == flow.request.hots:
if flow.request.scheme == 'https':
flow.request.scheme = 'https'
flow.request.host = 'blog.ibeats.top'
flow.request.prot = 443

运行

1
mitmproxy -s forward.py -p 3128

帮助文档

官方文档官方script

vim最近配上了python mode插件,后来发现项目下经常会多出来一个.repoproject文件夹,谷歌无果,接下来写python项目时就会碰上卡死的问题。pyhotn mode带来很棒的支持,但是这个卡死就实在不能忍受。

今天发现卡死的时候状态显示regenerate repo cache…,那么肯定和python mode的repo有关,先不去考虑repo是什么,谷歌regenerate repo cache后来找到了答案。

Solution

编辑你的~/.vimrc,添加以下配置,禁用repo

1
2
3
" close python mode Regenerate repo cache
let g:pymode_rope = 0
let g:pymode_rope_lookup_project = 0

Reason

rope 这个插件在文件保存的时候创建 rope 信息的时候,需要非常长的时间,让 vim 长时间无法响应。

Clone my config in github

github: dotfile

我喜欢在手机上的备忘录里面写一些东西,然后截屏分享出去,有时写多了就不能截一张Screenshot,然后就想弄一个长微博生成器。一般长微博生成器最后都是生成一张图片,我的编程习惯一般都是首选python,然后使用了Pillow库来编写的,不建议使用PIL,而是去选择friendly PIL,就是Pillow库。

思路

如果效果好看则使用头图和页脚,中间则是标题跟正文,这样基本就可以生成长微博。头图使用一个图片,长微博宽度以头图为准,默认则是750(IP6的分辨率1334*750)。文章区则是根据长微博宽度和文字大小算出每行的字符数来生成区块。最终进行拼接。页脚就不用再次多说。

项目

** 2016年07月03日更新**

  • 添加了daemon
  • 添加了colored logger
  • 优化了启动方式
  • 整理代码
  • 可选使用dnspod token进行授权验证

使用第三方的DDNS服务感觉总是不是太稳定,所以就利用DNSPOD的API编写了一个DDNS的Server。目前依然在开发当中,已经实现了动态域名的功能,接下来是添加更多的功能,使之更加稳定和易用。接下来就是要开始按照计划进行迭代。如果有兴趣一起开发的朋友可以邮箱联系我。

系统环境

ubuntu14.04 Desktop x64

编译nginx

apt-get安装的nginx并不支持websocket,需要添加nginx-push-stream-module模块,所以我们要重新编译nginx。

编译参考模块给出的 参考地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
git clone https://github.com/wandenberg/nginx-push-stream-module.git
# download nginx latest
wget http://nginx.org/download/nginx-1.9.10.tar.gz

# unpack, configure and build
tar zxvf nginx-1.9.10.tar.gz
cd nginx-1.9.10

# add Openssl model,generate Makefile
./configure --add-module=../nginx-push-stream-module --with-http_ssl_module

# if the HTTP rewrite module requires the PCRE library.
# sudo apt-get install libpcre3 libpcre3-dev
# sudo apt-get install openssl libssl-dev

make & sudo make install

更多config配置,使用./config –help默认安装在/usr/local/nginx下

配置websocket

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# add the push_stream_shared_memory_size to your http context
http {
push_stream_shared_memory_size 32M;

# define publisher and subscriber endpoints in your server context
server {
location /channels-stats {
# activate channels statistics mode for this location
push_stream_channels_statistics;

# query string based channel id
push_stream_channels_path $arg_id;
}

location /pub {
# activate publisher (admin) mode for this location
push_stream_publisher admin;

# query string based channel id
push_stream_channels_path $arg_id;
}

location ~ /sub/(.*) {
# activate subscriber (streaming) mode for this location
push_stream_subscriber;

# positional channel path
push_stream_channels_path $1;
}
}
}

配置一个publisher,配置一个subscriber,以id区分每一个channel也可以直接nginx加载misc/nginx.conf

测试

推荐使用curl直接测试,也可以选择使用iocat测试,需要安装node.js以及npm

1
2
3
4
5
6
7
8
9
10
npm install iocat -g

# WebSocket Client
iocat ws://127.0.0.1:80/sub/1

# WebSocket Server
iocat -l -p 80

# or curl
curl -s -v -X POST 'http://127.0.0.1/pub?id=1' -d 'Hello World!'