Ejemplo n.º 1
0
 def flush(self, key):
     ''' flush flows to db '''
     flows = self.flowmap[key]
     stream = BytesIO()
     writer = io.FlowWriter(stream)
     for flow in flows:
         writer.add(flow)
     self.db[key] = stream.getvalue()
Ejemplo n.º 2
0
    def get(self):
        self.set_header("Content-Disposition", "attachment; filename=flows")
        self.set_header("Content-Type", "application/octet-stream")

        bio = BytesIO()
        fw = io.FlowWriter(bio)
        for f in self.view:
            fw.add(f)

        self.write(bio.getvalue())
        bio.close()
Ejemplo n.º 3
0
 def my_tools_save_flow_to_txt(self,
                               flows: typing.Sequence[mitmproxy.flow.Flow],
                               path: mitmproxy.types.Path):
     try:
         f = self.my_tools_open_file(path)
     except IOError as v:
         raise exceptions.CommandError(v) from v
     stream = io.FlowWriter(f)
     for i in flows:
         stream.add(i)
     f.close()
Ejemplo n.º 4
0
 def _write_flows(self, path, flows):
     if not path:
         return
     path = os.path.expanduser(path)
     try:
         f = open(path, "wb")
         fw = io.FlowWriter(f)
         for i in flows:
             fw.add(i)
         f.close()
     except IOError as v:
         signals.status_message.send(message=v.strerror)
Ejemplo n.º 5
0
 def __init__(self, flow_name):
     print("Capture Module Loaded")
     if not get_flow_file(flow_name, True):
         print("[ERROR] Invalid Project Name")
         sys.exit(0)
     self.flow_file = get_flow_file(flow_name, True)
     self.http_dump_file = get_flow_file(flow_name, True) + ".txt"
     self.make_dir([self.flow_file, self.http_dump_file])
     self.display_out = settings.DISPLAY_OUT
     if self.flow_file:
         self.f = open(self.flow_file, "wb")  # type: typing.IO[bytes]
         self.w = io.FlowWriter(self.f)
     if self.http_dump_file:
         self.http_f = open(self.http_dump_file, "w")
Ejemplo n.º 6
0
 def save(self, flows: typing.Sequence[flow.Flow], path: mitmproxy.types.Path) -> None:
     """
         Save flows to a file. If the path starts with a +, flows are
         appended to the file, otherwise it is over-written.
     """
     try:
         f = self.open_file(path)
     except IOError as v:
         raise exceptions.CommandError(v) from v
     stream = io.FlowWriter(f)
     for i in flows:
         stream.add(i)
     f.close()
     ctx.log.alert("Saved %s flows." % len(flows))
Ejemplo n.º 7
0
 def save(self, flows: typing.Sequence[flow.Flow],
          path: mitmproxy.types.Path) -> None:
     """
         Save flows to a file. If the path starts with a +, flows are
         appended to the file, otherwise it is over-written.
     """
     try:
         with open(_path(path), _mode(path)) as f:
             stream = io.FlowWriter(f)
             for i in flows:
                 stream.add(i)
     except OSError as e:
         raise exceptions.CommandError(e) from e
     ctx.log.alert(f"Saved {len(flows)} flows.")
Ejemplo n.º 8
0
def write_data(path, corrupt=False):
    with open(path, "wb") as tf:
        w = io.FlowWriter(tf)
        for i in range(3):
            f = tflow.tflow(resp=True)
            w.add(f)
        for i in range(3):
            f = tflow.tflow(err=True)
            w.add(f)
        f = tflow.ttcpflow()
        w.add(f)
        f = tflow.ttcpflow(err=True)
        w.add(f)
        if corrupt:
            tf.write(b"flibble")
Ejemplo n.º 9
0
def response(flow):
    """
    mitmdumps调用的脚本函数
    如果请求中包含需要的请求流,就在保存后终止运行
    Parameters
    ----------
    flow: http.HTTPFlow
    请求流, 通过命令调用

    Returns
    -------
        None
    """
    url = urllib.parse.unquote(flow.request.url)
    outfile = sys.argv[3]
    f = typing.IO[bytes] = open(outfile, 'wb')
    w = io.FlowWriter(f)
    if "mp.weixin.qq.com/mp/getappmsgext" in url:
        w.add(flow)
        f.close()
        exit()
Ejemplo n.º 10
0
 def __init__(self, path):
     if path == "-":
         f = sys.stdout
     else:
         f = open(path, "wb")
     self.w = io.FlowWriter(f)
Ejemplo n.º 11
0
 def flowfile(self, path):
     with open(path, "wb") as f:
         fw = io.FlowWriter(f)
         t = tflow.tflow(resp=True)
         fw.add(t)
Ejemplo n.º 12
0
 def _write_flows(self, path, flows):
     with open(path, "wb") as f:
         fw = io.FlowWriter(f)
         for i in flows:
             fw.add(i)
Ejemplo n.º 13
0
 def __init__(self, path: str) -> None:
     self.f = open(path, "wb")
     self.w = io.FlowWriter(self.f)
Ejemplo n.º 14
0
import os
import re
import sys

from mitmproxy import io

(_, inpath, outpath) = sys.argv

key_re = re.compile(r"([&?]key=)[^&]+")
id_re = re.compile(r"^(/(?:groups|users)/)\d+/")

inf = open(inpath, 'rb')
freader = io.FlowReader(inf)
outf = open(outpath, 'wb')
fwriter = io.FlowWriter(outf)
for i in freader.stream():
    i.request.path = id_re.sub(r"\1none/", key_re.sub(r"\1none",
                                                      i.request.path))
    fwriter.add(i)
outf.close()
inf.close()
Ejemplo n.º 15
0
 def flowfile(self, path):
     f = open(path, "wb")
     fw = io.FlowWriter(f)
     t = tutils.tflow(resp=True)
     fw.add(t)
     f.close()
Ejemplo n.º 16
0
def tdump(path, flows):
    with open(path, "wb") as f:
        w = io.FlowWriter(f)
        for i in flows:
            w.add(i)
Ejemplo n.º 17
0
 def __init__(self, path: str) -> None:
     self.f: typing.IO[bytes] = open(path, "wb")
     self.w = io.FlowWriter(self.f)
Ejemplo n.º 18
0
 def __init__(self, path: str) -> None:
     if path == "-":
         f = sys.stdout  # type: typing.IO[typing.Any]
     else:
         f = open(path, "wb")
     self.w = io.FlowWriter(f)
Ejemplo n.º 19
0
def tdump(path, flows):
    w = io.FlowWriter(open(path, "wb"))
    for i in flows:
        w.add(i)
Ejemplo n.º 20
0
        for i in range(1, len(group_list)):
            first_mem.append(flow_list[group_list[i].member[0]])

        for m in first_mem[1:]:
            try:
                for key in m.content_dict.keys():
                    try:
                        m.content_dict[key] = m.content_dict[key][0]
                    except:
                        pass
            except:
                pass

        fuzz_list = list()
        output = open('fuzz_log', "wb")
        fwriter = io.FlowWriter(output)
        output_rule = {}
        output_rule['value'] = []
        output_rule['ptn_num'] = []
        output_rule['resp_rule'] = [None] * (len(group_list))
        #for test !!!
        output_rule['resp_rule'][13] = [('content', 'hasMoreItems', 10,
                                         'content', 'count')]

        for i in rule_dict:
            #print(rule_dict[i])
            order = rule_dict[i].g_order
            if len(set(order)) == 1 or rule_dict[i].dir == 'resp':
                print(i)
                print([order, rule_dict[i]])
                continue