From ef571aa9e7de38516f5eafb7387f23692b4cbb1f Mon Sep 17 00:00:00 2001 From: yogevc Date: Sun, 1 Nov 2015 14:41:33 +0200 Subject: [PATCH 1/5] Changed http.py to be compatible with python 3.4 --- scapy_http/http.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scapy_http/http.py b/scapy_http/http.py index 781ed46..98ae11c 100644 --- a/scapy_http/http.py +++ b/scapy_http/http.py @@ -21,7 +21,10 @@ def _parse_headers(s): - the headers in a dictionary - the body ''' try: - headers, body = s.split("\r\n\r\n", 1) + crlfcrlf = b"\x0d\x0a\x0d\x0a" + crlfcrlfIndex = s.find(crlfcrlf) + headers = s[:crlfcrlfIndex + len(crlfcrlf)].decode("utf-8") + body = s[crlfcrlfIndex + len(crlfcrlf):] except: headers = s body = '' @@ -206,7 +209,8 @@ def guess_payload_class(self, payload): r"(?:.+?) " r"HTTP/\d\.\d$" ) - req = payload[:payload.index("\r\n")] + crlfIndex = payload.index("\r\n".encode()) + req = payload[:crlfIndex].decode("utf-8") result = prog.match(req) if result: return HTTPRequest From 552adea3b244b1b2e12e9d4d5f016f4f5e5299bb Mon Sep 17 00:00:00 2001 From: Luca Invernizzi Date: Sun, 1 Nov 2015 20:52:37 -0800 Subject: [PATCH 2/5] Support Python 3 --- example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.py b/example.py index 72ce396..9692a81 100644 --- a/example.py +++ b/example.py @@ -14,5 +14,5 @@ packets = scapy.rdpcap('example_network_traffic.pcap') for p in packets: - print '=' * 78 + print('=' * 78) p.show() From eff348c2d4f8259f477bc02a768ddd481d51f6c5 Mon Sep 17 00:00:00 2001 From: yogevc Date: Mon, 9 Nov 2015 15:15:58 +0200 Subject: [PATCH 3/5] More 3.4 fixes --- scapy_http/http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scapy_http/http.py b/scapy_http/http.py index 98ae11c..67f3d3d 100644 --- a/scapy_http/http.py +++ b/scapy_http/http.py @@ -67,12 +67,12 @@ def _self_build(obj, field_pos_list=None): ''' Takse an HTTPRequest or HTTPResponse object, and creates its internal scapy representation as a string. That is, generates the HTTP packet as a string ''' - p = "" + p = b"" for f in obj.fields_desc: val = obj.getfieldval(f.name) if not val: continue - val += '\r\n' + val += b"\x0d\x0a\x0d\x0a" # '\r\n' if f.name in ['Method', 'Headers', 'Additional-Headers', 'Status-Line']: p = f.addfield(obj, p, val) else: From 0009f28b161e258d9b0f24d3528cf7e5e0ff1478 Mon Sep 17 00:00:00 2001 From: yogevc Date: Mon, 9 Nov 2015 15:15:58 +0200 Subject: [PATCH 4/5] More 3.4 fixes --- scapy_http/http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scapy_http/http.py b/scapy_http/http.py index 98ae11c..ca2ebb0 100644 --- a/scapy_http/http.py +++ b/scapy_http/http.py @@ -67,12 +67,12 @@ def _self_build(obj, field_pos_list=None): ''' Takse an HTTPRequest or HTTPResponse object, and creates its internal scapy representation as a string. That is, generates the HTTP packet as a string ''' - p = "" + p = b"" for f in obj.fields_desc: val = obj.getfieldval(f.name) if not val: continue - val += '\r\n' + val += b"\x0d\x0a" # '\r\n' if f.name in ['Method', 'Headers', 'Additional-Headers', 'Status-Line']: p = f.addfield(obj, p, val) else: From 01df483ff89802d4feb3a98fa85edd96ae1ea377 Mon Sep 17 00:00:00 2001 From: Luca Invernizzi Date: Sat, 19 Dec 2015 21:17:36 -0800 Subject: [PATCH 5/5] Mention Scapy3k compat in README (fixes #17) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bad2a5f..f5300fe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Scapy-http ========== -Support for parsing HTTP in Scapy (http://www.secdev.org/projects/scapy/). +Support for parsing HTTP in [Scapy](http://www.secdev.org/projects/scapy/). Compatible with [Scapy3k](https://github.com/phaethon/scapy). Installation