From 38011743bbc514962977be1cd8b539ab9ea25adb Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 4 Feb 2015 15:01:03 +0100 Subject: [PATCH] Patch for an Issue #1157 --- lib/request/connect.py | 2 +- lib/request/redirecthandler.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/request/connect.py b/lib/request/connect.py index 2cf6ea99e..ef7cd40fe 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -166,7 +166,7 @@ class Connect(object): if not kb.dnsMode and conn: headers = conn.info() - if headers and (headers.getheader(HTTP_HEADER.CONTENT_ENCODING, "").lower() in ("gzip", "deflate")\ + if headers and hasattr(headers, "getheader") and (headers.getheader(HTTP_HEADER.CONTENT_ENCODING, "").lower() in ("gzip", "deflate")\ or "text" not in headers.getheader(HTTP_HEADER.CONTENT_TYPE, "").lower()): retVal = conn.read(MAX_CONNECTION_TOTAL_SIZE) if len(retVal) == MAX_CONNECTION_TOTAL_SIZE: diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index fca69c8dc..23b5a5774 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -5,6 +5,7 @@ Copyright (c) 2006-2015 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ +import types import urllib2 import urlparse @@ -124,6 +125,25 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) except urllib2.HTTPError, e: result = e + + # Dirty hack for http://bugs.python.org/issue15701 + try: + result.info() + except AttributeError: + def _(self): + return getattr(self, "hdrs") or {} + result.info = types.MethodType(_, result) + + if not hasattr(result, "read"): + def _(self, length=None): + return e.msg + result.read = types.MethodType(_, result) + + if not getattr(result, "url", None): + result.url = redurl + + if not getattr(result, "code", None): + result.code = 999 except: redurl = None result = fp