Ejemplo n.º 1
0
    def _process_flow(self, f):
        self.state.delete_flow(f)
        if self.filt and not f.match(self.filt):
            return

        if self.o.flow_detail == 0:
            return

        if f.request:
            print(str_request(f, self.showhost), file=self.outfile)
            self._print_message(f.request)

        if f.response:
            if f.response.content == http.CONTENT_MISSING:
                sz = "(content missing)"
            else:
                sz = utils.pretty_size(len(f.response.content))
            print(" << %s %s" % (str_response(f.response), sz),
                  file=self.outfile)
            self._print_message(f.response)

        if f.error:
            print(" << {}".format(f.error.msg), file=self.outfile)

        self.outfile.flush()
Ejemplo n.º 2
0
    def _echo_response_line(self, flow):
        if flow.response.is_replay:
            replay = click.style("[replay] ", fg="yellow", bold=True)
        else:
            replay = ""

        code = flow.response.status_code
        code_color = None
        if 200 <= code < 300:
            code_color = "green"
        elif 300 <= code < 400:
            code_color = "magenta"
        elif 400 <= code < 600:
            code_color = "red"
        code = click.style(str(code), fg=code_color, bold=True, blink=(code == 418))
        reason = click.style(bytes_to_escaped_str(flow.response.reason), fg=code_color, bold=True)

        if flow.response.content is None:
            size = "(content missing)"
        else:
            size = pretty_size(len(flow.response.content))
        size = click.style(size, bold=True)

        arrows = click.style("<<", bold=True)

        line = "{replay} {arrows} {code} {reason} {size}".format(
            replay=replay,
            arrows=arrows,
            code=code,
            reason=reason,
            size=size
        )
        self.echo(line)
Ejemplo n.º 3
0
 def __repr__(self):
     return "<HTTPResponse: {code} {msg} ({contenttype}, {size})>".format(
         code=self.code,
         msg=self.msg,
         contenttype=self.headers.get_first("content-type", "?"),
         size=utils.pretty_size(len(self.content))
     )
Ejemplo n.º 4
0
 def __repr__(self):
     size = utils.pretty_size(len(self.content)) if self.content else "content missing"
     return "<HTTPResponse: {code} {msg} ({contenttype}, {size})>".format(
         code=self.code,
         msg=self.msg,
         contenttype=self.headers.get_first("content-type", "unknown content type"),
         size=size
     )
Ejemplo n.º 5
0
 def __repr__(self):
     size = utils.pretty_size(len(
         self.content)) if self.content else "content missing"
     return "<HTTPResponse: {code} {msg} ({contenttype}, {size})>".format(
         code=self.code,
         msg=self.msg,
         contenttype=self.headers.get_first("content-type",
                                            "unknown content type"),
         size=size)
