From 907f63d063b0abf866f19d1cf67b9b420a90a489 Mon Sep 17 00:00:00 2001 From: javi Date: Sat, 26 May 2018 23:04:19 +0200 Subject: [PATCH] deflate encoding --- src/wfuzz/externals/reqresp/Response.py | 16 ++++++++++++++++ tests/test_acceptance.py | 1 + 2 files changed, 17 insertions(+) diff --git a/src/wfuzz/externals/reqresp/Response.py b/src/wfuzz/externals/reqresp/Response.py index 8b12f16c..101fbc3a 100644 --- a/src/wfuzz/externals/reqresp/Response.py +++ b/src/wfuzz/externals/reqresp/Response.py @@ -1,6 +1,7 @@ import string from io import BytesIO import gzip +import zlib from .TextParser import TextParser @@ -152,5 +153,20 @@ def parseResponse(self, rawheader, rawbody=None, type="curl"): gzipper = gzip.GzipFile(fileobj=compressedstream) rawbody = gzipper.read() self.delHeader("Content-Encoding") + elif self.header_equal("Content-Encoding", "deflate"): + deflated_data = None + try: + deflater = zlib.decompressobj() + deflated_data = deflater.decompress(rawbody) + deflated_data += deflater.flush() + except zlib.error: + try: + deflater = zlib.decompressobj(-zlib.MAX_WBITS) + deflated_data = deflater.decompress(rawbody) + deflated_data += deflater.flush() + except zlib.error: + deflated_data = '' + rawbody = deflated_data + self.delHeader("Content-Encoding") self.__content = rawbody.decode('utf-8', errors='replace') diff --git a/tests/test_acceptance.py b/tests/test_acceptance.py index 7d0cef4b..c353e321 100644 --- a/tests/test_acceptance.py +++ b/tests/test_acceptance.py @@ -43,6 +43,7 @@ ("test_gzip", "%s/FUZZ" % HTTPBIN_URL, [["gzip"]], dict(filter="content~'\"gzipped\":true'"), [(200, '/gzip')], None), ("test_response_utf8", "%s/encoding/FUZZ" % HTTPBIN_URL, [["utf8"]], dict(), [(200, '/encoding/utf8')], None), ("test_image", "%s/image/FUZZ" % HTTPBIN_URL, [["jpeg"]], dict(filter="content~'JFIF'"), [(200, '/image/jpeg')], None), + ("test_deflate", "%s/FUZZ" % HTTPBIN_URL, [["deflate"]], dict(filter="content~'\"deflated\":true'"), [(200, '/deflate')], None), ("test_robots_disallow", "%s/FUZZ" % HTTPBIN_URL, [["robots.txt"]], dict(script="robots"), [(200, '/deny'), (200, '/robots.txt')], None), ("test_response_base64", "%s/base64/FUZZ" % HTTPBIN_URL, None, dict(filter="content~'HTTPBIN is awesome'", payloads=[("list", dict(values="HTTPBIN is awesome", encoder=["base64"]))]), [(200, '/base64/SFRUUEJJTiBpcyBhd2Vzb21l')], None),