From b39d38b99a85ac935040295838258db20d3d2f4d Mon Sep 17 00:00:00 2001 From: Kayvan Date: Thu, 23 Apr 2015 11:17:19 -0700 Subject: [PATCH 1/4] Fixing the Now compatible with the mitmproxy 0.11.3 Fixes this error: raceback (most recent call last): File "/usr/local/bin/pmproxy", line 9, in load_entry_point('PostmanProxy==0.1.5', 'console_scripts', 'pmproxy')() File "/Library/Python/2.7/site-packages/postmanproxy/main.py", line 91, in main start_creator_proxy(args) File "/Library/Python/2.7/site-packages/postmanproxy/main.py", line 45, in start_creator_proxy cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem") TypeError: __init__() got an unexpected keyword argument 'cacert' --- postmanproxy/main.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/postmanproxy/main.py b/postmanproxy/main.py index 640b2a5..34c542e 100644 --- a/postmanproxy/main.py +++ b/postmanproxy/main.py @@ -2,6 +2,7 @@ from postman.collection_creator_proxy import CollectionCreatorProxy from postman.header_filter_proxy import HeaderFilterProxy from libmproxy import controller, proxy +from libmproxy.proxy.server import ProxyServer import argparse import signal import sys @@ -41,10 +42,8 @@ def start_creator_proxy(options): } collection = Collection(name, path) - config = proxy.ProxyConfig( - cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem") - ) - server = proxy.ProxyServer(config, port) + config = proxy.ProxyConfig(port=port) + server = ProxyServer(config) if options.tcp_connection == 'false': tcp_connection = False @@ -62,10 +61,8 @@ def start_creator_proxy(options): def start_filter_proxy(options): print "Press Ctrl+C to stop the proxy" port = int(options.port) - config = proxy.ProxyConfig( - cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem") - ) - server = proxy.ProxyServer(config, port) + config = proxy.ProxyConfig(port=port) + server = ProxyServer(config) m = HeaderFilterProxy(server) m.run() @@ -95,4 +92,4 @@ def main(): start_creator_proxy(args) if __name__ == "__main__": - main() \ No newline at end of file + main() From dd348141ec083ca1ccff79f95110a70fe2e408e9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 May 2015 08:56:42 +0900 Subject: [PATCH 2/4] Proper support for mitmproxy 0.11.3. Addresses the argument change to HTTPFlow. --- postmanproxy/postman/collection_creator_proxy.py | 12 +++++++----- postmanproxy/postman/request.py | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/postmanproxy/postman/collection_creator_proxy.py b/postmanproxy/postman/collection_creator_proxy.py index 2c9dde0..a33ee6e 100644 --- a/postmanproxy/postman/collection_creator_proxy.py +++ b/postmanproxy/postman/collection_creator_proxy.py @@ -59,7 +59,7 @@ def send_to_postman(self, request): try: TCP_IP = self.tcp_host TCP_PORT = self.tcp_port - BUFFER_SIZE = 1024 * 100 + BUFFER_SIZE = 1048573 MESSAGE = json.dumps(request.get_json()) print MESSAGE @@ -105,8 +105,9 @@ def run(self): except KeyboardInterrupt: self.shutdown() - def handle_request(self, msg): + def handle_request(self, flow): try: + msg = flow.request request = Request(self.collection.id) request.init_from_proxy(msg) @@ -140,8 +141,9 @@ def handle_request(self, msg): except Exception as ex: logging.exception("Something awful happened!") - msg.reply() + flow.reply(flow.response) - def handle_response(self, msg): + def handle_response(self, flow): print "Sent response" - msg.reply() \ No newline at end of file + flow.reply(flow.response) + diff --git a/postmanproxy/postman/request.py b/postmanproxy/postman/request.py index 4fc4b07..a511298 100644 --- a/postmanproxy/postman/request.py +++ b/postmanproxy/postman/request.py @@ -87,7 +87,9 @@ def get_urlencoded_body(self, data, header, method): return d def get_name(self, proxy_request): - return proxy_request.path + path = proxy_request.path + name = path[:30] + return name def get_url(self, proxy_request): if proxy_request.port == 443: @@ -156,4 +158,4 @@ def init_from_proxy(self, proxy_request): else: pass except Exception as ex: - logging.exception("Something awful happened!") \ No newline at end of file + logging.exception("Something awful happened!") From a5243fb9934b22b74d516e4d9b41eb3a7a273dec Mon Sep 17 00:00:00 2001 From: Kayvan Date: Tue, 9 Jun 2015 12:53:58 -0700 Subject: [PATCH 3/4] fixing the errors --- postmanproxy/postman/collection_creator_proxy.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/postmanproxy/postman/collection_creator_proxy.py b/postmanproxy/postman/collection_creator_proxy.py index a33ee6e..b66826b 100644 --- a/postmanproxy/postman/collection_creator_proxy.py +++ b/postmanproxy/postman/collection_creator_proxy.py @@ -59,7 +59,7 @@ def send_to_postman(self, request): try: TCP_IP = self.tcp_host TCP_PORT = self.tcp_port - BUFFER_SIZE = 1048573 + BUFFER_SIZE = 1048573 MESSAGE = json.dumps(request.get_json()) print MESSAGE @@ -108,10 +108,10 @@ def run(self): def handle_request(self, flow): try: msg = flow.request - request = Request(self.collection.id) - request.init_from_proxy(msg) + request2 = Request(self.collection.id) + request2.init_from_proxy(msg) - print request.headers + print request2.headers allowed_host = True allowed_method = True allowed_status_code = True @@ -131,12 +131,12 @@ def handle_request(self, flow): if allowed_method and allowed_host and allowed_status_code: print self.rules if not self.rules['restricted_headers']: - self.remove_restricted_headers(request) + self.remove_restricted_headers(request2) - self.collection.add_request(request) + self.collection.add_request(request2) if self.tcp_connection: - self.send_to_postman(request) + self.send_to_postman(request2) print "Sent to Postman" except Exception as ex: logging.exception("Something awful happened!") From 808e4c8bf5a71439dae29e88c8ca02d0fc827897 Mon Sep 17 00:00:00 2001 From: Kayvan Date: Thu, 2 Jul 2015 15:10:35 -0700 Subject: [PATCH 4/4] Rename Collection.py to collection.py --- postmanproxy/postman/{Collection.py => collection.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename postmanproxy/postman/{Collection.py => collection.py} (97%) diff --git a/postmanproxy/postman/Collection.py b/postmanproxy/postman/collection.py similarity index 97% rename from postmanproxy/postman/Collection.py rename to postmanproxy/postman/collection.py index d396922..cf0b984 100644 --- a/postmanproxy/postman/Collection.py +++ b/postmanproxy/postman/collection.py @@ -59,4 +59,4 @@ def save(self): data = self.get_json() with open(target, 'w') as outfile: - json.dump(data, outfile) \ No newline at end of file + json.dump(data, outfile)