2012-04-02 23:10:25 +00:00
|
|
|
import urwid
|
2016-06-01 02:06:57 +00:00
|
|
|
|
2017-01-10 14:09:08 +00:00
|
|
|
from mitmproxy import http
|
2016-10-19 02:25:39 +00:00
|
|
|
from mitmproxy.tools.console import common, searchable
|
2016-10-19 20:45:18 +00:00
|
|
|
from mitmproxy.utils import human
|
2016-12-20 15:49:38 +00:00
|
|
|
from mitmproxy.utils import strutils
|
2012-04-02 23:10:25 +00:00
|
|
|
|
2015-03-30 20:49:07 +00:00
|
|
|
|
|
|
|
def maybe_timestamp(base, attr):
|
2016-04-02 19:33:51 +00:00
|
|
|
if base is not None and getattr(base, attr):
|
2016-06-07 05:12:52 +00:00
|
|
|
return human.format_timestamp_with_milli(getattr(base, attr))
|
2015-03-30 20:49:07 +00:00
|
|
|
else:
|
|
|
|
return "active"
|
|
|
|
|
|
|
|
|
2017-01-10 14:09:08 +00:00
|
|
|
def flowdetails(state, flow: http.HTTPFlow):
|
2015-03-29 06:21:54 +00:00
|
|
|
text = []
|
2012-04-02 23:10:25 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
sc = flow.server_conn
|
2016-11-22 21:22:56 +00:00
|
|
|
cc = flow.client_conn
|
2015-03-29 06:21:54 +00:00
|
|
|
req = flow.request
|
|
|
|
resp = flow.response
|
2016-11-22 21:22:56 +00:00
|
|
|
metadata = flow.metadata
|
|
|
|
|
2017-01-10 14:09:08 +00:00
|
|
|
if metadata is not None and len(metadata) > 0:
|
2016-11-22 21:22:56 +00:00
|
|
|
parts = [[str(k), repr(v)] for k, v in metadata.items()]
|
|
|
|
text.append(urwid.Text([("head", "Metadata:")]))
|
|
|
|
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
|
2012-04-02 23:10:25 +00:00
|
|
|
|
2016-01-26 10:14:19 +00:00
|
|
|
if sc is not None:
|
2015-03-29 06:21:54 +00:00
|
|
|
text.append(urwid.Text([("head", "Server Connection:")]))
|
|
|
|
parts = [
|
2017-02-20 23:20:44 +00:00
|
|
|
["Address", "{}:{}".format(sc.address[0], sc.address[1])],
|
|
|
|
["Resolved Address", "{}:{}".format(sc.ip_address[0], sc.ip_address[1])],
|
2015-03-29 06:21:54 +00:00
|
|
|
]
|
2017-01-10 14:09:08 +00:00
|
|
|
if resp:
|
|
|
|
parts.append(["HTTP Version", resp.http_version])
|
2016-12-17 12:49:18 +00:00
|
|
|
if sc.alpn_proto_negotiated:
|
|
|
|
parts.append(["ALPN", sc.alpn_proto_negotiated])
|
2012-04-02 23:10:25 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
text.extend(
|
|
|
|
common.format_keyvals(parts, key="key", val="text", indent=4)
|
|
|
|
)
|
2015-03-03 03:44:31 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
c = sc.cert
|
|
|
|
if c:
|
|
|
|
text.append(urwid.Text([("head", "Server Certificate:")]))
|
2014-02-05 23:53:39 +00:00
|
|
|
parts = [
|
2015-05-30 00:03:28 +00:00
|
|
|
["Type", "%s, %s bits" % c.keyinfo],
|
2015-03-29 06:21:54 +00:00
|
|
|
["SHA1 digest", c.digest("sha1")],
|
|
|
|
["Valid to", str(c.notafter)],
|
|
|
|
["Valid from", str(c.notbefore)],
|
|
|
|
["Serial", str(c.serial)],
|
|
|
|
[
|
|
|
|
"Subject",
|
|
|
|
urwid.BoxAdapter(
|
|
|
|
urwid.ListBox(
|
|
|
|
common.format_keyvals(
|
|
|
|
c.subject,
|
|
|
|
key="highlight",
|
|
|
|
val="text"
|
|
|
|
)
|
|
|
|
),
|
|
|
|
len(c.subject)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"Issuer",
|
|
|
|
urwid.BoxAdapter(
|
|
|
|
urwid.ListBox(
|
|
|
|
common.format_keyvals(
|
|
|
|
c.issuer, key="highlight", val="text"
|
|
|
|
)
|
|
|
|
),
|
|
|
|
len(c.issuer)
|
|
|
|
)
|
|
|
|
]
|
2014-02-05 23:53:39 +00:00
|
|
|
]
|
2015-03-04 17:02:01 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
if c.altnames:
|
|
|
|
parts.append(
|
2012-04-02 23:10:25 +00:00
|
|
|
[
|
2015-03-29 06:21:54 +00:00
|
|
|
"Alt names",
|
2016-12-20 15:49:38 +00:00
|
|
|
", ".join(strutils.bytes_to_escaped_str(x) for x in c.altnames)
|
2012-04-02 23:10:25 +00:00
|
|
|
]
|
2015-03-29 06:21:54 +00:00
|
|
|
)
|
|
|
|
text.extend(
|
|
|
|
common.format_keyvals(parts, key="key", val="text", indent=4)
|
|
|
|
)
|
2012-04-02 23:10:25 +00:00
|
|
|
|
2016-01-26 10:14:19 +00:00
|
|
|
if cc is not None:
|
2015-03-29 06:21:54 +00:00
|
|
|
text.append(urwid.Text([("head", "Client Connection:")]))
|
2015-03-03 03:44:31 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
parts = [
|
2017-02-20 23:20:44 +00:00
|
|
|
["Address", "{}:{}".format(cc.address[0], cc.address[1])],
|
2015-03-29 06:21:54 +00:00
|
|
|
]
|
2017-01-10 14:09:08 +00:00
|
|
|
if req:
|
|
|
|
parts.append(["HTTP Version", req.http_version])
|
2016-10-26 06:36:14 +00:00
|
|
|
if cc.tls_version:
|
|
|
|
parts.append(["TLS Version", cc.tls_version])
|
2016-10-25 01:59:54 +00:00
|
|
|
if cc.sni:
|
|
|
|
parts.append(["Server Name Indication", cc.sni])
|
2016-10-26 03:32:42 +00:00
|
|
|
if cc.cipher_name:
|
|
|
|
parts.append(["Cipher Name", cc.cipher_name])
|
2016-12-17 12:49:18 +00:00
|
|
|
if cc.alpn_proto_negotiated:
|
|
|
|
parts.append(["ALPN", cc.alpn_proto_negotiated])
|
2015-03-04 17:02:01 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
text.extend(
|
|
|
|
common.format_keyvals(parts, key="key", val="text", indent=4)
|
|
|
|
)
|
2015-03-03 21:38:16 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
parts = []
|
|
|
|
|
2016-04-02 19:33:51 +00:00
|
|
|
if cc is not None and cc.timestamp_start:
|
2015-03-30 20:49:07 +00:00
|
|
|
parts.append(
|
|
|
|
[
|
2016-04-02 19:33:51 +00:00
|
|
|
"Client conn. established",
|
|
|
|
maybe_timestamp(cc, "timestamp_start")
|
2015-03-30 20:49:07 +00:00
|
|
|
]
|
|
|
|
)
|
2016-04-02 19:33:51 +00:00
|
|
|
if cc.ssl_established:
|
|
|
|
parts.append(
|
|
|
|
[
|
|
|
|
"Client conn. TLS handshake",
|
|
|
|
maybe_timestamp(cc, "timestamp_ssl_setup")
|
|
|
|
]
|
|
|
|
)
|
2016-11-22 21:22:56 +00:00
|
|
|
|
2016-04-02 19:33:51 +00:00
|
|
|
if sc is not None and sc.timestamp_start:
|
2015-03-30 20:49:07 +00:00
|
|
|
parts.append(
|
|
|
|
[
|
2016-04-02 19:33:51 +00:00
|
|
|
"Server conn. initiated",
|
|
|
|
maybe_timestamp(sc, "timestamp_start")
|
|
|
|
]
|
|
|
|
)
|
|
|
|
parts.append(
|
|
|
|
[
|
|
|
|
"Server conn. TCP handshake",
|
|
|
|
maybe_timestamp(sc, "timestamp_tcp_setup")
|
|
|
|
]
|
|
|
|
)
|
|
|
|
if sc.ssl_established:
|
|
|
|
parts.append(
|
|
|
|
[
|
|
|
|
"Server conn. TLS handshake",
|
|
|
|
maybe_timestamp(sc, "timestamp_ssl_setup")
|
|
|
|
]
|
|
|
|
)
|
2016-11-22 21:22:56 +00:00
|
|
|
|
2016-04-02 19:33:51 +00:00
|
|
|
if req is not None and req.timestamp_start:
|
|
|
|
parts.append(
|
|
|
|
[
|
|
|
|
"First request byte",
|
|
|
|
maybe_timestamp(req, "timestamp_start")
|
|
|
|
]
|
|
|
|
)
|
|
|
|
parts.append(
|
|
|
|
[
|
|
|
|
"Request complete",
|
|
|
|
maybe_timestamp(req, "timestamp_end")
|
|
|
|
]
|
|
|
|
)
|
2016-11-22 21:22:56 +00:00
|
|
|
|
2016-04-02 19:33:51 +00:00
|
|
|
if resp is not None and resp.timestamp_start:
|
|
|
|
parts.append(
|
|
|
|
[
|
|
|
|
"First response byte",
|
|
|
|
maybe_timestamp(resp, "timestamp_start")
|
|
|
|
]
|
|
|
|
)
|
|
|
|
parts.append(
|
|
|
|
[
|
|
|
|
"Response complete",
|
|
|
|
maybe_timestamp(resp, "timestamp_end")
|
2015-03-30 20:49:07 +00:00
|
|
|
]
|
|
|
|
)
|
2015-03-29 06:21:54 +00:00
|
|
|
|
2016-04-02 19:33:51 +00:00
|
|
|
if parts:
|
|
|
|
# sort operations by timestamp
|
|
|
|
parts = sorted(parts, key=lambda p: p[1])
|
2015-03-29 06:21:54 +00:00
|
|
|
|
2016-04-02 19:33:51 +00:00
|
|
|
text.append(urwid.Text([("head", "Timing:")]))
|
|
|
|
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
|
2016-11-22 21:22:56 +00:00
|
|
|
|
2015-03-29 06:21:54 +00:00
|
|
|
return searchable.Searchable(state, text)
|