From 44a5070bf54da2e1f90e096833b5519806c1c31f Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Tue, 13 Jan 2015 23:18:28 -0300 Subject: [PATCH 01/15] added pyperclip dependency --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 953df2bb2..f9c8d15e8 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,8 @@ deps = { "pyasn1>0.1.2", "pyOpenSSL>=0.14", "tornado>=4.0.2", - "configargparse>=0.9.3" + "configargparse>=0.9.3", + "pyperclip>=1.5.7" } script_deps = { "mitmproxy": { From 34d355a62b3103e322793e2af652ee0aa867ddaf Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 10:52:52 -0300 Subject: [PATCH 02/15] wip - content copy is working, header representation is not --- libmproxy/console/flowlist.py | 16 ++++++++++++++++ libmproxy/protocol/http.py | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index c896ba33e..89dc56a9f 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,5 +1,6 @@ from __future__ import absolute_import import urwid +import pyperclip from . import common def _mkhelp(): @@ -136,6 +137,11 @@ class ConnectionItem(common.WWrap): self.state.last_saveload, self.master.server_playback_path ) + def server_copy_response(self, k): + if k == "c": + pyperclip.copy(self.flow.response_content()) + elif k == "t": + pyperclip.copy(self.flow.response_headers()) def keypress(self, (maxcol,), key): key = common.shortcuts(key) @@ -202,6 +208,16 @@ class ConnectionItem(common.WWrap): self.master.run_script_once, self.flow ) + elif key == "g": + #copy flow part + self.master.prompt_onekey( + "Copy Response", + ( + ("content", "c"), + ("headers", "h"), + ), + self.server_copy_response, + ) else: return key diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index da7c42404..4de1c0a6b 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -953,6 +953,21 @@ class HTTPFlow(Flow): c += self.response.replace(pattern, repl, *args, **kwargs) return c + def response_content(self): + s = "[No Content]" + with decoded(self.response): + s = self.response.content + return s + + def response_headers(self): + with decoded(self.response): + sh = "" + for i in self.flow.response.headers: + v = self.flow.response.headers[i] + for j in v: + sh += str(i)+"="+str(v[j])+"\n" + return sh + class HttpAuthenticationError(Exception): def __init__(self, auth_headers=None): From a4bfa677e95b058c50d49b4b3ae986351ed0cbf8 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 12:03:40 -0300 Subject: [PATCH 03/15] now content and header are working and exception for binary files are handled correctly --- libmproxy/console/flowlist.py | 13 ++++++++++--- libmproxy/protocol/http.py | 14 ++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 89dc56a9f..655df74df 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -13,6 +13,7 @@ def _mkhelp(): ("D", "duplicate flow"), ("e", "toggle eventlog"), ("F", "toggle follow flow list"), + ("g", "copy response(content/headers) to clipboard"), ("l", "set limit filter pattern"), ("L", "load saved flows"), ("r", "replay request"), @@ -139,9 +140,15 @@ class ConnectionItem(common.WWrap): ) def server_copy_response(self, k): if k == "c": - pyperclip.copy(self.flow.response_content()) - elif k == "t": - pyperclip.copy(self.flow.response_headers()) + try: + pyperclip.copy(self.flow.response_content()) + except TypeError: + self.master.statusbar.message("Content is binary or can be converted to text") + elif k == "h": + try: + pyperclip.copy(self.flow.response_headers()) + except TypeError: + self.master.statusbar.message("Error converting headers to text") def keypress(self, (maxcol,), key): key = common.shortcuts(key) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 4de1c0a6b..f822fcc85 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -954,20 +954,18 @@ class HTTPFlow(Flow): return c def response_content(self): - s = "[No Content]" with decoded(self.response): s = self.response.content + if s == None: + s = "[No content]" return s def response_headers(self): with decoded(self.response): - sh = "" - for i in self.flow.response.headers: - v = self.flow.response.headers[i] - for j in v: - sh += str(i)+"="+str(v[j])+"\n" - return sh - + s = str(self.response.headers) + if s == None: + s = "[]" + return s class HttpAuthenticationError(Exception): def __init__(self, auth_headers=None): From 36ec20bbb8a0b91a265849c48a660b3fd29d7122 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 12:09:14 -0300 Subject: [PATCH 04/15] removed invalid comment and unneeded safe text --- libmproxy/console/flowlist.py | 1 - libmproxy/protocol/http.py | 4 ---- 2 files changed, 5 deletions(-) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 655df74df..d48f75a49 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -216,7 +216,6 @@ class ConnectionItem(common.WWrap): self.flow ) elif key == "g": - #copy flow part self.master.prompt_onekey( "Copy Response", ( diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index f822fcc85..9846fc5b0 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -956,15 +956,11 @@ class HTTPFlow(Flow): def response_content(self): with decoded(self.response): s = self.response.content - if s == None: - s = "[No content]" return s def response_headers(self): with decoded(self.response): s = str(self.response.headers) - if s == None: - s = "[]" return s class HttpAuthenticationError(Exception): From d49eafad8b51bab837dc74d140aa04ed8c477cbc Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 12:36:19 -0300 Subject: [PATCH 05/15] added copy functionality to flowview too --- libmproxy/console/flowview.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 9e305b8a4..25b085c35 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -4,7 +4,7 @@ import urwid from . import common, grideditor, contentview from .. import utils, flow, controller from ..protocol.http import HTTPResponse, CONTENT_MISSING, decoded - +import pyperclip class SearchError(Exception): pass @@ -19,6 +19,7 @@ def _mkhelp(): ("D", "duplicate flow"), ("e", "edit request/response"), ("f", "load full body data"), + ("g", "copy response(content/headers) to clipboard"), ("m", "change body display mode for this entity"), (None, common.highlight_key("automatic", "a") + @@ -648,6 +649,18 @@ class FlowView(common.WWrap): ) self.master.refresh_flow(self.flow) + def server_copy_response(self, k): + if k == "c": + try: + pyperclip.copy(self.flow.response_content()) + except TypeError: + self.master.statusbar.message("Content is binary or can be converted to text") + elif k == "h": + try: + pyperclip.copy(self.flow.response_headers()) + except TypeError: + self.master.statusbar.message("Error converting headers to text") + def delete_body(self, t): if t == "m": val = CONTENT_MISSING @@ -751,6 +764,15 @@ class FlowView(common.WWrap): ) self.master.refresh_flow(self.flow) self.master.statusbar.message("") + elif key == "g": + self.master.prompt_onekey( + "Copy Response", + ( + ("content", "c"), + ("headers", "h"), + ), + self.server_copy_response, + ) elif key == "m": p = list(contentview.view_prompts) p.insert(0, ("Clear", "C")) From 6b8fb147d07d75aa81b0d5b5861c3cbbaeec7fbb Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 14:45:19 -0300 Subject: [PATCH 06/15] used get_decoded_content and removed decode call from headers as max suggested --- libmproxy/console/flowlist.py | 4 ++-- libmproxy/console/flowview.py | 4 ++-- libmproxy/protocol/http.py | 10 ---------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index d48f75a49..236bd5084 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -141,12 +141,12 @@ class ConnectionItem(common.WWrap): def server_copy_response(self, k): if k == "c": try: - pyperclip.copy(self.flow.response_content()) + pyperclip.copy(self.flow.response.get_decoded_content()) except TypeError: self.master.statusbar.message("Content is binary or can be converted to text") elif k == "h": try: - pyperclip.copy(self.flow.response_headers()) + pyperclip.copy(str(self.flow.response.headers)) except TypeError: self.master.statusbar.message("Error converting headers to text") diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 25b085c35..08a0148f5 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -652,12 +652,12 @@ class FlowView(common.WWrap): def server_copy_response(self, k): if k == "c": try: - pyperclip.copy(self.flow.response_content()) + pyperclip.copy(self.flow.response.get_decoded_content()) except TypeError: self.master.statusbar.message("Content is binary or can be converted to text") elif k == "h": try: - pyperclip.copy(self.flow.response_headers()) + pyperclip.copy(str(self.flow.response.headers)) except TypeError: self.master.statusbar.message("Error converting headers to text") diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 9846fc5b0..50691ea2d 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -953,16 +953,6 @@ class HTTPFlow(Flow): c += self.response.replace(pattern, repl, *args, **kwargs) return c - def response_content(self): - with decoded(self.response): - s = self.response.content - return s - - def response_headers(self): - with decoded(self.response): - s = str(self.response.headers) - return s - class HttpAuthenticationError(Exception): def __init__(self, auth_headers=None): super(HttpAuthenticationError, self).__init__( From 95f0b4b506230ee43ea7a6d736ab752400747bbb Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 16:44:59 -0300 Subject: [PATCH 07/15] trying to fix travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2dc898c21..e66501f1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ sudo: false python: - "2.7" - pypy +before_install: + - "sudo apt-get install -y xclip" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: - "pip install --upgrade --src . -r requirements.txt" From c97fe682303dbaeca551fd2c200a9f11e17749c6 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Wed, 14 Jan 2015 16:48:49 -0300 Subject: [PATCH 08/15] trying to fix travis take 2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e66501f1c..a4215e686 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: python -sudo: false +sudo: true python: - "2.7" - pypy From 0a2d2d93903ccc730cc7c2ca52f57a276d75bf83 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Thu, 15 Jan 2015 08:46:10 -0300 Subject: [PATCH 09/15] removed pyperclip hard dependencies --- .travis.yml | 4 +--- libmproxy/console/flowlist.py | 28 +++++++++++++++++----------- libmproxy/console/flowview.py | 28 +++++++++++++++++----------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4215e686..2dc898c21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: python -sudo: true +sudo: false python: - "2.7" - pypy -before_install: - - "sudo apt-get install -y xclip" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: - "pip install --upgrade --src . -r requirements.txt" diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 236bd5084..d611dc6e1 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,7 +1,10 @@ from __future__ import absolute_import import urwid -import pyperclip from . import common +try: + import pyperclip +except: + pyperclip = False def _mkhelp(): text = [] @@ -139,16 +142,19 @@ class ConnectionItem(common.WWrap): self.master.server_playback_path ) def server_copy_response(self, k): - if k == "c": - try: - pyperclip.copy(self.flow.response.get_decoded_content()) - except TypeError: - self.master.statusbar.message("Content is binary or can be converted to text") - elif k == "h": - try: - pyperclip.copy(str(self.flow.response.headers)) - except TypeError: - self.master.statusbar.message("Error converting headers to text") + if pyperclip: + if k == "c": + try: + pyperclip.copy(self.flow.response.get_decoded_content()) + except TypeError: + self.master.statusbar.message("Content is binary or can be converted to text") + elif k == "h": + try: + pyperclip.copy(str(self.flow.response.headers)) + except TypeError: + self.master.statusbar.message("Error converting headers to text") + else: + self.master.statusbar.message("No clipboard support on your system, sorry.") def keypress(self, (maxcol,), key): key = common.shortcuts(key) diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 08a0148f5..667a74074 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -4,7 +4,10 @@ import urwid from . import common, grideditor, contentview from .. import utils, flow, controller from ..protocol.http import HTTPResponse, CONTENT_MISSING, decoded -import pyperclip +try: + import pyperclip +except: + pyperclip = False class SearchError(Exception): pass @@ -650,16 +653,19 @@ class FlowView(common.WWrap): self.master.refresh_flow(self.flow) def server_copy_response(self, k): - if k == "c": - try: - pyperclip.copy(self.flow.response.get_decoded_content()) - except TypeError: - self.master.statusbar.message("Content is binary or can be converted to text") - elif k == "h": - try: - pyperclip.copy(str(self.flow.response.headers)) - except TypeError: - self.master.statusbar.message("Error converting headers to text") + if pyperclip: + if k == "c": + try: + pyperclip.copy(self.flow.response.get_decoded_content()) + except TypeError: + self.master.statusbar.message("Content is binary or can be converted to text") + elif k == "h": + try: + pyperclip.copy(str(self.flow.response.headers)) + except TypeError: + self.master.statusbar.message("Error converting headers to text") + else: + self.master.statusbar.message("No clipboard support on your system, sorry.") def delete_body(self, t): if t == "m": From b77cd1af606997f81890c1542f69d11daeda53b6 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Thu, 15 Jan 2015 09:36:59 -0300 Subject: [PATCH 10/15] extracted server_copy_response to common --- libmproxy/console/common.py | 20 +++++++++++++++++++- libmproxy/console/flowlist.py | 22 +++------------------- libmproxy/console/flowview.py | 24 ++++-------------------- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 3e6e5ccc5..3ba89f8e4 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -3,7 +3,10 @@ import urwid import urwid.util from .. import utils from ..protocol.http import CONTENT_MISSING - +try: + import pyperclip +except: + pyperclip = False VIEW_LIST = 0 VIEW_FLOW = 1 @@ -161,6 +164,21 @@ def raw_format_flow(f, focus, extended, padding): pile.append(urwid.Columns(resp, dividechars=1)) return urwid.Pile(pile) +def server_copy_response( k, response, statusbar): + if pyperclip: + if k == "c": + try: + pyperclip.copy(response.get_decoded_content()) + except TypeError: + statusbar.message("Content is binary or can be converted to text") + elif k == "h": + try: + pyperclip.copy(str(response.headers)) + except TypeError: + statusbar.message("Error converting headers to text") + else: + statusbar.message("No clipboard support on your system, sorry.") + class FlowCache: @utils.LRUCache(200) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index d611dc6e1..2dc20544c 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,10 +1,6 @@ from __future__ import absolute_import import urwid from . import common -try: - import pyperclip -except: - pyperclip = False def _mkhelp(): text = [] @@ -141,20 +137,6 @@ class ConnectionItem(common.WWrap): self.state.last_saveload, self.master.server_playback_path ) - def server_copy_response(self, k): - if pyperclip: - if k == "c": - try: - pyperclip.copy(self.flow.response.get_decoded_content()) - except TypeError: - self.master.statusbar.message("Content is binary or can be converted to text") - elif k == "h": - try: - pyperclip.copy(str(self.flow.response.headers)) - except TypeError: - self.master.statusbar.message("Error converting headers to text") - else: - self.master.statusbar.message("No clipboard support on your system, sorry.") def keypress(self, (maxcol,), key): key = common.shortcuts(key) @@ -228,7 +210,9 @@ class ConnectionItem(common.WWrap): ("content", "c"), ("headers", "h"), ), - self.server_copy_response, + common.server_copy_response, + self.flow.response, + self.master.statusbar ) else: return key diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 667a74074..abca2ed63 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -4,10 +4,7 @@ import urwid from . import common, grideditor, contentview from .. import utils, flow, controller from ..protocol.http import HTTPResponse, CONTENT_MISSING, decoded -try: - import pyperclip -except: - pyperclip = False + class SearchError(Exception): pass @@ -652,21 +649,6 @@ class FlowView(common.WWrap): ) self.master.refresh_flow(self.flow) - def server_copy_response(self, k): - if pyperclip: - if k == "c": - try: - pyperclip.copy(self.flow.response.get_decoded_content()) - except TypeError: - self.master.statusbar.message("Content is binary or can be converted to text") - elif k == "h": - try: - pyperclip.copy(str(self.flow.response.headers)) - except TypeError: - self.master.statusbar.message("Error converting headers to text") - else: - self.master.statusbar.message("No clipboard support on your system, sorry.") - def delete_body(self, t): if t == "m": val = CONTENT_MISSING @@ -777,7 +759,9 @@ class FlowView(common.WWrap): ("content", "c"), ("headers", "h"), ), - self.server_copy_response, + common.server_copy_response, + self.flow.response, + self.master.statusbar ) elif key == "m": p = list(contentview.view_prompts) From affb57ed08ca5167d38a21affeb84d8de2a77501 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Thu, 15 Jan 2015 12:37:26 -0300 Subject: [PATCH 11/15] added support for saving file if content is binary. still wip --- libmproxy/console/common.py | 44 +++++++++++++++++++++++++++++++---- libmproxy/console/flowlist.py | 3 ++- libmproxy/console/flowview.py | 3 ++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 3ba89f8e4..84dc8aeff 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -1,6 +1,7 @@ from __future__ import absolute_import import urwid import urwid.util +import os from .. import utils from ..protocol.http import CONTENT_MISSING try: @@ -164,20 +165,55 @@ def raw_format_flow(f, focus, extended, padding): pile.append(urwid.Columns(resp, dividechars=1)) return urwid.Pile(pile) -def server_copy_response( k, response, statusbar): +## common save body parts +def _save_body(path, master, state, content): + if not path: + return + state.last_saveload = path + path = os.path.expanduser(path) + try: + f = file(path, "wb") + f.write(str(content)) + f.close() + except IOError, v: + master.statusbar.message(v.strerror) + +def save_body(k, master, state, content): + if k == "y": + master.path_prompt( + "Save response body: ", + state.last_saveload, + _save_body, + master, + state, + content, + ) + +## common server_copy_response parts +def server_copy_response( k, master, state, response): if pyperclip: if k == "c": try: pyperclip.copy(response.get_decoded_content()) except TypeError: - statusbar.message("Content is binary or can be converted to text") + master.prompt_onekey( + "Content is binary do you want to save it to a file instead?", + ( + ("yes", "y"), + ("no", "n"), + ), + save_body, + master, + state, + response.get_decoded_content(), + ) elif k == "h": try: pyperclip.copy(str(response.headers)) except TypeError: - statusbar.message("Error converting headers to text") + master.statusbar.message("Error converting headers to text") else: - statusbar.message("No clipboard support on your system, sorry.") + master.statusbar.message("No clipboard support on your system, sorry.") class FlowCache: diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 2dc20544c..214c10db4 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -211,8 +211,9 @@ class ConnectionItem(common.WWrap): ("headers", "h"), ), common.server_copy_response, + self.master, + self.state, self.flow.response, - self.master.statusbar ) else: return key diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index abca2ed63..bc0b5f83b 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -760,8 +760,9 @@ class FlowView(common.WWrap): ("headers", "h"), ), common.server_copy_response, + self.master, + self.state, self.flow.response, - self.master.statusbar ) elif key == "m": p = list(contentview.view_prompts) From 7ba7d64bacc36821eddaaf2862f7a098949b2d4e Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Thu, 15 Jan 2015 12:57:00 -0300 Subject: [PATCH 12/15] used save_body from common when b key is pressed --- libmproxy/console/common.py | 8 +++---- libmproxy/console/flowview.py | 41 ++++++++++++----------------------- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 84dc8aeff..29e593730 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -166,7 +166,7 @@ def raw_format_flow(f, focus, extended, padding): return urwid.Pile(pile) ## common save body parts -def _save_body(path, master, state, content): +def save_body(path, master, state, content): if not path: return state.last_saveload = path @@ -178,12 +178,12 @@ def _save_body(path, master, state, content): except IOError, v: master.statusbar.message(v.strerror) -def save_body(k, master, state, content): +def ask_save_body(k, master, state, content): if k == "y": master.path_prompt( "Save response body: ", state.last_saveload, - _save_body, + save_body, master, state, content, @@ -202,7 +202,7 @@ def server_copy_response( k, master, state, response): ("yes", "y"), ("no", "n"), ), - save_body, + ask_save_body, master, state, response.get_decoded_content(), diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index bc0b5f83b..b964b92a1 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -508,22 +508,6 @@ class FlowView(common.WWrap): self.flow.request.method = i[0].upper() self.master.refresh_flow(self.flow) - def save_body(self, path): - if not path: - return - self.state.last_saveload = path - if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: - c = self.flow.request - else: - c = self.flow.response - path = os.path.expanduser(path) - try: - f = file(path, "wb") - f.write(str(c.content)) - f.close() - except IOError, v: - self.master.statusbar.message(v.strerror) - def set_url(self, url): request = self.flow.request try: @@ -691,17 +675,20 @@ class FlowView(common.WWrap): elif key == "b": if conn: if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: - self.master.path_prompt( - "Save request body: ", - self.state.last_saveload, - self.save_body - ) - else: - self.master.path_prompt( - "Save response body: ", - self.state.last_saveload, - self.save_body - ) + msg = "Save request body: " + content = self.flow.request.content + else: + msg = "Save response body: " + content = self.flow.response.content + + self.master.path_prompt( + msg, + self.state.last_saveload, + common.save_body, + self.master, + self.state, + content, + ) elif key == "d": if self.state.flow_count() == 1: self.master.view_flowlist() From d80e2e2b2b125a6b38baef6e9ba6d4282354775a Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Fri, 16 Jan 2015 12:13:55 -0300 Subject: [PATCH 13/15] added support for copying request (content|header) to clipboard --- libmproxy/console/common.py | 13 ++++++------- libmproxy/console/flowlist.py | 15 ++++++++++++++- libmproxy/console/flowview.py | 15 ++++++++++++++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 29e593730..33738c0a8 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -181,7 +181,7 @@ def save_body(path, master, state, content): def ask_save_body(k, master, state, content): if k == "y": master.path_prompt( - "Save response body: ", + "Save message content: ", state.last_saveload, save_body, master, @@ -189,12 +189,12 @@ def ask_save_body(k, master, state, content): content, ) -## common server_copy_response parts -def server_copy_response( k, master, state, response): +## common copy_message parts +def copy_message( k, master, state, message): if pyperclip: if k == "c": try: - pyperclip.copy(response.get_decoded_content()) + pyperclip.copy(message.get_decoded_content()) except TypeError: master.prompt_onekey( "Content is binary do you want to save it to a file instead?", @@ -205,17 +205,16 @@ def server_copy_response( k, master, state, response): ask_save_body, master, state, - response.get_decoded_content(), + message.get_decoded_content(), ) elif k == "h": try: - pyperclip.copy(str(response.headers)) + pyperclip.copy(str(message.headers)) except TypeError: master.statusbar.message("Error converting headers to text") else: master.statusbar.message("No clipboard support on your system, sorry.") - class FlowCache: @utils.LRUCache(200) def format_flow(self, *args): diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 214c10db4..77803a516 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -13,6 +13,7 @@ def _mkhelp(): ("e", "toggle eventlog"), ("F", "toggle follow flow list"), ("g", "copy response(content/headers) to clipboard"), + ("G", "copy request(content/headers) to clipboard"), ("l", "set limit filter pattern"), ("L", "load saved flows"), ("r", "replay request"), @@ -210,11 +211,23 @@ class ConnectionItem(common.WWrap): ("content", "c"), ("headers", "h"), ), - common.server_copy_response, + common.copy_message, self.master, self.state, self.flow.response, ) + elif key == "G": + self.master.prompt_onekey( + "Copy Request", + ( + ("content", "c"), + ("headers", "h"), + ), + common.copy_message, + self.master, + self.state, + self.flow.request, + ) else: return key diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index b964b92a1..a759f1098 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -20,6 +20,7 @@ def _mkhelp(): ("e", "edit request/response"), ("f", "load full body data"), ("g", "copy response(content/headers) to clipboard"), + ("G", "copy request(content/headers) to clipboard"), ("m", "change body display mode for this entity"), (None, common.highlight_key("automatic", "a") + @@ -746,11 +747,23 @@ class FlowView(common.WWrap): ("content", "c"), ("headers", "h"), ), - common.server_copy_response, + common.copy_message, self.master, self.state, self.flow.response, ) + elif key == "G": + self.master.prompt_onekey( + "Copy Request", + ( + ("content", "c"), + ("headers", "h"), + ), + common.copy_message, + self.master, + self.state, + self.flow.request, + ) elif key == "m": p = list(contentview.view_prompts) p.insert(0, ("Clear", "C")) From e5922ae30ad1074fd2412019db3d6dff9cc010a1 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Fri, 16 Jan 2015 13:08:25 -0300 Subject: [PATCH 14/15] added support for 'b' key in flowlist --- libmproxy/console/common.py | 28 ++++++++++++++++++++++++++++ libmproxy/console/flowlist.py | 13 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 33738c0a8..2f6c909cf 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -189,8 +189,36 @@ def ask_save_body(k, master, state, content): content, ) +def which_body_save(k, master, state, flow): + if k == "q": + master.path_prompt( + "Save request content: ", + state.last_saveload, + save_body, + master, + state, + flow.request.get_decoded_content(), + ) + elif k == "r": + if flow.response: + master.path_prompt( + "Save response content: ", + state.last_saveload, + save_body, + master, + state, + flow.response.get_decoded_content(), + ) + else: + master.statusbar.message("Flow has no response") + ## common copy_message parts def copy_message( k, master, state, message): + if not message: + # only response could be None + master.statusbar.message("Flow has no response") + return + if pyperclip: if k == "c": try: diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 77803a516..8fc9c6165 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -7,6 +7,7 @@ def _mkhelp(): keys = [ ("A", "accept all intercepted flows"), ("a", "accept this intercepted flow"), + ("b", "save request/response body"), ("C", "clear flow list or eventlog"), ("d", "delete flow"), ("D", "duplicate flow"), @@ -228,6 +229,18 @@ class ConnectionItem(common.WWrap): self.state, self.flow.request, ) + elif key == "b": + self.master.prompt_onekey( + "Save", + ( + ("request", "q"), + ("response", "r"), + ), + common.which_body_save, + self.master, + self.state, + self.flow, + ) else: return key From 82d8c93261c6efe8314e68a34070ce960f308972 Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Tue, 3 Feb 2015 15:41:09 -0300 Subject: [PATCH 15/15] added copy to clipboard support for url --- libmproxy/console/common.py | 5 +++++ libmproxy/console/flowlist.py | 3 ++- libmproxy/console/flowview.py | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 2f6c909cf..b7c464760 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -240,6 +240,11 @@ def copy_message( k, master, state, message): pyperclip.copy(str(message.headers)) except TypeError: master.statusbar.message("Error converting headers to text") + elif k == "u": + try: + pyperclip.copy(message.url) + except TypeError: + master.statusbar.message("Error copying url to clipboard") else: master.statusbar.message("No clipboard support on your system, sorry.") diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 8fc9c6165..fa430fdd7 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -14,7 +14,7 @@ def _mkhelp(): ("e", "toggle eventlog"), ("F", "toggle follow flow list"), ("g", "copy response(content/headers) to clipboard"), - ("G", "copy request(content/headers) to clipboard"), + ("G", "copy request(content/headers/url) to clipboard"), ("l", "set limit filter pattern"), ("L", "load saved flows"), ("r", "replay request"), @@ -223,6 +223,7 @@ class ConnectionItem(common.WWrap): ( ("content", "c"), ("headers", "h"), + ("url", "u"), ), common.copy_message, self.master, diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index a759f1098..c01bb08ff 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -20,7 +20,7 @@ def _mkhelp(): ("e", "edit request/response"), ("f", "load full body data"), ("g", "copy response(content/headers) to clipboard"), - ("G", "copy request(content/headers) to clipboard"), + ("G", "copy request(content/headers/url) to clipboard"), ("m", "change body display mode for this entity"), (None, common.highlight_key("automatic", "a") + @@ -758,6 +758,7 @@ class FlowView(common.WWrap): ( ("content", "c"), ("headers", "h"), + ("url", "u"), ), common.copy_message, self.master,