Ejemplo n.º 6
0
    def _process_flow(self, f):
        self.state.delete_flow(f)
        if self.filt and not f.match(self.filt):
            return

        if f.response:
            if self.o.flow_detail > 0:
                if f.response.content == http.CONTENT_MISSING:
                    sz = "(content missing)"
                else:
                    sz = utils.pretty_size(len(f.response.content))
                result = " << %s %s"%(str_response(f.response), sz)
            if self.o.flow_detail > 1:
                result = result + "\n\n" + self.indent(4, f.response.headers)
            if self.o.flow_detail > 2:
                if f.response.content == http.CONTENT_MISSING:
                    cont = self.indent(4, "(content missing)")
                elif utils.isBin(f.response.content):
                    d = netlib.utils.hexdump(f.response.content)
                    d = "\n".join("%s\t%s %s"%i for i in d)
                    cont = self.indent(4, d)
                elif f.response.content:
                    cont = self.indent(4, f.response.content)
                else:
                    cont = ""
                result = result + "\n\n" + cont
        elif f.error:
            result = " << %s"%f.error.msg

        if self.o.generated_replay_script:
            self.add_replay_code(f, result)

        if self.o.flow_detail == 1:
            print >> self.outfile, str_request(f, self.showhost)
            print >> self.outfile, result

        elif self.o.flow_detail == 2:
            print >> self.outfile, str_request(f, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        elif self.o.flow_detail >= 3:
            print >> self.outfile, str_request(f, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            if f.request.content != http.CONTENT_MISSING and utils.isBin(f.request.content):
                d = netlib.utils.hexdump(f.request.content)
                d = "\n".join("%s\t%s %s"%i for i in d)
                print >> self.outfile, self.indent(4, d)
            elif f.request.content:
                print >> self.outfile, self.indent(4, f.request.content)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        if self.o.flow_detail:
            self.outfile.flush()
Ejemplo n.º 7
0
def trailer(clen, txt, limit):
    rem = clen - limit
    if rem > 0:
        txt.append(urwid.Text(""))
        txt.append(
            urwid.Text([
                ("highlight",
                 "... %s of data not shown. Press " % utils.pretty_size(rem)),
                ("key", "f"), ("highlight", " to load all data.")
            ]))
Ejemplo n.º 8
0
    def _process_flow(self, f):
        self.state.delete_flow(f)
        if self.filt and not f.match(self.filt):
            return

        if f.response:
            if self.o.flow_detail > 0:
                if f.response.content == http.CONTENT_MISSING:
                    sz = "(content missing)"
                else:
                    sz = utils.pretty_size(len(f.response.content))
                result = " << %s %s" % (str_response(f.response), sz)
            if self.o.flow_detail > 1:
                result = result + "\n\n" + self.indent(4, f.response.headers)
            if self.o.flow_detail > 2:
                if f.response.content == http.CONTENT_MISSING:
                    cont = self.indent(4, "(content missing)")
                elif utils.isBin(f.response.content):
                    d = netlib.utils.hexdump(f.response.content)
                    d = "\n".join("%s\t%s %s" % i for i in d)
                    cont = self.indent(4, d)
                elif f.response.content:
                    cont = self.indent(4, f.response.content)
                else:
                    cont = ""
                result = result + "\n\n" + cont
        elif f.error:
            result = " << %s" % f.error.msg

        if self.o.flow_detail == 1:
            print >> self.outfile, str_request(f, self.showhost)
            print >> self.outfile, result
        elif self.o.flow_detail == 2:
            print >> self.outfile, str_request(f, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        elif self.o.flow_detail >= 3:
            print >> self.outfile, str_request(f, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            if f.request.content != http.CONTENT_MISSING and utils.isBin(
                    f.request.content):
                d = netlib.utils.hexdump(f.request.content)
                d = "\n".join("%s\t%s %s" % i for i in d)
                print >> self.outfile, self.indent(4, d)
            elif f.request.content:
                print >> self.outfile, self.indent(4, f.request.content)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        if self.o.flow_detail:
            self.outfile.flush()
Ejemplo n.º 9
0
def trailer(clen, txt, limit):
    rem = clen - limit
    if rem > 0:
        txt.append(urwid.Text(""))
        txt.append(
            urwid.Text(
                [
                    ("highlight", "... %s of data not shown. Press " % utils.pretty_size(rem)),
                    ("key", "f"),
                    ("highlight", " to load all data.")
                ]
            )
        )
Ejemplo n.º 10
0
 def human_readable(self):
     vals = ["ws frame:", OPCODE.get_name(self.opcode, hex(self.opcode)).lower()]
     flags = []
     for i in ["fin", "rsv1", "rsv2", "rsv3", "mask"]:
         if getattr(self, i):
             flags.append(i)
     if flags:
         vals.extend([":", "|".join(flags)])
     if self.masking_key:
         vals.append(":key=%s" % repr(self.masking_key))
     if self.payload_length:
         vals.append(" %s" % utils.pretty_size(self.payload_length))
     return "".join(vals)
Ejemplo n.º 11
0
    def __repr__(self):
        # return "Response(%s - %s)" % (self.status_code, self.msg)

        if self.body:
            size = utils.pretty_size(len(self.body))
        else:
            size = "content missing"
        # TODO: Remove "(unknown content type, content missing)" edge-case
        return "<Response: {status_code} {msg} ({contenttype}, {size})>".format(
            status_code=self.status_code,
            msg=self.msg,
            contenttype=self.headers.get("content-type", "unknown content type"),
            size=size,
        )
Ejemplo n.º 12
0
    def __repr__(self):
        # return "Response(%s - %s)" % (self.status_code, self.msg)

        if self.body:
            size = utils.pretty_size(len(self.body))
        else:
            size = "content missing"
        # TODO: Remove "(unknown content type, content missing)" edge-case
        return "<Response: {status_code} {msg} ({contenttype}, {size})>".format(
            status_code=self.status_code,
            msg=self.msg,
            contenttype=self.headers.get_first("content-type",
                                               "unknown content type"),
            size=size)
Ejemplo n.º 13
0
    def _process_flow(self, f):
        self.state.delete_flow(f)
        if self.filt and not f.match(self.filt):
            return

        if f.response:
            sz = utils.pretty_size(len(f.response.content))
            if self.o.verbosity > 0:
                result = " << %s %s"%(str_response(f.response), sz)
            if self.o.verbosity > 1:
                result = result + "\n\n" + self.indent(4, f.response.headers)
            if self.o.verbosity > 2:
                if utils.isBin(f.response.content):
                    d = netlib.utils.hexdump(f.response.content)
                    d = "\n".join("%s\t%s %s"%i for i in d)
                    cont = self.indent(4, d)
                elif f.response.content:
                    cont = self.indent(4, f.response.content)
                else:
                    cont = ""
                result = result + "\n\n" + cont
        elif f.error:
            result = " << %s"%f.error.msg

        if self.o.verbosity == 1:
            print >> self.outfile, str_request(f.request, self.showhost)
            print >> self.outfile, result
        elif self.o.verbosity == 2:
            print >> self.outfile, str_request(f.request, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        elif self.o.verbosity >= 3:
            print >> self.outfile, str_request(f.request, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            if utils.isBin(f.request.content):
                d = netlib.utils.hexdump(f.request.content)
                d = "\n".join("%s\t%s %s"%i for i in d)
                cont = self.indent(4, d)

                print >> self.outfile, cont
            elif f.request.content:
                print >> self.outfile, self.indent(4, f.request.content)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        if self.o.verbosity:
            self.outfile.flush()
Ejemplo n.º 14
0
    def __repr__(self):
        # return "Response(%s - %s)" % (self.status_code, self.msg)

        if self.body:
            size = utils.pretty_size(len(self.body))
        else:
            size = "content missing"
        return "<HTTPResponse: {status_code} {msg} ({contenttype}, {size})>".format(
            status_code=self.status_code,
            msg=self.msg,
            contenttype=self.headers.get_first(
                "content-type", "unknown content type"
            ),
            size=size
        )
Ejemplo n.º 15
0
 def human_readable(self):
     vals = [
         "ws frame:",
         OPCODE.get_name(self.opcode, hex(self.opcode)).lower()
     ]
     flags = []
     for i in ["fin", "rsv1", "rsv2", "rsv3", "mask"]:
         if getattr(self, i):
             flags.append(i)
     if flags:
         vals.extend([":", "|".join(flags)])
     if self.masking_key:
         vals.append(":key=%s" % repr(self.masking_key))
     if self.payload_length:
         vals.append(" %s" % utils.pretty_size(self.payload_length))
     return "".join(vals)
Ejemplo n.º 16
0
    def _process_flow(self, f):
        self.state.delete_flow(f)
        if self.filt and not f.match(self.filt):
            return

        if f.response:
            sz = utils.pretty_size(len(f.response.content))
            if self.o.verbosity > 0:
                result = " << %s %s" % (str_response(f.response), sz)
            if self.o.verbosity > 1:
                result = result + "\n\n" + self.indent(4, f.response.headers)
            if self.o.verbosity > 2:
                if utils.isBin(f.response.content):
                    d = netlib.utils.hexdump(f.response.content)
                    d = "\n".join("%s\t%s %s" % i for i in d)
                    cont = self.indent(4, d)
                elif f.response.content:
                    cont = self.indent(4, f.response.content)
                else:
                    cont = ""
                result = result + "\n\n" + cont
        elif f.error:
            result = " << %s" % f.error.msg

        if self.o.verbosity == 1:
            print >> self.outfile, str_request(f.request, self.showhost)
            print >> self.outfile, result
        elif self.o.verbosity == 2:
            print >> self.outfile, str_request(f.request, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        elif self.o.verbosity >= 3:
            print >> self.outfile, str_request(f.request, self.showhost)
            print >> self.outfile, self.indent(4, f.request.headers)
            if utils.isBin(f.request.content):
                print >> self.outfile, self.indent(
                    4, netlib.utils.hexdump(f.request.content))
            elif f.request.content:
                print >> self.outfile, self.indent(4, f.request.content)
            print >> self.outfile
            print >> self.outfile, result
            print >> self.outfile, "\n"
        if self.o.verbosity:
            self.outfile.flush()
Ejemplo n.º 17
0
    def _process_flow(self, f):
        self.state.delete_flow(f)
        if self.filt and not f.match(self.filt):
            return

        if self.o.flow_detail == 0:
            return

        if f.request:
            print(str_request(f, self.showhost), file=self.outfile)
            self._print_message(f.request)

        if f.response:
            if f.response.content == http.CONTENT_MISSING:
                sz = "(content missing)"
            else:
                sz = utils.pretty_size(len(f.response.content))
            print(" << %s %s" % (str_response(f.response), sz), file=self.outfile)
            self._print_message(f.response)

        if f.error:
            print(" << {}".format(f.error.msg), file=self.outfile)

        self.outfile.flush()
Ejemplo n.º 18
0
    def _echo_response_line(self, flow):
        if flow.response.is_replay:
            replay = click.style("[replay] ", fg="yellow", bold=True)
        else:
            replay = ""

        code = flow.response.status_code
        code_color = None
        if 200 <= code < 300:
            code_color = "green"
        elif 300 <= code < 400:
            code_color = "magenta"
        elif 400 <= code < 600:
            code_color = "red"
        code = click.style(str(code),
                           fg=code_color,
                           bold=True,
                           blink=(code == 418))
        reason = click.style(bytes_to_escaped_str(flow.response.reason),
                             fg=code_color,
                             bold=True)

        if flow.response.content is None:
            size = "(content missing)"
        else:
            size = pretty_size(len(flow.response.content))
        size = click.style(size, bold=True)

        arrows = click.style("<<", bold=True)

        line = "{replay} {arrows} {code} {reason} {size}".format(replay=replay,
                                                                 arrows=arrows,
                                                                 code=code,
                                                                 reason=reason,
                                                                 size=size)
        self.echo(line)
Ejemplo n.º 19
0
def test_pretty_size():
    assert utils.pretty_size(100) == "100B"
    assert utils.pretty_size(1024) == "1kB"
    assert utils.pretty_size(1024 + (1024 / 2.0)) == "1.5kB"
    assert utils.pretty_size(1024 * 1024) == "1MB"
Ejemplo n.º 20
0
 def __repr__(self):
     return "<HTTPResponse: {code} {msg} ({contenttype}, {size})>".format(
         code=self.code,
         msg=self.msg,
         contenttype=self.headers.get_first("content-type", "?"),
         size=utils.pretty_size(len(self.content)))
Ejemplo n.º 21
0
def test_pretty_size():
    assert utils.pretty_size(100) == "100B"
    assert utils.pretty_size(1024) == "1kB"
    assert utils.pretty_size(1024 + (1024 / 2.0)) == "1.5kB"
    assert utils.pretty_size(1024 * 1024) == "1MB"