mitmproxy开发与被动扫描(一)

Posted by bfpiaoran on October 30, 2017

前一阵子想写被动扫描来着  后来种种原因搁置了

好久没写代码了  又重新弄了下

找了一下

http://www.freebuf.com/sectool/76361.html

发现系统的描述只有freebuf一篇

但是版本更新 libmproxy库早已经更名

没有中文翻译  英语差的人伤不起啊

感觉拿它扫json劫持还是蛮可以的

但是做被动扫描有几块 没有想好

首先是去重   如果仅仅是对url做md5然后比对的话还是蛮简单的

但是问题是同url相同参数但是参数的值不一样也会造成md5不相同

现在想做的是先判断method  然后用&分割?后面的参数

首先要安装证书

现在命令行使用mitmdump之后可以在./mitmproxy

在命令行使用命令 mitmdump –script  get_flow.py

from mitmproxy import http
import mysql_control,filter

def response(flow: http.HTTPFlow) -> None:
    req = flow.request.get_state()
    method = req['method'].decode()
    url = req['host'].decode()+req['path'].decode()
    header = req['headers']
    host = req['host'].decode()
    request_content = req['content']
    head = {}
    if filter.filter(url):
        for i in header:
            head[i[0].decode()] = i[1].decode()
        head = str(head)
        response_content = flow.response.get_state()['content']
        with open('test.txt','a') as e:
            e.write(method+'\n')
            e.write(url+'\n')
            e.write('==========\n')
        # try:
        #     mysql_control.add_scan(method=method, url=url, host=host,request_content=request_content,
        #                            header=head, response_content=response_content)
        #     print('ok')
        # except Exception as e:
        #     print(e)

 

之后写个过滤器  filter.py



def filter(data):
    filter_list = ['callback']
    for i in filter_list:
        if i in data:
            print('===========')
            print('true')
            print(data)
            return True
    return False


这里执行后就能简单的获取带有callback属性的请求

然后输出在记事本里 但然也可以写到数据库里等等

然后写一个验证json劫持的就可以了